def provide_presets(self,devicename): devices = presets.get() device = devices[devicename] 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 if preset.container == "application/ogg": self.containerchoice.set_active(0) elif preset.container == "video/x-matroska": self.containerchoice.set_active(1) elif preset.container == "video/x-msvideo": self.containerchoice.set_active(2) elif preset.container == "video/mpeg,mpegversion=2,systemstream=true": self.containerchoice.set_active(3) elif preset.container == "video/mpegts,systemstream=true,packetsize=188": self.containerchoice.set_active(4) elif preset.container == "video/mpegts,systemstream=true,packetsize=192": self.containerchoice.set_active(5) elif preset.container == "video/x-flv": self.containerchoice.set_active(6) elif preset.container == "video/quicktime,variant=apple": self.containerchoice.set_active(7) elif preset.container == "video/quicktime,variant=iso": self.containerchoice.set_active(8) elif preset.container == "video/quicktime,variant=3gpp": self.containerchoice.set_active(9) elif preset.container == "application/mxf": self.containerchoice.set_active(10) elif preset.container == "video/x-ms-asf": self.containerchoice.set_active(11) elif preset.container == "video/webm": self.containerchoice.set_active(12) else: print "failed to set container format from preset data" # Check for number of passes # passes = preset.vcodec.passes #if passes == "0": self.multipass = False
def __init__(self): #Set up i18n for module in gtk.glade, gettext: module.bindtextdomain("transmageddon","../../share/locale") module.textdomain("transmageddon") #Set the Glade file self.gladefile = "transmageddon.glade" gtk.glade.XML.__init__ (self, self.gladefile) #Define functionality of our button and main window self.TopWindow = self.get_widget("TopWindow") self.FileChooser = self.get_widget("FileChooser") self.videoinformation = self.get_widget("videoinformation") self.audioinformation = self.get_widget("audioinformation") self.CodecBox = self.get_widget("CodecBox") self.presetchoice = self.get_widget("presetchoice") self.containerchoice = self.get_widget("containerchoice") self.codec_buttons = dict() for c in supported_audio_codecs: self.codec_buttons[c] = self.get_widget(c+"button") self.codec_buttons[c].connect("clicked", self.on_audiobutton_pressed, c) for c in supported_video_codecs: self.codec_buttons[c] = self.get_widget(c+"button") self.codec_buttons[c].connect("clicked", self.on_videobutton_pressed, c) self.transcodebutton = self.get_widget("transcodebutton") self.ProgressBar = self.get_widget("ProgressBar") self.cancelbutton = self.get_widget("cancelbutton") self.StatusBar = self.get_widget("StatusBar") self.TopWindow.connect("destroy", gtk.main_quit) self.signal_autoconnect(self) # Initialize User Interface # Set the Videos XDG UserDir as the default directory for the filechooser, # also make sure directory exists if 'get_user_special_dir' in glib.__dict__: self.VideoDirectory = glib.get_user_special_dir(glib.USER_DIRECTORY_VIDEOS) else: self.VideoDirectory = os.getenv('HOME') CheckDir = os.path.isdir(self.VideoDirectory) if CheckDir == (False): os.mkdir(self.VideoDirectory) self.FileChooser.set_current_folder(self.VideoDirectory) # Setting AppIcon FileExist = os.path.isfile("../../share/pixmaps/transmageddon.png") if FileExist: self.TopWindow.set_icon_from_file("../../share/pixmaps/transmageddon.png") else: try: self.TopWindow.set_icon_from_file("transmageddon.png") except: print "failed to find appicon" # default all but top box to insensitive by default # self.containerchoice.set_sensitive(False) self.CodecBox.set_sensitive(False) self.transcodebutton.set_sensitive(False) self.cancelbutton.set_sensitive(False) self.presetchoice.set_sensitive(False) # set default values for various variables self.AudioCodec = "vorbis" self.VideoCodec = "theora" self.ProgressBar.set_text(_("Transcoding Progress")) self.p_duration = gst.CLOCK_TIME_NONE self.p_time = gst.FORMAT_TIME # Populate the Container format combobox self.lst = supported_containers for i in self.lst: self.containerchoice.append_text(i) # Populate presets combobox selected = 0 for x, (id, device) in enumerate(sorted(presets.get().items(), lambda x, y: cmp(x[1].make + x[1].model, y[1].make + y[1].model))): iter = self.presetchoice.append_text(str(device)) if id == "computer": selected = x self.presetchoice.prepend_text("No Presets")
def provide_presets(self): 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 # calculate number of channels chanmin, chanmax = preset.acodec.channels if int(self.audiodata[0]['audiochannels']) < int(chanmax): if int(self.audiodata[0]['audiochannels']) > int(chanmin): channels = int(self.audiodata[0]['audiochannels']) else: channels = int(chanmin) else: channels = int(chanmax) self.audiodata[0]['outputaudiocaps'] = Gst.caps_from_string( preset.acodec.name + "," + "channels=" + str(channels)) # 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 owidth, oheight = self.videodata[0]['videowidth'], self.videodata[0][ 'videoheight'] # Get Display aspect ratio pixelaspectratio = preset.vcodec.aspectratio # Scale width / height down if self.videodata[0]['videowidth'] > wmax: self.videodata[0]['videowidth'] = wmax self.videodata[0]['videoheight'] = int( (float(wmax) / owidth) * oheight) if self.videodata[0]['videoheight'] > hmax: self.videodata[0]['videoheight'] = hmax self.videodata[0]['videowidth'] = int( (float(hmax) / oheight) * owidth) # Some encoders like x264enc are not able to handle odd height or widths if self.videodata[0]['videowidth'] % 2: self.videodata[0]['videowidth'] += 1 if self.videodata[0]['videoheight'] % 2: self.videodata[0]['videoheight'] += 1 # Add any required padding if self.blackborderflag == True: self.videodata[0]['videowidth'] = wmax self.videodata[0]['videoheight'] = hmax # 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.videodata[0]['videonum'] / self.videodata[0]['videodenom'] 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.videodata[0]['videonum'] denom = self.videodata[0]['videodenom'] # FIXME Question - should num and denom values be updated in self.videodata? self.videodata[0]['outputvideocaps'] = Gst.caps_from_string( preset.vcodec.name + "," + "height=" + str(self.videodata[0]['videoheight']) + "," + "width=" + str(self.videodata[0]['videowidth']) + "," + "framerate=" + str(num) + "/" + str(denom))
def provide_presets(self): 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 # calculate number of channels chanmin, chanmax = preset.acodec.channels if int(self.audiodata[0]["audiochannels"]) < int(chanmax): if int(self.audiodata[0]["audiochannels"]) > int(chanmin): channels = int(self.audiodata[0]["audiochannels"]) else: channels = int(chanmin) else: channels = int(chanmax) self.audiodata[0]["outputaudiocaps"] = Gst.caps_from_string( preset.acodec.name + "," + "channels=" + str(channels) ) # 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 owidth, oheight = self.videodata[0]["videowidth"], self.videodata[0]["videoheight"] # Get Display aspect ratio pixelaspectratio = preset.vcodec.aspectratio # Scale width / height down if self.videodata[0]["videowidth"] > wmax: self.videodata[0]["videowidth"] = wmax self.videodata[0]["videoheight"] = int((float(wmax) / owidth) * oheight) if self.videodata[0]["videoheight"] > hmax: self.videodata[0]["videoheight"] = hmax self.videodata[0]["videowidth"] = int((float(hmax) / oheight) * owidth) # Some encoders like x264enc are not able to handle odd height or widths if self.videodata[0]["videowidth"] % 2: self.videodata[0]["videowidth"] += 1 if self.videodata[0]["videoheight"] % 2: self.videodata[0]["videoheight"] += 1 # Add any required padding if self.blackborderflag == True: self.videodata[0]["videowidth"] = wmax self.videodata[0]["videoheight"] = hmax # 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.videodata[0]["videonum"] / self.videodata[0]["videodenom"] 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.videodata[0]["videonum"] denom = self.videodata[0]["videodenom"] # FIXME Question - should num and denom values be updated in self.videodata? self.videodata[0]["outputvideocaps"] = Gst.caps_from_string( preset.vcodec.name + "," + "height=" + str(self.videodata[0]["videoheight"]) + "," + "width=" + str(self.videodata[0]["videowidth"]) + "," + "framerate=" + str(num) + "/" + str(denom) )
def __init__(self): #Set up i18n gettext.bindtextdomain("transmageddon","../../share/locale") gettext.textdomain("transmageddon") self.builder = gtk.Builder() # Set the translation domain of builder # please note the call *right after* the builder is created self.builder.set_translation_domain("transmageddon") #initialize discoverer self.discovered = gst.pbutils.Discoverer(5000000000) self.discovered.connect('discovered', self.succeed) self.discovered.start() #Set the Glade file self.uifile = "transmageddon.ui" self.builder.add_from_file(self.uifile) self.builder.connect_signals(self) # Initialize User Interface self.audiorows=[] # set up the lists for holding the codec combobuttons self.videorows=[] self.audiocodecs=[] # create lists to store the ordered lists of codecs self.videocodecs=[] # set flag so we remove bogus value from menu only once self.bogus=0 # these dynamic comboboxes allow us to support files with multiple streams eventually def dynamic_comboboxes_audio(streams,extra = []): streams=1 # this will become a variable once we support multiple streams vbox = gtk.VBox() x=-1 while x < (streams-1): x=x+1 # print "x is " + str(x) store = gtk.ListStore(gobject.TYPE_STRING, *extra) combo = gtk.ComboBox(store) text_cell = gtk.CellRendererText() combo.pack_start(text_cell, True) combo.add_attribute(text_cell, 'text', 0) self.audiorows.append(combo) vbox.add(self.audiorows[x]) return vbox def dynamic_comboboxes_video(streams,extra = []): streams=1 vbox = gtk.VBox() x=-1 while x < (streams-1): x=x+1 store = gtk.ListStore(gobject.TYPE_STRING, *extra) combo = gtk.ComboBox(store) text_cell = gtk.CellRendererText() combo.pack_start(text_cell, True) combo.add_attribute(text_cell, 'text', 0) self.videorows.append(combo) vbox.add(self.videorows[x]) return vbox #Define functionality of our button and main window self.TopWindow = self.builder.get_object("TopWindow") self.FileChooser = self.builder.get_object("FileChooser") self.videoinformation = self.builder.get_object("videoinformation") self.audioinformation = self.builder.get_object("audioinformation") self.videocodec = self.builder.get_object("videocodec") self.audiocodec = self.builder.get_object("audiocodec") self.audiobox = dynamic_comboboxes_audio([gobject.TYPE_PYOBJECT]) self.videobox = dynamic_comboboxes_video([gobject.TYPE_PYOBJECT]) self.CodecBox = self.builder.get_object("CodecBox") self.presetchoice = self.builder.get_object("presetchoice") self.containerchoice = self.builder.get_object("containerchoice") self.rotationchoice = self.builder.get_object("rotationchoice") self.transcodebutton = self.builder.get_object("transcodebutton") self.ProgressBar = self.builder.get_object("ProgressBar") self.cancelbutton = self.builder.get_object("cancelbutton") self.StatusBar = self.builder.get_object("StatusBar") self.CodecBox.attach(self.audiobox, 0, 1, 1, 2, yoptions = gtk.FILL) self.CodecBox.attach(self.videobox, 2, 3, 1, 2, yoptions = gtk.FILL) self.CodecBox.show_all() 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 path = "" if uri.startswith('file:\\\\\\'): # windows path = uri[8:] # 8 is len('file:///') elif uri.startswith('file://'): # nautilus, rox path = uri[7:] # 7 is len('file://') elif uri.startswith('file:'): # xffm path = uri[5:] # 5 is len('file:') return path def on_drag_data_received(widget, context, x, y, selection, target_type, \ timestamp): if target_type == TARGET_TYPE_URI_LIST: uri = selection.data.strip('\r\n\x00') self.builder.get_object ("FileChooser").set_uri(uri) self.TopWindow.connect('drag_data_received', on_drag_data_received) self.TopWindow.drag_dest_set( gtk.DEST_DEFAULT_MOTION | gtk.DEST_DEFAULT_HIGHLIGHT | gtk.DEST_DEFAULT_DROP, dnd_list, \ gtk.gdk.ACTION_COPY) self.start_time = False self.multipass = False self.passcounter = False # Set the Videos XDG UserDir as the default directory for the filechooser # also make sure directory exists if 'get_user_special_dir' in glib.__dict__: self.videodirectory = \ glib.get_user_special_dir(glib.USER_DIRECTORY_VIDEOS) self.audiodirectory = \ glib.get_user_special_dir(glib.USER_DIRECTORY_MUSIC) else: print "XDG video or audio directory not available" self.videodirectory = os.getenv('HOME') self.audiodirectory = os.getenv('HOME') if self.videodirectory is None: print "XDG video or audio directory not available" self.videodirectory = os.getenv('HOME') self.audiodirectory = os.getenv('HOME') CheckDir = os.path.isdir(self.videodirectory) if CheckDir == (False): os.mkdir(self.videodirectory) CheckDir = os.path.isdir(self.audiodirectory) if CheckDir == (False): os.mkdir(self.audiodirectory) self.FileChooser.set_current_folder(self.videodirectory) # Setting AppIcon FileExist = os.path.isfile("../../share/pixmaps/transmageddon.svg") if FileExist: self.TopWindow.set_icon_from_file( \ "../../share/pixmaps/transmageddon.svg") else: try: self.TopWindow.set_icon_from_file("transmageddon.svg") except: print "failed to find appicon" # default all but top box to insensitive by default # self.containerchoice.set_sensitive(False) self.CodecBox.set_sensitive(False) self.transcodebutton.set_sensitive(False) self.cancelbutton.set_sensitive(False) self.presetchoice.set_sensitive(False) self.containerchoice.set_sensitive(False) self.rotationchoice.set_sensitive(False) # set default values for various variables self.AudioCodec = "vorbis" self.VideoCodec = "theora" self.ProgressBar.set_text(_("Transcoding Progress")) self.container = False self.vsourcecaps = False self.asourcecaps = False self.videopasstoggle=False # toggle for passthrough mode chosen self.audiopasstoggle=False self.videopass=False # toggle for enabling adding of video passthrough on menu self.audiopass=False self.containertoggle=False # used to not check for encoders with pbutils self.discover_done=False # lets us know that discover is finished self.missingtoggle=False self.interlaced=False self.havevideo=False # tracks if input file got video self.haveaudio=False self.devicename = "nopreset" self.nocontaineroptiontoggle=False self.outputdirectory=False # directory for holding output directory value # create variables to store passthrough options slot in the menu self.audiopassmenuno=1 self.videopassmenuno=1 self.videonovideomenuno=-2 # 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.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 self.p_time = gst.FORMAT_TIME # Populate the Container format combobox for i in supported_containers: self.containerchoice.append_text(i) # add i18n "No container"option self.containerchoice.append_text(_("No container (Audio-only)")) # Populate the rotatation box self.rotationlist = [_("No rotation (default)"),\ _("Clockwise 90 degrees"), \ _("Rotate 180 degrees"), _("Counterclockwise 90 degrees"), \ _("Horizontal flip"), _("Vertical flip"), \ _("Upper left diagonal flip"), _("Upper right diagnonal flip") ] for y in self.rotationlist: self.rotationchoice.append_text(y) self.rotationchoice.set_active(0) self.rotationvalue = int(0) # Populate Device Presets combobox devicelist = [] shortname = [] preset_list = sorted(presets.get().items(), key = (lambda x: x[1].make + x[1].model)) for x, (name, device) in enumerate(preset_list): self.presetchoice.append_text(str(device)) devicelist.append(str(device)) shortname.append(str(name)) #for (name, device) in (presets.get().items()): # shortname.append(str(name)) self.presetchoices = dict(zip(devicelist, shortname)) self.presetchoice.prepend_text(_("No Presets")) self.waiting_for_signal="False"
def provide_presets(self): devices = presets.get() device = devices[self.preset] preset = device.presets["Normal"] # set audio and video caps from preset file self.audiocaps=gst.Caps(preset.acodec.name) self.videocaps=gst.Caps(preset.vcodec.name) # Check for black border boolean border = preset.vcodec.border if border == "Y": self.blackborderflag = True else: self.blackborderflag = False # 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 # 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 # Add any required padding if self.blackborderflag == True: width=wmax height=hmax # 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
def provide_presets(self): devices = presets.get() device = devices[self.preset] preset = device.presets["Normal"] # set audio and video caps from preset file self.audiocaps = gst.Caps(preset.acodec.name) self.videocaps = gst.Caps(preset.vcodec.name) # Check for black border boolean border = preset.vcodec.border if border == "Y": self.blackborderflag = True else: self.blackborderflag = False # 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 # 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 # Add any required padding if self.blackborderflag == True: width = wmax height = hmax # 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 "transcoder_engine.py:" print "=============================================" print "height:", height print "width:", width print "=============================================" # print "final height " + str(height) + " final width " + str(width) return height, width, num, denom, pixelaspectratio