Skip to content

Commit 23b0bb4

Browse files
committed
safety fixes
1 parent 99bafca commit 23b0bb4

File tree

9 files changed

+49
-14
lines changed

9 files changed

+49
-14
lines changed

CHANGES

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Version 5.12.0
44

55
* Adding automatic downloads for rigaya encoders on Windows
6-
* Adding audio normalization (thanks to Xoanon88)
6+
* Adding #45 audio normalization (thanks to HannesJo0139, Marco Ravich, Kirill, Werner Robitza, Type-Delta, Xoanon88)
77
* Adding ability to add subtitle or audio track
88
* Fixing custom_crf not being found (thanks to Norbert)
99

fastflix/data/languages.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10797,3 +10797,11 @@ Add Audio Track:
1079710797
eng: Add Audio Track
1079810798
Add Text Based Subtitle Track:
1079910799
eng: Add Text Based Subtitle Track
10800+
Audio Normalization:
10801+
eng: Audio Normalization
10802+
This will run the audio normalization process on all streams of:
10803+
eng: This will run the audio normalization process on all streams of
10804+
"and create an output file with audio format ":
10805+
eng: "and create an output file with audio format "
10806+
Please make sure the source and output files are specified:
10807+
eng: Please make sure the source and output files are specified

fastflix/encoders/modify/settings_panel.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from fastflix.language import t
1010
from fastflix.models.encode import ModifySettings
1111
from fastflix.models.fastflix_app import FastFlixApp
12-
from fastflix.shared import message
12+
from fastflix.shared import message, yes_no_message
1313
from fastflix.widgets.background_tasks import AudioNoramlize
1414
from fastflix.resources import loading_movie, get_icon
1515

@@ -40,17 +40,21 @@ def __init__(self, parent, main, app: FastFlixApp):
4040
grid.addWidget(self.audio_normalize, 2, 0, 1, 1)
4141
grid.addWidget(self.extract_label, 2, 2, 1, 1)
4242

43+
self.audio_format_combo = QtWidgets.QComboBox()
44+
self.audio_format_combo.addItems(self.app.fastflix.config.sane_audio_selection)
45+
grid.addWidget(self.audio_format_combo, 2, 1, 1, 1)
46+
4347
add_audio_track = QtWidgets.QPushButton(t("Add Audio Track"))
4448
add_audio_track.clicked.connect(self.select_audio_file)
4549
self.add_audio_track_file_path = QtWidgets.QLineEdit()
4650
grid.addWidget(add_audio_track, 3, 0, 1, 1)
47-
grid.addWidget(self.add_audio_track_file_path, 3, 2, 1, 1)
51+
grid.addWidget(self.add_audio_track_file_path, 3, 1, 1, 2)
4852

4953
add_sub_track = QtWidgets.QPushButton(t("Add Text Based Subtitle Track"))
5054
add_sub_track.clicked.connect(self.select_subtitle_file)
5155
self.add_sub_track_file_path = QtWidgets.QLineEdit()
5256
grid.addWidget(add_sub_track, 4, 0, 1, 1)
53-
grid.addWidget(self.add_sub_track_file_path, 4, 2, 1, 1)
57+
grid.addWidget(self.add_sub_track_file_path, 4, 1, 1, 2)
5458

5559
grid.addWidget(QtWidgets.QWidget(), 6, 0, 6, 1)
5660
grid.addLayout(self._add_custom(disable_both_passes=True), 11, 0, 1, 6)
@@ -85,7 +89,26 @@ def select_subtitle_file(self):
8589
self.main.build_commands()
8690

8791
def select_run_audio_normalize(self):
88-
self.norm_thread = AudioNoramlize(self.app, self.main, self.signal)
92+
try:
93+
in_path = Path(self.app.fastflix.current_video.source)
94+
out_path = Path(self.app.fastflix.current_video.video_settings.output_path)
95+
assert in_path.exists()
96+
assert out_path.parent.exists()
97+
except Exception:
98+
message(t("Please make sure the source and output files are specified"))
99+
return
100+
101+
audio_type = self.audio_format_combo.currentText()
102+
resp = yes_no_message(
103+
t("This will run the audio normalization process on all streams of")
104+
+ f"\n{in_path}\n"
105+
+ t("and create an output file with audio format ")
106+
+ f"{audio_type}\n@ {out_path}\n",
107+
title="Audio Normalization",
108+
)
109+
if not resp:
110+
return
111+
self.norm_thread = AudioNoramlize(self.app, self.main, audio_type, self.signal)
89112
self.norm_thread.start()
90113
self.movie.start()
91114
self.extract_label.show()

fastflix/models/encode.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
3-
from pathlib import Path
43
from typing import Optional, Union
54

65
from pydantic import BaseModel, Field, field_validator
@@ -49,7 +48,7 @@ class AttachmentTrack(BaseModel):
4948
outdex: int
5049
index: Optional[int] = None
5150
attachment_type: str = "cover"
52-
file_path: Optional[Path] = None
51+
file_path: Optional[str] = None
5352
filename: Optional[str] = None
5453

5554

fastflix/models/video.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class VideoSettings(BaseModel):
8989
video_title: str = ""
9090
video_track_title: str = ""
9191
selected_track: int = 0
92-
output_path: Path = None
92+
output_path: Path | None = None
9393
# scale: Optional[str] = None
9494
resolution_method: str = "auto"
9595
resolution_custom: str | None = None
@@ -198,7 +198,7 @@ class Video(BaseModel):
198198
duration: Union[float, int] = 0
199199
streams: Box = None
200200

201-
work_path: Path = None
201+
work_path: Path | None = None
202202
format: Box = None
203203
interlaced: Union[str, bool] = False
204204
concat: bool = False

fastflix/widgets/background_tasks.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,12 @@ def run(self):
9090

9191

9292
class AudioNoramlize(QtCore.QThread):
93-
def __init__(self, app: FastFlixApp, main, signal):
93+
def __init__(self, app: FastFlixApp, main, audio_type, signal):
9494
super().__init__(main)
9595
self.main = main
9696
self.app = app
9797
self.signal = signal
98+
self.audio_type = audio_type
9899

99100
def run(self):
100101
try:
@@ -103,7 +104,7 @@ def run(self):
103104
if not out_file:
104105
self.signal.emit("No source video provided")
105106
normalizer = FFmpegNormalize(
106-
audio_codec="aac", extension=out_file.suffix.lstrip("."), video_codec="copy", progress=True
107+
audio_codec=self.audio_type, extension=out_file.suffix.lstrip("."), video_codec="copy", progress=True
107108
)
108109
logger.info(f"Running audio normalization - will output video to {str(out_file)}")
109110
normalizer.add_media_file(str(self.app.fastflix.current_video.source), str(out_file))

fastflix/widgets/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ def __init__(self, parent, app: FastFlixApp):
175175
self.scale_updating = False
176176
self.last_thumb_hash = ""
177177
self.page_updating = False
178+
self.previous_encoder_no_audio = False
178179

179180
self.large_preview = LargePreview(self)
180181

@@ -778,8 +779,9 @@ def init_encoder_drop_down(self):
778779
def change_encoder(self):
779780
if not self.initialized or not self.convert_to:
780781
return
781-
self.video_options.change_conversion(self.convert_to)
782+
self.video_options.change_conversion(self.convert_to, previous_encoder_no_audio=self.previous_encoder_no_audio)
782783
self.update_output_type()
784+
self.previous_encoder_no_audio = self.convert_to.lower() in ("copy", "modify", "gif")
783785

784786
def update_output_type(self):
785787
self.widgets.output_type_combo.clear()

fastflix/widgets/panels/cover_panel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def update_cover_settings(self):
224224
AttachmentTrack(
225225
index=index,
226226
outdex=start_outdex,
227-
file_path=attachment,
227+
file_path=str(attachment),
228228
filename=filename,
229229
attachment_type="cover",
230230
)

fastflix/widgets/video_options.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def _get_audio_formats(self, encoder=None):
118118
def audio_formats(self):
119119
return self._get_audio_formats()
120120

121-
def change_conversion(self, conversion):
121+
def change_conversion(self, conversion, previous_encoder_no_audio=False):
122122
conversion = conversion.strip()
123123
encoder = self.app.fastflix.encoders[conversion]
124124
self.current_settings.close()
@@ -158,6 +158,8 @@ def change_conversion(self, conversion):
158158
if not self.reloading:
159159
self.audio.allowed_formats(self._get_audio_formats(encoder))
160160
# self.update_profile()
161+
if previous_encoder_no_audio:
162+
self.audio.new_source(self.audio_formats)
161163

162164
def get_settings(self):
163165
if not self.app.fastflix.current_video:

0 commit comments

Comments
 (0)