@@ -155,16 +155,16 @@ get_default_crf(const char *codec_name)
155155}
156156
157157struct setparam_param {
158- setparam_param (map<string, string> &lo, set<string> &bo) : lavc_opts(lo), blacklist_opts(bo) {}
159158 struct video_desc desc {};
160159 bool have_preset = false ;
161160 int periodic_intra = -1 ; // /< -1 default; 0 disable/not enable; 1 enable
162161 int interlaced_dct = -1 ; // /< -1 default; 0 disable/not enable; 1 enable
163162 int header_inserter_req = -1 ;
164163 string thread_mode;
165164 int slices = -1 ;
166- map<string, string> &lavc_opts; // /< user-supplied options from command-line
167- set<string> &blacklist_opts; // /< options that should be blacklisted
165+ map<string, string>
166+ lavc_opts; // /< set to user-supplied options before the setparam
167+ // /< call which may alter those
168168 long long int requested_bitrate = 0 ;
169169 double requested_bpp = 0 ;
170170 double requested_crf = -1 ;
@@ -281,12 +281,11 @@ struct state_video_compress_libav {
281281
282282 struct video_desc compressed_desc{};
283283
284- struct setparam_param params{lavc_opts, blacklist_opts} ;
284+ struct setparam_param params;
285285 string req_encoder;
286286 int requested_gop = DEFAULT_GOP_SIZE;
287287
288- map<string, string> lavc_opts; // /< user-supplied options from command-line
289- set<string> blacklist_opts; // /< options that has been processed by setparam handlers and should not be passed to codec
288+ map<string, string> req_lavc_opts; // /< user-supplied options from command-line
290289
291290 bool hwenc = false ;
292291 AVFrame *hwframe = nullptr ;
@@ -603,7 +602,7 @@ parse_fmt(struct state_video_compress_libav *s, char *fmt) noexcept(false)
603602 replace_all (c_val_dup, DELDEL, " :" );
604603 string key, val;
605604 key = string (item, strchr (item, ' =' ));
606- s->lavc_opts [key] = c_val_dup;
605+ s->req_lavc_opts [key] = c_val_dup;
607606 free (c_val_dup);
608607 } else {
609608 log_msg (LOG_LEVEL_ERROR, " [lavc] Error: unknown option %s.\n " ,
@@ -885,6 +884,7 @@ bool set_codec_ctx_params(struct state_video_compress_libav *s, AVPixelFormat pi
885884
886885 // make a copy because set_param callbacks may adjust parameters
887886 struct setparam_param params = s->params ;
887+ params.lavc_opts = s->req_lavc_opts ;
888888
889889 // average bit per pixel
890890 const double avg_bpp = params.requested_bpp > 0.0
@@ -942,10 +942,7 @@ bool set_codec_ctx_params(struct state_video_compress_libav *s, AVPixelFormat pi
942942 s->header_inserter = params.header_inserter_req == 1 ;
943943
944944 // set user supplied parameters
945- for (auto const &item : s->lavc_opts ) {
946- if (s->blacklist_opts .count (item.first ) == 1 ) {
947- continue ;
948- }
945+ for (auto const &item : params.lavc_opts ) {
949946 if (!check_av_opt_set<const char *, true >(
950947 s->codec_ctx ->priv_data , item.first .c_str (), item.second .c_str ())) {
951948 return false ;
@@ -1302,16 +1299,16 @@ static void check_duration(struct state_video_compress_libav *s, time_ns_t dur_p
13021299 string hint;
13031300 string quality_hurt = " latency" ;
13041301 if (regex_match (s->codec_ctx ->codec ->name , regex (" .*nvenc.*" ))) {
1305- if (s->lavc_opts .find (" delay" ) == s->lavc_opts .end ()) {
1302+ if (s->req_lavc_opts .find (" delay" ) == s->req_lavc_opts .end ()) {
13061303 hint = " \" delay=<frames>\" option to NVENC compression (2 suggested)" ;
13071304 }
13081305 } else if (strcmp (s->codec_ctx ->codec ->name , " libaom-av1" ) == 0 ) {
1309- if (s->lavc_opts .find (" cpu-used" ) == s->lavc_opts .end ()) {
1306+ if (s->req_lavc_opts .find (" cpu-used" ) == s->req_lavc_opts .end ()) {
13101307 hint = " \" cpu-used=8\" option for quality/speed trade-off to AOM AV1 compression (values 0-8 allowed)" ;
13111308 quality_hurt = " quality" ;
13121309 }
13131310 } else if (strcmp (s->codec_ctx ->codec ->name , " libsvt_hevc" ) == 0 ) {
1314- if (s->lavc_opts .find (" preset" ) == s->lavc_opts .end ()) {
1311+ if (s->req_lavc_opts .find (" preset" ) == s->req_lavc_opts .end ()) {
13151312 hint =
13161313 " \" preset=12\" option for quality/speed trade-off "
13171314 " to libsvt_hevc compression (values 0-12 allowed)" ;
@@ -1859,9 +1856,9 @@ configure_x264_x265(AVCodecContext *codec_ctx, struct setparam_param *param)
18591856 }
18601857
18611858 string x265_params;
1862- if (param->lavc_opts .find (" x265-params" ) != param->lavc_opts .end ()) {
1863- x265_params = param-> lavc_opts . at ( " x265-params " ) ;
1864- param->blacklist_opts . insert ( " x265-params " );
1859+ if (auto it = param->lavc_opts .find (" x265-params" ); it != param->lavc_opts .end ()) {
1860+ x265_params = it-> second ;
1861+ param->lavc_opts . erase (it );
18651862 }
18661863 auto x265_params_append = [&](const string &key, const string &val) {
18671864 if (x265_params.find (key) == string::npos) {
@@ -1908,7 +1905,7 @@ static void configure_qsv_h264_hevc(AVCodecContext *codec_ctx, struct setparam_p
19081905 const char *rc = DEFAULT_QSV_RC;
19091906 if (auto it = param->lavc_opts .find (" rc" ); it != param->lavc_opts .end ()) {
19101907 rc = it->second .c_str ();
1911- param->blacklist_opts . insert ( " rc " );
1908+ param->lavc_opts . erase (it );
19121909 }
19131910 if (strcmp (rc, " help" ) == 0 ) {
19141911 col () << " \n\n "
0 commit comments