4

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.

Dan Tumaykin
  • 1,213
  • 2
  • 17
  • 37
  • 2
    i_slice_max_size should work correctly. if you have problems with it then you need to provide more info about your encode code and code for muxing/writing encoded NALs. Also for starting it would be good if you will provide your encoded stream which you have problems to decode. – nobody555 Mar 22 '14 at 14:17
  • ^ This. The problem is not x264. it is your network or playback code. – szatmary Mar 22 '14 at 21:09
  • @szatmary - you were right, the problem was not with x264, but both with network and playback code. Thank you! – Dan Tumaykin Mar 25 '14 at 20:04

1 Answers1

3

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.

Dan Tumaykin
  • 1,213
  • 2
  • 17
  • 37