generate
Browse files- README.md +2 -2
- app.py +51 -0
- requirements.txt +1 -0
README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
colorFrom: red
|
5 |
colorTo: gray
|
6 |
sdk: gradio
|
|
|
1 |
---
|
2 |
+
title: ffprobe to display media info
|
3 |
+
emoji: ℹ️
|
4 |
colorFrom: red
|
5 |
colorTo: gray
|
6 |
sdk: gradio
|
app.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# prompt: make a gradio app using ffmpeg.probe to display media info
|
2 |
+
|
3 |
+
import gradio as gr
|
4 |
+
import ffmpeg
|
5 |
+
|
6 |
+
|
7 |
+
def get_media_info(file_path):
|
8 |
+
"""
|
9 |
+
Uses ffmpeg to probe the media file and extract information.
|
10 |
+
"""
|
11 |
+
try:
|
12 |
+
probe = ffmpeg.probe(file_path)
|
13 |
+
video_stream = next((stream for stream in probe['streams'] if stream['codec_type'] == 'video'), None)
|
14 |
+
audio_stream = next((stream for stream in probe['streams'] if stream['codec_type'] == 'audio'), None)
|
15 |
+
|
16 |
+
if video_stream:
|
17 |
+
width = int(video_stream['width'])
|
18 |
+
height = int(video_stream['height'])
|
19 |
+
frame_rate = video_stream['avg_frame_rate']
|
20 |
+
frame_count = int(video_stream['nb_frames'])
|
21 |
+
else:
|
22 |
+
width, height, frame_rate, frame_count = None, None, None, None
|
23 |
+
|
24 |
+
if audio_stream:
|
25 |
+
sample_rate = int(audio_stream['sample_rate'])
|
26 |
+
channels = int(audio_stream['channels'])
|
27 |
+
else:
|
28 |
+
sample_rate, channels = None, None
|
29 |
+
|
30 |
+
return {
|
31 |
+
'width': width,
|
32 |
+
'height': height,
|
33 |
+
'frame_rate': frame_rate,
|
34 |
+
'frame_count': frame_count,
|
35 |
+
'sample_rate': sample_rate,
|
36 |
+
'channels': channels,
|
37 |
+
}
|
38 |
+
|
39 |
+
except Exception as e:
|
40 |
+
return {'error': str(e)}
|
41 |
+
|
42 |
+
|
43 |
+
iface = gr.Interface(
|
44 |
+
fn=get_media_info,
|
45 |
+
inputs=gr.inputs.File(label="Upload Media File"),
|
46 |
+
outputs=gr.outputs.JSON(label="Media Information"),
|
47 |
+
title="Media Info Extractor",
|
48 |
+
description="Upload a media file (video or audio) to extract information using ffmpeg.",
|
49 |
+
)
|
50 |
+
|
51 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
ffmpeg-python
|