2006-11-07 11:47:26 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# gst-python
|
|
|
|
# Copyright (C) 2006 Andy Wingo <wingo at pobox.com>
|
|
|
|
#
|
|
|
|
# This library is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Library General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2 of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# Library General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Library General Public
|
|
|
|
# License along with this library; if not, write to the
|
2013-11-25 17:01:48 +00:00
|
|
|
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
2006-11-07 11:47:26 +00:00
|
|
|
# Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
import pygtk
|
|
|
|
pygtk.require('2.0')
|
|
|
|
import gobject
|
|
|
|
gobject.threads_init()
|
|
|
|
import pygst
|
|
|
|
pygst.require('0.10')
|
|
|
|
import gst
|
|
|
|
from gst.extend import discoverer
|
|
|
|
|
|
|
|
def fail(path):
|
|
|
|
print "error: %r does not appear to be a media file" % path
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
def succeed(d):
|
|
|
|
def pp(prop, val):
|
|
|
|
print '%s: %s' % (prop, val)
|
|
|
|
pp('media type', d.mimetype)
|
|
|
|
|
|
|
|
pp('has video', d.is_video)
|
|
|
|
if d.is_video:
|
|
|
|
pp('video caps', d.videocaps)
|
2007-07-27 11:04:55 +00:00
|
|
|
pp('video width (pixels)', d.videowidth)
|
|
|
|
pp('video height (pixels)', d.videoheight)
|
2008-12-06 14:13:55 +00:00
|
|
|
pp('video length (hh:mm:ss)', gst.TIME_ARGS(d.videolength))
|
2007-07-27 11:04:55 +00:00
|
|
|
pp('framerate (fps)', '%s/%s' % (d.videorate.num, d.videorate.denom))
|
2006-11-07 11:47:26 +00:00
|
|
|
|
|
|
|
pp('has audio', d.is_audio)
|
|
|
|
if d.is_audio:
|
|
|
|
pp('audio caps', d.audiocaps)
|
|
|
|
pp('audio format', d.audiofloat and 'floating-point' or 'integer')
|
2007-07-27 11:04:55 +00:00
|
|
|
pp('sample rate (Hz)', d.audiorate)
|
|
|
|
pp('sample width (bits)', d.audiowidth)
|
|
|
|
pp('sample depth (bits)', d.audiodepth)
|
2008-12-06 14:13:55 +00:00
|
|
|
pp('audio length (hh:mm:ss)', gst.TIME_ARGS(d.audiolength))
|
2006-11-07 11:47:26 +00:00
|
|
|
pp('audio channels', d.audiochannels)
|
2008-12-06 14:13:55 +00:00
|
|
|
|
2006-11-07 11:47:26 +00:00
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
def discover(path):
|
|
|
|
def discovered(d, is_media):
|
|
|
|
if is_media:
|
|
|
|
succeed(d)
|
|
|
|
else:
|
|
|
|
fail(path)
|
|
|
|
|
|
|
|
d = discoverer.Discoverer(path)
|
|
|
|
d.connect('discovered', discovered)
|
|
|
|
d.discover()
|
|
|
|
gobject.MainLoop().run()
|
|
|
|
|
|
|
|
def usage():
|
|
|
|
print >>sys.stderr, "usage: gst-discover PATH-TO-MEDIA-FILE"
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
def main(argv):
|
|
|
|
if len(argv) != 2:
|
|
|
|
usage()
|
|
|
|
path = argv.pop()
|
|
|
|
if not os.path.isfile(path):
|
|
|
|
print >>sys.stderr, "error: file %r does not exist" % path
|
|
|
|
usage()
|
|
|
|
|
|
|
|
return discover(path)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(main(sys.argv))
|