Skip to content

Commit

Permalink
Add audio transcoding options
Browse files Browse the repository at this point in the history
  • Loading branch information
hstr0100 committed Nov 24, 2024
1 parent 468ab27 commit b29f6f1
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -145,11 +146,24 @@ protected List<String> 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"
));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,14 @@ private JPanel createResolutionSettings() {
false
);

addComboBox(itemPanel, gbcItem,
"settings.audio_codec",
AudioCodecEnum.class,
qualitySettings::getAudioCodec,
qualitySettings::setAudioCodec,
false
);

panel.add(itemPanel);
}

Expand Down
2 changes: 2 additions & 0 deletions core/src/main/resources/lang/language_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/resources/lang/language_es_MX.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/resources/lang/language_pt_BR.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit b29f6f1

Please sign in to comment.