[Jahshaka-cvs] jah/jahtools/encoder flv.ui, NONE, 1.1 encoder.py, 1.11, 1.12
Status: Beta
Brought to you by:
jahshaka
From: tim <tim...@us...> - 2007-03-19 14:23:59
|
Update of /cvsroot/jahshaka/jah/jahtools/encoder In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv5954 Modified Files: encoder.py Added Files: flv.ui Log Message: encoder - added flv support Index: encoder.py =================================================================== RCS file: /cvsroot/jahshaka/jah/jahtools/encoder/encoder.py,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- encoder.py 5 Feb 2007 09:53:20 -0000 1.11 +++ encoder.py 19 Mar 2007 14:23:53 -0000 1.12 @@ -75,6 +75,13 @@ self.audio_modes[ self.audio_keys[ 2 ] ] = 44100 self.audio_modes[ self.audio_keys[ 3 ] ] = 48000 + self.bit_rate_keys = [ "50", "100", "200", "400" ] + self.bit_rate_modes = {} + self.bit_rate_modes[ self.bit_rate_keys[ 0 ] ] = 50 + self.bit_rate_modes[ self.bit_rate_keys[ 1 ] ] = 100 + self.bit_rate_modes[ self.bit_rate_keys[ 2 ] ] = 200 + self.bit_rate_modes[ self.bit_rate_keys[ 3 ] ] = 400 + self.dv_keys = [ "PAL", "PAL 16:9", "NTSC", "NTSC 16:9" ] self.dv_modes = {} self.dv_modes[ self.dv_keys[ 0 ] ] = { "rescale": (720, 576), "fps": (25, 1), "sar": (59, 54), "aspect_ratio": 4.0 / 3.0 } @@ -82,6 +89,13 @@ self.dv_modes[ self.dv_keys[ 2 ] ] = { "rescale": (720, 480), "fps": (30000, 1001), "sar": (10, 11), "aspect_ratio": 4.0 / 3.0 } self.dv_modes[ self.dv_keys[ 3 ] ] = { "rescale": (720, 480), "fps": (30000, 1001), "sar": (40, 33), "aspect_ratio": 16.0 / 9.0 } + self.flv_rescale_keys = [ "320x240", "427x240", "640x480", "854x480" ] + self.flv_rescale_modes = { } + self.flv_rescale_modes[ self.rescale_keys[ 0 ] ] = ( 320, 240 ) + self.flv_rescale_modes[ self.rescale_keys[ 1 ] ] = ( 427, 240 ) + self.flv_rescale_modes[ self.rescale_keys[ 2 ] ] = ( 640, 480 ) + self.flv_rescale_modes[ self.rescale_keys[ 3 ] ] = ( 854, 480 ) + # setup the ui self.app = app self.handle = jahwidgets.create_ui_from_file( utilities.get_absolute_path( "encoder.ui" ), jahwidgets.widget_handle() ) @@ -109,7 +123,7 @@ self.progress_label_prop.set( "idle" ) # populate known types - self.encoder_types = [ "mjpeg", "dv" ] + self.encoder_types = [ "mjpeg", "dv", "flv" ] jahwidgets.set_value( "encoder_type:items", self.handle, openpluginlib.any( self.encoder_types ) ) self.encoder_config = {} @@ -121,6 +135,10 @@ "hookup": self.dv_hookup, "encode": self.dv_encode } + self.encoder_config[ "flv" ] = { "ui": "flv.ui", + "hookup": self.flv_hookup, + "encode": self.flv_encode + } self.encoder_ui_handle = None self.type_changed( self.types_prop ) @@ -194,14 +212,18 @@ self.encoder_ui_handle.show( True ) def construct_input_sub_filter( self, input, _in, out, fps, audio ): + audio_str = "enable_audio=0" + if audio: + audio_str = "frequency=%i" % audio + return [ input, - "filter:conform", - "filter:resampler", "frequency=%i" % ( audio ), + "filter:conform", + "filter:resampler", + audio_str, "filter:clip", "in=%i" % ( _in ), "out=%i" % ( out ), - #"filter:threader", - "filter:wrapper", "fps_num=%i" % ( fps[0] ), "fps_den=%i" % ( fps[1] ) ] + "filter:frame_rate", "fps_num=%i" % ( fps[0] ), "fps_den=%i" % ( fps[1] ) ] - def construct_filter_graph_description( self, sar, fps, rescale, audio ): + def construct_filter_graph_description( self, sar, fps, rescale, audio, bit_rate = 0 ): graph = [ "colour:", "width=%i" % ( rescale[0] ), "height=%i" % ( rescale[1] ), @@ -216,6 +238,10 @@ graph.extend( [ "filter:playlist", "slots=%i" % ( len( self.media_list ) ), "filter:deinterlace", "filter:composite", "@0.out=@1.rpn_length" ] ) + + if bit_rate: + graph.extend( [ "video_bit_rate=%i" % bit_rate ] ) + return graph # mjpeg methods @@ -257,6 +283,30 @@ self.init_progress, self.update_progress ) + # flv methods + def flv_hookup( self ): + jahwidgets.set_value( "rescale:items", self.handle, openpluginlib.any( self.flv_rescale_keys ) ) + jahwidgets.set_value( "fps:items", self.handle, openpluginlib.any( self.fps_keys ) ) + jahwidgets.set_value( "bit_rate:items", self.handle, openpluginlib.any( self.bit_rate_keys ) ) + + def flv_encode( self ): + fps = self.fps_modes[ self.fps_keys[ jahwidgets.get_value( "fps:currentItem", self.handle ).as_int() ] ] + rescale = self.flv_rescale_modes[ self.rescale_keys[ jahwidgets.get_value( "rescale:currentItem", self.handle ).as_int() ] ] + bit_rate = self.bit_rate_modes[ self.bit_rate_keys[ jahwidgets.get_value( "bit_rate:currentItem", self.handle ).as_int() ] ] + bit_rate *= 1000 + + graph = self.construct_filter_graph_description( ( 1, 1 ), fps, rescale, 0, bit_rate ) + print graph + + output = self.get_output_filename( "flv" ) + store_props = { "name": output, "vcodec": "flv", "aspect_ratio": "1.0" } + + rpn.rpn( graph, + store_props, + self.query_cancel, + self.init_progress, + self.update_progress ) + # # Run the main method if required # @@ -283,7 +333,18 @@ enc = encoder( app ) if not len( sys.argv ) == 0: - enc.set_media_information( pickle.load( open( sys.argv[ 0 ], "r" ) ) ) + try: + enc.set_media_information( pickle.load( open( sys.argv[ 0 ], "r" ) ) ) + except: + desc = {} + desc[ "filename" ] = utilities.get_absolute_path( sys.argv[0] ) + desc[ "in" ] = 0; + desc[ "out" ] = -1; + desc_list = [] + desc_list.append( desc ) + + enc.set_media_information( desc_list ) + enc.show() # Execute the application --- NEW FILE: flv.ui --- <!DOCTYPE UI><UI version="3.3" stdsetdef="1"> <class>Form1</class> <widget class="QWidget"> <property name="name"> <cstring>Form1</cstring> </property> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>233</width> <height>97</height> </rect> </property> <property name="caption"> <string>Form1</string> </property> <grid> <property name="name"> <cstring>unnamed</cstring> </property> <widget class="jahwidgets::qt3::ComboBox" row="0" column="1"> <property name="name"> <cstring>rescale</cstring> </property> </widget> <widget class="jahwidgets::qt3::Label" row="0" column="0"> <property name="name"> <cstring>label1_2</cstring> </property> <property name="text"> <string>rescale:</string> </property> <property name="alignment"> <set>AlignVCenter|AlignRight</set> </property> </widget> <widget class="jahwidgets::qt3::ComboBox" row="1" column="1"> <property name="name"> <cstring>fps</cstring> </property> </widget> <widget class="jahwidgets::qt3::Label" row="1" column="0"> <property name="name"> <cstring>label1_3</cstring> </property> <property name="text"> <string>frame rate:</string> </property> <property name="alignment"> <set>AlignVCenter|AlignRight</set> </property> </widget> <widget class="jahwidgets::qt3::Label" row="2" column="0"> <property name="name"> <cstring>label1_3_2</cstring> </property> <property name="text"> <string>bit rate (kbps):</string> </property> <property name="alignment"> <set>AlignVCenter|AlignRight</set> </property> </widget> <widget class="jahwidgets::qt3::ComboBox" row="2" column="1"> <property name="name"> <cstring>bit_rate</cstring> </property> </widget> </grid> </widget> <customwidgets> </customwidgets> <layoutdefaults spacing="6" margin="11"/> <includehints> <includehint>combobox.h</includehint> <includehint>label.h</includehint> <includehint>combobox.h</includehint> <includehint>label.h</includehint> <includehint>label.h</includehint> <includehint>combobox.h</includehint> </includehints> </UI> |