-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add documents about querying metadata of media using ffprobe
- Loading branch information
1 parent
065b289
commit 4721474
Showing
4 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Querying metadata | ||
|
||
You can use **python-ffmpeg** to query the metadata of an input file using `ffprobe`. | ||
|
||
=== "Synchronous API" | ||
|
||
```python | ||
import json | ||
|
||
from ffmpeg import FFmpeg | ||
|
||
|
||
def main(): | ||
ffprobe = FFmpeg(executable="ffprobe").input( | ||
"input.mp4", | ||
print_format="json", # ffprobe will output the results in JSON format | ||
show_streams=None, | ||
) | ||
|
||
media = json.loads(ffprobe.execute()) | ||
|
||
print(f"# Video") | ||
print(f"- Codec: {media['streams'][0]['codec_name']}") | ||
print(f"- Resolution: {media['streams'][0]['width']} X {media['streams'][0]['height']}") | ||
print(f"- Duration: {media['streams'][0]['duration']}") | ||
print("") | ||
|
||
print(f"# Audio") | ||
print(f"- Codec: {media['streams'][1]['codec_name']}") | ||
print(f"- Sample Rate: {media['streams'][1]['sample_rate']}") | ||
print(f"- Duration: {media['streams'][1]['duration']}") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() | ||
``` | ||
|
||
=== "Asynchronous API" | ||
|
||
``` python | ||
import asyncio | ||
import json | ||
|
||
from ffmpeg.asyncio import FFmpeg | ||
|
||
|
||
async def main(): | ||
ffprobe = FFmpeg(executable="ffprobe").input( | ||
"input.mp4", | ||
print_format="json", # ffprobe will output the results in JSON format | ||
show_streams=None, | ||
) | ||
|
||
media = json.loads(await ffprobe.execute()) | ||
|
||
print(f"# Video") | ||
print(f"- Codec: {media['streams'][0]['codec_name']}") | ||
print(f"- Resolution: {media['streams'][0]['width']} X {media['streams'][0]['height']}") | ||
print(f"- Duration: {media['streams'][0]['duration']}") | ||
print("") | ||
|
||
print(f"# Audio") | ||
print(f"- Codec: {media['streams'][1]['codec_name']}") | ||
print(f"- Sample Rate: {media['streams'][1]['sample_rate']}") | ||
print(f"- Duration: {media['streams'][1]['duration']}") | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(main()) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import asyncio | ||
import json | ||
|
||
from ffmpeg.asyncio import FFmpeg | ||
|
||
|
||
async def main(): | ||
ffmpeg = FFmpeg(executable="ffprobe").input( | ||
"input.mp4", | ||
print_format="json", # ffprobe will output the results in JSON format | ||
show_streams=None, | ||
) | ||
|
||
media = json.loads(await ffmpeg.execute()) | ||
|
||
print(f"# Video") | ||
print(f"- Codec: {media['streams'][0]['codec_name']}") | ||
print(f"- Resolution: {media['streams'][0]['width']} X {media['streams'][0]['height']}") | ||
print(f"- Duration: {media['streams'][0]['duration']}") | ||
print("") | ||
|
||
print(f"# Audio") | ||
print(f"- Codec: {media['streams'][1]['codec_name']}") | ||
print(f"- Sample Rate: {media['streams'][1]['sample_rate']}") | ||
print(f"- Duration: {media['streams'][1]['duration']}") | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from __future__ import annotations | ||
|
||
import json | ||
|
||
from ffmpeg import FFmpeg | ||
|
||
|
||
def main(): | ||
ffmpeg = FFmpeg(executable="ffprobe").input( | ||
"input.mp4", | ||
print_format="json", | ||
show_streams=None, | ||
) | ||
|
||
media = json.loads(ffmpeg.execute()) | ||
|
||
print(f"# Video") | ||
print(f"- Codec: {media['streams'][0]['codec_name']}") | ||
print(f"- Resolution: {media['streams'][0]['width']} X {media['streams'][0]['height']}") | ||
print(f"- Duration: {media['streams'][0]['duration']}") | ||
print("") | ||
|
||
print(f"# Audio") | ||
print(f"- Codec: {media['streams'][1]['codec_name']}") | ||
print(f"- Sample Rate: {media['streams'][1]['sample_rate']}") | ||
print(f"- Duration: {media['streams'][1]['duration']}") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters