@@ -726,9 +726,14 @@ static inline bool check_av_opt_set(void *priv_data, const char *key, T val, con
726726 if constexpr (std::is_same_v<T, int >) {
727727 ret = av_opt_set_int (priv_data, key, val, 0 );
728728 val_str = to_string (val);
729+ } else if constexpr (std::is_same_v<T, double >) {
730+ ret = av_opt_set_double (priv_data, key, val, 0 );
731+ val_str = to_string (val);
729732 } else if constexpr (std::is_same_v<T, const char *>) {
730733 ret = av_opt_set (priv_data, key, val, 0 );
731734 val_str = val;
735+ } else {
736+ static_assert (!std::is_same_v<T, T>, " unsupported type" );
732737 }
733738 if (ret != 0 ) {
734739 string err = string (MOD_NAME) + " Unable to set " + (desc ? desc : key) + " to " + val_str;
@@ -756,16 +761,12 @@ bool set_codec_ctx_params(struct state_video_compress_libav *s, AVPixelFormat pi
756761 // set quality
757762 if (s->requested_cqp >= 0 || (is_vaapi && s->requested_crf == -1.0 && s->requested_bitrate == 0 && s->requested_bpp == 0.0 )) {
758763 int cqp = s->requested_cqp >= 0 ? s->requested_cqp : DEFAULT_CQP;
759- if (int rc = av_opt_set_int (s->codec_ctx ->priv_data , " qp" , cqp, 0 )) {
760- print_libav_error (LOG_LEVEL_WARNING, MOD_NAME " Warning: Unable to set CQP" , rc);
761- } else {
764+ if (check_av_opt_set<int >(s->codec_ctx ->priv_data , " qp" , cqp, " CQP" )) {
762765 LOG (LOG_LEVEL_INFO) << MOD_NAME " Setting CQP to " << cqp << " \n " ;
763766 }
764767 } else if (s->requested_crf >= 0.0 || (is_x264_x265 && s->requested_bitrate == 0 && s->requested_bpp == 0.0 )) {
765768 double crf = s->requested_crf >= 0.0 ? s->requested_crf : DEFAULT_X264_X265_CRF;
766- if (int rc = av_opt_set_double (s->codec_ctx ->priv_data , " crf" , crf, 0 )) {
767- print_libav_error (LOG_LEVEL_WARNING, MOD_NAME " Warning: Unable to set CRF" , rc);
768- } else {
769+ if (check_av_opt_set<double >(s->codec_ctx ->priv_data , " crf" , crf)) {
769770 log_msg (LOG_LEVEL_INFO, " [lavc] Setting CRF to %.2f.\n " , crf);
770771 }
771772 } else {
@@ -801,9 +802,7 @@ bool set_codec_ctx_params(struct state_video_compress_libav *s, AVPixelFormat pi
801802 }
802803
803804 if (!preset.empty () && preset != DONT_SET_PRESET) {
804- if (av_opt_set (s->codec_ctx ->priv_data , " preset" , preset.c_str (), 0 ) != 0 ) {
805- LOG (LOG_LEVEL_WARNING) << " [lavc] Warning: Unable to set preset.\n " ;
806- } else {
805+ if (check_av_opt_set<const char *>(s->codec_ctx ->priv_data , " preset" , preset.c_str ())) {
807806 LOG (LOG_LEVEL_INFO) << " [lavc] Setting preset to " << preset << " .\n " ;
808807 }
809808 }
@@ -1751,15 +1750,11 @@ static void setparam_default(AVCodecContext *codec_ctx, struct setparam_param *
17511750
17521751static void setparam_jpeg (AVCodecContext *codec_ctx, struct setparam_param * /* param */ )
17531752{
1754- if (av_opt_set (codec_ctx->priv_data , " huffman" , " default" , 0 ) != 0 ) {
1755- log_msg (LOG_LEVEL_WARNING, " [lavc] Warning: Cannot set default Huffman tables.\n " );
1756- }
1753+ check_av_opt_set<const char *>(codec_ctx->priv_data , " huffman" , " default" , " Huffman tables" );
17571754}
17581755
17591756static void configure_amf ([[maybe_unused]] AVCodecContext *codec_ctx, [[maybe_unused]] struct setparam_param *param) {
1760- if (int ret = av_opt_set (codec_ctx->priv_data , " header_insertion_mode" , " gop" , 0 )) {
1761- print_libav_error (LOG_LEVEL_WARNING, MOD_NAME " Unable to header_insertion_mode for AMF" , ret);
1762- }
1757+ check_av_opt_set<const char *>(codec_ctx->priv_data , " header_insertion_mode" , " gop" , " header_insertion_mode for AMF" );
17631758}
17641759
17651760ADD_TO_PARAM (" lavc-h264-interlaced-dct" , " * lavc-h264-interlaced-dct\n "
0 commit comments