Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
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
8 changes: 6 additions & 2 deletions 8 README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
ffprobe-python module
=====================

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

Usage::
Usage:

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

from ffprobe import FFProbe

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

# Video stream
# metadata=FFProbe('http://some-streaming-url.com:8080/stream')

for stream in metadata.streams:
if stream.is_video():
print('Stream contains {} frames.'.format(stream.frames()))
Expand Down
16 changes: 10 additions & 6 deletions 16 ffprobe/ffprobe.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, path_to_video):
except FileNotFoundError:
raise IOError('ffprobe not found.')

if os.path.isfile(self.path_to_video):
if os.path.isfile(self.path_to_video) or self.path_to_video.startswith('http'):
if platform.system() == 'Windows':
cmd = ["ffprobe", "-show_streams", self.path_to_video]
else:
Expand Down Expand Up @@ -105,7 +105,7 @@ def __init__(self, path_to_video):
elif stream.is_attachment():
self.attachment.append(stream)
else:
raise IOError('No such media file ' + self.path_to_video)
raise IOError('No such media file or stream is not responding: ' + self.path_to_video)

def __repr__(self):
return "<FFprobe: {metadata}, {video}, {audio}, {subtitle}, {attachment}>".format(**vars(self))
Expand Down Expand Up @@ -204,10 +204,14 @@ def frames(self):
Returns the length of a video stream in frames. Returns 0 if not a video stream.
"""
if self.is_video() or self.is_audio():
try:
frame_count = int(self.__dict__.get('nb_frames', ''))
except ValueError:
raise FFProbeError('None integer frame count')
if self.__dict__.get('nb_frames', '') != 'N/A':
try:
frame_count = int(self.__dict__.get('nb_frames', ''))
except ValueError:
raise FFProbeError('None integer frame count')
else:
# When N/A is returned, set frame_count to 0 too
frame_count = 0
else:
frame_count = 0

Expand Down
26 changes: 26 additions & 0 deletions 26 tests/ffprobe_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
os.path.join(test_dir, './data/SampleVideo_1280x720_1mb.mp4'),
]

# Taken from https://bitmovin.com/mpeg-dash-hls-examples-sample-streams
test_streams = [
'https://bitdash-a.akamaihd.net/content/MI201109210084_1/m3u8s/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.m3u8',
'https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8'
]

def test_video ():
for test_video in test_videos:
media = FFProbe(test_video)
Expand All @@ -30,3 +36,23 @@ def test_video ():
print(e)
except Exception as e:
print(e)

def test_stream ():
for test_stream in test_streams:
media = FFProbe(test_stream)
print('File:', test_stream)
print('\tStreams:', len(media.streams))
for index, stream in enumerate(media.streams, 1):
print('\tStream: ', index)
try:
if stream.is_video():
frame_rate = stream.frames() / stream.duration_seconds()
print('\t\tFrame Rate:', frame_rate)
print('\t\tFrame Size:', stream.frame_size())
print('\t\tDuration:', stream.duration_seconds())
print('\t\tFrames:', stream.frames())
print('\t\tIs video:', stream.is_video())
except FFProbeError as e:
print(e)
except Exception as e:
print(e)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.