Skip to content

Commit

Permalink
decavcodec: fix issues with audio that has no explicit channel_layout
Browse files Browse the repository at this point in the history
ffmpeg doesn't set a default channel layout for audio that has no
explicit layout (e.g. pcm_216le).  So we need to guess it from the
number of channels.

Fixes "no audio" in HandBrake#1387
  • Loading branch information
jstebbins committed Jun 4, 2018
1 parent 4822cd7 commit 7f882a0
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions libhb/decavcodec.c
Original file line number Diff line number Diff line change
Expand Up @@ -738,18 +738,28 @@ static int decavcodecaBSInfo( hb_work_object_t *w, const hb_buffer_t *buf,
info->sample_bit_depth = context->bits_per_raw_sample;

int bps = av_get_bits_per_sample(context->codec_id);
int channels = av_get_channel_layout_nb_channels(frame->channel_layout);
if (bps > 0)
int channels;
if (frame->channel_layout != 0)
{
info->bitrate = bps * channels * info->rate.num;
channels = av_get_channel_layout_nb_channels(
frame->channel_layout);
}
else if (context->bit_rate > 0)
else
{
info->bitrate = context->bit_rate;
channels = frame->channels;
}
else

info->bitrate = bps * channels * info->rate.num;
if (info->bitrate <= 0)
{
info->bitrate = 1;
if (context->bit_rate > 0)
{
info->bitrate = context->bit_rate;
}
else
{
info->bitrate = 1;
}
}

if (truehd_mono)
Expand Down Expand Up @@ -780,6 +790,13 @@ static int decavcodecaBSInfo( hb_work_object_t *w, const hb_buffer_t *buf,
info->channel_layout = frame->channel_layout;
}
}
if (info->channel_layout == 0)
{
// Channel layout was not set. Guess a layout based
// on number of channels.
info->channel_layout = av_get_default_channel_layout(
frame->channels);
}
if (context->codec_id == AV_CODEC_ID_AC3 ||
context->codec_id == AV_CODEC_ID_EAC3)
{
Expand Down Expand Up @@ -2203,6 +2220,7 @@ static void decodeAudio(hb_work_private_t *pv, packet_info_t * packet_info)
else
{
AVFrameSideData *side_data;
uint64_t channel_layout;
if ((side_data =
av_frame_get_side_data(pv->frame,
AV_FRAME_DATA_DOWNMIX_INFO)) != NULL)
Expand All @@ -2227,8 +2245,13 @@ static void decodeAudio(hb_work_private_t *pv, packet_info_t * packet_info)
center_mix_level,
downmix_info->lfe_mix_level);
}
hb_audio_resample_set_channel_layout(pv->resample,
pv->frame->channel_layout);
channel_layout = pv->frame->channel_layout;
if (channel_layout == 0)
{
channel_layout = av_get_default_channel_layout(
pv->frame->channels);
}
hb_audio_resample_set_channel_layout(pv->resample, channel_layout);
hb_audio_resample_set_sample_fmt(pv->resample,
pv->frame->format);
if (hb_audio_resample_update(pv->resample))
Expand Down

0 comments on commit 7f882a0

Please sign in to comment.