Skip to content

Commit

Permalink
libhb: add TrueHD encoding (HandBrake#5464)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nomis101 authored Dec 17, 2023
1 parent 5fb0ba8 commit e74b389
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
1 change: 1 addition & 0 deletions contrib/ffmpeg/module.defs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ FFMPEG.CONFIGURE.extra = \
--enable-libspeex \
--disable-encoder=libspeex \
--enable-decoder=libspeex \
--enable-encoder=truehd \
--enable-libvpx \
--disable-decoder=libvpx_* \
--enable-encoder=libvpx_vp8 \
Expand Down
33 changes: 30 additions & 3 deletions libhb/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ enum
HB_GID_ACODEC_MP2_PASS,
HB_GID_ACODEC_MP3,
HB_GID_ACODEC_MP3_PASS,
HB_GID_ACODEC_TRUEHD,
HB_GID_ACODEC_TRUEHD_PASS,
HB_GID_ACODEC_VORBIS,
HB_GID_ACODEC_OPUS,
Expand Down Expand Up @@ -159,6 +160,10 @@ hb_rate_internal_t hb_audio_rates[] =
{ { "32", 32000, }, NULL, 1, },
{ { "44.1", 44100, }, NULL, 1, },
{ { "48", 48000, }, NULL, 1, },
{ { "88.2", 88200, }, NULL, 1, },
{ { "96", 96000, }, NULL, 1, },
{ { "176.4", 176400, },NULL, 1, },
{ { "192", 192000, },NULL, 1, },
};
int hb_audio_rates_count = sizeof(hb_audio_rates) / sizeof(hb_audio_rates[0]);

Expand Down Expand Up @@ -424,19 +429,20 @@ hb_encoder_internal_t hb_audio_encoders[] =
{ { "AC3 Passthru", "copy:ac3", "AC3 Passthru", HB_ACODEC_AC3_PASS, HB_MUX_MASK_MP4|HB_MUX_MASK_MKV, }, NULL, 0, 1, HB_GID_ACODEC_AC3_PASS, },
{ { "E-AC3", "eac3", "E-AC3 (libavcodec)", HB_ACODEC_FFEAC3, HB_MUX_MASK_MP4|HB_MUX_AV_MKV, }, NULL, 0, 1, HB_GID_ACODEC_EAC3, },
{ { "E-AC3 Passthru", "copy:eac3", "E-AC3 Passthru", HB_ACODEC_EAC3_PASS, HB_MUX_MASK_MP4|HB_MUX_AV_MKV, }, NULL, 0, 1, HB_GID_ACODEC_EAC3_PASS, },
{ { "TrueHD", "truehd", "TrueHD", HB_ACODEC_FFTRUEHD, HB_MUX_MASK_MP4|HB_MUX_AV_MKV, }, NULL, 0, 1, HB_GID_ACODEC_TRUEHD, },
{ { "TrueHD Passthru", "copy:truehd","TrueHD Passthru", HB_ACODEC_TRUEHD_PASS, HB_MUX_MASK_MP4|HB_MUX_AV_MKV, }, NULL, 0, 1, HB_GID_ACODEC_TRUEHD_PASS,},
{ { "DTS Passthru", "copy:dts", "DTS Passthru", HB_ACODEC_DCA_PASS, HB_MUX_MASK_MP4|HB_MUX_MASK_MKV, }, NULL, 0, 1, HB_GID_ACODEC_DTS_PASS, },
{ { "DTS-HD Passthru", "copy:dtshd", "DTS-HD Passthru", HB_ACODEC_DCA_HD_PASS, HB_MUX_MASK_MP4|HB_MUX_MASK_MKV, }, NULL, 0, 1, HB_GID_ACODEC_DTSHD_PASS, },
{ { "MP2 Passthru", "copy:mp2", "MP2 Passthru", HB_ACODEC_MP2_PASS, HB_MUX_MASK_MKV, }, NULL, 0, 1, HB_GID_ACODEC_MP2_PASS, },
{ { "MP3", "mp3", "MP3 (libmp3lame)", HB_ACODEC_LAME, HB_MUX_MASK_MP4|HB_MUX_MASK_MKV, }, NULL, 0, 1, HB_GID_ACODEC_MP3, },
{ { "MP3 Passthru", "copy:mp3", "MP3 Passthru", HB_ACODEC_MP3_PASS, HB_MUX_MASK_MP4|HB_MUX_MASK_MKV, }, NULL, 0, 1, HB_GID_ACODEC_MP3_PASS, },
{ { "Vorbis", "vorbis", "Vorbis (libvorbis)", HB_ACODEC_VORBIS, HB_MUX_MASK_WEBM|HB_MUX_MASK_MKV, }, NULL, 0, 1, HB_GID_ACODEC_VORBIS, },
{ { "Vorbis", "vorbis", "Vorbis (libvorbis)", HB_ACODEC_VORBIS, HB_MUX_MASK_WEBM|HB_MUX_MASK_MKV, }, NULL, 0, 1, HB_GID_ACODEC_VORBIS, },
{ { "FLAC 16-bit", "flac16", "FLAC 16-bit (libavcodec)", HB_ACODEC_FFFLAC, HB_MUX_MASK_MKV, }, NULL, 0, 1, HB_GID_ACODEC_FLAC, },
{ { "FLAC 24-bit", "flac24", "FLAC 24-bit (libavcodec)", HB_ACODEC_FFFLAC24, HB_MUX_MASK_MKV, }, NULL, 0, 1, HB_GID_ACODEC_FLAC, },
{ { "FLAC Passthru", "copy:flac", "FLAC Passthru", HB_ACODEC_FLAC_PASS, HB_MUX_MASK_MKV, }, NULL, 0, 1, HB_GID_ACODEC_FLAC_PASS, },
{ { "Opus", "opus", "Opus (libopus)", HB_ACODEC_OPUS, HB_MUX_MASK_MP4|HB_MUX_MASK_WEBM|HB_MUX_MASK_MKV, }, NULL, 0, 1, HB_GID_ACODEC_OPUS, },
{ { "Opus Passthru", "copy:opus", "Opus Passthru", HB_ACODEC_OPUS_PASS, HB_MUX_MASK_MP4|HB_MUX_MASK_WEBM|HB_MUX_MASK_MKV, }, NULL, 0, 1, HB_GID_ACODEC_OPUS_PASS, },
{ { "Auto Passthru", "copy", "Auto Passthru", HB_ACODEC_AUTO_PASS, HB_MUX_MASK_MP4|HB_MUX_MASK_MKV, }, NULL, 0, 1, HB_GID_ACODEC_AUTO_PASS, },
{ { "Auto Passthru", "copy", "Auto Passthru", HB_ACODEC_AUTO_PASS, HB_MUX_MASK_MP4|HB_MUX_MASK_MKV, }, NULL, 0, 1, HB_GID_ACODEC_AUTO_PASS, },
};
int hb_audio_encoders_count = sizeof(hb_audio_encoders) / sizeof(hb_audio_encoders[0]);
static int hb_audio_encoder_is_enabled(int encoder)
Expand Down Expand Up @@ -476,6 +482,9 @@ static int hb_audio_encoder_is_enabled(int encoder)
case HB_ACODEC_OPUS:
return avcodec_find_encoder(AV_CODEC_ID_OPUS) != NULL;

case HB_ACODEC_FFTRUEHD:
return avcodec_find_encoder(AV_CODEC_ID_TRUEHD) != NULL;

// the following encoders are always enabled
case HB_ACODEC_LAME:
case HB_ACODEC_VORBIS:
Expand Down Expand Up @@ -920,6 +929,21 @@ int hb_audio_samplerate_is_supported(int samplerate, uint32_t codec)
default:
return 0;
}
case HB_ACODEC_FFTRUEHD:
switch (samplerate)
{
// TrueHD only supports samplerates 44.1kHz, 48kHz, 88.2kHz,
// 96kHz, 176.4kHz, and 192kHz.
case 44100:
case 48000:
case 88200:
case 96000:
case 176400:
case 192000:
return 1;
default:
return 0;
}
default:
return 1;
}
Expand Down Expand Up @@ -1093,6 +1117,7 @@ int hb_audio_bitrate_get_default(uint32_t codec, int samplerate, int mixdown)
{
case HB_ACODEC_FFFLAC:
case HB_ACODEC_FFFLAC24:
case HB_ACODEC_FFTRUEHD:
goto fail;

// 96, 224, 640 Kbps
Expand Down Expand Up @@ -1280,6 +1305,7 @@ void hb_audio_bitrate_get_limits(uint32_t codec, int samplerate, int mixdown,
// Bitrates don't apply to "lossless" audio
case HB_ACODEC_FFFLAC:
case HB_ACODEC_FFFLAC24:
case HB_ACODEC_FFTRUEHD:
*low = *high = -1;
return;

Expand Down Expand Up @@ -2487,9 +2513,10 @@ int hb_mixdown_get_default(uint32_t codec, uint64_t layout)
mixdown = HB_AMIXDOWN_7POINT1;
break;

// the (E-)AC-3 encoder defaults to the best mixdown up to 5.1
// the (E-)AC-3 and TrueHD encoder defaults to the best mixdown up to 5.1
case HB_ACODEC_AC3:
case HB_ACODEC_FFEAC3:
case HB_ACODEC_FFTRUEHD:
mixdown = HB_AMIXDOWN_5POINT1;
break;

Expand Down
4 changes: 4 additions & 0 deletions libhb/encavcodecaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ static int encavcodecaInit(hb_work_object_t *w, hb_job_t *job)
}
break;

case HB_ACODEC_FFTRUEHD:
codec_id = AV_CODEC_ID_TRUEHD;
break;

case HB_ACODEC_LAME:
codec_name = "libmp3lame";
break;
Expand Down
2 changes: 1 addition & 1 deletion libhb/handbrake/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ struct hb_job_s
};

/* Audio starts here */
/* Audio Codecs: Update win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/NativeConstants.cs when changing these consts */
/* Audio Codecs: Update win/CS/HandBrake.Interop/Interop/HbLib/NativeConstants.cs when changing these consts */
#define HB_ACODEC_INVALID 0x00000000
#define HB_ACODEC_NONE 0x00000001
#define HB_ACODEC_MASK 0x0FFFFF01
Expand Down

0 comments on commit e74b389

Please sign in to comment.