Back on Transmageddon and new GStreamer features

Been working on Transmageddon again this weekend as the work Edward has been doing on GES has been making its way into GStreamer-plugins-base and gst-python. The most import change for now is the new discoverer service. For those who used gst-python you might know the old version of it, which is basically an API for getting information about a multimedia file. Unfortunately the old Python version had some shortcomings, but thanks to the work that has been done for GES and Rygel we now have a new C based on in plugins-base which works a lot better. So those who had problems with Transmageddon in the past not recognizing files and thus not operating properly should now have more luck. Also the new discoverer process will tell me if a file is interlaced so I can easily now add support for deinterlacing in Transmageddon.

Anyway, I thought I share my half-done implementation of gst-discover in Python. You find a better version in C in gst-plugins-base/tools or a nice Vala version at live.gnome.org. But if you are familiar with Python the code below should at least give you an inkling on how to use the API from Python. Or check out the code of transmageddon for how to use the asynch version of the API.

#!/usr/bin/env python
# gst-python

import os
import sys

import pygtk
pygtk.require('2.0')
import gobject
gobject.threads_init()
import pygst
pygst.require('0.10')
import gst
import gst.pbutils

class discover:
    def __init__(self):
	self.audiostreams=[]
    def set_file(self,file):
        self.file_uri=("file://"+filepath)
	newitem = gst.pbutils.Discoverer(50000000000)
	self.info = newitem.discover_uri(self.file_uri)

	self.streaminfo=self.info.get_stream_info()
	self.duration= (self.info.get_duration()/1000000000.0)
	self.container = self.streaminfo.get_caps()
	seekbool = self.info.get_seekable()
	if seekbool is True:
		self.seekable="Yes"
	else:
		self.seekable="No"
	audiostreamcounter=-1

	for i in self.info.get_stream_list():
		audiostreamcounter=audiostreamcounter+1
		if isinstance(i, gst.pbutils.DiscovererAudioInfo):
			audiocaps=i.get_caps()
			self.audiostreams.append(gst.pbutils.get_codec_description(audiocaps))
			self.audiotags=i.get_tags()	

		if isinstance(i, gst.pbutils.DiscovererVideoInfo):
			self.videocaps=i.get_caps()
			self.videotags=i.get_tags()
			interlacedbool = i.is_interlaced()
			if interlacedbool is True:
				self.interlaced ="Yes"
			else:
				self.interlaced="No"
			self.videoheight=i.get_height()
			self.videowidth=i.get_width()


    def create_report(self): # Create properties report
		print "Analyzing " + str(self.file_uri)
		print "Topology:"
		print "  container: " + gst.pbutils.get_codec_description(self.container)
		beancounter=0
		for item in self.audiostreams:
			beancounter=beancounter+1
			print "    audio stream " +str(beancounter) + ": " + self.audiostreams[beancounter-1]

		print "    video stream: " + gst.pbutils.get_codec_description(self.videocaps)
		print " "
		print "Properties:"
		print "  Duration: " + str(self.duration)
		print "  Seekable: " + str(self.seekable)
		print "  Video interlaced: " + str(self.interlaced)
		print "  Video height: " + str(self.videoheight)
		print "  Video width: " + str(self.videowidth)
		print "  Audio Tags: " 
		audiofile_tags = {}
		for akey in self.audiotags.keys():
			audiofile_tags[akey] = self.audiotags[akey]
			print "      " + akey, '\t', self.audiotags[akey]
		print "  Video Tags: "
		videofile_tags = {}
		for vkey in self.videotags.keys():
			videofile_tags[vkey] = self.videotags[vkey]
			print "      " + vkey, '\t', self.videotags[vkey]

if __name__=="__main__":
    if len(sys.argv)>1:
        file = sys.argv[1]
        pwd = os.getcwd()
        filepath = os.path.join(pwd,file)
        discovering = discover()
	discovering.set_file(file)
        discovering.create_report()
    else:
        print "select an audio file"



This program should give you an output like this one:

python newdiscoverer.py /home/cschalle/Videos/diracpromo.vob 
Analyzing file:///home/cschalle/Videos/diracpromo.vob
Topology:
  container: MPEG-2 System Stream
    audio stream 1: MPEG-1 Layer 2 (MP2)
    video stream: MPEG-2 Video
 
Properties:
  Duration: 735.672
  Seekable: Yes
  Video interlaced: No
  Video height: 576
  Video width: 720
  Audio Tags: 
      audio-codec 	MPEG 1 Audio, Layer 2
      bitrate 	384000
      has-crc 	True
      channel-mode 	stereo
  Video Tags: 
      bitrate 	8000000

2 thoughts on “Back on Transmageddon and new GStreamer features

Comments are closed.