Skip to content

Commit

Permalink
libhb: ui: add Opus passthru. Enable Opus in MP4. (#4393)
Browse files Browse the repository at this point in the history
* libhb: ui: add Opus passthru. Enable Opus in MP4.
  • Loading branch information
galad87 committed Jun 7, 2022
1 parent bbf5101 commit 91622cb
Show file tree
Hide file tree
Showing 24 changed files with 213 additions and 73 deletions.
4 changes: 4 additions & 0 deletions gtk/src/audiohandler.c
Expand Up @@ -338,6 +338,10 @@ int ghb_get_copy_mask(GhbValue *settings)
{
mask |= HB_ACODEC_TRUEHD_PASS;
}
if (ghb_dict_get_bool(settings, "AudioAllowOPUSPass"))
{
mask |= HB_ACODEC_OPUS_PASS;
}
return mask;
}

Expand Down
21 changes: 21 additions & 0 deletions gtk/src/ghb3.ui
Expand Up @@ -6278,6 +6278,27 @@ This permits AAC passthru to be selected when automatic passthru selection is en
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="AudioAllowOPUSPass">
<property name="label" translatable="yes">Opus</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="tooltip_text" translatable="yes">Enable this if your playback device supports Opus.
This permits Opus passthru to be selected when automatic passthru selection is enabled.</property>
<property name="halign">start</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="audio_passthru_widget_changed_cb" swapped="no"/>
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">4</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
</object>
<packing>
<property name="position">0</property>
Expand Down
1 change: 1 addition & 0 deletions gtk/src/internal_defaults.json.template
Expand Up @@ -18,6 +18,7 @@
"AudioAllowEAC3Pass": false,
"AudioAllowFLACPass": false,
"AudioAllowTRUEHDPass": false,
"AudioAllowOPUSPass": false,
"AudioBitrate": "192",
"AudioEncoder": "copy:ac3",
"AudioTrack": 0,
Expand Down
8 changes: 8 additions & 0 deletions gtk/src/presets.c
Expand Up @@ -468,6 +468,10 @@ ghb_preset_to_settings(GhbValue *settings, GhbValue *preset)
case HB_ACODEC_TRUEHD_PASS:
ghb_dict_set_bool(settings, "AudioAllowTRUEHDPass", 1);
break;
case HB_ACODEC_OPUS:
case HB_ACODEC_OPUS_PASS:
ghb_dict_set_bool(settings, "AudioAllowOPUSPass", 1);
break;
}
}
}
Expand Down Expand Up @@ -1696,6 +1700,10 @@ GhbValue* ghb_create_copy_mask(GhbValue *settings)
{
ghb_array_append(copy_mask, ghb_string_value_new("copy:truehd"));
}
if (ghb_dict_get_bool(settings, "AudioAllowOPUSPass"))
{
ghb_array_append(copy_mask, ghb_string_value_new("copy:opus"));
}
return copy_mask;
}

Expand Down
4 changes: 3 additions & 1 deletion libhb/common.c
Expand Up @@ -92,6 +92,7 @@ enum
HB_GID_ACODEC_TRUEHD_PASS,
HB_GID_ACODEC_VORBIS,
HB_GID_ACODEC_OPUS,
HB_GID_ACODEC_OPUS_PASS,
HB_GID_MUX_MKV,
HB_GID_MUX_MP4,
HB_GID_MUX_WEBM,
Expand Down Expand Up @@ -417,7 +418,8 @@ hb_encoder_internal_t hb_audio_encoders[] =
{ { "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_WEBM|HB_MUX_MASK_MKV, }, NULL, 0, 1, HB_GID_ACODEC_OPUS, },
{ { "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, },
};
int hb_audio_encoders_count = sizeof(hb_audio_encoders) / sizeof(hb_audio_encoders[0]);
Expand Down
3 changes: 2 additions & 1 deletion libhb/handbrake/common.h
Expand Up @@ -833,7 +833,7 @@ struct hb_job_s
#define HB_ACODEC_OPUS 0x04000000
#define HB_ACODEC_FF_MASK 0x0FFF2800
#define HB_ACODEC_PASS_FLAG 0x40000000
#define HB_ACODEC_PASS_MASK (HB_ACODEC_AC3 | HB_ACODEC_DCA | HB_ACODEC_DCA_HD | HB_ACODEC_FFAAC | HB_ACODEC_FFEAC3 | HB_ACODEC_FFFLAC | HB_ACODEC_MP2 | HB_ACODEC_MP3 | HB_ACODEC_FFTRUEHD)
#define HB_ACODEC_PASS_MASK (HB_ACODEC_AC3 | HB_ACODEC_DCA | HB_ACODEC_DCA_HD | HB_ACODEC_FFAAC | HB_ACODEC_FFEAC3 | HB_ACODEC_FFFLAC | HB_ACODEC_MP2 | HB_ACODEC_MP3 | HB_ACODEC_FFTRUEHD | HB_ACODEC_OPUS)
#define HB_ACODEC_AUTO_PASS (HB_ACODEC_PASS_FLAG | HB_ACODEC_PASS_MASK)
#define HB_ACODEC_ANY (HB_ACODEC_PASS_FLAG | HB_ACODEC_MASK)
#define HB_ACODEC_AAC_PASS (HB_ACODEC_PASS_FLAG | HB_ACODEC_FFAAC)
Expand All @@ -845,6 +845,7 @@ struct hb_job_s
#define HB_ACODEC_MP2_PASS (HB_ACODEC_PASS_FLAG | HB_ACODEC_MP2)
#define HB_ACODEC_MP3_PASS (HB_ACODEC_PASS_FLAG | HB_ACODEC_MP3)
#define HB_ACODEC_TRUEHD_PASS (HB_ACODEC_PASS_FLAG | HB_ACODEC_FFTRUEHD)
#define HB_ACODEC_OPUS_PASS (HB_ACODEC_PASS_FLAG | HB_ACODEC_OPUS)

#define HB_SUBSTREAM_BD_TRUEHD 0x72
#define HB_SUBSTREAM_BD_AC3 0x76
Expand Down
2 changes: 2 additions & 0 deletions libhb/preset.c
Expand Up @@ -3361,6 +3361,8 @@ static void import_audio_0_0_0(hb_value_t *preset)
hb_value_array_append(copy, hb_value_string("copy:mp3"));
if (hb_value_get_bool(hb_dict_get(preset, "AudioAllowAACPass")))
hb_value_array_append(copy, hb_value_string("copy:aac"));
if (hb_value_get_bool(hb_dict_get(preset, "AudioAllowOPUSPass")))
hb_value_array_append(copy, hb_value_string("copy:opus"));
if (hb_value_get_bool(hb_dict_get(preset, "AudioAllowAC3Pass")))
hb_value_array_append(copy, hb_value_string("copy:ac3"));
if (hb_value_get_bool(hb_dict_get(preset, "AudioAllowDTSPass")))
Expand Down
8 changes: 8 additions & 0 deletions libhb/stream.c
Expand Up @@ -5440,6 +5440,14 @@ static void add_ffmpeg_audio(hb_title_t *title, hb_stream_t *stream, int id)
audio->config.in.codec = HB_ACODEC_MP3;
break;

case AV_CODEC_ID_OPUS:
{
int len = MIN(codecpar->extradata_size, HB_CONFIG_MAX_SIZE);
memcpy(audio->priv.config.extradata.bytes, codecpar->extradata, len);
audio->priv.config.extradata.length = len;
audio->config.in.codec = HB_ACODEC_OPUS;
} break;

default:
break;
}
Expand Down

0 comments on commit 91622cb

Please sign in to comment.