oxtimeline/oxgst/info.py

77 lines
2.9 KiB
Python
Raw Normal View History

2009-01-18 08:39:14 +00:00
#!/usr/bin/python
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
# GPL 2008
import gobject
gobject.threads_init()
import os
import pygst
pygst.require("0.10")
import gst
2009-01-27 09:52:25 +00:00
from gst.extend import discoverer
2009-01-18 08:39:14 +00:00
codec_list = {
2009-01-27 09:52:25 +00:00
'MPEG-1 layer 3': 'MPEG-1 Audio layer 3',
'MPEG-1 layer 3 audio': 'MPEG-1 Audio layer 3',
'MPEG 1 Audio, Layer 2': 'MPEG-1 Audio layer 2',
2009-01-18 08:39:14 +00:00
'VP6 Flash video': 'VP6',
'AC-3 audio': 'AC-3',
'Uncompressed 16-bit PCM audio': 'Uncompressed 16-bit PCM',
'Generic DV': 'DV Video',
}
2009-01-27 09:52:25 +00:00
class Info(dict):
def __init__(self, path):
2009-07-15 07:54:21 +00:00
self._stream_id = 0
self['video'] = []
self['audio'] = []
2009-01-27 09:52:25 +00:00
self['size'] = os.stat(path).st_size
mainloop = gobject.MainLoop()
def discovered(d, is_media):
if is_media:
if d.is_video:
2009-07-15 07:54:21 +00:00
c = {}
c['width'] = d.videowidth
c['height'] = d.videoheight
self['duration'] = float(d.videolength)/gst.SECOND
c["framerate"] = "%d:%d" % (d.videorate.num, d.videorate.denom)
2009-01-27 09:52:25 +00:00
s = d.videocaps[0]
2009-07-15 07:54:21 +00:00
par = gst.Fraction(1, 1)
2009-01-27 09:52:25 +00:00
if 'pixel-aspect-ratio' in s.keys():
2009-07-15 07:54:21 +00:00
par = s['pixel-aspect-ratio']
c["pixel_aspect_ratio"] = "%s:%s" %(par.num, par.denom)
dar = gst.Fraction(d.videowidth * par.num, d.videoheight * par.denom)
if 'display-aspect-ratio' in s.keys():
dar = s['display-aspect-ratio']
c["display_aspect_ratio"] = "%s:%s" %(dar.num, dar.denom)
if 'video-codec' in d.tags:
c['codec'] = codec_list.get(d.tags['video-codec'], d.tags['video-codec'])
c['id'] = self._stream_id
self._stream_id += 1
self['video'].append(c)
2009-01-27 09:52:25 +00:00
if d.is_audio:
2009-07-15 07:54:21 +00:00
c = {}
2009-01-27 09:52:25 +00:00
#self['audio caps'] = d.audiocaps
#self['audio format'] = d.audiofloat and 'floating-point' or 'integer'
#self['sample width (bits)'] = d.audiowidth
#self['sample depth (bits)'] = d.audiodepth
2009-07-15 07:54:21 +00:00
c['samplerate'] = d.audiorate
if 'duration' not in self:
2009-07-15 07:54:21 +00:00
self['duration'] = float(d.audiolength)/gst.SECOND
c['channels'] = d.audiochannels
2009-01-27 09:52:25 +00:00
2009-07-15 07:54:21 +00:00
if 'audio-codec' in d.tags:
c['codec'] = codec_list.get(d.tags['audio-codec'], d.tags['audio-codec'])
c['id'] = self._stream_id
self._stream_id += 1
self['audio'].append(c)
2009-01-27 09:52:25 +00:00
mainloop.quit()
d = discoverer.Discoverer(path)
d.connect('discovered', discovered)
d.discover()
mainloop.run()
2009-01-18 08:39:14 +00:00