[transmageddon] Add presets being applied to transcoding - some issues with video caps freezing transcoding still
- From: Christian Fredrik Kalager Schaller <uraeus src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [transmageddon] Add presets being applied to transcoding - some issues with video caps freezing transcoding still
- Date: Sat, 9 Apr 2011 20:57:46 +0000 (UTC)
commit 5e9b25018c154a06c972b8dc3c5259905049ff1b
Author: Christian Fredrik Kalager Schaller <christian schaller collabora co uk>
Date: Sat Apr 9 21:56:02 2011 +0100
Add presets being applied to transcoding
- some issues with video caps freezing transcoding still
src/transcoder_engine.py | 153 ++++++++++++++++++++++++++++++++++++++--------
src/transmageddon.py | 5 +-
2 files changed, 130 insertions(+), 28 deletions(-)
---
diff --git a/src/transcoder_engine.py b/src/transcoder_engine.py
index b6ef648..e1b7a71 100644
--- a/src/transcoder_engine.py
+++ b/src/transcoder_engine.py
@@ -51,16 +51,16 @@ class Transcoder(gobject.GObject):
# Choose plugin based on Codec Name
# or switch to remuxing mode if any of the values are set to 'pastr'
self.stoptoggle=False
- self.audiocaps = AUDIOCODECVALUE
- self.videocaps = VIDEOCODECVALUE
+ self.audiocaps = gst.Caps(AUDIOCODECVALUE)
+ self.videocaps = gst.Caps(VIDEOCODECVALUE)
self.audiopasstoggle = AUDIOPASSTOGGLE
self.interlaced = INTERLACED
self.videopasstoggle = VIDEOPASSTOGGLE
self.doaudio= False
- if self.audiopasstoggle == False:
- self.AudioEncoderPlugin = codecfinder.get_audio_encoder_element(self.audiocaps)
- if self.videopasstoggle == False:
- self.VideoEncoderPlugin = codecfinder.get_video_encoder_element(self.videocaps)
+ # if self.audiopasstoggle == False:
+ # self.AudioEncoderPlugin = codecfinder.get_audio_encoder_element(self.audiocaps)
+ #if self.videopasstoggle == False:
+ # self.VideoEncoderPlugin = codecfinder.get_video_encoder_element(self.videocaps)
self.preset = PRESET
self.oheight = OHEIGHT
self.owidth = OWIDTH
@@ -80,6 +80,20 @@ class Transcoder(gobject.GObject):
if self.multipass != False:
self.cachefile = (str(glib.get_user_cache_dir())+"/"+"multipass-cache-file"+self.timestamp+".log")
+ #gather preset data if relevant
+ if self.preset != "nopreset":
+ height, width, num, denom, pixelaspectratio = self.provide_presets()
+ for acap in self.audiocaps:
+ acap["rate"] = self.samplerate
+ acap["channels"] = self.channels
+ for vcap in self.videocaps:
+ vcap["height"] = height
+ vcap["width"] = width
+ vcap["framerate"] = gst.Fraction(num, denom)
+ if pixelaspectratio != gst.Fraction(0, 0):
+ vcap["pixel-aspect-ratio"] = pixelaspectratio
+
+
# Create transcoding pipeline
self.pipeline = gst.Pipeline("TranscodingPipeline")
self.pipeline.set_state(gst.STATE_PAUSED)
@@ -88,17 +102,11 @@ class Transcoder(gobject.GObject):
self.uridecoder.set_property("uri", FILECHOSEN)
self.uridecoder.connect("pad-added", self.OnDynamicPad)
- # self.gstmultiqueue = gst.element_factory_make("multiqueue")
- # self.multiqueueaudiosinkpad = self.gstmultiqueue.get_request_pad("sink0")
- # self.multiqueuevideosinkpad = self.gstmultiqueue.get_request_pad("sink1")
- # self.multiqueueaudiosrcpad = self.gstmultiqueue.get_pad("src0")
- # self.multiqueuevideosrcpad = self.gstmultiqueue.get_pad("src1")
-
- # self.pipeline.add(self.gstmultiqueue)
-
self.encodebinprofile = gst.pbutils.EncodingContainerProfile ("ogg", None , gst.Caps(self.containercaps), None)
- self.videoprofile = gst.pbutils.EncodingVideoProfile (gst.Caps(self.videocaps), None, gst.caps_new_any(), 0)
- self.audioprofile = gst.pbutils.EncodingAudioProfile (gst.Caps(self.audiocaps), None, gst.caps_new_any(), 0)
+ print "self.videocaps is " + str(self.videocaps)
+ print "self.audiocaps is " + str(self.audiocaps)
+ self.videoprofile = gst.pbutils.EncodingVideoProfile (self.videocaps, None, gst.caps_new_any(), 0)
+ self.audioprofile = gst.pbutils.EncodingAudioProfile (self.audiocaps, None, gst.caps_new_any(), 0)
self.encodebinprofile.add_profile(self.videoprofile)
self.encodebinprofile.add_profile(self.audioprofile)
@@ -136,10 +144,7 @@ class Transcoder(gobject.GObject):
nwidth = height
nheight = width
height = nheight
- width = nwidth
-
- #self.fakesink = gst.element_factory_make("fakesink", "fakesink")
- #self.pipeline.add(self.fakesink)
+ width = nwidth
self.uridecoder.set_state(gst.STATE_PAUSED)
self.encodebin.set_state(gst.STATE_PAUSED)
@@ -149,15 +154,113 @@ class Transcoder(gobject.GObject):
self.uridecoder.connect("no-more-pads", self.noMorePads) # we need to wait on this one before going further
# print "connecting to no-more-pads"
+ # Gather preset values and create preset elements
+ def provide_presets(self):
+ print "providing presets"
+ devices = presets.get()
+ device = devices[self.preset]
+ preset = device.presets["Normal"]
+
+ # Check for black border boolean
+ border = preset.vcodec.border
+ if border == "Y":
+ self.blackborderflag = True
+ else:
+ self.blackborderflag = False
+
+ # Check for audio samplerate
+ self.samplerate = int(preset.acodec.samplerate)
+
+ # calculate number of channels
+ chanmin, chanmax = preset.acodec.channels
+ if int(self.achannels) < int(chanmax):
+ if int(self.achannels) > int(chanmin):
+ self.channels = int(self.achannels)
+ else:
+ self.channels = int(chanmin)
+ else:
+ self.channels = int(chanmax)
+
+ # Check if rescaling is needed and calculate new video width/height keeping aspect ratio
+ # Also add black borders if needed
+ wmin, wmax = preset.vcodec.width
+ hmin, hmax = preset.vcodec.height
+ width, height = self.owidth, self.oheight
+ # print "owidth is " + str(self.owidth) + " oheight is " + str(self.oheight)
+ self.vpreset = []
+ voutput = preset.vcodec.presets[0].split(", ")
+ for x in voutput:
+ self.vpreset.append(x)
+ self.apreset = []
+ aoutput = preset.acodec.presets[0].split(", ")
+ for x in aoutput:
+ self.apreset.append(x)
+
+ # Get Display aspect ratio
+ pixelaspectratio = preset.vcodec.aspectratio[0]
+
+ # Scale width / height down
+ if self.owidth > wmax:
+ width = wmax
+ height = int((float(wmax) / self.owidth) * self.oheight)
+ if height > hmax:
+ height = hmax
+ width = int((float(hmax) / self.oheight) * self.owidth)
+
# Some encoders like x264enc are not able to handle odd height or widths
- # if width % 2:
- # width += 1
- # if height % 2:
- # height += 1
+ if width % 2:
+ width += 1
+ if height % 2:
+ height += 1
+
+ # Add any required padding
+ if self.blackborderflag == True:
+ if width < wmin and height < hmin:
+ wpx = (wmin - width) / 2
+ hpx = (hmin - height) / 2
+ self.vbox['left'] = -wpx
+ self.vbox['right'] = -wpx
+ self.vbox['top'] = -hpx
+ self.vbox['bottom'] = -hpx
+ elif width < wmin:
+ # print "adding width borders"
+ px = (wmin - width) / 2
+ self.vbox['left'] = -px
+ self.vbox['right'] = -px
+ self.vbox['top'] = -0
+ self.vbox['bottom'] = -0
+ elif height < hmin:
+ # print " adding height borders"
+ px = (hmin - height) / 2
+ self.vbox['top'] = -px
+ self.vbox['bottom'] = -px
+ self.vbox['left'] = -int(0)
+ self.vbox['right'] = -int(0)
+ else:
+ self.vbox['top'] = -int(0)
+ self.vbox['bottom'] = -int(0)
+ self.vbox['left'] = -int(0)
+ self.vbox['right'] = -int(0)
+ # Setup video framerate and add to caps -
+ # FIXME: Is minimum framerate really worthwhile checking for?
+ # =================================================================
+ rmin = preset.vcodec.rate[0].num / float(preset.vcodec.rate[0].denom)
+ rmax = preset.vcodec.rate[1].num / float(preset.vcodec.rate[1].denom)
+ rmaxtest = preset.vcodec.rate[1]
+ orate = self.fratenum / self.frateden
+ if orate > rmax:
+ num = preset.vcodec.rate[1].num
+ denom = preset.vcodec.rate[1].denom
+ elif orate < rmin:
+ num = preset.vcodec.rate[0].num
+ denom = preset.vcodec.rate[0].denom
+ else:
+ num = self.fratenum
+ denom = self.frateden
# print "final height " + str(height) + " final width " + str(width)
- # return height, width, num, denom, pixelaspectratio
+ return height, width, num, denom, pixelaspectratio
def noMorePads(self, dbin):
if (self.multipass == False) or (self.passcounter == int(0)):
diff --git a/src/transmageddon.py b/src/transmageddon.py
index 7f1834e..f03f120 100644
--- a/src/transmageddon.py
+++ b/src/transmageddon.py
@@ -273,8 +273,6 @@ class TransmageddonUI:
self.presetchoice.set_sensitive(False)
self.containerchoice.set_sensitive(False)
self.rotationchoice.set_sensitive(False)
- # self.codec_buttons["apass"].set_sensitive(False)
- # self.codec_buttons["vpass"].set_sensitive(False)
# set default values for various variables
self.AudioCodec = "vorbis"
@@ -446,7 +444,7 @@ class TransmageddonUI:
self.CodecBox.set_sensitive(True)
self.presetchoice.set_sensitive(True)
self.cancelbutton.set_sensitive(False)
- self.transcodebutton.set_sensitive(False)
+ self.transcodebutton.set_sensitive(True)
self.rotationchoice.set_sensitive(True)
self.start_time = False
self.ProgressBar.set_text(_("Done Transcoding"))
@@ -737,6 +735,7 @@ class TransmageddonUI:
self.rotationchoice.set_sensitive(True)
self.presetchoice.set_active(0)
self.cancelbutton.set_sensitive(False)
+ self.transcodebutton.set_sensitive(True)
self._cancel_encoding = transcoder_engine.Transcoder.Pipeline(self._transcoder,"null")
self.ProgressBar.set_fraction(0.0)
self.ProgressBar.set_text(_("Transcoding Progress"))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]