Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
ffprobe python module
=====================
# ffprobe python module


A wrapper around the ffprobe command to extract metadata from media files.

Usage::
```python
#!/usr/bin/env python

#!/usr/bin/env python

from ffprobe3 import FFProbe
from ffprobe3 import FFProbe

metadata=FFProbe('test-media-file.mov')
metadata=FFProbe('test-media-file.mov')

for stream in metadata.streams:
if stream.is_video():
print('Stream contains {} frames.'.format(stream.frames()))
for stream in metadata.streams:
if stream.is_video():
print('Stream contains {} frames.'.format(stream.frames()))
```


(The MIT License)
Expand Down
22 changes: 21 additions & 1 deletion ffprobe3/ffprobe.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ def __init__(self, video_file):
self.created = None
self.duration = None
self.start = None
self.bitrate = None
self.bit_rate = None
self.sample_rate = None
self.bits_per_sample = None
self.channels = None
self.streams = []
self.video = []
self.audio = []
Expand All @@ -47,6 +50,23 @@ def __init__(self, video_file):
self.streams.append(FFStream(data_lines))
data_lines = []
else:
kvPair = a.strip().split('=')
if len(kvPair) > 1:
if kvPair[0] == "codec_name":
self.format = kvPair[1]
elif kvPair[0] == "created":
self.created = kvPair[1]
elif kvPair[0] == "duration":
self.duration = float(kvPair[1])
elif kvPair[0] == "bit_rate":
self.bit_rate = int(kvPair[1])
elif kvPair[0] == "sample_rate":
self.sample_rate = int(kvPair[1])
elif kvPair[0] == "bits_per_sample":
self.bits_per_sample = int(kvPair[1])
elif kvPair[0] == "channels":
self.channels = int(kvPair[1])

data_lines.append(a)
for a in iter(p.stderr.readline, b''):
a = a.decode('UTF-8')
Expand Down
Binary file removed tests/data/SampleVideo_1280x720_50mb.mp4
Binary file not shown.
Binary file removed tests/data/SampleVideo_360x240_50mb.mp4
Binary file not shown.
4 changes: 2 additions & 2 deletions tests/ffprobe-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
test_videos = [
os.path.join(test_dir, './data/SampleVideo_720x480_5mb.mp4'),
os.path.join(test_dir, './data/SampleVideo_1280x720_1mb.mp4'),
os.path.join(test_dir, './data/SampleVideo_360x240_50mb.mp4'),
os.path.join(test_dir, './data/SampleVideo_1280x720_50mb.mp4'),
# os.path.join(test_dir, './data/SampleVideo_360x240_50mb.mp4'),
# os.path.join(test_dir, './data/SampleVideo_1280x720_50mb.mp4'),
]

for test_video in test_videos:
Expand Down