add g726 support
This commit is contained in:
parent
96c3effce1
commit
b1c0b8ef78
|
@ -28,6 +28,11 @@ add_to_arr(transcode_levels, [
|
|||
f"speex-q{quality}" for quality in range(0, 11)
|
||||
])
|
||||
|
||||
g726_bitrates = ["16", "24", "32", "40"]
|
||||
add_to_arr(transcode_levels, [
|
||||
f"g726-{bitrate}k" for bitrate in g726_bitrates
|
||||
])
|
||||
|
||||
# Extra Default Mappings
|
||||
preset_transcode_levels = {
|
||||
"mp3-low": "mp3-v4",
|
||||
|
|
|
@ -12,6 +12,8 @@ class TranscodeConfig:
|
|||
container = ""
|
||||
bitrate = ""
|
||||
quality = ""
|
||||
sample_rate = ""
|
||||
channels = ""
|
||||
|
||||
def load_from_dict(self, data):
|
||||
if "use_quality" in data:
|
||||
|
@ -28,6 +30,10 @@ class TranscodeConfig:
|
|||
self.bitrate = data["bitrate"]
|
||||
if "quality" in data:
|
||||
self.quality = data["quality"]
|
||||
if "sample_rate" in data:
|
||||
self.sample_rate = data["sample_rate"]
|
||||
if "channels" in data:
|
||||
self.channels = data["channels"]
|
||||
return self
|
||||
|
||||
def get_transcode_config(file: File, level: str):
|
||||
|
@ -35,6 +41,17 @@ def get_transcode_config(file: File, level: str):
|
|||
if level in preset_transcode_levels.keys():
|
||||
level = preset_transcode_levels["level"]
|
||||
|
||||
if level.startswith("g726-") and level.endswith("k"):
|
||||
conf.container = "matroska"
|
||||
conf.file_extension = "mkv"
|
||||
conf.encoder = "g726"
|
||||
conf.sample_rate = "8000"
|
||||
conf.channels = "1"
|
||||
conf.use_bitrate = True
|
||||
# includes the k at end
|
||||
conf.bitrate = level.replace("g726-", "")
|
||||
return conf
|
||||
|
||||
if level.startswith("opus-") and level.endswith("k"):
|
||||
conf.container = "ogg"
|
||||
conf.file_extension = "opus"
|
||||
|
@ -97,6 +114,15 @@ def transcode(file: File, config: TranscodeConfig, dest: str):
|
|||
ffmpeg_command.append("-f")
|
||||
ffmpeg_command.append(config.container)
|
||||
|
||||
if len(config.sample_rate) != 0:
|
||||
ffmpeg_command.append("-ar")
|
||||
ffmpeg_command.append(config.sample_rate)
|
||||
|
||||
if len(config.channels) != 0:
|
||||
ffmpeg_command.append("-ac")
|
||||
ffmpeg_command.append(config.channels)
|
||||
|
||||
|
||||
if config.use_quality:
|
||||
ffmpeg_command.append("-q:a")
|
||||
ffmpeg_command.append(config.quality)
|
||||
|
@ -113,6 +139,6 @@ def transcode(file: File, config: TranscodeConfig, dest: str):
|
|||
ffmpeg_command.append(f"artist=\"{artist}\"")
|
||||
|
||||
ffmpeg_command.append(dest)
|
||||
|
||||
print(ffmpeg_command)
|
||||
# TODO: check for errors
|
||||
run_command(ffmpeg_command)
|
||||
|
|
1
tconf.json
Normal file
1
tconf.json
Normal file
|
@ -0,0 +1 @@
|
|||
{"file_extension": "flac", "encoder": "flac"}
|
Loading…
Reference in a new issue