简体   繁体   English

x264:使用NAL大小限制会破坏流

[英]x264: Using NAL size limitation ruins the stream

I'm using x264 to compress a video stream from a webcam with this settings: 我正在使用x264通过以下设置压缩来自网络摄像头的视频流:

x264_param_default_preset(&param, "veryfast", "zerolatency");

param.i_threads = 1;
param.i_fps_den = 1;
param.b_annexb = 1;

param.i_keyint_max = 30;
param.rc.i_rc_method = X264_RC_CRF;
param.rc.f_rf_constant = 25;
param.rc.f_rf_constant_max = 35;

param.b_repeat_headers = 1;
x264_param_apply_profile(&param, "baseline");

param.i_slice_max_size = X264_NAL_MAX_SIZE;

I would like to fit NAL into MTU size, but if I set a small max size, the stream is ruined - it blinks randomly between black and white, with some clues of original image in background. 我想将NAL设置为MTU大小,但是如果我设置了一个小的最大尺寸,则流被破坏 - 它在黑白之间随机闪烁,背景中有一些原始图像的线索。 The bigger is the max_size, less probable is for the stream to be ruined. max_size越大,流被破坏的可能性越小。 So my question is - can we have small NALUs and a correct video stream? 所以我的问题是 - 我们可以拥有小型NALU和正确的视频流吗?

UPD: I use FFmpeg as a decoder. UPD:我使用FFmpeg作为解码器。

The problem actually was not with x264. 实际上问题不在于x264。 I assumed x264 is fine and checked every other single piece of pipeline. 我假设x264很好并且检查了其他每一条管道。 The problem was - I used to send NAL singly over the network to avcodec decoder - which is exactly the thing the decoder can't handle ( explanation ). 问题是 - 我曾经通过网络单独发送NAL到avcodec解码器 - 这正是解码器无法处理的事情( 解释 )。 Took me a while to figure it out. 我花了一段时间来搞清楚。

Once I have recomposed NAL units into original groups, deriving from same frames, the problem disappeared. 一旦我将NAL单元重新组合成原始组,从相同的帧导出,问题就消失了。 This also explains why the problem was more easily reproduced with a combination of small NALs and a lot of movement - it produced a lot of single NALs, which avcodec was unable to decode properly. 这也解释了为什么问题更容易通过小NAL和大量移动的组合再现 - 它产生了很多单个NAL,avcodec无法正确解码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM