3

I'm trying to use ffmpeg/libx264 to encode and transmit a real-time video, when I use av_dict_set(&opts, "tune", "zerolatency", 0); the system works well. As the X264 encode parameters are set by ffmpeg using av_dict_set, for some research purpose I want to change them by myself. But some parameters in x264_param_t can not correspond to those parameters in AVCodecContext, such as vfr_input. So I want to know if there is a directly way to transmit parameters into X264 encoder when using libx264 in ffmpeg.


Can anyone help me? Thanks

songqi
  • 31
  • 1
  • 3

1 Answers1

4

Try calling av_opt_set with the codec context priv_data structure:

AVCodec *codec = avcodec_find_encoder(AV_CODEC_ID_H264);
AVCodecContext *codecContex = avcodec_alloc_context3(codec);
av_opt_set(codecContex->priv_data, "preset", "ultrafast", 0);
av_opt_set(codecContex->priv_data, "tune", "zerolatency", 0);

Error checking omitted for brevity.

kshahar
  • 10,423
  • 9
  • 49
  • 73
  • Using these options, though my decoding lags heavily. Neglecting 150 ms for encoding a frame and 150 ms for decoding,it almost takes 6 to 7 seconds later to see the current frame at decoded output,, where this sync issue may come from?? Also, got_output is set after `12 calls` to `avcodec_encode_video2` Any workaround? – nmxprime Jan 29 '14 at 09:25
  • @nmxprime How did you configure AVCodecContext? Try to use a minimal configuration based on the [encoding_decoding.c](http://ffmpeg.org/doxygen/trunk/decoding__encoding_8c-source.html) example. – kshahar Jan 29 '14 at 15:19
  • Yeah i got it! As those presets are overridden by user setting, i got delay, because of the CBR setting i configured! I want to set `vbv-buffersize`. tried `av_opt_set_int`, but not working, returned -ve value. – nmxprime Jan 30 '14 at 04:04