Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
nschlia committed Jan 21, 2024
1 parent 200a3fa commit 9c2ad45
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
6 changes: 3 additions & 3 deletions src/ffmpeg_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand All @@ -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(),
Expand All @@ -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
{
Expand Down
32 changes: 16 additions & 16 deletions src/ffmpeg_transcoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
//}

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}

Expand All @@ -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;
Expand Down Expand Up @@ -2213,15 +2213,15 @@ 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());
}

// Open the encoder for the stream to use it later.
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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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());
}
}

Expand All @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion src/ffmpeg_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/transcode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down

0 comments on commit 9c2ad45

Please sign in to comment.