summaryrefslogtreecommitdiffstats
path: root/libhb/decavcodec.c
diff options
context:
space:
mode:
authorJohn Stebbins <[email protected]>2018-06-04 11:04:11 -0700
committerJohn Stebbins <[email protected]>2018-06-04 11:04:11 -0700
commit7f882a03af4e9680eafe34a6c36bbec9baef4dca (patch)
treec0c3be9d8caa50e0521a1718cf6c1a83857e939e /libhb/decavcodec.c
parent4822cd72fbeebb0996770ec890e42bb09d9b297f (diff)
decavcodec: fix issues with audio that has no explicit channel_layout
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 https://github.com/HandBrake/HandBrake/issues/1387
Diffstat (limited to 'libhb/decavcodec.c')
-rw-r--r--libhb/decavcodec.c41
1 files changed, 32 insertions, 9 deletions
diff --git a/libhb/decavcodec.c b/libhb/decavcodec.c
index dd044f3a8..db677db1c 100644
--- a/libhb/decavcodec.c
+++ b/libhb/decavcodec.c
@@ -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)
@@ -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)
{
@@ -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)
@@ -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))