ffmpeg-python-helper 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,9 @@
1
+ from .ffmpeg_api import FFMPEG
2
+
3
+ __all__ = [
4
+ 'FFMPEG'
5
+ ]
6
+
7
+ def main():
8
+ ffmpeg = FFMPEG()
9
+ print(ffmpeg.executable)
@@ -0,0 +1,4 @@
1
+ [diffend] Oversized file quarantined before diffing.
2
+ name: ffmpeg_python_helper/_bundled/ffmpeg.exe
3
+ size: 105674240 bytes
4
+ sha256: f1dd57a9afb2893250fe3ea227899eb4779cbe8c2a2d0915761f2318a09140ca
@@ -0,0 +1,121 @@
1
+ import subprocess
2
+ from pathlib import Path
3
+
4
+ class FFMPEG:
5
+ def __init__(self) -> None:
6
+ import shutil
7
+ self.executable = shutil.which('ffmpeg')
8
+
9
+ if self.executable is None:
10
+ raise FileNotFoundError("""
11
+ FFmpeg is not installed or could not be found in PATH.
12
+ Please install FFmpeg and make sure it is available
13
+ in your system PATH.
14
+ """)
15
+
16
+ @classmethod
17
+ def api(cls):
18
+ return cls()
19
+
20
+ def execute(self, *args : str):
21
+ if self.executable:
22
+ result = subprocess.run([self.executable, *args], capture_output=True, text=True)
23
+ return result.stdout.strip(), result.stderr.strip()
24
+
25
+ raise FileNotFoundError("""
26
+ No ffmpeg executable found.
27
+
28
+ Please Install ffmpeg first.
29
+ """)
30
+
31
+ def reformat(self, input_file : str, output_file : str):
32
+ if not Path(input_file).exists():
33
+ raise FileNotFoundError(f"""
34
+ Input file {input_file} did not found .
35
+
36
+ Please check filename and directory if correct.
37
+ """)
38
+
39
+ stdout, stderr = self.execute("-i", input_file, output_file)
40
+
41
+ if stdout:
42
+ print(stdout)
43
+ else:
44
+ print(stderr)
45
+
46
+ def gif(self,
47
+ input_file : str,
48
+ output_file : str,
49
+ fps = 10,
50
+ scale = 320
51
+ ):
52
+ input_path = Path(input_file)
53
+ output_path = Path(output_file)
54
+
55
+ if not input_path.exists():
56
+ raise FileNotFoundError(
57
+ f"Input file {input_file} was not found."
58
+ )
59
+
60
+ filter_graph : str = (
61
+ f"fps={fps},"
62
+ f"scale={scale}:-1:flags=lanczos,"
63
+ "split[s0][s1];"
64
+ "[s0]palettegen[p];"
65
+ "[s1][p]paletteuse"
66
+ )
67
+
68
+ stdout, stderr = self.execute(
69
+ "-y",
70
+ "-i", str(input_path),
71
+ "-vf", filter_graph,
72
+ str(output_path),
73
+ )
74
+
75
+ if not output_path.exists():
76
+ raise RuntimeError(
77
+ f"GIF was not created: {output_file}"
78
+ )
79
+
80
+ return stdout, stderr
81
+
82
+ def trim(
83
+ self,
84
+ input_file: str,
85
+ output_file: str,
86
+ start: float = 0,
87
+ duration: float | None = None,
88
+ ):
89
+ input_path = Path(input_file)
90
+ output_path = Path(output_file)
91
+
92
+ if not input_path.exists():
93
+ raise FileNotFoundError(
94
+ f"Input file {input_file} was not found."
95
+ )
96
+
97
+ if start < 0:
98
+ raise ValueError("start must be greater than or equal to 0")
99
+
100
+ if duration is not None and duration <= 0:
101
+ raise ValueError("duration must be greater than 0")
102
+
103
+ args = [
104
+ "-y",
105
+ "-ss", str(start),
106
+ "-i", str(input_path),
107
+ ]
108
+
109
+ if duration is not None:
110
+ args.extend(["-t", str(duration)])
111
+
112
+ args.append(str(output_path))
113
+
114
+ stdout, stderr = self.execute(*args)
115
+
116
+ if not output_path.exists():
117
+ raise RuntimeError(
118
+ f"Trimmed video was not created: {output_file}"
119
+ )
120
+
121
+ return stdout, stderr
@@ -0,0 +1,9 @@
1
+ Metadata-Version: 2.3
2
+ Name: ffmpeg-python-helper
3
+ Version: 0.1.0
4
+ Summary: Add your description here
5
+ Author: marjon
6
+ Author-email: marjon <marjongodito@gmanmi.com>
7
+ Requires-Python: >=3.14
8
+ Description-Content-Type: text/markdown
9
+
@@ -0,0 +1,7 @@
1
+ ffmpeg_python_helper/__init__.py,sha256=_8jV2YNFzNWRGPEeiXCPrNqgW6w1sdJ9XWoPjK5h33Q,123
2
+ ffmpeg_python_helper/_bundled/ffmpeg.exe,sha256=8d1Xqa-yiTJQ_j6iJ4metHecvowqLQkVdh8jGKCRQMo,105674240
3
+ ffmpeg_python_helper/ffmpeg_api.py,sha256=BbOzeaAepWrGvi--YmFJkQedsSMJ-NT4XRYRp2JRMxY,3317
4
+ ffmpeg_python_helper-0.1.0.dist-info/WHEEL,sha256=y6e-a5KI2W-qDAJKfh9Xr81bin8NgUdfWgz3VSXXpe4,80
5
+ ffmpeg_python_helper-0.1.0.dist-info/entry_points.txt,sha256=M9t-tNA-GePbZIBMosX7vgLqg88pjImAYzSQ_fErZzA,68
6
+ ffmpeg_python_helper-0.1.0.dist-info/METADATA,sha256=A9Yu67-lbGGrN8Fj8O8nKv5O2ODInjKhETTvbU7P_bw,226
7
+ ffmpeg_python_helper-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: uv 0.12.9
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ ffmpeg-python-helper = ffmpeg_python_helper:main
3
+