Question

I'm using x264 to compress a video stream from a webcam with this settings:

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. The bigger is the max_size, less probable is for the stream to be ruined. So my question is - can we have small NALUs and a correct video stream?

UPD: I use FFmpeg as a decoder.

Was it helpful?

Solution

The problem actually was not with x264. I assumed x264 is fine and checked every other single piece of pipeline. 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). Took me a while to figure it out.

Once I have recomposed NAL units into original groups, deriving from same frames, the problem disappeared. 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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top