typed-ffmpeg-compatible 3.0.1__py3-none-any.whl → 3.2.1__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.
- typed_ffmpeg/__init__.py +2 -1
- typed_ffmpeg/_version.py +21 -0
- typed_ffmpeg/compile/compile_cli.py +413 -13
- typed_ffmpeg/compile/compile_python.py +3 -4
- typed_ffmpeg/ffprobe/__init__.py +0 -0
- typed_ffmpeg/ffprobe/parse.py +133 -0
- typed_ffmpeg/ffprobe/probe.py +272 -0
- typed_ffmpeg/ffprobe/schema.py +455 -0
- typed_ffmpeg/ffprobe/xml2json.py +70 -0
- {typed_ffmpeg_compatible-3.0.1.dist-info → typed_ffmpeg_compatible-3.2.1.dist-info}/METADATA +36 -17
- typed_ffmpeg_compatible-3.2.1.dist-info/RECORD +57 -0
- {typed_ffmpeg_compatible-3.0.1.dist-info → typed_ffmpeg_compatible-3.2.1.dist-info}/WHEEL +2 -1
- typed_ffmpeg_compatible-3.2.1.dist-info/top_level.txt +1 -0
- typed_ffmpeg/common/cache/.gitignore +0 -3
- typed_ffmpeg/common/cache/FFMpegFilterManuallyDefined/acrossover.json +0 -6
- typed_ffmpeg/common/cache/FFMpegFilterManuallyDefined/afir.json +0 -9
- typed_ffmpeg/common/cache/FFMpegFilterManuallyDefined/aiir.json +0 -6
- typed_ffmpeg/common/cache/FFMpegFilterManuallyDefined/ainterleave.json +0 -9
- typed_ffmpeg/common/cache/FFMpegFilterManuallyDefined/amerge.json +0 -9
- typed_ffmpeg/common/cache/FFMpegFilterManuallyDefined/amix.json +0 -9
- typed_ffmpeg/common/cache/FFMpegFilterManuallyDefined/amovie.json +0 -6
- typed_ffmpeg/common/cache/FFMpegFilterManuallyDefined/anequalizer.json +0 -6
- typed_ffmpeg/common/cache/FFMpegFilterManuallyDefined/aphasemeter.json +0 -6
- typed_ffmpeg/common/cache/FFMpegFilterManuallyDefined/asegment.json +0 -6
- typed_ffmpeg/common/cache/FFMpegFilterManuallyDefined/aselect.json +0 -6
- typed_ffmpeg/common/cache/FFMpegFilterManuallyDefined/asplit.json +0 -6
- typed_ffmpeg/common/cache/FFMpegFilterManuallyDefined/astreamselect.json +0 -9
- typed_ffmpeg/common/cache/FFMpegFilterManuallyDefined/bm3d.json +0 -6
- typed_ffmpeg/common/cache/FFMpegFilterManuallyDefined/channelsplit.json +0 -6
- typed_ffmpeg/common/cache/FFMpegFilterManuallyDefined/concat.json +0 -9
- typed_ffmpeg/common/cache/FFMpegFilterManuallyDefined/decimate.json +0 -6
- typed_ffmpeg/common/cache/FFMpegFilterManuallyDefined/ebur128.json +0 -6
- typed_ffmpeg/common/cache/FFMpegFilterManuallyDefined/extractplanes.json +0 -6
- typed_ffmpeg/common/cache/FFMpegFilterManuallyDefined/fieldmatch.json +0 -6
- typed_ffmpeg/common/cache/FFMpegFilterManuallyDefined/guided.json +0 -6
- typed_ffmpeg/common/cache/FFMpegFilterManuallyDefined/headphone.json +0 -6
- typed_ffmpeg/common/cache/FFMpegFilterManuallyDefined/hstack.json +0 -9
- typed_ffmpeg/common/cache/FFMpegFilterManuallyDefined/interleave.json +0 -9
- typed_ffmpeg/common/cache/FFMpegFilterManuallyDefined/join.json +0 -9
- typed_ffmpeg/common/cache/FFMpegFilterManuallyDefined/libplacebo.json +0 -9
- typed_ffmpeg/common/cache/FFMpegFilterManuallyDefined/limitdiff.json +0 -6
- typed_ffmpeg/common/cache/FFMpegFilterManuallyDefined/mergeplanes.json +0 -6
- typed_ffmpeg/common/cache/FFMpegFilterManuallyDefined/mix.json +0 -9
- typed_ffmpeg/common/cache/FFMpegFilterManuallyDefined/movie.json +0 -6
- typed_ffmpeg/common/cache/FFMpegFilterManuallyDefined/premultiply.json +0 -6
- typed_ffmpeg/common/cache/FFMpegFilterManuallyDefined/segment.json +0 -6
- typed_ffmpeg/common/cache/FFMpegFilterManuallyDefined/select.json +0 -6
- typed_ffmpeg/common/cache/FFMpegFilterManuallyDefined/signature.json +0 -9
- typed_ffmpeg/common/cache/FFMpegFilterManuallyDefined/split.json +0 -6
- typed_ffmpeg/common/cache/FFMpegFilterManuallyDefined/streamselect.json +0 -9
- typed_ffmpeg/common/cache/FFMpegFilterManuallyDefined/unpremultiply.json +0 -6
- typed_ffmpeg/common/cache/FFMpegFilterManuallyDefined/vstack.json +0 -9
- typed_ffmpeg/common/cache/FFMpegFilterManuallyDefined/xmedian.json +0 -9
- typed_ffmpeg/common/cache/FFMpegFilterManuallyDefined/xstack.json +0 -9
- typed_ffmpeg/common/cache/list/filters.json +0 -90747
- typed_ffmpeg/common/cache/list/options.json +0 -1694
- typed_ffmpeg/probe.py +0 -75
- typed_ffmpeg_compatible-3.0.1.dist-info/RECORD +0 -95
- typed_ffmpeg_compatible-3.0.1.dist-info/entry_points.txt +0 -3
- {typed_ffmpeg_compatible-3.0.1.dist-info → typed_ffmpeg_compatible-3.2.1.dist-info/licenses}/LICENSE +0 -0
@@ -0,0 +1,272 @@
|
|
1
|
+
"""
|
2
|
+
Module for analyzing media files with ffprobe.
|
3
|
+
|
4
|
+
This module provides functionality to extract detailed metadata from media files
|
5
|
+
using FFmpeg's ffprobe utility. It returns a structured representation of the
|
6
|
+
file's format, streams, and other relevant information.
|
7
|
+
"""
|
8
|
+
|
9
|
+
import json
|
10
|
+
import logging
|
11
|
+
import subprocess
|
12
|
+
from pathlib import Path
|
13
|
+
from typing import Any
|
14
|
+
|
15
|
+
from ..exceptions import FFMpegExecuteError
|
16
|
+
from ..utils.escaping import convert_kwargs_to_cmd_line_args
|
17
|
+
from ..utils.run import command_line
|
18
|
+
from .parse import parse_ffprobe
|
19
|
+
from .schema import ffprobeType
|
20
|
+
|
21
|
+
logger = logging.getLogger(__name__)
|
22
|
+
|
23
|
+
|
24
|
+
def _probe(
|
25
|
+
filename: str | Path,
|
26
|
+
*,
|
27
|
+
show_program_version: bool = False,
|
28
|
+
show_library_versions: bool = False,
|
29
|
+
show_pixel_formats: bool = False,
|
30
|
+
show_packets: bool = False,
|
31
|
+
show_frames: bool = False,
|
32
|
+
show_programs: bool = False,
|
33
|
+
show_streams: bool = True,
|
34
|
+
show_chapters: bool = False,
|
35
|
+
show_format: bool = True,
|
36
|
+
show_error: bool = False,
|
37
|
+
cmd: str = "ffprobe",
|
38
|
+
timeout: int | None = None,
|
39
|
+
format: str = "json",
|
40
|
+
**kwargs: Any,
|
41
|
+
) -> str:
|
42
|
+
"""
|
43
|
+
Analyze a media file using ffprobe and return its metadata as a dictionary.
|
44
|
+
|
45
|
+
This function executes ffprobe to extract detailed information about a media file,
|
46
|
+
including format metadata (container format, duration, bitrate) and stream information
|
47
|
+
(codecs, resolution, sample rate, etc). The result is returned as a Python dictionary
|
48
|
+
parsed from ffprobe's JSON output.
|
49
|
+
|
50
|
+
Args:
|
51
|
+
filename: Path to the media file to analyze
|
52
|
+
cmd: Path or name of the ffprobe executable
|
53
|
+
timeout: Maximum time in seconds to wait for ffprobe to complete (default: None, wait indefinitely)
|
54
|
+
show_program_version: Show the program version
|
55
|
+
show_library_versions: Show the library versions
|
56
|
+
show_pixel_formats: Show the pixel formats
|
57
|
+
show_packets: Show the packets. Note: When both show_packets and show_frames are True,
|
58
|
+
ffprobe will output a combined "packets_and_frames" section instead of separate sections.
|
59
|
+
show_frames: Show the frames. Note: When both show_packets and show_frames are True,
|
60
|
+
ffprobe will output a combined "packets_and_frames" section instead of separate sections.
|
61
|
+
show_programs: Show the programs
|
62
|
+
show_streams: Show the streams
|
63
|
+
show_chapters: Show the chapters
|
64
|
+
show_format: Show the format
|
65
|
+
show_error: Show the error
|
66
|
+
**kwargs: Additional arguments to pass to ffprobe as command line parameters
|
67
|
+
(e.g., loglevel="quiet", skip_frame="nokey")
|
68
|
+
|
69
|
+
Returns:
|
70
|
+
A dictionary containing the parsed JSON output from ffprobe with format and stream information
|
71
|
+
|
72
|
+
Raises:
|
73
|
+
FFMpegExecuteError: If ffprobe returns a non-zero exit code
|
74
|
+
subprocess.TimeoutExpired: If the timeout is reached before ffprobe completes
|
75
|
+
|
76
|
+
Example:
|
77
|
+
```python
|
78
|
+
info = probe("video.mp4")
|
79
|
+
print(f"Duration: {float(info['format']['duration']):.2f} seconds")
|
80
|
+
print(f"Streams: {len(info['streams'])}")
|
81
|
+
```
|
82
|
+
"""
|
83
|
+
args = [
|
84
|
+
cmd,
|
85
|
+
*(["-show_program_version"] if show_program_version else []),
|
86
|
+
*(["-show_library_versions"] if show_library_versions else []),
|
87
|
+
*(["-show_pixel_formats"] if show_pixel_formats else []),
|
88
|
+
*(["-show_packets"] if show_packets else []),
|
89
|
+
*(["-show_frames"] if show_frames else []),
|
90
|
+
*(["-show_programs"] if show_programs else []),
|
91
|
+
*(["-show_streams"] if show_streams else []),
|
92
|
+
*(["-show_chapters"] if show_chapters else []),
|
93
|
+
*(["-show_format"] if show_format else []),
|
94
|
+
*(["-show_error"] if show_error else []),
|
95
|
+
"-of",
|
96
|
+
format,
|
97
|
+
]
|
98
|
+
args += convert_kwargs_to_cmd_line_args(kwargs)
|
99
|
+
args += [str(filename)]
|
100
|
+
|
101
|
+
logger.info("Running ffprobe command: %s", command_line(args))
|
102
|
+
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
103
|
+
|
104
|
+
if timeout is not None:
|
105
|
+
out, err = p.communicate(timeout=timeout)
|
106
|
+
else:
|
107
|
+
out, err = p.communicate()
|
108
|
+
|
109
|
+
retcode = p.poll()
|
110
|
+
if p.returncode != 0:
|
111
|
+
raise FFMpegExecuteError(
|
112
|
+
retcode=retcode, cmd=command_line(args), stdout=out, stderr=err
|
113
|
+
)
|
114
|
+
|
115
|
+
return out.decode("utf-8")
|
116
|
+
|
117
|
+
|
118
|
+
def probe(
|
119
|
+
filename: str | Path,
|
120
|
+
*,
|
121
|
+
show_program_version: bool = False,
|
122
|
+
show_library_versions: bool = False,
|
123
|
+
show_pixel_formats: bool = False,
|
124
|
+
show_packets: bool = False,
|
125
|
+
show_frames: bool = False,
|
126
|
+
show_programs: bool = False,
|
127
|
+
show_streams: bool = True,
|
128
|
+
show_chapters: bool = False,
|
129
|
+
show_format: bool = True,
|
130
|
+
show_error: bool = False,
|
131
|
+
cmd: str = "ffprobe",
|
132
|
+
timeout: int | None = None,
|
133
|
+
**kwargs: Any,
|
134
|
+
) -> dict[str, Any]:
|
135
|
+
"""
|
136
|
+
Analyze a media file using ffprobe and return its metadata as a dictionary.
|
137
|
+
|
138
|
+
This function executes ffprobe to extract detailed information about a media file,
|
139
|
+
including format metadata (container format, duration, bitrate) and stream information
|
140
|
+
(codecs, resolution, sample rate, etc). The result is returned as a Python dictionary
|
141
|
+
parsed from ffprobe's JSON output.
|
142
|
+
|
143
|
+
Args:
|
144
|
+
filename: Path to the media file to analyze
|
145
|
+
cmd: Path or name of the ffprobe executable
|
146
|
+
timeout: Maximum time in seconds to wait for ffprobe to complete (default: None, wait indefinitely)
|
147
|
+
show_program_version: Show the program version
|
148
|
+
show_library_versions: Show the library versions
|
149
|
+
show_pixel_formats: Show the pixel formats
|
150
|
+
show_packets: Show the packets. Note: When both show_packets and show_frames are True,
|
151
|
+
ffprobe will output a combined "packets_and_frames" section instead of separate sections.
|
152
|
+
show_frames: Show the frames. Note: When both show_packets and show_frames are True,
|
153
|
+
ffprobe will output a combined "packets_and_frames" section instead of separate sections.
|
154
|
+
show_programs: Show the programs
|
155
|
+
show_streams: Show the streams
|
156
|
+
show_chapters: Show the chapters
|
157
|
+
show_format: Show the format
|
158
|
+
show_error: Show the error
|
159
|
+
**kwargs: Additional arguments to pass to ffprobe as command line parameters
|
160
|
+
(e.g., loglevel="quiet", skip_frame="nokey")
|
161
|
+
|
162
|
+
Returns:
|
163
|
+
A dictionary containing the parsed JSON output from ffprobe with format and stream information
|
164
|
+
|
165
|
+
Raises:
|
166
|
+
FFMpegExecuteError: If ffprobe returns a non-zero exit code
|
167
|
+
subprocess.TimeoutExpired: If the timeout is reached before ffprobe completes
|
168
|
+
|
169
|
+
Example:
|
170
|
+
```python
|
171
|
+
info = probe("video.mp4")
|
172
|
+
print(f"Duration: {float(info['format']['duration']):.2f} seconds")
|
173
|
+
print(f"Streams: {len(info['streams'])}")
|
174
|
+
```
|
175
|
+
"""
|
176
|
+
return json.loads(
|
177
|
+
_probe(
|
178
|
+
filename,
|
179
|
+
show_program_version=show_program_version,
|
180
|
+
show_library_versions=show_library_versions,
|
181
|
+
show_pixel_formats=show_pixel_formats,
|
182
|
+
show_packets=show_packets,
|
183
|
+
show_frames=show_frames,
|
184
|
+
show_programs=show_programs,
|
185
|
+
show_streams=show_streams,
|
186
|
+
show_chapters=show_chapters,
|
187
|
+
show_format=show_format,
|
188
|
+
show_error=show_error,
|
189
|
+
cmd=cmd,
|
190
|
+
timeout=timeout,
|
191
|
+
**kwargs,
|
192
|
+
)
|
193
|
+
)
|
194
|
+
|
195
|
+
|
196
|
+
def probe_obj(
|
197
|
+
filename: str | Path,
|
198
|
+
*,
|
199
|
+
show_program_version: bool = False,
|
200
|
+
show_library_versions: bool = False,
|
201
|
+
show_pixel_formats: bool = False,
|
202
|
+
show_packets: bool = False,
|
203
|
+
show_frames: bool = False,
|
204
|
+
show_programs: bool = False,
|
205
|
+
show_streams: bool = True,
|
206
|
+
show_chapters: bool = False,
|
207
|
+
show_format: bool = True,
|
208
|
+
show_error: bool = False,
|
209
|
+
cmd: str = "ffprobe",
|
210
|
+
timeout: int | None = None,
|
211
|
+
**kwargs: Any,
|
212
|
+
) -> ffprobeType | None:
|
213
|
+
"""
|
214
|
+
Analyze a media file using ffprobe and return its metadata as a dataclass.
|
215
|
+
|
216
|
+
This function executes ffprobe to extract detailed information about a media file,
|
217
|
+
including format metadata (container format, duration, bitrate) and stream information
|
218
|
+
(codecs, resolution, sample rate, etc). The result is returned as a Python dataclass
|
219
|
+
parsed from ffprobe's output.
|
220
|
+
|
221
|
+
Args:
|
222
|
+
filename: Path to the media file to analyze
|
223
|
+
cmd: Path or name of the ffprobe executable
|
224
|
+
timeout: Maximum time in seconds to wait for ffprobe to complete (default: None, wait indefinitely)
|
225
|
+
show_program_version: Show the program version
|
226
|
+
show_library_versions: Show the library versions
|
227
|
+
show_pixel_formats: Show the pixel formats
|
228
|
+
show_packets: Show the packets. Note: When both show_packets and show_frames are True,
|
229
|
+
ffprobe will output a combined "packets_and_frames" section instead of separate sections.
|
230
|
+
show_frames: Show the frames. Note: When both show_packets and show_frames are True,
|
231
|
+
ffprobe will output a combined "packets_and_frames" section instead of separate sections.
|
232
|
+
show_programs: Show the programs
|
233
|
+
show_streams: Show the streams
|
234
|
+
show_chapters: Show the chapters
|
235
|
+
show_format: Show the format
|
236
|
+
show_error: Show the error
|
237
|
+
**kwargs: Additional arguments to pass to ffprobe as command line parameters
|
238
|
+
(e.g., loglevel="quiet", skip_frame="nokey")
|
239
|
+
|
240
|
+
Returns:
|
241
|
+
A dataclass containing the parsed ffprobe output
|
242
|
+
|
243
|
+
Raises:
|
244
|
+
FFMpegExecuteError: If ffprobe returns a non-zero exit code
|
245
|
+
subprocess.TimeoutExpired: If the timeout is reached before ffprobe completes
|
246
|
+
|
247
|
+
Example:
|
248
|
+
```python
|
249
|
+
info = probe_obj("video.mp4")
|
250
|
+
print(f"Duration: {float(info.format.duration):.2f} seconds")
|
251
|
+
print(f"Streams: {len(info.streams)}")
|
252
|
+
```
|
253
|
+
"""
|
254
|
+
|
255
|
+
xml = _probe(
|
256
|
+
filename,
|
257
|
+
show_program_version=show_program_version,
|
258
|
+
show_library_versions=show_library_versions,
|
259
|
+
show_pixel_formats=show_pixel_formats,
|
260
|
+
show_packets=show_packets,
|
261
|
+
show_frames=show_frames,
|
262
|
+
show_programs=show_programs,
|
263
|
+
show_streams=show_streams,
|
264
|
+
show_chapters=show_chapters,
|
265
|
+
show_format=show_format,
|
266
|
+
show_error=show_error,
|
267
|
+
cmd=cmd,
|
268
|
+
timeout=timeout,
|
269
|
+
format="xml",
|
270
|
+
**kwargs,
|
271
|
+
)
|
272
|
+
return parse_ffprobe(xml)
|