Skip to content

Commit

Permalink
Version 2.6.3 (#72)
Browse files Browse the repository at this point in the history
* Fixing #71 #26 encoding issues in video files (thanks to -L0Lock-)
* Fixing tempfile issue with recursion on cleanup
* Fixing SVT AV1 command building raising errors on bad crop
  • Loading branch information
cdgriffith authored Sep 19, 2020
1 parent 4009ec0 commit b437d03
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 28 deletions.
7 changes: 7 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
---------

Version 2.6.3
~~~~~~~~~~~~~

* Fixing #71 #26 encoding issues in video files (thanks to -L0Lock-)
* Fixing tempfile issue with recursion on cleanup
* Fixing SVT AV1 command building raising errors on bad crop

Version 2.6.2
~~~~~~~~~~~~~

Expand Down
4 changes: 3 additions & 1 deletion fastflix/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ def main():
if file.is_file() and file.name.lower() in ("ffprobe", "ffprobe.exe"):
ffprobe = file

logger.addHandler(logging.FileHandler(log_dir / f"flix_{datetime.now().isoformat().replace(':', '.')}"))
logger.addHandler(
logging.FileHandler(log_dir / f"flix_{datetime.now().isoformat().replace(':', '.')}", encoding="utf-8")
)

config_file = Path(data_path, "fastflix.json")
if not config_file.exists():
Expand Down
6 changes: 4 additions & 2 deletions fastflix/plugins/svt_av1/command_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@ def build(
assert crop_check[0] % 8 == 0
assert crop_check[1] % 8 == 0
except AssertionError:
raise FlixError("CROP BAD: Video height and main_width must be divisible by 8")
logger.error("CROP BAD: Video height and main_width must be divisible by 8")
return []
else:
crop_height = height % 8
crop_width = width % 8
if crop_height or crop_width:
raise FlixError("CROP BAD: Video height and main_width must be divisible by 8")
logger.error("CROP BAD: Video height and main_width must be divisible by 8")
return []

assert height <= 2160
assert width <= 4096
Expand Down
2 changes: 1 addition & 1 deletion fastflix/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__version__ = "2.6.2"
__version__ = "2.6.3"
__author__ = "Chris Griffith"
31 changes: 8 additions & 23 deletions fastflix/widgets/command_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from subprocess import Popen, PIPE, STDOUT
import os
import signal
import secrets

import reusables

Expand All @@ -23,7 +24,8 @@
class CommandRunner(QtCore.QThread):
def __init__(self, parent, command_list, work_dir):
super().__init__(parent)
self.tempdir = tempfile.TemporaryDirectory(prefix="temp_", dir=work_dir)
self.tempdir = str(Path(work_dir) / f"temp_{secrets.token_hex(12)}")
os.makedirs(self.tempdir, exist_ok=True)
self.app = parent
self.command_list = command_list
self.process = None
Expand All @@ -37,21 +39,21 @@ def replace_temps(self, command):
file_numbers = set(self.re_tempfile.findall(command))
for num, ext in file_numbers:
if num not in self.temp_files:
self.temp_files[num] = Path(self.tempdir.name, f"{uuid4().hex}.{ext}")
self.temp_files[num] = Path(self.tempdir, f"{uuid4().hex}.{ext}")
command = command.replace(f"<tempfile.{num}.{ext}>", str(self.temp_files[num]))
for num in set(self.re_tempdir.findall(command)):
if num not in self.temp_dirs:
self.temp_dirs[num] = Path(tempfile.mkdtemp(prefix=f"{num}_", dir=self.tempdir.name))
self.temp_dirs[num] = Path(tempfile.mkdtemp(prefix=f"{num}_", dir=self.tempdir))
command = command.replace(f"<tempdir.{num}>", str(self.temp_dirs[num]))
return command

def loop_creates(self, dirs, files):
for num, ext in files:
if num not in self.temp_files:
self.temp_files[num] = Path(self.tempdir.name, f"{uuid4().hex}.{ext}")
self.temp_files[num] = Path(self.tempdir, f"{uuid4().hex}.{ext}")
for num in dirs:
if num not in self.temp_dirs:
self.temp_dirs[num] = Path(tempfile.mkdtemp(prefix=f"{num}_", dir=self.tempdir.name))
self.temp_dirs[num] = Path(tempfile.mkdtemp(prefix=f"{num}_", dir=self.tempdir))

@staticmethod
def replace_loop_args(command, index, items):
Expand Down Expand Up @@ -116,7 +118,6 @@ def run(self):
try:
for command in self.command_list:
if self.killed:
self.tempdir.cleanup()
return
if command.ensure_paths:
for path in command.ensure_paths:
Expand All @@ -135,25 +136,14 @@ def run(self):
return self.app.completed.emit(str(code))
except Exception as err:
logger.exception(f"Could not run commands - {err}")
self.tempdir.cleanup()
if not self.killed:
self.app.completed.emit(1)
else:
self.tempdir.cleanup()
if not self.killed:
self.app.completed.emit(0)

def start_exec(self, command):
return Popen(
command,
shell=True,
cwd=self.tempdir.name,
stdin=PIPE,
stdout=PIPE,
stderr=STDOUT,
universal_newlines=True,
preexec_fn=os.setsid if not reusables.win_based else None,
)
return Popen(command, shell=True, cwd=self.tempdir, stdout=PIPE, stderr=STDOUT, encoding="utf-8")

def is_alive(self):
if not self.process:
Expand All @@ -164,13 +154,8 @@ def kill(self):
logger.info(f"Killing worker process {self.process.pid}")
if self.process:
try:
if reusables.win_based:
os.kill(self.process.pid, signal.CTRL_C_EVENT)
else:
os.killpg(os.getpgid(self.process.pid), signal.SIGTERM)
self.process.terminate()
except Exception as err:
logger.exception(f"Couldn't terminate process: {err}")
self.killed = True
self.app.cancelled.emit()
self.exit()
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "fastflix"
version = "2.6.2"
version = "2.6.3"
description = "Easy to use video encoder GUI wrapper"
authors = ["Chris Griffith <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit b437d03

Please sign in to comment.