feat: ExportWorker with ffmpeg command builder
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
from PyQt6.QtCore import QThread, pyqtSignal
|
||||||
from PyQt6.QtWidgets import QApplication, QMainWindow
|
from PyQt6.QtWidgets import QApplication, QMainWindow
|
||||||
|
|
||||||
|
|
||||||
@@ -14,6 +16,40 @@ def format_time(seconds: float) -> str:
|
|||||||
return f"{m}:{s:04.1f}"
|
return f"{m}:{s:04.1f}"
|
||||||
|
|
||||||
|
|
||||||
|
def build_ffmpeg_command(input_path: str, start: float, output_path: str) -> list:
|
||||||
|
return [
|
||||||
|
"ffmpeg", "-y",
|
||||||
|
"-ss", str(start),
|
||||||
|
"-i", input_path,
|
||||||
|
"-t", "8",
|
||||||
|
"-c:v", "libx264",
|
||||||
|
"-c:a", "aac",
|
||||||
|
output_path,
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class ExportWorker(QThread):
|
||||||
|
finished = pyqtSignal(str) # output path
|
||||||
|
error = pyqtSignal(str) # error message
|
||||||
|
|
||||||
|
def __init__(self, input_path: str, start: float, output_path: str):
|
||||||
|
super().__init__()
|
||||||
|
self._input = input_path
|
||||||
|
self._start = start
|
||||||
|
self._output = output_path
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
cmd = build_ffmpeg_command(self._input, self._start, self._output)
|
||||||
|
try:
|
||||||
|
result = subprocess.run(cmd, capture_output=True, text=True, timeout=120)
|
||||||
|
if result.returncode == 0:
|
||||||
|
self.finished.emit(self._output)
|
||||||
|
else:
|
||||||
|
self.error.emit(result.stderr[-500:])
|
||||||
|
except Exception as e:
|
||||||
|
self.error.emit(str(e))
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
win = MainWindow()
|
win = MainWindow()
|
||||||
|
|||||||
+11
-1
@@ -1,4 +1,4 @@
|
|||||||
from main import build_export_path, format_time
|
from main import build_export_path, format_time, build_ffmpeg_command
|
||||||
|
|
||||||
|
|
||||||
def test_build_export_path_first():
|
def test_build_export_path_first():
|
||||||
@@ -21,3 +21,13 @@ def test_format_time_rounding():
|
|||||||
|
|
||||||
def test_format_time_no_sixty_rollover():
|
def test_format_time_no_sixty_rollover():
|
||||||
assert format_time(59.95) == "0:59.9"
|
assert format_time(59.95) == "0:59.9"
|
||||||
|
|
||||||
|
|
||||||
|
def test_ffmpeg_command():
|
||||||
|
cmd = build_ffmpeg_command("/in/video.mp4", 12.5, "/out/clip_001.mp4")
|
||||||
|
assert cmd[0] == "ffmpeg"
|
||||||
|
assert "-ss" in cmd
|
||||||
|
assert str(12.5) in cmd
|
||||||
|
assert "-t" in cmd
|
||||||
|
assert "8" in cmd
|
||||||
|
assert cmd[-1] == "/out/clip_001.mp4"
|
||||||
|
|||||||
Reference in New Issue
Block a user