diff --git a/danmaku_workflow.py b/danmaku_workflow.py index 534cbd8..cdceaed 100644 --- a/danmaku_workflow.py +++ b/danmaku_workflow.py @@ -4,16 +4,17 @@ import platform import subprocess import sys import threading +from hashlib import md5 from typing import Optional, IO, Union from datetime import datetime, timedelta from PyQt5 import QtGui from PyQt5.QtCore import Qt, QThread, pyqtSignal from PyQt5.QtWidgets import QWidget, QLabel, QApplication, QFrame, QVBoxLayout, QPushButton, \ - QSizePolicy, QMessageBox, QProgressBar -from danmaku_xml_helper import get_file_start, diff_danmaku_files, danmaku_to_subtitle + QSizePolicy, QMessageBox +from danmaku_xml_helper import get_file_start, diff_danmaku_files from config import load_config, FFMPEG_EXEC, DANMAKU_FACTORY_EXEC, FFMPEG_USE_INTEL_GPU, FFMPEG_USE_NVIDIA_GPU, \ - VIDEO_BITRATE, VIDEO_CLIP_EACH_SEC, VIDEO_CLIP_OVERFLOW_SEC + VIDEO_BITRATE, VIDEO_CLIP_EACH_SEC, VIDEO_CLIP_OVERFLOW_SEC, VIDEO_RESOLUTION, DANMAKU_SPEED, DEFAULT_FONT_NAME class Job: @@ -329,7 +330,7 @@ class WorkerThread(QThread): "-qmin", "10", "-qmax", "32", "-crf", "16", # "-t", "10", new_filename - ], stdout=subprocess.PIPE) + ], **subprocess_args(True)) elif FFMPEG_USE_INTEL_GPU: if platform.system().lower() == "windows": print("[+]Use Intel QSV Acceleration") @@ -343,7 +344,7 @@ class WorkerThread(QThread): "-qmin", "10", "-qmax", "32", "-crf", "16", # "-t", "10", new_filename - ], stdout=subprocess.PIPE) + ], **subprocess_args(True)) else: print("[+]Use Intel VAAPI Acceleration") encode_process = subprocess.Popen([ @@ -356,7 +357,7 @@ class WorkerThread(QThread): "-qmin", "10", "-qmax", "32", "-crf", "16", # "-t", "10", new_filename - ], stdout=subprocess.PIPE) + ], **subprocess_args(True)) else: print("[+]Use CPU Encode") encode_process = subprocess.Popen([ @@ -369,7 +370,7 @@ class WorkerThread(QThread): "-qmin", "10", "-qmax", "32", "-crf", "16", # "-t", "10", new_filename - ], stdout=subprocess.PIPE) + ], **subprocess_args(True)) self.handle_ffmpeg_output(encode_process.stdout) return encode_process.wait() @@ -533,6 +534,18 @@ def base_ts_to_filename(start_ts: float, is_mp4=False) -> str: return base_start.strftime("%Y%m%d_%H%M.flv") +def danmaku_to_subtitle(file: Union[os.PathLike[str], str], time_shift: float): + new_subtitle_name = md5(file.encode("utf-8")).hexdigest() + ".ass" + process = subprocess.Popen(( + DANMAKU_FACTORY_EXEC, "--ignore-warnings", + "-r", str(VIDEO_RESOLUTION), "-s", str(DANMAKU_SPEED), "-f", "5", + "-S", "40", "-N", str(DEFAULT_FONT_NAME), "--showmsgbox", "FALSE", + "-O", "255", "-L", "1", "-D", "0", + "-o", "ass", new_subtitle_name, "-i", file, "-t", str(time_shift) + ), **subprocess_args(True)) + process.wait() + return new_subtitle_name + # Create a set of arguments which make a ``subprocess.Popen`` (and # variants) call work with or without Pyinstaller, ``--noconsole`` or # not, on Windows and Linux. Typical use:: @@ -588,7 +601,7 @@ def check_exec(name: Union[os.PathLike[str], str]) -> bool: if is_windows(): check_process = subprocess.Popen([ "where.exe", name - ], stdout=subprocess.PIPE) + ], **subprocess_args(True)) check_process.wait() return len(check_process.stdout.readlines()) > 0 elif is_linux(): diff --git a/danmaku_xml_helper.py b/danmaku_xml_helper.py index 0fb6c46..fb82b79 100644 --- a/danmaku_xml_helper.py +++ b/danmaku_xml_helper.py @@ -1,8 +1,6 @@ import datetime import os import argparse -import subprocess -from hashlib import md5 from typing import Union from bs4 import BeautifulSoup @@ -43,19 +41,6 @@ def diff_danmaku_files(base_file: Union[os.PathLike[str], str], file: Union[os.P return get_file_start(file) - get_file_start(base_file) -def danmaku_to_subtitle(file: Union[os.PathLike[str], str], time_shift: float): - new_subtitle_name = md5(file.encode("utf-8")).hexdigest() + ".ass" - process = subprocess.Popen(( - DANMAKU_FACTORY_EXEC, "--ignore-warnings", - "-r", str(VIDEO_RESOLUTION), "-s", str(DANMAKU_SPEED), "-f", "5", - "-S", "40", "-N", str(DEFAULT_FONT_NAME), "--showmsgbox", "FALSE", - "-O", "255", "-L", "1", "-D", "0", - "-o", "ass", new_subtitle_name, "-i", file, "-t", str(time_shift) - )) - process.wait() - return new_subtitle_name - - if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument("base", help="以此为标准")