Skip to content

Commit

Permalink
隐藏 ffmpeg 终端窗口
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiyiYo committed Feb 15, 2025
1 parent e83b2a6 commit a7f911a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
34 changes: 30 additions & 4 deletions app/service/ffmpeg_service.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,43 @@
# coding:utf-8
from pathlib import Path
import subprocess
from typing import Union
from PySide6.QtCore import Qt, Signal, Property, QObject
from PySide6.QtGui import QPixmap, QPainter, QColor
from PySide6.QtWidgets import QWidget, QHBoxLayout, QVBoxLayout
import sys
from PySide6.QtCore import QObject

import ffmpeg
from ffmpeg._run import output_operator

from ..common.config import cfg
from ..common.utils import removeFile


# monkey patch
@output_operator()
def patched_run_async(
stream_spec,
cmd='ffmpeg',
pipe_stdin=False,
pipe_stdout=False,
pipe_stderr=False,
quiet=False,
overwrite_output=False,
):
# hide windows console
creationflags = 0
if sys.platform == "win32":
creationflags = subprocess.CREATE_NO_WINDOW

args = ffmpeg._run.compile(stream_spec, cmd, overwrite_output=overwrite_output)
stdin_stream = subprocess.PIPE if pipe_stdin else None
stdout_stream = subprocess.PIPE if pipe_stdout or quiet else None
stderr_stream = subprocess.PIPE if pipe_stderr or quiet else None
return subprocess.Popen(
args, stdin=stdin_stream, stdout=stdout_stream, stderr=stderr_stream, creationflags=creationflags
)

ffmpeg._run.run_async = patched_run_async


class FFmpegService(QObject):

def __init__(self, parent=None):
Expand Down
2 changes: 1 addition & 1 deletion app/service/m3u8dl_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def _onDownloadFinished(self, process: QProcess, task: Task, code, status: QProc
if status == QProcess.ExitStatus.NormalExit:
# save cover
TaskExecutor.runTask(ffmpegService.saveVideoCover, task.videoPath, task.coverPath).then(
lambda: self.coverSaved.emit(task))
lambda: self.coverSaved.emit(task), lambda e: self.logger.error(e))

self.downloadFinished.emit(task, True, "")
task.success()
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ PySide6==6.6.2
PySide6-Fluent-Widgets>=1.7.4
m3u8
requests
ffmpeg-python
ffmpeg-python==0.2.0
nuitka==2.6.4

0 comments on commit a7f911a

Please sign in to comment.