Skip to content

Commit

Permalink
* Adding #345 Change the default priority of spawned tools (thanks to…
Browse files Browse the repository at this point in the history
… Maximo Piva)

* Adding #371 Add "Stay on Top" (thanks to Hexenhammer)
  • Loading branch information
cdgriffith committed Aug 16, 2022
1 parent de017a9 commit 480811d
Show file tree
Hide file tree
Showing 39 changed files with 196 additions and 100 deletions.
4 changes: 3 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
* Adding new GUI backend PySide6
* Adding default source directory (thanks to Battlestar1965)
* Adding hidden tabs for things that are not supported for a certain codec
* Fixing settings panel would always want a restart if any paths to executables were filled on windows
* Adding #345 Change the default priority of spawned tools (thanks to Maximo Piva)
* Adding #371 Add "Stay on Top" (thanks to Hexenhammer)
* Fixing settings panel would always want a restart if any paths to executables were filled on Windows
* Removing support and builds for Windows 7 and 8
* Removing support and builds for MacOS 10

Expand Down
33 changes: 30 additions & 3 deletions fastflix/command_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,36 @@
# -*- coding: utf-8 -*-
import datetime
import logging
import re
import secrets
import shlex
from pathlib import Path
from subprocess import PIPE
from threading import Thread

from psutil import Popen
from typing import Literal

from psutil import (
Popen,
HIGH_PRIORITY_CLASS,
REALTIME_PRIORITY_CLASS,
IDLE_PRIORITY_CLASS,
NORMAL_PRIORITY_CLASS,
ABOVE_NORMAL_PRIORITY_CLASS,
BELOW_NORMAL_PRIORITY_CLASS,
)

logger = logging.getLogger("fastflix-core")

__all__ = ["BackgroundRunner"]

priority_levels = {
"Realtime": REALTIME_PRIORITY_CLASS,
"High": HIGH_PRIORITY_CLASS,
"Above Normal": ABOVE_NORMAL_PRIORITY_CLASS,
"Normal": NORMAL_PRIORITY_CLASS,
"Below Normal": BELOW_NORMAL_PRIORITY_CLASS,
"Idle": IDLE_PRIORITY_CLASS,
}


class BackgroundRunner:
def __init__(self, log_queue):
Expand Down Expand Up @@ -70,6 +87,16 @@ def start_exec(self, command, work_dir: str = None, shell: bool = False, errors=

Thread(target=self.read_output).start()

def change_priority(
self, new_priority: Literal["Realtime", "High", "Above Normal", "Normal", "Below Normal", "Idle"]
):
try:
if self.process:
self.process.nice(priority_levels[new_priority])
logger.info(f"Set command priority to {new_priority}")
except Exception:
logger.exception(f"Could not set process priority to {new_priority}")

def read_output(self):
with open(self.output_file, "r", encoding="utf-8", errors="ignore") as out_file, open(
self.error_output_file, "r", encoding="utf-8", errors="ignore"
Expand Down
8 changes: 8 additions & 0 deletions fastflix/conversion_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
from pathlib import Path
from queue import Empty
from typing import Literal

import reusables
from appdirs import user_data_dir
Expand All @@ -27,6 +28,7 @@ def queue_worker(gui_proc, worker_queue, status_queue, log_queue):
command = None
work_dir = None
log_name = ""
priority: Literal["Realtime", "High", "Above Normal", "Normal", "Below Normal", "Idle"] = "Normal"

def start_command():
nonlocal currently_encoding
Expand All @@ -44,6 +46,7 @@ def start_command():
command,
work_dir=work_dir,
)
runner.change_priority(priority)

while True:
if currently_encoding and not runner.is_alive():
Expand Down Expand Up @@ -103,3 +106,8 @@ def start_command():
runner.resume()
except Exception:
logger.exception("Could not resume command")

if request[0] == "priority":
priority = request[1]
if runner.is_alive():
runner.change_priority(priority)
24 changes: 24 additions & 0 deletions fastflix/data/languages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6923,3 +6923,27 @@ No Default Source Folder:
por: Sem pasta de origem por defeito
swe: Ingen standardkällmapp
pol: Nie Domyślny folder źródłowy
Stay on Top:
eng: Stay on Top
deu: Oben bleiben
fra: Rester au top
ita: Rimanere al top
spa: Manténgase en la cima
zho: 保持巅峰状态
jpn: トップに君臨する
rus: Оставайтесь на вершине
por: Fique no topo
swe: Håll dig på topp
pol: Zostań na szczycie
Priority:
eng: Priority
deu: Priorität
fra: Priorité
ita: Priorità
spa: Prioridad
zho: 优先权
jpn: 優先順位
rus: Приоритет
por: Prioridade
swe: Prioritet
pol: Priorytet
3 changes: 1 addition & 2 deletions fastflix/encoders/common/attachments.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
from pathlib import Path
from typing import List

from fastflix.models.encode import AttachmentTrack
from fastflix.shared import clean_file_string
Expand All @@ -15,7 +14,7 @@ def image_type(file: Path):
return mime_type, ext_type


def build_attachments(attachments: List[AttachmentTrack]) -> str:
def build_attachments(attachments: list[AttachmentTrack]) -> str:

commands = []
for attachment in attachments:
Expand Down
7 changes: 3 additions & 4 deletions fastflix/encoders/common/encc_helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from typing import List, Dict
import logging

from fastflix.models.video import SubtitleTrack, AudioTrack
Expand All @@ -9,11 +8,11 @@
logger = logging.getLogger("fastflix")


def get_stream_pos(streams) -> Dict:
def get_stream_pos(streams) -> dict:
return {x.index: i for i, x in enumerate(streams, start=1)}


def build_audio(audio_tracks: List[AudioTrack], audio_streams):
def build_audio(audio_tracks: list[AudioTrack], audio_streams):
command_list = []
copies = []
track_ids = set()
Expand Down Expand Up @@ -47,7 +46,7 @@ def build_audio(audio_tracks: List[AudioTrack], audio_streams):
return f" --audio-copy {','.join(copies)} {' '.join(command_list)}" if copies else f" {' '.join(command_list)}"


def build_subtitle(subtitle_tracks: List[SubtitleTrack], subtitle_streams, video_height: int) -> str:
def build_subtitle(subtitle_tracks: list[SubtitleTrack], subtitle_streams, video_height: int) -> str:
command_list = []
copies = []
stream_ids = get_stream_pos(subtitle_streams)
Expand Down
4 changes: 2 additions & 2 deletions fastflix/encoders/common/helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
import uuid
from pathlib import Path
from typing import List, Tuple, Union, Optional, Dict
from typing import Tuple, Union, Optional

import reusables
from pydantic import BaseModel, Field
Expand Down Expand Up @@ -107,7 +107,7 @@ def generate_ending(
def generate_filters(
selected_track,
source=None,
crop: Optional[Dict] = None,
crop: Optional[dict] = None,
scale=None,
scale_filter="lanczos",
remove_hdr=False,
Expand Down
2 changes: 1 addition & 1 deletion fastflix/encoders/common/subtitles.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


def build_subtitle(
subtitle_tracks: List[SubtitleTrack], subtitle_file_index=0
subtitle_tracks: list[SubtitleTrack], subtitle_file_index=0
) -> Tuple[str, Union[int, None], Union[str, None]]:
command_list = []
burn_in_track = None
Expand Down
3 changes: 0 additions & 3 deletions fastflix/encoders/ffmpeg_hevc_nvenc/settings_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
from PySide6 import QtCore, QtWidgets

from fastflix.encoders.common.setting_panel import SettingPanel
from fastflix.language import t
from fastflix.models.encode import FFmpegNVENCSettings
from fastflix.models.fastflix_app import FastFlixApp
from fastflix.shared import link
from fastflix.exceptions import FastFlixInternalException

logger = logging.getLogger("fastflix")

Expand Down
2 changes: 1 addition & 1 deletion fastflix/encoders/h264_videotoolbox/settings_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging

from box import Box
from PySide6 import QtCore, QtWidgets
from PySide6 import QtWidgets

from fastflix.encoders.common.setting_panel import SettingPanel
from fastflix.models.encode import H264VideoToolboxSettings
Expand Down
4 changes: 1 addition & 3 deletions fastflix/encoders/hevc_videotoolbox/settings_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
import logging

from box import Box
from PySide6 import QtCore, QtWidgets
from PySide6 import QtWidgets

from fastflix.encoders.common.setting_panel import SettingPanel
from fastflix.language import t
from fastflix.models.encode import HEVCVideoToolboxSettings
from fastflix.models.fastflix_app import FastFlixApp
from fastflix.shared import link

logger = logging.getLogger("fastflix")

Expand Down
2 changes: 0 additions & 2 deletions fastflix/encoders/hevc_x265/settings_panel.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
from pathlib import Path

from box import Box
from PySide6 import QtCore, QtGui, QtWidgets

from fastflix.encoders.common.setting_panel import SettingPanel
Expand Down
2 changes: 0 additions & 2 deletions fastflix/encoders/nvencc_avc/settings_panel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
import logging
from typing import List, Optional

from box import Box
from PySide6 import QtCore, QtWidgets, QtGui
Expand All @@ -10,7 +9,6 @@
from fastflix.models.encode import NVEncCAVCSettings
from fastflix.models.fastflix_app import FastFlixApp
from fastflix.shared import link
from fastflix.exceptions import FastFlixInternalException
from fastflix.resources import loading_movie, get_icon

logger = logging.getLogger("fastflix")
Expand Down
2 changes: 0 additions & 2 deletions fastflix/encoders/nvencc_hevc/settings_panel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
import logging
from typing import List, Optional

from box import Box
from PySide6 import QtCore, QtWidgets, QtGui
Expand All @@ -10,7 +9,6 @@
from fastflix.models.encode import NVEncCSettings
from fastflix.models.fastflix_app import FastFlixApp
from fastflix.shared import link
from fastflix.exceptions import FastFlixInternalException
from fastflix.resources import loading_movie, get_icon

logger = logging.getLogger("fastflix")
Expand Down
4 changes: 1 addition & 3 deletions fastflix/encoders/qsvencc_avc/settings_panel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
import logging
from typing import List, Optional

from box import Box
from PySide6 import QtCore, QtWidgets, QtGui
Expand All @@ -10,8 +9,7 @@
from fastflix.models.encode import QSVEncCH264Settings
from fastflix.models.fastflix_app import FastFlixApp
from fastflix.shared import link
from fastflix.exceptions import FastFlixInternalException
from fastflix.resources import loading_movie, get_icon
from fastflix.resources import get_icon

logger = logging.getLogger("fastflix")

Expand Down
2 changes: 0 additions & 2 deletions fastflix/encoders/qsvencc_hevc/settings_panel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
import logging
from typing import List, Optional

from box import Box
from PySide6 import QtCore, QtWidgets, QtGui
Expand All @@ -10,7 +9,6 @@
from fastflix.models.encode import QSVEncCSettings
from fastflix.models.fastflix_app import FastFlixApp
from fastflix.shared import link
from fastflix.exceptions import FastFlixInternalException
from fastflix.resources import loading_movie, get_icon

logger = logging.getLogger("fastflix")
Expand Down
6 changes: 3 additions & 3 deletions fastflix/encoders/svt_av1_avif/command_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@reusables.log_exception("fastflix", show_traceback=True)
def build(fastflix: FastFlix):
settings: SVTAVIFSettings = fastflix.current_video.video_settings.video_encoder_settings
beginning, ending = generate_all(fastflix, "libsvtav1", audio=False, subs=False)
beginning, ending = generate_all(fastflix, "libsvtav1", audio=False)

beginning += f"-strict experimental " f"-preset {settings.speed} " f"{generate_color_details(fastflix)} "

Expand Down Expand Up @@ -74,10 +74,10 @@ def convert_me(two_numbers, conversion_rate=50_000) -> str:
pass_type = "bitrate" if settings.bitrate else "QP"

if settings.bitrate:
command_1 = f"{beginning} -b:v {settings.bitrate} {settings.extra} {ending}"
command_1 = f"{beginning} -b:v {settings.bitrate} {settings.extra} {ending} -f avif "

elif settings.qp is not None:
command_1 = f"{beginning} -{settings.qp_mode} {settings.qp} {settings.extra} {ending}"
command_1 = f"{beginning} -{settings.qp_mode} {settings.qp} {settings.extra} {ending} -f avif "
else:
return []
return [Command(command=command_1, name=f"{pass_type}", exe="ffmpeg")]
2 changes: 1 addition & 1 deletion fastflix/encoders/svt_av1_avif/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
video_dimension_divisor = 8
icon = str(Path(pkg_resources.resource_filename(__name__, f"../../data/encoders/icon_svt_av1.png")).resolve())

enable_subtitles = False
enable_subtitles = True
enable_audio = False
enable_attachments = False
enable_concat = True
Expand Down
6 changes: 3 additions & 3 deletions fastflix/ff_queue.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from typing import List, Optional
from typing import Optional
import os
from pathlib import Path
import logging
Expand All @@ -17,7 +17,7 @@
logger = logging.getLogger("fastflix")


def get_queue(queue_file: Path) -> List[Video]:
def get_queue(queue_file: Path) -> list[Video]:
if not queue_file.exists():
return []

Expand Down Expand Up @@ -68,7 +68,7 @@ def get_queue(queue_file: Path) -> List[Video]:
return queue


def save_queue(queue: List[Video], queue_file: Path, config: Optional[Config] = None):
def save_queue(queue: list[Video], queue_file: Path, config: Optional[Config] = None):
items = []

if config is not None:
Expand Down
Loading

0 comments on commit 480811d

Please sign in to comment.