@@ -255,7 +255,7 @@ void FFmpegWriter::SetVideoOptions(bool has_video, std::string codec, Fraction f
255255 }
256256 if (bit_rate >= 1000 ) // bit_rate is the bitrate in b/s
257257 info.video_bit_rate = bit_rate;
258- if ((bit_rate >= 0 ) && (bit_rate < 64 )) // bit_rate is the bitrate in crf
258+ if ((bit_rate >= 0 ) && (bit_rate < 256 )) // bit_rate is the bitrate in crf
259259 info.video_bit_rate = bit_rate;
260260
261261 info.interlaced_frame = interlaced;
@@ -341,7 +341,7 @@ void FFmpegWriter::SetOption(StreamType stream, std::string name, std::string va
341341 // Was option found?
342342 if (option || (name == " g" || name == " qmin" || name == " qmax" || name == " max_b_frames" || name == " mb_decision" ||
343343 name == " level" || name == " profile" || name == " slices" || name == " rc_min_rate" || name == " rc_max_rate" ||
344- name == " rc_buffer_size" || name == " crf" || name == " cqp" )) {
344+ name == " rc_buffer_size" || name == " crf" || name == " cqp" || name == " qp " )) {
345345 // Check for specific named options
346346 if (name == " g" )
347347 // Set gop_size
@@ -462,6 +462,18 @@ void FFmpegWriter::SetOption(StreamType stream, std::string name, std::string va
462462 case AV_CODEC_ID_AV1 :
463463 c->bit_rate = 0 ;
464464 av_opt_set_int (c->priv_data , " crf" , std::min (std::stoi (value),63 ), 0 );
465+ if (strstr (info.vcodec .c_str (), " svt_av1" ) != NULL ) {
466+ // av_opt_set_int(c->priv_data, "qp", std::min(std::stoi(value),63), 0);
467+ av_opt_set_int (c->priv_data , " preset" , 6 , 0 );
468+ av_opt_set_int (c->priv_data , " forced-idr" ,1 ,0 );
469+ }
470+ if (strstr (info.vcodec .c_str (), " rav1e" ) != NULL ) {
471+ // av_opt_set_int(c->priv_data, "qp", std::min(std::stoi(value),255), 0);
472+ av_opt_set_int (c->priv_data , " speed" , 7 , 0 );
473+ av_opt_set_int (c->priv_data , " tile-rows" , 2 , 0 );
474+ av_opt_set_int (c->priv_data , " tile-columns" , 4 , 0 );
475+ // av_opt_set(c->priv_data, "tile-row", "", 0);
476+ }
465477 break ;
466478#endif
467479 case AV_CODEC_ID_VP8 :
@@ -503,6 +515,36 @@ void FFmpegWriter::SetOption(StreamType stream, std::string name, std::string va
503515 c->bit_rate = (int ) (mbs);
504516 }
505517 }
518+ #endif
519+ } else if (name == " qp" ) {
520+ // encode quality and special settings like lossless
521+ // This might be better in an extra methods as more options
522+ // and way to set quality are possible
523+ #if (LIBAVCODEC_VERSION_MAJOR >= 58)
524+ switch (c->codec_id ) {
525+ case AV_CODEC_ID_AV1 :
526+ c->bit_rate = 0 ;
527+ av_opt_set_int (c->priv_data , " qp" , std::min (std::stoi (value),63 ), 0 );
528+ if (strstr (info.vcodec .c_str (), " svt_av1" ) != NULL ) {
529+ av_opt_set_int (c->priv_data , " qp" , std::min (std::stoi (value),63 ), 0 );
530+ av_opt_set_int (c->priv_data , " preset" , 6 , 0 );
531+ av_opt_set_int (c->priv_data , " forced-idr" ,1 ,0 );
532+ }
533+ if (strstr (info.vcodec .c_str (), " rav1e" ) != NULL ) {
534+ av_opt_set_int (c->priv_data , " qp" , std::min (std::stoi (value),255 ), 0 );
535+ av_opt_set_int (c->priv_data , " speed" , 7 , 0 );
536+ av_opt_set_int (c->priv_data , " tile-rows" , 2 , 0 );
537+ av_opt_set_int (c->priv_data , " tile-columns" , 4 , 0 );
538+ // av_opt_set(c->priv_data, "tile-row", "", 0);
539+ }
540+ if (strstr (info.vcodec .c_str (), " aom" ) != NULL ) {
541+ // Hack to set tiles; libaom doesn have qp only crf
542+ av_opt_set_int (c->priv_data , " crf" , std::min (std::stoi (value),63 ), 0 );
543+ av_opt_set_int (c->priv_data , " tile-rows" , 1 , 0 ); // log2 of number of rows
544+ av_opt_set_int (c->priv_data , " tile-columns" , 2 , 0 ); // log2 of number of columns
545+ }
546+ break ;
547+ }
506548#endif
507549 } else {
508550 // Set AVOption
0 commit comments