Skip to content

Commit

Permalink
Use PyAV only for rendering video
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattBlue committed Oct 16, 2024
1 parent a170bf2 commit 578a145
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 207 deletions.
37 changes: 0 additions & 37 deletions auto_editor/ffwrapper.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from __future__ import annotations

import os.path
import sys
from dataclasses import dataclass
from fractions import Fraction
from pathlib import Path
from re import search
from shutil import which
from subprocess import PIPE, Popen, run
from typing import Any
Expand Down Expand Up @@ -52,41 +50,6 @@ def run(self, cmd: list[str]) -> None:
sys.stderr.write(f"{' '.join(cmd)}\n\n")
run(cmd)

def run_check_errors(
self, cmd: list[str], show_out: bool = False, path: str | None = None
) -> None:
process = self.Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
_, stderr = process.communicate()

if process.stdin is not None:
process.stdin.close()
output = stderr.decode("utf-8", "replace")

error_list = (
r"Unknown encoder '.*'",
r"-q:v qscale not available for encoder\. Use -b:v bitrate instead\.",
r"Specified sample rate .* is not supported",
r'Unable to parse option value ".*"',
r"Error setting option .* to value .*\.",
r"Undefined constant or missing '.*' in '.*'",
r"DLL .* failed to open",
r"Incompatible pixel format '.*' for codec '[A-Za-z0-9_]*'",
r"Unrecognized option '.*'",
r"Permission denied",
)

if self.debug:
print(f"stderr: {output}")

for item in error_list:
if check := search(item, output):
self.log.error(check.group())

if path is not None and not os.path.isfile(path):
self.log.error(f"The file {path} was not created.")
if show_out and not self.debug:
print(f"stderr: {output}")

def Popen(
self, cmd: list[str], stdin: Any = None, stdout: Any = PIPE, stderr: Any = None
) -> Popen:
Expand Down
23 changes: 22 additions & 1 deletion auto_editor/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import os.path
from dataclasses import dataclass, field
from fractions import Fraction
from re import search
from subprocess import PIPE

import av
from av.audio.resampler import AudioResampler
Expand Down Expand Up @@ -222,4 +224,23 @@ def mux_quality_media(
cmd.extend(["-map", "0:d?"])

cmd.append(output_path)
ffmpeg.run_check_errors(cmd, path=output_path)

process = ffmpeg.Popen(cmd, stdout=PIPE, stderr=PIPE)
stderr = process.communicate()[1].decode("utf-8", "replace")
error_list = (
r"Unknown encoder '.*'",
r"-q:v qscale not available for encoder\. Use -b:v bitrate instead\.",
r"Specified sample rate .* is not supported",
r'Unable to parse option value ".*"',
r"Error setting option .* to value .*\.",
r"DLL .* failed to open",
r"Incompatible pixel format '.*' for codec '[A-Za-z0-9_]*'",
r"Unrecognized option '.*'",
r"Permission denied",
)
for item in error_list:
if check := search(item, stderr):
log.error(check.group())

if not os.path.isfile(output_path):
log.error(f"The file {output_path} was not created.")
Loading

0 comments on commit 578a145

Please sign in to comment.