Skip to content

Commit

Permalink
Possibly working audio updates
Browse files Browse the repository at this point in the history
  • Loading branch information
cdgriffith committed Apr 17, 2024
1 parent 36ad9db commit 51ee9fb
Show file tree
Hide file tree
Showing 31 changed files with 728 additions and 510 deletions.
120 changes: 120 additions & 0 deletions fastflix/data/languages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10595,3 +10595,123 @@ Custom:
ukr: Нестандартний
kor: 사용자 지정
ron: Personalizat
Codec:
eng: Codec
deu: Codec
fra: Codec
ita: Codec
spa: Códec
jpn: コーデック
rus: Кодек
por: Codec
swe: Kodning
pol: Kodek
chs: 编解码器
ukr: Кодек
kor: 코덱
ron: Codec
Near Lossless:
eng: Near Lossless
deu: Fast verlustfrei
fra: Presque sans perte
ita: Quasi senza perdita
spa: Casi sin pérdidas
jpn: ニア・ロスレス
rus: Почти без потерь
por: Quase sem perdas
swe: Nära förlustfri
pol: Near Lossless
chs: 近乎无损
ukr: Майже без втрат
kor: 거의 무손실
ron: Aproape fără pierderi
High Quality:
eng: High Quality
deu: Hohe Qualität
fra: Haute qualité
ita: Alta qualità
spa: Alta calidad
jpn: 高品質
rus: Высокое качество
por: Alta qualidade
swe: Hög kvalitet
pol: Wysoka jakość
chs: 高质量
ukr: Висока якість
kor: 고품질
ron: De înaltă calitate
Medium Quality:
eng: Medium Quality
deu: Mittlere Qualität
fra: Qualité moyenne
ita: Qualità media
spa: Calidad media
jpn: ミディアム・クオリティ
rus: Среднее качество
por: Qualidade média
swe: Medelhög kvalitet
pol: Średnia jakość
chs: 中等质量
ukr: Середня якість
kor: 중간 품질
ron: Calitate medie
Low Quality:
eng: Low Quality
deu: Geringe Qualität
fra: Faible qualité
ita: Bassa qualità
spa: Baja calidad
jpn: 低品質
rus: Низкое качество
por: Baixa qualidade
swe: Låg kvalitet
pol: Niska jakość
chs: 低质量
ukr: Низька якість
kor: 낮은 품질
ron: Calitate scăzută
Custom Bitrate:
eng: Custom Bitrate
deu: Benutzerdefinierte Bitrate
fra: Bitrate personnalisé
ita: Bitrate personalizzato
spa: Velocidad de bits personalizada
jpn: カスタム・ビットレート
rus: Пользовательский битрейт
por: Taxa de bits personalizada
swe: Anpassad bitrate
pol: Niestandardowa szybkość transmisji
chs: 自定义比特率
ukr: Користувацький бітрейт
kor: 사용자 지정 비트레이트
ron: Bitrate personalizat
Audio Quality:
eng: Audio Quality
deu: Audio-Qualität
fra: Qualité audio
ita: Qualità audio
spa: Calidad de audio
jpn: オーディオ品質
rus: Качество звука
por: Qualidade áudio
swe: Ljudkvalitet
pol: Jakość dźwięku
chs: 音频质量
ukr: Якість звуку
kor: 오디오 품질
ron: Calitatea audio
Channel Layout:
eng: Channel Layout
deu: Kanal-Layout
fra: Disposition des canaux
ita: Layout del canale
spa: Disposición de los canales
jpn: チャンネルレイアウト
rus: Расположение каналов
por: Disposição dos canais
swe: Kanalens layout
pol: Układ kanałów
chs: 通道布局
ukr: Розташування каналів
kor: 채널 레이아웃
ron: Canal Layout
3 changes: 2 additions & 1 deletion fastflix/encoders/common/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def build_audio(audio_tracks, audio_file_index=0):
)
bitrate = ""
if track.conversion_codec not in lossless:
bitrate = f"-b:{track.outdex} {track.conversion_bitrate} "
channel_layout = f'-filter:{track.outdex} aformat=channel_layouts="{track.raw_info.channel_layout}"'
bitrate = f"-b:{track.outdex} {track.conversion_bitrate} {channel_layout}"
command_list.append(f"-c:{track.outdex} {track.conversion_codec} {bitrate} {downmix}")

if getattr(track, "dispositions", None):
Expand Down
9 changes: 8 additions & 1 deletion fastflix/encoders/common/encc_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def build_audio(audio_tracks: list[AudioTrack], audio_streams):
stream_ids = get_stream_pos(audio_streams)

for track in sorted(audio_tracks, key=lambda x: x.outdex):
if not track.enabled:
continue
if track.index in track_ids:
logger.warning("*EncC does not support copy and duplicate of audio tracks!")
track_ids.add(track.index)
Expand All @@ -98,7 +100,10 @@ def build_audio(audio_tracks: list[AudioTrack], audio_streams):
downmix = f"--audio-stream {audio_id}?:{track.downmix}" if track.downmix else ""
bitrate = ""
if track.conversion_codec not in lossless:
bitrate = f"--audio-bitrate {audio_id}?{track.conversion_bitrate.rstrip('k')} "
if track.conversion_bitrate:
bitrate = f"--audio-bitrate {audio_id}?{track.conversion_bitrate} "
else:
bitrate = f"--audio-profile {audio_id}?{track.conversion_aq} "
command_list.append(
f"{downmix} --audio-codec {audio_id}?{track.conversion_codec} {bitrate} "
f"--audio-metadata {audio_id}?clear"
Expand Down Expand Up @@ -130,6 +135,8 @@ def build_subtitle(subtitle_tracks: list[SubtitleTrack], subtitle_streams, video
scale = ",scale=2.0" if video_height > 1800 else ""

for track in sorted(subtitle_tracks, key=lambda x: x.outdex):
if not track.enabled:
continue
sub_id = stream_ids[track.index]
if track.burn_in:
command_list.append(f"--vpp-subburn track={sub_id}{scale}")
Expand Down
6 changes: 3 additions & 3 deletions fastflix/encoders/common/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,18 +250,18 @@ def generate_all(
) -> Tuple[str, str, str]:
settings = fastflix.current_video.video_settings.video_encoder_settings

audio = build_audio(fastflix.current_video.video_settings.audio_tracks) if audio else ""
audio = build_audio(fastflix.current_video.audio_tracks) if audio else ""

subtitles, burn_in_track, burn_in_type = "", None, None
if subs:
subtitles, burn_in_track, burn_in_type = build_subtitle(fastflix.current_video.video_settings.subtitle_tracks)
subtitles, burn_in_track, burn_in_type = build_subtitle(fastflix.current_video.subtitle_tracks)
if burn_in_type == "text":
for i, x in enumerate(fastflix.current_video.streams["subtitle"]):
if x["index"] == burn_in_track:
burn_in_track = i
break

attachments = build_attachments(fastflix.current_video.video_settings.attachment_tracks)
attachments = build_attachments(fastflix.current_video.attachment_tracks)

enable_opencl = fastflix.opencl_support
if "enable_opencl" in filters_extra:
Expand Down
2 changes: 2 additions & 0 deletions fastflix/encoders/common/subtitles.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def build_subtitle(
burn_in_type = None
subs_enabled = False
for track in subtitle_tracks:
if not track.enabled:
continue
if track.burn_in:
burn_in_track = track.index
burn_in_type = track.subtitle_type
Expand Down
4 changes: 2 additions & 2 deletions fastflix/encoders/nvencc_av1/command_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ def build(fastflix: FastFlix):
(f"--vpp-colorspace hdr2sdr=mobius" if video.video_settings.remove_hdr else ""),
remove_hdr,
"--psnr --ssim" if settings.metrics else "",
build_audio(video.video_settings.audio_tracks, video.streams.audio),
build_subtitle(video.video_settings.subtitle_tracks, video.streams.subtitle, video_height=video.height),
build_audio(video.audio_tracks, video.streams.audio),
build_subtitle(video.subtitle_tracks, video.streams.subtitle, video_height=video.height),
settings.extra,
"-o",
f'"{clean_file_string(video.video_settings.output_path)}"',
Expand Down
4 changes: 2 additions & 2 deletions fastflix/encoders/nvencc_avc/command_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ def build(fastflix: FastFlix):
(f"--vpp-colorspace hdr2sdr=mobius" if video.video_settings.remove_hdr else ""),
remove_hdr,
"--psnr --ssim" if settings.metrics else "",
build_audio(video.video_settings.audio_tracks, video.streams.audio),
build_subtitle(video.video_settings.subtitle_tracks, video.streams.subtitle, video_height=video.height),
build_audio(video.audio_tracks, video.streams.audio),
build_subtitle(video.subtitle_tracks, video.streams.subtitle, video_height=video.height),
settings.extra,
"-o",
f'"{clean_file_string(video.video_settings.output_path)}"',
Expand Down
4 changes: 2 additions & 2 deletions fastflix/encoders/nvencc_hevc/command_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ def build(fastflix: FastFlix):
(f"--vpp-colorspace hdr2sdr=mobius" if video.video_settings.remove_hdr else ""),
remove_hdr,
"--psnr --ssim" if settings.metrics else "",
build_audio(video.video_settings.audio_tracks, video.streams.audio),
build_subtitle(video.video_settings.subtitle_tracks, video.streams.subtitle, video_height=video.height),
build_audio(video.audio_tracks, video.streams.audio),
build_subtitle(video.subtitle_tracks, video.streams.subtitle, video_height=video.height),
settings.extra,
"-o",
f'"{clean_file_string(video.video_settings.output_path)}"',
Expand Down
4 changes: 2 additions & 2 deletions fastflix/encoders/qsvencc_av1/command_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ def build(fastflix: FastFlix):
("--adapt-ltr" if settings.adapt_ltr else ""),
("--adapt-cqm" if settings.adapt_cqm else ""),
"--psnr --ssim" if settings.metrics else "",
build_audio(video.video_settings.audio_tracks, video.streams.audio),
build_subtitle(video.video_settings.subtitle_tracks, video.streams.subtitle, video_height=video.height),
build_audio(video.audio_tracks, video.streams.audio),
build_subtitle(video.subtitle_tracks, video.streams.subtitle, video_height=video.height),
settings.extra,
"-o",
f'"{clean_file_string(video.video_settings.output_path)}"',
Expand Down
4 changes: 2 additions & 2 deletions fastflix/encoders/qsvencc_avc/command_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ def build(fastflix: FastFlix):
("--adapt-ltr" if settings.adapt_ltr else ""),
("--adapt-cqm" if settings.adapt_cqm else ""),
"--psnr --ssim" if settings.metrics else "",
build_audio(video.video_settings.audio_tracks, video.streams.audio),
build_subtitle(video.video_settings.subtitle_tracks, video.streams.subtitle, video_height=video.height),
build_audio(video.audio_tracks, video.streams.audio),
build_subtitle(video.subtitle_tracks, video.streams.subtitle, video_height=video.height),
settings.extra,
"-o",
f'"{clean_file_string(video.video_settings.output_path)}"',
Expand Down
4 changes: 2 additions & 2 deletions fastflix/encoders/qsvencc_hevc/command_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ def build(fastflix: FastFlix):
("--adapt-ltr" if settings.adapt_ltr else ""),
("--adapt-cqm" if settings.adapt_cqm else ""),
"--psnr --ssim" if settings.metrics else "",
build_audio(video.video_settings.audio_tracks, video.streams.audio),
build_subtitle(video.video_settings.subtitle_tracks, video.streams.subtitle, video_height=video.height),
build_audio(video.audio_tracks, video.streams.audio),
build_subtitle(video.subtitle_tracks, video.streams.subtitle, video_height=video.height),
settings.extra,
"-o",
f'"{clean_file_string(video.video_settings.output_path)}"',
Expand Down
4 changes: 2 additions & 2 deletions fastflix/encoders/vceencc_av1/command_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ def build(fastflix: FastFlix):
(f"--vpp-colorspace hdr2sdr=mobius" if video.video_settings.remove_hdr else ""),
remove_hdr,
"--psnr --ssim" if settings.metrics else "",
build_audio(video.video_settings.audio_tracks, video.streams.audio),
build_subtitle(video.video_settings.subtitle_tracks, video.streams.subtitle, video_height=video.height),
build_audio(video.audio_tracks, video.streams.audio),
build_subtitle(video.subtitle_tracks, video.streams.subtitle, video_height=video.height),
settings.extra,
"-o",
f'"{clean_file_string(video.video_settings.output_path)}"',
Expand Down
4 changes: 2 additions & 2 deletions fastflix/encoders/vceencc_avc/command_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ def build(fastflix: FastFlix):
(f"--vpp-colorspace hdr2sdr=mobius" if video.video_settings.remove_hdr else ""),
remove_hdr,
"--psnr --ssim" if settings.metrics else "",
build_audio(video.video_settings.audio_tracks, video.streams.audio),
build_subtitle(video.video_settings.subtitle_tracks, video.streams.subtitle, video_height=video.height),
build_audio(video.audio_tracks, video.streams.audio),
build_subtitle(video.subtitle_tracks, video.streams.subtitle, video_height=video.height),
settings.extra,
"-o",
f'"{clean_file_string(video.video_settings.output_path)}"',
Expand Down
4 changes: 2 additions & 2 deletions fastflix/encoders/vceencc_hevc/command_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ def build(fastflix: FastFlix):
(f"--vpp-colorspace hdr2sdr=mobius" if video.video_settings.remove_hdr else ""),
remove_hdr,
"--psnr --ssim" if settings.metrics else "",
build_audio(video.video_settings.audio_tracks, video.streams.audio),
build_subtitle(video.video_settings.subtitle_tracks, video.streams.subtitle, video_height=video.height),
build_audio(video.audio_tracks, video.streams.audio),
build_subtitle(video.subtitle_tracks, video.streams.subtitle, video_height=video.height),
settings.extra,
"-o",
f'"{clean_file_string(video.video_settings.output_path)}"',
Expand Down
14 changes: 7 additions & 7 deletions fastflix/ff_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ def get_queue(queue_file: Path) -> list[Video]:
video["video_settings"]["output_path"] = Path(video["video_settings"]["output_path"])
encoder_settings = video["video_settings"]["video_encoder_settings"]
ves = [x(**encoder_settings) for x in setting_types.values() if x().name == encoder_settings["name"]][0]
audio = [AudioTrack(**x) for x in video["video_settings"]["audio_tracks"]]
subtitles = [SubtitleTrack(**x) for x in video["video_settings"]["subtitle_tracks"]]
# TODO breaks - audio = [AudioTrack(**x) for x in video["audio_tracks"]]
# TODO breaks subtitles = [SubtitleTrack(**x) for x in video["subtitle_tracks"]]
attachments = []
for x in video["video_settings"]["attachment_tracks"]:
for x in video["attachment_tracks"]:
try:
attachment_path = x.pop("file_path")
except KeyError:
Expand All @@ -50,9 +50,9 @@ def get_queue(queue_file: Path) -> list[Video]:
crop = None
if video["video_settings"]["crop"]:
crop = Crop(**video["video_settings"]["crop"])
del video["video_settings"]["audio_tracks"]
del video["video_settings"]["subtitle_tracks"]
del video["video_settings"]["attachment_tracks"]
del video["audio_tracks"]
del video["subtitle_tracks"]
del video["attachment_tracks"]
del video["video_settings"]["video_encoder_settings"]
del video["status"]
del video["video_settings"]["crop"]
Expand Down Expand Up @@ -108,7 +108,7 @@ def update_conversion_command(vid, old_path: str, new_path: str):
str(new_metadata_file),
)
video["video_settings"]["video_encoder_settings"]["hdr10plus_metadata"] = str(new_metadata_file)
for track in video["video_settings"]["attachment_tracks"]:
for track in video["attachment_tracks"]:
if track.get("file_path"):
if not Path(track["file_path"]).exists():
logger.exception("Could not save cover to queue recovery location, removing cover")
Expand Down
7 changes: 7 additions & 0 deletions fastflix/flix.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,9 @@ def get_auto_crop(
)

width, height, x_crop, y_crop = None, None, None, None
if not output.stderr:
return 0, 0, 0, 0

for line in output.stderr.splitlines():
if line.startswith("[Parsed_cropdetect"):
w, h, x, y = [int(x) for x in line.rsplit("=")[1].split(":")]
Expand Down Expand Up @@ -429,6 +432,10 @@ def detect_interlaced(app: FastFlixApp, config: Config, source: Path, **_):
logger.exception("Error while running the interlace detection command")
return

if not output.stderr:
logger.warning("Could not extract interlaced information")
return

for line in output.stderr.splitlines():
if "Single frame detection" in line:
try:
Expand Down
7 changes: 3 additions & 4 deletions fastflix/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
import logging
import os
import shutil
from distutils.version import StrictVersion
from packaging import version
from pathlib import Path
from typing import Literal
import json
import sys

from appdirs import user_data_dir
from box import Box, BoxError
Expand Down Expand Up @@ -266,7 +265,7 @@ def load(self, portable_mode=False):
if "version" not in data:
raise ConfigError(f"Corrupt config file. Please fix or remove {self.config_path}")

if StrictVersion(__version__) < StrictVersion(data.version):
if version.parse(__version__) < version.parse(data.version):
logger.warning(
f"This FastFlix version ({__version__}) is older "
f"than the one that generated the config file ({data.version}), "
Expand Down Expand Up @@ -315,7 +314,7 @@ def load(self, portable_mode=False):

# 5.2.0 remove ext
self.output_name_format = self.output_name_format.replace(".{ext}", "").replace("{ext}", "")
# if StrictVersion(__version__) > StrictVersion(data.version):
# if version.parse(__version__) > version.parse(data.version):
# logger.info(f"Clearing possible old config values from fastflix {data.verion}")
# self.vceencc_encoders = []
# self.nvencc_encoders = []
Expand Down
Loading

0 comments on commit 51ee9fb

Please sign in to comment.