From 9c2ad450c325cb0d18e442e47655e75727f9b93e Mon Sep 17 00:00:00 2001 From: Norbert Schlia Date: Sun, 21 Jan 2024 23:12:47 +0100 Subject: [PATCH] Refactoring --- src/ffmpeg_base.cc | 6 +++--- src/ffmpeg_transcoder.cc | 32 ++++++++++++++++---------------- src/ffmpeg_utils.h | 2 +- src/transcode.cc | 4 ++-- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/ffmpeg_base.cc b/src/ffmpeg_base.cc index 0f58fa30..9f1d3a03 100644 --- a/src/ffmpeg_base.cc +++ b/src/ffmpeg_base.cc @@ -229,7 +229,7 @@ void FFmpeg_Base::video_info(bool out_file, const AVFormatContext *format_ctx, c Logging::debug(out_file ? virtname() : filename(), "Video %1 #%2: %3@%4 [%5]", out_file ? "out" : "in", stream->index, - get_codec_name(stream->codecpar->codec_id, false), + get_codec_name(stream->codecpar->codec_id), format_bitrate((stream->codecpar->bit_rate != 0) ? stream->codecpar->bit_rate : format_ctx->bit_rate).c_str(), format_duration(duration).c_str()); } @@ -254,7 +254,7 @@ void FFmpeg_Base::audio_info(bool out_file, const AVFormatContext *format_ctx, c Logging::debug(out_file ? virtname() : filename(), "Audio %1 #2: %3@%4 %5 Channels %6 [%7]", out_file ? "out" : "in", stream->index, - get_codec_name(stream->codecpar->codec_id, false), + get_codec_name(stream->codecpar->codec_id), format_bitrate((stream->codecpar->bit_rate != 0) ? stream->codecpar->bit_rate : format_ctx->bit_rate).c_str(), get_channels(stream->codecpar), format_samplerate(stream->codecpar->sample_rate).c_str(), @@ -274,7 +274,7 @@ void FFmpeg_Base::subtitle_info(bool out_file, const AVFormatContext * /*format_ Logging::debug(out_file ? virtname() : filename(), "Subtitle %1 #%2: %3", out_file ? "out" : "in", stream->index, - get_codec_name(stream->codecpar->codec_id, false)); + get_codec_name(stream->codecpar->codec_id)); } else { diff --git a/src/ffmpeg_transcoder.cc b/src/ffmpeg_transcoder.cc index 79490496..67f7ace6 100644 --- a/src/ffmpeg_transcoder.cc +++ b/src/ffmpeg_transcoder.cc @@ -991,7 +991,7 @@ int FFmpeg_Transcoder::open_decoder(AVFormatContext *format_ctx, AVCodecContext if (check_hwaccel_dec_blocked(input_stream->codecpar->codec_id, input_stream->codecpar->profile)) { const char *profile = ::avcodec_profile_name(codec_id, input_stream->codecpar->profile); - Logging::info(filename(), "Codec '%1' profile '%2' is blocked from hardware decoding. Reverting to software decoder.", ::get_codec_name(codec_id, false), profile != nullptr ? profile : "unknown"); + Logging::info(filename(), "Codec '%1' profile '%2' is blocked from hardware decoding. Reverting to software decoder.", ::get_codec_name(codec_id), profile != nullptr ? profile : "unknown"); m_hwaccel_dec_mode = HWACCELMODE_FALLBACK; } } @@ -1959,7 +1959,7 @@ int FFmpeg_Transcoder::add_stream(AVCodecID codec_id) ret = prepare_codec(output_codec_ctx->priv_data, m_out.m_filetype); if (ret < 0) { - Logging::error(virtname(), "Could not set profile for %1 output codec %2 (error '%3').", get_media_type_string(output_codec->type), get_codec_name(codec_id, false), ffmpeg_geterror(ret).c_str()); + Logging::error(virtname(), "Could not set profile for %1 output codec %2 (error '%3').", get_media_type_string(output_codec->type), get_codec_name(codec_id), ffmpeg_geterror(ret).c_str()); return ret; } @@ -1968,7 +1968,7 @@ int FFmpeg_Transcoder::add_stream(AVCodecID codec_id) //ret = av_opt_set(output_codec_ctx->priv_data, "crf", "36", AV_OPT_SEARCH_CHILDREN); //if (ret < 0) //{ - // Logging::error(virtname(), "Could not set 'crf' for %1 output codec %2 (error '%3').", get_media_type_string(output_codec->type), get_codec_name(codec_id, false), ffmpeg_geterror(ret).c_str()); + // Logging::error(virtname(), "Could not set 'crf' for %1 output codec %2 (error '%3').", get_media_type_string(output_codec->type), get_codec_name(codec_id), ffmpeg_geterror(ret).c_str()); // return ret; //} @@ -1991,13 +1991,13 @@ int FFmpeg_Transcoder::add_stream(AVCodecID codec_id) //ret = av_opt_set(output_codec_ctx->priv_data, "rc_mode", "CQP", AV_OPT_SEARCH_CHILDREN); //if (ret < 0) //{ - // Logging::error(virtname(), "Could not set 'rc_mode=CQP' for %1 output codec %2 (error '%3').", get_media_type_string(output_codec->type), get_codec_name(codec_id, false), ffmpeg_geterror(ret).c_str()); + // Logging::error(virtname(), "Could not set 'rc_mode=CQP' for %1 output codec %2 (error '%3').", get_media_type_string(output_codec->type), get_codec_name(codec_id), ffmpeg_geterror(ret).c_str()); // return ret; //} //ret = av_opt_set(output_codec_ctx->priv_data, "qp", "23", AV_OPT_SEARCH_CHILDREN); //if (ret < 0) //{ - // Logging::error(virtname(), "Could not set 'qp' for %1 output codec %2 (error '%3').", get_media_type_string(output_codec->type), get_codec_name(codec_id, false), ffmpeg_geterror(ret).c_str()); + // Logging::error(virtname(), "Could not set 'qp' for %1 output codec %2 (error '%3').", get_media_type_string(output_codec->type), get_codec_name(codec_id), ffmpeg_geterror(ret).c_str()); // return ret; //} output_codec_ctx->global_quality = 34; @@ -2041,7 +2041,7 @@ int FFmpeg_Transcoder::add_stream(AVCodecID codec_id) ret = av_opt_set(output_codec_ctx->priv_data, "profile", "high422", 0); if (ret < 0) { - Logging::error(virtname(), "Could not set profile=high422 for %1 output codec %2 (error '%3').", get_media_type_string(output_codec->type), get_codec_name(codec_id, false), ffmpeg_geterror(ret).c_str()); + Logging::error(virtname(), "Could not set profile=high422 for %1 output codec %2 (error '%3').", get_media_type_string(output_codec->type), get_codec_name(codec_id), ffmpeg_geterror(ret).c_str()); return ret; } break; @@ -2091,7 +2091,7 @@ int FFmpeg_Transcoder::add_stream(AVCodecID codec_id) ret = av_opt_set(output_codec_ctx->priv_data, "profile", "high444", 0); if (ret < 0) { - Logging::error(virtname(), "Could not set profile=high444 for %1 output codec %2 (error '%3').", get_media_type_string(output_codec->type), get_codec_name(codec_id, false), ffmpeg_geterror(ret).c_str()); + Logging::error(virtname(), "Could not set profile=high444 for %1 output codec %2 (error '%3').", get_media_type_string(output_codec->type), get_codec_name(codec_id), ffmpeg_geterror(ret).c_str()); return ret; } break; @@ -2111,7 +2111,7 @@ int FFmpeg_Transcoder::add_stream(AVCodecID codec_id) ret = prepare_codec(output_codec_ctx->priv_data, FILETYPE_WEBM); if (ret < 0) { - Logging::error(virtname(), "Could not set profile for %1 output codec %2 (error '%3').", get_media_type_string(output_codec->type), get_codec_name(codec_id, false), ffmpeg_geterror(ret).c_str()); + Logging::error(virtname(), "Could not set profile for %1 output codec %2 (error '%3').", get_media_type_string(output_codec->type), get_codec_name(codec_id), ffmpeg_geterror(ret).c_str()); return ret; } break; @@ -2121,7 +2121,7 @@ int FFmpeg_Transcoder::add_stream(AVCodecID codec_id) ret = prepare_codec(output_codec_ctx->priv_data, FILETYPE_PRORES); if (ret < 0) { - Logging::error(virtname(), "Could not set profile for %1 output codec %2 (error '%3').", get_media_type_string(output_codec->type), get_codec_name(codec_id, false), ffmpeg_geterror(ret).c_str()); + Logging::error(virtname(), "Could not set profile for %1 output codec %2 (error '%3').", get_media_type_string(output_codec->type), get_codec_name(codec_id), ffmpeg_geterror(ret).c_str()); return ret; } @@ -2137,7 +2137,7 @@ int FFmpeg_Transcoder::add_stream(AVCodecID codec_id) ret = prepare_codec(output_codec_ctx->priv_data, FILETYPE_ALAC); if (ret < 0) { - Logging::error(virtname(), "Could not set profile for %1 output codec %2 (error '%3').", get_media_type_string(output_codec->type), get_codec_name(codec_id, false), ffmpeg_geterror(ret).c_str()); + Logging::error(virtname(), "Could not set profile for %1 output codec %2 (error '%3').", get_media_type_string(output_codec->type), get_codec_name(codec_id), ffmpeg_geterror(ret).c_str()); return ret; } break; @@ -2213,7 +2213,7 @@ int FFmpeg_Transcoder::add_stream(AVCodecID codec_id) if (!av_dict_get(opt, "threads", nullptr, 0)) { - Logging::trace(virtname(), "Setting threads to auto for codec %1.", get_codec_name(output_codec_ctx->codec_id, false)); + Logging::trace(virtname(), "Setting threads to auto for codec %1.", get_codec_name(output_codec_ctx->codec_id)); dict_set_with_check(&opt, "threads", "auto", 0, virtname()); } @@ -2221,7 +2221,7 @@ int FFmpeg_Transcoder::add_stream(AVCodecID codec_id) ret = avcodec_open2(output_codec_ctx, output_codec, &opt); if (ret < 0) { - Logging::error(virtname(), "Could not open %1 output codec %2 for stream #%3 (error '%4').", get_media_type_string(output_codec->type), get_codec_name(codec_id, false), output_stream->index, ffmpeg_geterror(ret).c_str()); + Logging::error(virtname(), "Could not open %1 output codec %2 for stream #%3 (error '%4').", get_media_type_string(output_codec->type), get_codec_name(codec_id), output_stream->index, ffmpeg_geterror(ret).c_str()); return ret; } @@ -2330,7 +2330,7 @@ int FFmpeg_Transcoder::add_subtitle_stream(AVCodecID codec_id, StreamRef & input ret = avcodec_open2(output_codec_ctx, output_codec, &opt); if (ret < 0) { - Logging::error(virtname(), "Could not open %1 output codec %2 for stream #%3 (error '%4').", get_media_type_string(output_codec->type), get_codec_name(codec_id, false), output_stream->index, ffmpeg_geterror(ret).c_str()); + Logging::error(virtname(), "Could not open %1 output codec %2 for stream #%3 (error '%4').", get_media_type_string(output_codec->type), get_codec_name(codec_id), output_stream->index, ffmpeg_geterror(ret).c_str()); return ret; } @@ -2540,7 +2540,7 @@ int FFmpeg_Transcoder::add_albumart_stream(const AVCodecContext * input_codec_ct ret = avcodec_open2(output_codec_ctx, output_codec, &opt); if (ret < 0) { - Logging::error(virtname(), "Could not open %1 output codec %2 for stream #%3 (error '%4').", get_media_type_string(output_codec->type), get_codec_name(input_codec->id, false), output_stream->index, ffmpeg_geterror(ret).c_str()); + Logging::error(virtname(), "Could not open %1 output codec %2 for stream #%3 (error '%4').", get_media_type_string(output_codec->type), get_codec_name(input_codec->id), output_stream->index, ffmpeg_geterror(ret).c_str()); return ret; } @@ -6113,7 +6113,7 @@ size_t FFmpeg_Transcoder::calculate_predicted_filesize() const if (!audio_size(&filesize, m_current_format->audio_codec(), input_audio_bit_rate, file_duration, channels, input_sample_rate, m_cur_sample_fmt)) { - Logging::warning(filename(), "Unsupported audio codec '%1' for format %2.", get_codec_name(m_current_format->audio_codec(), false), m_current_format->desttype().c_str()); + Logging::warning(filename(), "Unsupported audio codec '%1' for format %2.", get_codec_name(m_current_format->audio_codec()), m_current_format->desttype().c_str()); } } @@ -6128,7 +6128,7 @@ size_t FFmpeg_Transcoder::calculate_predicted_filesize() const if (!video_size(&filesize, m_current_format->video_codec(), input_video_bit_rate, file_duration, width, height, interleaved, framerate)) { - Logging::warning(filename(), "Unsupported video codec '%1' for format %2.", get_codec_name(m_current_format->video_codec(), false), m_current_format->desttype().c_str()); + Logging::warning(filename(), "Unsupported video codec '%1' for format %2.", get_codec_name(m_current_format->video_codec()), m_current_format->desttype().c_str()); } } // else /** @todo Feature #2260: Add picture size */ diff --git a/src/ffmpeg_utils.h b/src/ffmpeg_utils.h index 621204ab..f04bfe8e 100644 --- a/src/ffmpeg_utils.h +++ b/src/ffmpeg_utils.h @@ -768,7 +768,7 @@ int show_caps(int device_only); * @param[in] long_name - If true, gets the long name. * @return Returns the codec name or "unknown" on error. */ -const char * get_codec_name(AVCodecID codec_id, bool long_name); +const char * get_codec_name(AVCodecID codec_id, bool long_name = false); /** * @brief Check if file type supports album arts. * @param[in] filetype - File type: MP3, MP4 etc. diff --git a/src/transcode.cc b/src/transcode.cc index ef0f6655..b0353f5e 100644 --- a/src/transcode.cc +++ b/src/transcode.cc @@ -307,12 +307,12 @@ bool transcoder_set_filesize(LPVIRTUALFILE virtualfile, int64_t duration, BITRAT if (!FFmpeg_Transcoder::audio_size(&filesize, current_format->audio_codec(), audio_bit_rate, duration, channels, sample_rate, sample_format)) { - Logging::warning(cache_entry->virtname(), "Unsupported audio codec '%1' for format %2.", get_codec_name(current_format->audio_codec(), false), current_format->desttype().c_str()); + Logging::warning(cache_entry->virtname(), "Unsupported audio codec '%1' for format %2.", get_codec_name(current_format->audio_codec()), current_format->desttype().c_str()); } if (!FFmpeg_Transcoder::video_size(&filesize, current_format->video_codec(), video_bit_rate, duration, width, height, interleaved, framerate)) { - Logging::warning(cache_entry->virtname(), "Unsupported video codec '%1' for format %2.", get_codec_name(current_format->video_codec(), false), current_format->desttype().c_str()); + Logging::warning(cache_entry->virtname(), "Unsupported video codec '%1' for format %2.", get_codec_name(current_format->video_codec()), current_format->desttype().c_str()); } if (!FFmpeg_Transcoder::total_overhead(&filesize, current_format->filetype()))