60 lines
2.3 KiB
Python
60 lines
2.3 KiB
Python
#!/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
|
|
from gst.extend import discoverer
|
|
|
|
|
|
codec_list = {
|
|
'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',
|
|
'VP6 Flash video': 'VP6',
|
|
'AC-3 audio': 'AC-3',
|
|
'Uncompressed 16-bit PCM audio': 'Uncompressed 16-bit PCM',
|
|
'Generic DV': 'DV Video',
|
|
}
|
|
|
|
class Info(dict):
|
|
def __init__(self, path):
|
|
self['size'] = os.stat(path).st_size
|
|
mainloop = gobject.MainLoop()
|
|
def discovered(d, is_media):
|
|
if is_media:
|
|
if d.is_video:
|
|
#self['video caps'] = d.videocaps
|
|
#self['framerate (fps)'] = '%s:%s' % (d.videorate.num, d.videorate.denom)
|
|
self['width'] = d.videowidth
|
|
self['height'] = d.videoheight
|
|
self['duration'] = d.videolength/gst.MSECOND
|
|
self['framerate'] = float(d.videorate)
|
|
s = d.videocaps[0]
|
|
if 'pixel-aspect-ratio' in s.keys():
|
|
self["pixel-aspect-ratio"] = "%d:%d" % (s['pixel-aspect-ratio'].num, s['pixel-aspect-ratio'].denom)
|
|
if d.is_audio:
|
|
#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
|
|
self['samplerate'] = d.audiorate
|
|
self['duration'] = max(self.get('duration', 0), d.audiolength/gst.MSECOND)
|
|
self['channels'] = d.audiochannels
|
|
|
|
if 'video-codec' in d.tags:
|
|
self['video-codec'] = codec_list.get(d.tags['video-codec'], d.tags['video-codec'])
|
|
if 'audio-codec' in d.tags:
|
|
self['audio-codec'] = codec_list.get(d.tags['audio-codec'], d.tags['audio-codec'])
|
|
mainloop.quit()
|
|
|
|
d = discoverer.Discoverer(path)
|
|
d.connect('discovered', discovered)
|
|
d.discover()
|
|
mainloop.run()
|
|
|