[transmageddon/gtk3] Commit current progress at hackfest, normal transcode and presets seems to work
- From: Christian Fredrik Kalager Schaller <uraeus src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [transmageddon/gtk3] Commit current progress at hackfest, normal transcode and presets seems to work
- Date: Thu, 26 Jan 2012 13:50:52 +0000 (UTC)
commit aad81cbb041872c509956b1fd7edd390516b3fcf
Author: Christian Fredrik Kalager Schaller <christian schaller collabora co uk>
Date: Thu Jan 26 13:49:04 2012 +0000
Commit current progress at hackfest, normal transcode and presets seems to work
src/gstfraction.py | 103 ++++++++++++++++++++++++++++++++++++++++++++++
src/presets.py | 14 +++---
src/transcoder_engine.py | 33 ++++-----------
src/transmageddon.py | 32 +++++++-------
4 files changed, 134 insertions(+), 48 deletions(-)
---
diff --git a/src/gstfraction.py b/src/gstfraction.py
new file mode 100644
index 0000000..9a2e2bb
--- /dev/null
+++ b/src/gstfraction.py
@@ -0,0 +1,103 @@
+# -*- Mode: Python -*-
+# vi:si:et:sw=4:sts=4:ts=4
+#
+# gst-fraction (taken from gst-python)
+# Copyright (C) 2002 David I. Lehn
+# Copyright (C) 2005-2010 Edward Hervey
+# Copyright (C) 2012 Christian F.K. Schaller
+#
+# 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
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+#
+
+import sys
+from gi.repository import GObject
+GObject.threads_init()
+from gi.repository import GLib
+
+class Fraction():
+ def __init__(self, num, denom=1):
+ self.num = num
+ self.denom = denom
+
+ def __repr__(self):
+ return '<gst.Fraction %d/%d>' % (self.num, self.denom)
+
+ def __eq__(self, other):
+ if isinstance(other, Fraction):
+ return self.num * other.denom == other.num * self.denom
+ return False
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __mul__(self, other):
+ if isinstance(other, Fraction):
+ return Fraction(self.num * other.num,
+ self.denom * other.denom)
+ elif isinstance(other, int):
+ return Fraction(self.num * other, self.denom)
+ raise TypeError
+
+ __rmul__ = __mul__
+
+ def __div__(self, other):
+ if isinstance(other, Fraction):
+ return Fraction(self.num * other.denom,
+ self.denom * other.num)
+ elif isinstance(other, int):
+ return Fraction(self.num, self.denom * other)
+ return TypeError
+
+ def __rdiv__(self, other):
+ if isinstance(other, int):
+ return Fraction(self.denom * other, self.num)
+ return TypeError
+
+ def __float__(self):
+ return float(self.num) / float(self.denom)
+
+try:
+ dlsave = sys.getdlopenflags()
+ from DLFCN import RTLD_GLOBAL, RTLD_LAZY
+except AttributeError:
+ # windows doesn't have sys.getdlopenflags()
+ RTLD_GLOBAL = -1
+ RTLD_LAZY = -1
+except ImportError:
+ RTLD_GLOBAL = -1
+ RTLD_LAZY = -1
+ import os
+ osname = os.uname()[0]
+ if osname == 'Linux' or osname == 'SunOS' or osname == 'FreeBSD' or osname == 'GNU/kFreeBSD' or osname == 'GNU':
+ machinename = os.uname()[4]
+ if machinename == 'mips' or machinename == 'mips64':
+ RTLD_GLOBAL = 0x4
+ RTLD_LAZY = 0x1
+ else:
+ RTLD_GLOBAL = 0x100
+ RTLD_LAZY = 0x1
+ elif osname == 'Darwin':
+ RTLD_GLOBAL = 0x8
+ RTLD_LAZY = 0x1
+ del os
+except:
+ RTLD_GLOBAL = -1
+ RTLD_LAZY = -1
+
+if RTLD_GLOBAL != -1 and RTLD_LAZY != -1:
+ sys.setdlopenflags(RTLD_LAZY | RTLD_GLOBAL)
+
+
diff --git a/src/presets.py b/src/presets.py
index 669aaba..2086e2a 100644
--- a/src/presets.py
+++ b/src/presets.py
@@ -43,7 +43,7 @@ import os
import sys
import urllib2
import xml.etree.ElementTree
-import fractions
+import gstfraction
from gi.repository import Gst
@@ -56,10 +56,10 @@ _log = logging.getLogger("transmageddon.presets")
UPDATE_LOCATION = "http://programmer-art.org" + \
"/media/releases/transmageddon-transcoder/presets/"
-class Fraction(fractions.Fraction):
+class Fraction(gstfraction.Fraction):
"""
An object for storing a fraction as two integers. This is a subclass
- of fractions.Fraction that allows initialization from a string representation
+ of gst.Fraction that allows initialization from a string representation
like "1/2".
"""
def __init__(self, value = "1"):
@@ -69,11 +69,11 @@ class Fraction(fractions.Fraction):
a '/' that represent a fraction
"""
parts = value.split("/")
-
+
if len(parts) == 1:
- fractions.Fraction.__init__(self, int(value), 1)
+ gstfraction.Fraction.__init__(self, int(value))
elif len(parts) == 2:
- fractions.Fraction.__init__(self, int(parts[0]), int(parts[1]))
+ gstfraction.Fraction.__init__(self, int(parts[0]))
else:
raise ValueError(_("Not a valid integer or fraction: %(value)s!") % {
"value": value,
@@ -367,7 +367,7 @@ def _load_preset(root):
preset.acodec = _load_audio_codec(child)
elif child.tag == "video":
preset.vcodec = _load_video_codec(child)
-
+
if preset.acodec and not preset.acodec.container:
preset.acodec.container = preset.container
diff --git a/src/transcoder_engine.py b/src/transcoder_engine.py
index e11cf7c..f5e1784 100644
--- a/src/transcoder_engine.py
+++ b/src/transcoder_engine.py
@@ -42,11 +42,9 @@ class Transcoder(GObject.GObject):
# Choose plugin based on Container name
self.container = CONTAINERCHOICE
- print "self.container is"
self.audiocaps = AUDIOCODECVALUE
if self.container != False:
self.containercaps = Gst.caps_from_string(codecfinder.containermap[CONTAINERCHOICE])
- print "self.containercaps"
# special case mp3 which is a no-container format with a container (id3mux)
else:
if self.audiocaps.intersect(Gst.caps_from_string("audio/mpeg, mpegversion=1, layer=3")):
@@ -91,19 +89,6 @@ class Transcoder(GObject.GObject):
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["channels"] = self.channels
- for vcap in self.videocaps:
- vcap["height"] = int(height)
- vcap["width"] = int(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()
self.pipeline.set_state(Gst.State.PAUSED)
@@ -151,8 +136,10 @@ class Transcoder(GObject.GObject):
if self.container==False:
self.encodebinprofile = GstPbutils.EncodingAudioProfile.new (self.audiocaps, audiopreset, Gst.Caps.new_any(), 0)
else:
- # print "self.audiocaps is " + str(self.audiocaps)
+ print "self.audiocaps is " + str(self.audiocaps)
audiopreset=None
+ capsy= self.audiocaps
+ print "capsy is " + str(capsy)
self.audioprofile = GstPbutils.EncodingAudioProfile.new(self.audiocaps, audiopreset, Gst.Caps.new_any(), 0)
self.encodebinprofile.add_profile(self.audioprofile)
if self.videocaps != "novid":
@@ -167,23 +154,19 @@ class Transcoder(GObject.GObject):
# print "creating encodebin " +str(self.encodebin)
self.encodebin.set_state(Gst.State.PAUSED)
- self.remuxcaps = Gst.Caps()
+ self.remuxcaps = Gst.Caps.new_empty()
if self.audiopasstoggle:
self.remuxcaps.append(self.audiocaps)
if self.videopasstoggle:
self.remuxcaps.append(self.videocaps)
if self.audiopasstoggle and not self.videopasstoggle:
- self.remuxcaps.append_structure(Gst.Structure("video/x-raw-rgb"))
- self.remuxcaps.append_structure(Gst.Structure("video/x-raw-yuv"))
+ self.remuxcaps.append_structure(Gst.Structure.from_string("video/x-raw"))
if self.videopasstoggle and not self.audiopasstoggle:
- self.remuxcaps.append_structure(Gst.Structure("audio/x-raw-float"))
- self.remuxcaps.append_structure(Gst.Structure("audio/x-raw-int"))
+ self.remuxcaps.append_structure(Gst.Structure.from_string("audio/x-raw"))
if self.videocaps=="novid":
if self.inputvideocaps != None:
self.remuxcaps.append(self.inputvideocaps)
- self.remuxcaps.append_structure(Gst.Structure("audio/x-raw-float"))
- self.remuxcaps.append_structure(Gst.Structure("audio/x-raw-int"))
-
+ self.remuxcaps.append_structure(Gst.Structure.from_string("audio/x-raw"))
if (self.audiopasstoggle) or (self.videopasstoggle) or (self.videocaps=="novid"):
self.uridecoder.set_property("caps", self.remuxcaps)
@@ -249,7 +232,7 @@ class Transcoder(GObject.GObject):
width, height = self.owidth, self.oheight
# Get Display aspect ratio
- pixelaspectratio = preset.vcodec.aspectratio[0]
+ pixelaspectratio = preset.vcodec.aspectratio
# Scale width / height down
if self.owidth > wmax:
diff --git a/src/transmageddon.py b/src/transmageddon.py
index c4c3af8..e80c815 100644
--- a/src/transmageddon.py
+++ b/src/transmageddon.py
@@ -219,8 +219,10 @@ class TransmageddonUI:
self.CodecBox.attach(self.videobox, 2, 3, 1, 2, yoptions = Gtk.AttachOptions.FILL)
self.CodecBox.show_all()
self.containerchoice.connect("changed", self.on_containerchoice_changed)
+ self.presetchoice.connect("changed", self.on_presetchoice_changed)
self.audiorows[0].connect("changed", self.on_audiocodec_changed)
self.videorows[0].connect("changed", self.on_videocodec_changed)
+
self.TopWindow.connect("destroy", Gtk.main_quit)
def get_file_path_from_dnd_dropped_uri(self, uri):
# get the path to file
@@ -319,8 +321,8 @@ class TransmageddonUI:
# create toggle so I can split codepath depending on if I using a preset
# or not
self.usingpreset=False
- self.presetaudiocodec="None"
- self.presetvideocodec="None"
+ self.presetaudiocodec=Gst.Caps.new_empty()
+ self.presetvideocodec=Gst.Caps.new_empty()
self.inputvideocaps=None # using this value to store videocodec name to feed uridecodebin to avoid decoding video when not keeping video
self.nocontainernumber = int(13) # this needs to be set to the number of the no container option in the menu (from 0)
self.p_duration = Gst.CLOCK_TIME_NONE
@@ -363,7 +365,8 @@ class TransmageddonUI:
for (name, device) in (presets.get().items()):
shortname.append(str(name))
- self.presetchoices = dict(zip(devicelist, shortname))
+ # self.presetchoices = dict(zip(devicelist, shortname))
+ self.presetchoices = shortname
self.presetchoice.prepend_text(_("No Presets"))
self.waiting_for_signal="False"
@@ -380,8 +383,9 @@ class TransmageddonUI:
preset = device.presets["Normal"]
self.usingpreset=True
self.containerchoice.set_active(-1) # resetting to -1 to ensure population of menu triggers
- self.presetaudiocodec=preset.acodec.name
- self.presetvideocodec=preset.vcodec.name
+ self.presetaudiocodec=Gst.caps_from_string(preset.acodec.name)
+ self.presetvideocodec=Gst.caps_from_string(preset.vcodec.name)
+ print "preset container is " +str(preset.container)
if preset.container == "application/ogg":
self.containerchoice.set_active(0)
elif preset.container == "video/x-matroska":
@@ -646,15 +650,10 @@ class TransmageddonUI:
else:
self.asourcecaps = audiointersect
output3 = Gst.Caps.to_string(videointersect)
- print "output is " + str(output3)
# test=videointersect.is_empty()
if videointersect.is_empty():
- print "is empty"
self.videopass=False
else:
- print "got caps"
- output3 = Gst.Caps.to_string(videointersect)
- print "output is " + str(output3)
self.videopass=True
if audiointersect.is_empty():
self.audiopass=False
@@ -944,7 +943,6 @@ class TransmageddonUI:
self.ProgressBar.set_fraction(0.0)
self.ProgressBar.set_text(_("Transcoding Progress"))
if self.builder.get_object("containerchoice").get_active() == self.nocontainernumber:
- # print "self.container is False"
self.container = False
self.videorows[0].set_active(self.videonovideomenuno)
self.videorows[0].set_sensitive(False)
@@ -952,7 +950,6 @@ class TransmageddonUI:
if self.builder.get_object("containerchoice").get_active()!= -1:
self.container = self.builder.get_object ("containerchoice").get_active_text()
self.check_for_elements()
- # print "self.container is " + str(self.container)
if self.discover_done == True:
self.check_for_passthrough(self.container)
self.populate_menu_choices()
@@ -961,7 +958,7 @@ class TransmageddonUI:
def on_presetchoice_changed(self, widget):
presetchoice = self.builder.get_object ("presetchoice").get_active()
- #print "presetchoice is " + str(presetchoice)
+ print "presetchoice is " +str(presetchoice)
self.ProgressBar.set_fraction(0.0)
if presetchoice == 0:
self.usingpreset=False
@@ -977,10 +974,13 @@ class TransmageddonUI:
self.CodecBox.set_sensitive(True)
self.transcodebutton.set_sensitive(True)
else:
+ print "we are using presets"
self.usingpreset=True
self.ProgressBar.set_fraction(0.0)
if presetchoice != None:
- self.devicename= self.presetchoices[presetchoice]
+ print self.presetchoices
+ print presetchoice
+ self.devicename= self.presetchoices[presetchoice-1]
self.provide_presets(self.devicename)
self.containerchoice.set_sensitive(False)
self.CodecBox.set_sensitive(False)
@@ -1000,7 +1000,7 @@ class TransmageddonUI:
if self.audiorows[0].get_active() == self.audiopassmenuno:
self.audiopasstoggle=True
elif self.usingpreset==True:
- self.AudioCodec = Gst.caps_from_string(self.presetaudiocodec)
+ self.AudioCodec = self.presetaudiocodec
def on_videocodec_changed(self, widget):
# print "videocodec changed"
@@ -1012,7 +1012,7 @@ class TransmageddonUI:
if self.videorows[0].get_active() == self.videopassmenuno:
self.videopasstoggle=True
elif self.usingpreset==True:
- self.VideoCodec = Gst.caps_from_string(self.presetvideocodec)
+ self.VideoCodec = self.presetvideocodec
def on_about_dialog_activate(self, widget):
print "activating about"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]