Skip to content

Commit

Permalink
Initial work for hdr10plus injection
Browse files Browse the repository at this point in the history
cdgriffith committed Feb 8, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 8523fcf commit c7f9c23
Showing 3 changed files with 163 additions and 0 deletions.
11 changes: 11 additions & 0 deletions fastflix/widgets/container.py
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@
from fastflix.widgets.settings import Settings
from fastflix.widgets.windows.concat import ConcatWindow
from fastflix.widgets.windows.multiple_files import MultipleFilesWindow
from fastflix.widgets.windows.hdr10plus_inject import HDR10PlusInjectWindow

logger = logging.getLogger("fastflix")

@@ -213,6 +214,12 @@ def init_menu(self):
concat_action.triggered.connect(self.show_concat)
tools_menu.addAction(concat_action)

hdr10p_inject_action = QAction(
QtGui.QIcon(get_icon("onyx-queue", self.app.fastflix.config.theme)), t("HDR10+ Inject"), self
)
hdr10p_inject_action.triggered.connect(self.show_hdr10p_inject)
tools_menu.addAction(hdr10p_inject_action)

wiki_action = QAction(self.si(QtWidgets.QStyle.SP_FileDialogInfoView), t("FastFlix Wiki"), self)
wiki_action.triggered.connect(self.show_wiki)

@@ -266,6 +273,10 @@ def show_concat(self):
self.concat = ConcatWindow(app=self.app, main=self.main)
self.concat.show()

def show_hdr10p_inject(self):
self.hdr10p_inject = HDR10PlusInjectWindow(app=self.app, main=self.main)
self.hdr10p_inject.show()

def show_about(self):
self.about = About(app=self.app)
self.about.show()
134 changes: 134 additions & 0 deletions fastflix/widgets/windows/hdr10plus_inject.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# -*- coding: utf-8 -*-
from pathlib import Path
import os
import logging
import secrets

from PySide6 import QtWidgets, QtGui, QtCore
from PySide6.QtWidgets import QAbstractItemView

from fastflix.language import t
from fastflix.flix import probe
from fastflix.shared import yes_no_message, error_message
from fastflix.widgets.progress_bar import ProgressBar, Task
from fastflix.resources import group_box_style, get_icon

logger = logging.getLogger("fastflix")


class HDR10PlusInjectWindow(QtWidgets.QWidget):
def __init__(self, app, main, items=None):
super().__init__(None)
self.app = app
self.main = main
self.selected_stream = None

self.movie_file = QtWidgets.QLineEdit()
self.movie_file.setEnabled(False)
self.movie_file.setFixedWidth(400)
self.movie_file_button = QtWidgets.QPushButton(
icon=QtGui.QIcon(get_icon("onyx-output", self.app.fastflix.config.theme))
)
self.movie_file_button.clicked.connect(self.movie_open)

self.hdr10p_file = QtWidgets.QLineEdit()
self.hdr10p_file.setEnabled(False)
self.hdr10p_file_button = QtWidgets.QPushButton(
icon=QtGui.QIcon(get_icon("onyx-output", self.app.fastflix.config.theme))
)
self.hdr10p_file_button.clicked.connect(self.hdr10p_open)

self.output_file = QtWidgets.QLineEdit()
self.output_file.setFixedWidth(400)
self.output_file_button = QtWidgets.QPushButton(
icon=QtGui.QIcon(get_icon("onyx-output", self.app.fastflix.config.theme))
)
self.output_file_button.clicked.connect(self.set_output_file)
self.output_file.textChanged.connect(self.prep_command)

line_1 = QtWidgets.QHBoxLayout()
line_1.addWidget(QtWidgets.QLabel("Movie File"))
line_1.addWidget(self.movie_file)
line_1.addWidget(self.movie_file_button)

line_3 = QtWidgets.QHBoxLayout()
line_3.addWidget(QtWidgets.QLabel("HDR10+ File"))
line_3.addWidget(self.hdr10p_file)
line_3.addWidget(self.hdr10p_file_button)

self.info_bubble = QtWidgets.QLabel("")
self.command_bubble = QtWidgets.QLabel("")
self.command_bubble.setFixedWidth(400)
self.command_bubble.setWordWrap(True)
self.command_bubble.setFixedHeight(400)

layout = QtWidgets.QVBoxLayout()

output_lin = QtWidgets.QHBoxLayout()
output_lin.addWidget(QtWidgets.QLabel("Output File"))
output_lin.addWidget(self.output_file)
output_lin.addWidget(self.output_file_button)

layout.addLayout(line_1)
layout.addWidget(self.info_bubble)
layout.addLayout(line_3)
layout.addLayout(output_lin)
layout.addWidget(self.command_bubble)
self.setLayout(layout)

def movie_open(self):
self.selected_stream = None
self.movie_file.setText("")
movie_name = QtWidgets.QFileDialog.getOpenFileName(self)
if not movie_name or not movie_name[0]:
return
try:
results = probe(self.app, movie_name[0])
except Exception as err:
error_message(f"Invalid file: {err}")
return
for result in results["streams"]:
if result["codec_type"] == "video":
if result["codec_name"] == "hevc":
self.selected_stream = result
break
if not self.selected_stream:
error_message("No HEVC video stream found")
return
self.info_bubble.setText(f"Selected stream index: {self.selected_stream['index']}")
self.movie_file.setText(movie_name[0])
self.prep_command()

def hdr10p_open(self):
hdr10p_file = QtWidgets.QFileDialog.getOpenFileName(self)
if not hdr10p_file or not hdr10p_file[0]:
return
self.hdr10p_file.setText(hdr10p_file[0])
self.prep_command()

def set_output_file(self):
filename = QtWidgets.QFileDialog.getSaveFileName(
self,
caption="Save Video As",
# dir=str(Path(*self.generate_output_filename)) + f"{self.widgets.output_type_combo.currentText()}",
# filter=f"Save File (*.{extension})",
)
if filename and filename[0]:
self.output_file.setText(filename[0])
self.prep_command()

def prep_command(self):
print("called prep")
if not self.movie_file.text() or not self.hdr10p_file.text() or not self.output_file.text():
print("Nope", "1", self.movie_file.text(), "2", self.hdr10p_file.text(), "3", self.output_file.text())
return

command = (
f'{self.app.fastflix.config.ffmpeg} -loglevel panic -i "{self.movie_file.text()}" '
f'-map 0:{self.selected_stream["index"]} -c:v copy -vbsf hevc_mp4toannexb -f hevc - | '
f"{self.app.fastflix.config.hdr10plus_parser} inject -i - -j {self.hdr10p_file.text()} -o - | "
f'{self.app.fastflix.config.ffmpeg} -loglevel panic -i - -i {self.movie_file.text()} -map 0:0 -c:0 copy -map 1:a -map 1:s -map 1:d -c:1 copy "{self.output_file.text()}"'
)
print(command)

self.command_bubble.setText(command)
18 changes: 18 additions & 0 deletions tests/test_application.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# -*- coding: utf-8 -*-
from unittest.mock import MagicMock

from box import Box

from fastflix.application import init_encoders, create_app
from fastflix.models.config import Config

# from fastflix.widgets.container import Container

# import pytest

fake_app = Box(default_box=True)
fake_app.fastflix.config = Config()

@@ -13,6 +19,18 @@ def test_init_encoders():
assert "encoders" in fake_app.fastflix


# def test_app(qtbot):
# # app = create_app(enable_scaling=False)
# container = Container(MagicMock())
# qtbot.addWidget(container)
# from pytestqt.qt_compat import qt_api
#
# qtbot.mouseClick(container.menuBar(), qt_api.QtCore.Qt.MouseButton.LeftButton)
#
# assert container.menuBar().actions()[0].text() == "File"
# #assert widget.greet_label.text() == "Hello!"


# def test_get_ffmpeg_version():
# ffmpeg_configuration(fake_app, fake_app.fastflix.config)
# assert getattr(fake_app.fastflix, "ffmpeg_version")

0 comments on commit c7f9c23

Please sign in to comment.