Skip to content

Commit

Permalink
Initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
simonh10 committed Jun 1, 2013
0 parents commit fa3f38e
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
@@ -0,0 +1,13 @@
ffprobe python module
=====================

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

(The MIT License)

Copyright © 2013 Simon Hargreaves <simon@simon-hargreaves.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Empty file added __init__.py
Empty file.
103 changes: 103 additions & 0 deletions ffprobe.py
@@ -0,0 +1,103 @@
#!/usr/bin/python

import subprocess
import re
import sys
import os

class FFProbe:
def __init__(self,video_file):
self.video_file=video_file
p = subprocess.check_output(["ffprobe","-show_streams",self.video_file],stderr=subprocess.PIPE,shell=True)
self.format=None
self.created=None
self.duration=None
self.start=None
self.bitrate=None
self.streams=[]
self.video=[]
self.audio=[]
datalines=[]
for a in str(p.decode(sys.stdout.encoding)).split('\n'):
if re.match('\[STREAM\]',a):
datalines=[]
elif re.match('\[\/STREAM\]',a):
self.streams.append(FFStream(datalines))
datalines=[]
else:
datalines.append(a)
for a in self.streams:
if a.isAudio():
self.audio.append(a)
if a.isVideo():
self.video.append(a)
class FFStream:
def __init__(self,datalines):
for a in datalines:
(key,val)=a.strip().split('=')
self.__dict__[key]=val
def isAudio(self):
val=False
if self.__dict__['codec_type']:
if str(self.__dict__['codec_type']) == 'audio':
val=True
return val
def isVideo(self):
val=False
if self.__dict__['codec_type']:
if self.codec_type == 'video':
val=True
return val
def isSubtitle(self):
val=False
if self.__dict__['codec_type']:
if str(self.codec_type)=='subtitle':
val=True
return val
def frameSize(self):
size=(0,0)
if self.isVideo():
if self.__dict__['width'] and self.__dict__['height']:
size=(int(self.__dict__['width']),int(self.__dict__['height']))
return size
def pixelFormat(self):
f=None
if self.isVideo():
if self.__dict__['pix_fmt']:
f=self.__dict__['pix_fmt']
return f
def frames(self):
f=0
if self.isVideo() or self.isAudio():
if self.__dict__['nb_frames']:
f=int(self.__dict__['nb_frames'])
return f
def durationSeconds(self):
f=0.0
if self.isVideo() or self.isAudio():
if self.__dict__['duration']:
f=float(self.__dict__['duration'])
return f
def language(self):
lang=None
if self.__dict__['TAG:language']:
lang=self.__dict__['TAG:language']
return lang

class VideoStream:
def __init__(self,probe_line):
pass
class AudioStream:
def __init__(self,probe_line):
pass

if __name__ == '__main__':
m=FFProbe("structured_data/EDLs/0001T_pull/0001T_PULL.mov")
for s in m.streams:
if s.isVideo():
framerate=s.frames()/s.durationSeconds()
print framerate
print s.frameSize()
print s.durationSeconds()
print s.frames()
print s.isVideo()

0 comments on commit fa3f38e

Please sign in to comment.