From b29f6f1502ce83b2319c77eeefebbd934f212451 Mon Sep 17 00:00:00 2001 From: hstr0100 Date: Sun, 24 Nov 2024 03:36:56 -0300 Subject: [PATCH] Add audio transcoding options --- .../gdownloader/settings/QualitySettings.java | 4 ++ .../settings/enums/AudioCodecEnum.java | 56 +++++++++++++++++++ .../settings/filters/GenericFilter.java | 20 ++++++- .../brlns/gdownloader/ui/SettingsPanel.java | 8 +++ .../resources/lang/language_en.properties | 2 + .../resources/lang/language_es_MX.properties | 2 + .../resources/lang/language_pt_BR.properties | 2 + 7 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 core/src/main/java/net/brlns/gdownloader/settings/enums/AudioCodecEnum.java diff --git a/core/src/main/java/net/brlns/gdownloader/settings/QualitySettings.java b/core/src/main/java/net/brlns/gdownloader/settings/QualitySettings.java index 34240d2..bc451f8 100644 --- a/core/src/main/java/net/brlns/gdownloader/settings/QualitySettings.java +++ b/core/src/main/java/net/brlns/gdownloader/settings/QualitySettings.java @@ -57,6 +57,10 @@ public class QualitySettings { @JsonProperty("FPS") private FPSEnum fps = FPSEnum.FPS_60; + @Builder.Default + @JsonProperty("AudioCodec") + private AudioCodecEnum audioCodec = AudioCodecEnum.NO_CODEC; + @Builder.Default @JsonProperty("AudioContainer") private AudioContainerEnum audioContainer = AudioContainerEnum.MP3; diff --git a/core/src/main/java/net/brlns/gdownloader/settings/enums/AudioCodecEnum.java b/core/src/main/java/net/brlns/gdownloader/settings/enums/AudioCodecEnum.java new file mode 100644 index 0000000..8c01ff5 --- /dev/null +++ b/core/src/main/java/net/brlns/gdownloader/settings/enums/AudioCodecEnum.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2024 hstr0100 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package net.brlns.gdownloader.settings.enums; + +import lombok.Getter; + +import static net.brlns.gdownloader.lang.Language.l10n; + +/** + * @author Gabriel / hstr0100 / vertx010 + */ +@Getter +public enum AudioCodecEnum implements ISettingsEnum, IContainerEnum { + NO_CODEC(""), + MP3("libmp3lame"), + AAC("aac"), + FLAC("flac"), + ALAC("alac"), + OPUS("libopus"), + VORBIS("libvorbis"); + + private final String ffmpegCodecName; + + private AudioCodecEnum(String ffmpegCodecNameIn) { + ffmpegCodecName = ffmpegCodecNameIn; + } + + @Override + public String getValue() { + return name().toLowerCase(); + } + + @Override + public String getTranslationKey() { + return ""; + } + + @Override + public String getDisplayName() { + return this == NO_CODEC ? l10n("enums.audio_codec.no_codec") : name().toLowerCase(); + } +} diff --git a/core/src/main/java/net/brlns/gdownloader/settings/filters/GenericFilter.java b/core/src/main/java/net/brlns/gdownloader/settings/filters/GenericFilter.java index 738b18e..5459196 100644 --- a/core/src/main/java/net/brlns/gdownloader/settings/filters/GenericFilter.java +++ b/core/src/main/java/net/brlns/gdownloader/settings/filters/GenericFilter.java @@ -28,6 +28,7 @@ import net.brlns.gdownloader.settings.QualitySettings; import net.brlns.gdownloader.settings.Settings; import net.brlns.gdownloader.settings.enums.AudioBitrateEnum; +import net.brlns.gdownloader.settings.enums.AudioCodecEnum; import net.brlns.gdownloader.settings.enums.DownloadTypeEnum; import net.brlns.gdownloader.settings.enums.VideoContainerEnum; import net.brlns.gdownloader.util.URLUtils; @@ -145,11 +146,24 @@ protected List buildArguments(DownloaderIdEnum downloaderId, DownloadTyp } } - if (config.isTranscodeAudioToAAC()) { + String codec = null; + if (quality.getAudioCodec() != AudioCodecEnum.NO_CODEC) { + // Check if the user has selected a custom audio codec. + codec = quality.getAudioCodec().getFfmpegCodecName(); + } else if (config.isTranscodeAudioToAAC()) { + // If no custom codec is set, check if "Convert audio to a widely supported codec" is enabled. + // If enabled, default to "aac". + codec = "aac"; // Opus is not supported by some native video players + } + + // If no codec is defined, the default audio codec provided by the source will be passed through. + if (codec != null) { + // Transcode audio (Note: This can be very slow on some machines). arguments.addAll(List.of( "--postprocessor-args", - // Opus is not supported by some native video players - "ffmpeg:-c:a aac -b:a " + (audioBitrate == AudioBitrateEnum.NO_AUDIO ? 320 : audioBitrate.getValue()) + "k" + // Use the selected codec. Default bitrate is 320 kbps unless otherwise specified. + "ffmpeg:-c:a " + codec + " -b:a " + + (audioBitrate == AudioBitrateEnum.NO_AUDIO ? 320 : audioBitrate.getValue()) + "k" )); } } diff --git a/core/src/main/java/net/brlns/gdownloader/ui/SettingsPanel.java b/core/src/main/java/net/brlns/gdownloader/ui/SettingsPanel.java index 350d789..ac666c5 100644 --- a/core/src/main/java/net/brlns/gdownloader/ui/SettingsPanel.java +++ b/core/src/main/java/net/brlns/gdownloader/ui/SettingsPanel.java @@ -1057,6 +1057,14 @@ private JPanel createResolutionSettings() { false ); + addComboBox(itemPanel, gbcItem, + "settings.audio_codec", + AudioCodecEnum.class, + qualitySettings::getAudioCodec, + qualitySettings::setAudioCodec, + false + ); + panel.add(itemPanel); } diff --git a/core/src/main/resources/lang/language_en.properties b/core/src/main/resources/lang/language_en.properties index 2887a41..4b6e9c9 100644 --- a/core/src/main/resources/lang/language_en.properties +++ b/core/src/main/resources/lang/language_en.properties @@ -2,6 +2,7 @@ startup=en-US translation by @hstr0100 dialog.confirm=Confirm dialog.download_playlist=Download Whole Playlist? enums.audio.no_audio=Do Not Download Separate Audio +enums.audio_codec.no_codec=Use Default Audio Codec enums.browser.default_browser=System Default enums.download_status.complete=COMPLETE enums.download_status.deduplicating=DEDUPLICATING @@ -112,6 +113,7 @@ gui.update=Updates gui.view_thumbnail=View Thumbnail settings.always_on_top=Keep Window Always On Top: settings.audio_bitrate=Audio Bitrate: +settings.audio_codec=Audio Codec Transcoding: settings.audio_container=Audio Format: settings.auto_download_retry=Automatically Retry Failed Downloads: settings.auto_download_start=Automatically Start Downloads: diff --git a/core/src/main/resources/lang/language_es_MX.properties b/core/src/main/resources/lang/language_es_MX.properties index decc602..0b0ed7b 100644 --- a/core/src/main/resources/lang/language_es_MX.properties +++ b/core/src/main/resources/lang/language_es_MX.properties @@ -2,6 +2,7 @@ startup=es-MX translation by @hstr0100 dialog.confirm=Confirmar dialog.download_playlist=\u00bfDescargar Playlist Completa? enums.audio.no_audio=No Descargar Audio Separado +enums.audio_codec.no_codec=Usar el C\u00f3dec Predeterminado enums.browser.default_browser=Navegador Predeterminado enums.download_status.complete=COMPLETADO enums.download_status.deduplicating=ELIMINANDO DUPLICADOS @@ -112,6 +113,7 @@ gui.update=Actualizaciones gui.view_thumbnail=Ver Miniatura settings.always_on_top=Mantener Ventana Siempre en la Parte Superior: settings.audio_bitrate=Bitrate de Audio: +settings.audio_codec=Transcodificaci\u00f3n de C\u00f3dec de Audio: settings.audio_container=Formato de Audio: settings.auto_download_retry=Reintentar descargas fallidas: settings.auto_download_start=Iniciar descargas autom\u00e1ticamente: diff --git a/core/src/main/resources/lang/language_pt_BR.properties b/core/src/main/resources/lang/language_pt_BR.properties index cc407a2..8ef0267 100644 --- a/core/src/main/resources/lang/language_pt_BR.properties +++ b/core/src/main/resources/lang/language_pt_BR.properties @@ -2,6 +2,7 @@ startup=pt-BR translation by @hstr0100 dialog.confirm=Confirmar dialog.download_playlist=Baixar Playlist Completa? enums.audio.no_audio=N\u00e3o Baixar Audio Separado +enums.audio_codec.no_codec=Usar o Codec Padr\u00e3o enums.browser.default_browser=Padr\u00e3o do Sistema enums.download_status.complete=CONCLU\u00cdDO enums.download_status.deduplicating=REMOVENDO DUPLICATAS @@ -112,6 +113,7 @@ gui.update=Atualiza\u00e7\u00f5es gui.view_thumbnail=Visualizar Miniatura settings.always_on_top=Manter Janela Sempre no Topo: settings.audio_bitrate=Bitrate do \u00c1udio: +settings.audio_codec=Transcodifica\u00e7\u00e3o do Codec de \u00c1udio: settings.audio_container=Formato de Audio: settings.auto_download_retry=Repetir downloads falhados: settings.auto_download_start=Iniciar downloads automaticamente: