Skip to content

Commit 8e6af48

Browse files
committed
Deprecate ffmpeg-python
1 parent 05e4473 commit 8e6af48

File tree

4 files changed

+30
-37
lines changed

4 files changed

+30
-37
lines changed

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ requires-python = ">=3.10"
1010
dependencies = [
1111
"faster-whisper>=1.0.3",
1212
"transformers>=4.39.3",
13-
"ffmpeg-python>=0.2.0",
1413
"torch>=2.2.2",
1514
"accelerate>=0.29.3",
1615
"cyclopts>=2.9.9",

src/koffee/overlay.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
"""Subtitle overlayer."""
22

33
import logging
4+
import subprocess
45
from pathlib import Path
56

6-
import ffmpeg
7-
87
from koffee.exceptions import SubtitleOverlayError
98

109
log = logging.getLogger(__name__)
@@ -18,12 +17,25 @@ def overlay_subtitles(
1817
"""Overlay subtitles to a video file."""
1918
log.info("Overlaying subtitles.")
2019

20+
cmd = [
21+
"ffmpeg",
22+
"-i",
23+
str(video_file_path),
24+
"-i",
25+
str(subtitle_file_path),
26+
"-c",
27+
"copy",
28+
"-c:s",
29+
"mov_text",
30+
"-metadata:s:s:0",
31+
"language=eng",
32+
"-y",
33+
str(output_file_path),
34+
]
35+
2136
try:
22-
ffmpeg.input(video_file_path).output(
23-
str(output_file_path), vf=f"subtitles={subtitle_file_path}"
24-
).run(overwrite_output=True, capture_stdout=True, capture_stderr=True)
25-
except ffmpeg.Error as error:
26-
error_message = error.stderr.decode("utf-8")
27-
raise SubtitleOverlayError(error_message) from error
37+
subprocess.run(cmd, capture_output=True, text=True, check=True)
38+
except subprocess.CalledProcessError as error:
39+
raise SubtitleOverlayError(error.stderr) from error
2840

2941
return output_file_path

tests/test_overlay.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""Tests for subtitle overlay."""
22

3+
import subprocess
34
from pathlib import Path
45

5-
import ffmpeg
66
import pytest
77
from pytest_mock import MockerFixture
88

@@ -44,10 +44,15 @@ def test_exception_handling(
4444
mocker: MockerFixture,
4545
) -> None:
4646
"""Tests that exception is caught and an error is raised."""
47-
mocker.patch("ffmpeg.input", side_effect=ffmpeg.Error("ffmpeg", "", b"FFmpegError"))
47+
mocker.patch(
48+
"subprocess.run",
49+
side_effect=subprocess.CalledProcessError(
50+
returncode=1, cmd=["ffmpeg"], stderr="FFmpegError"
51+
),
52+
)
4853

4954
with pytest.raises(SubtitleOverlayError) as exc_info:
5055
overlay_subtitles(subtitle_file_path, video_file_path, output_file_path)
5156

52-
assert isinstance(exc_info.value.__cause__, ffmpeg.Error)
57+
assert isinstance(exc_info.value.__cause__, subprocess.CalledProcessError)
5358
assert "FFmpegError" in str(exc_info.value)

uv.lock

Lines changed: 2 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)