Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check if stream audio/video in FFmpeg_Transcoder::can_copy_stream #152

Merged
merged 2 commits into from
Dec 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions src/ffmpeg_transcoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,29 @@ bool FFmpeg_Transcoder::can_copy_stream(const AVStream *stream) const
return false;
}

AVMediaType codec_type = stream->codecpar->codec_type;
AVCodecID codec_in = stream->codecpar->codec_id;
std::string codec_type_str;
AVCodecID codec_out;
int64_t bitrate_out;
if (codec_type == AVMEDIA_TYPE_VIDEO)
{
codec_type_str = "video";
codec_out = m_current_format->video_codec();
bitrate_out = params.m_videobitrate;
}
else if (codec_type == AVMEDIA_TYPE_AUDIO)
{
codec_type_str = "audio";
codec_out = m_current_format->audio_codec();
bitrate_out = params.m_audiobitrate;
}
else
{
// Codec is not video or audio
return false;
}

if ((params.m_autocopy == AUTOCOPY_MATCH || params.m_autocopy == AUTOCOPY_MATCHLIMIT))
{
// Any codec supported by output format OK
Expand All @@ -810,7 +833,8 @@ bool FFmpeg_Transcoder::can_copy_stream(const AVStream *stream) const
else if ((params.m_autocopy == AUTOCOPY_STRICT || params.m_autocopy == AUTOCOPY_STRICTLIMIT))
{
// Output codec must strictly match
if (stream->codecpar->codec_id != m_current_format->audio_codec())
Logging::debug(virtname(), "Check autocopy strict: %1: %2 -> %3", codec_type_str.c_str(), avcodec_get_name(codec_in), avcodec_get_name(codec_out));
if (codec_in != codec_out)
{
// Different codecs - no auto copy
return false;
Expand All @@ -820,7 +844,7 @@ bool FFmpeg_Transcoder::can_copy_stream(const AVStream *stream) const
if (params.m_autocopy == AUTOCOPY_MATCHLIMIT || params.m_autocopy == AUTOCOPY_STRICTLIMIT)
{
BITRATE orig_bit_rate = (stream->codecpar->bit_rate != 0) ? stream->codecpar->bit_rate : m_in.m_format_ctx->bit_rate;
if (get_output_bit_rate(orig_bit_rate, params.m_audiobitrate))
if (get_output_bit_rate(orig_bit_rate, bitrate_out))
{
// Bit rate changed, no auto copy
Logging::info(virtname(), "Because the bit rate has changed, no auto copy is possible.");
Expand Down
Loading