Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you enable "veryfast" libx264 preset from code using libavcodec?

Tags:

ffmpeg

x264

I'm using libx264 via ffmpeg (in a C++ program), and I need to know how to activate the "veryfast" preset. A grep in the x264 source tree yields:

include/x264.h:static const char * const x264_preset_names[] = { "ultrafast", "superfast", "veryfast", "faster", "fast", "medium", "slow", "slower", "veryslow", "placebo", 0 };

Which inclines me to believe that x264 itself supports this preset as opposed to just being implemented in ffmpeg as a collection of other settings. So, the question is: How do I get ffmpeg to activate the x264 "veryfast" preset?

like image 215
dicroce Avatar asked Oct 02 '13 20:10

dicroce


2 Answers

You gotta create a dictionary and then use this dictionary with all the parameters you need when opening the codec!

AVDictionary * codec_options( 0 );
av_dict_set( &codec_options, "preset", "veryfast", 0 );
// av_dict_set( &codec_options, "AnyCodecParameter", "Value", 0 );
avcodec_open2( codecContext, videoCodec, &codec_options );
like image 147
Wagner Patriota Avatar answered Jan 04 '23 04:01

Wagner Patriota


libavutil defines av_opt_set().... All you have to do is include "libavutil/opt.h" and then:

av_opt_set(codecContext->priv_data, "preset", "veryfast", 0);
like image 33
dicroce Avatar answered Jan 04 '23 05:01

dicroce