~nico-inattendu/luciole/bug_740324

« back to all changes in this revision

Viewing changes to luciole/project/export/export_video.py

  • Committer: NicoInattendu
  • Date: 2011-02-28 18:27:56 UTC
  • mfrom: (123.1.54 luciole-with-sound)
  • Revision ID: nico@inattendu.org-20110228182756-weonszu8zpzermrl
initial merge with luciole-with-sound branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
# related third party imports
45
45
import gobject
46
46
 
 
47
from pitivi.log.loggable import Loggable
 
48
 
47
49
# local application/library specific imports
48
50
import luciole.base.tools as LT
49
51
import luciole.base.exceptions as L_EXCEP
219
221
 
220
222
 
221
223
 
222
 
class MyExportThread(threading.Thread):
 
224
class MyExportThread(threading.Thread, Loggable):
223
225
    """ Export Thread. Thread in charge to enconde video in Yuv format
224
226
        to DV, DVD or XVID format
225
227
    """
237
239
            None, 
238
240
            "abort thread work")
239
241
  
240
 
    def __init__(self, export_type, video_out_path, yuv_queue, export_gui_obj) :
 
242
    def __init__(self, export_type, video_out_path, yuv_queue, export_gui_obj, audio_in_path = None) :
241
243
        """ Init export video Thread"""
 
244
        Loggable.__init__(self)
242
245
        super(MyExportThread, self).__init__()
243
 
        self.logger = logging.getLogger('luciole')
244
246
        self.__abort = False
245
247
        (self._export_type, self._video_in_path, self._video_out_path) = \
246
248
                (export_type, None, video_out_path)
247
249
        self.__queue = yuv_queue
248
250
        self._export_gui_obj = export_gui_obj
249
 
        self.__with_sound = False
250
251
        #only PAL is supported
251
252
        self.__video_format = "PAL"
252
 
        # no sound by default
253
 
        self.__with_sound = False
 
253
        self._audio_in_path = audio_in_path
 
254
 
254
255
    
 
256
        
255
257
    def _on_finish(self, abort):
256
258
        """Callback function. Raised when conversions is finished"""
257
259
        # update gui progress bar
309
311
            # add input video name
310
312
            ffmpeg_cmd.append('-i')
311
313
            ffmpeg_cmd.append(self._video_in_path)
 
314
            if self._audio_in_path is not None :
 
315
                ffmpeg_cmd.append('-i')
 
316
                ffmpeg_cmd.append(self._audio_in_path)
 
317
 
312
318
            # add video conversion options
313
319
            coding_command = DICT_ENCODER["PAL"][EXPORT_DV]       
314
320
            for ffmpeg_w in coding_command.split() : 
319
325
            #
320
326
            # launch ffmpeg subprocess
321
327
            #
322
 
            self.logger.debug("command :%s" % ffmpeg_cmd)
 
328
            self.debug("command :%s" , ffmpeg_cmd)
323
329
            sb_encoder = SP.Popen(ffmpeg_cmd, stdout=SP.PIPE, stderr=SP.PIPE)
324
330
            
325
331
            #
356
362
                for mencoder_w in coding_command.split() :
357
363
                    mencoder_cmd.append(mencoder_w)
358
364
            #finally add the input and output :
 
365
            if self._audio_in_path is not None :
 
366
                mencoder_cmd.append('-audiofile')
 
367
                mencoder_cmd.append(self._audio_in_path)
359
368
            mencoder_cmd.append(self._video_in_path)
360
369
            mencoder_cmd.append('-o')
361
370
            mencoder_cmd.append(self._video_out_path)
363
372
            #
364
373
            # launch mencoder command
365
374
            #
366
 
            self.logger.debug("command :%s" % mencoder_cmd)
 
375
            self.debug("command :%s" , mencoder_cmd)
367
376
            sb_encoder = SP.Popen(mencoder_cmd, stdout=SP.PIPE, stderr=SP.PIPE)
368
377
 
369
378
            #
429
438
            
430
439
 
431
440
 
432
 
class ExportVideo(object) :
 
441
class ExportVideo(Loggable) :
433
442
    """ 
434
443
    Class in charge of managing exports. The class use threads for conversions
435
444
    """
479
488
        else :
480
489
            msg = "[", self.__class__.__name__, \
481
490
                    "] ", value, " not in correct type"
482
 
            self.logger.info(msg)
 
491
            self.info(msg)
483
492
    def __del_image_input_type(self): 
484
493
        """ deleter for image_input_type """
485
494
        del self.__image_input_type
635
644
 
636
645
    def __init__(self, tmp_dir, export_gui_obj):
637
646
        """Init of class"""
 
647
        Loggable.__init__(self)
638
648
        self.__tmp_dir = os.path.join(tmp_dir,"export") 
639
 
        self.logger = logging.getLogger('luciole')
640
649
        self._clean_tmp_dir()
641
650
        
642
651
        # input image list
675
684
        self._t_encoder = None
676
685
        self._video_path = None
677
686
        self.__image_dir = None
 
687
        self._audio_in_path = None
678
688
        if self.__video_format == "PAL":
679
689
            self.__video_res = (720, 576)
680
690
        # export gui obj    
696
706
            'export_type' = the type of export 
697
707
                            (EXPORT_DV,EXPORT_DVD,EXPORT_XVID)
698
708
            'fpi' = the frame rate
 
709
            'soundfile" = path of sound file 
699
710
            """
700
711
 
701
712
        
714
725
            #
715
726
            # Check input parameters
716
727
            #
717
 
            self.logger.debug("export Data : %s "%export_data)
 
728
            self.debug("export Data : %s ",export_data)
718
729
            export_is_valid = False
719
730
            if export_data.has_key('image_input') :
720
731
                self.__image_input_type = export_data['image_input']
758
769
            else :
759
770
                export_is_valid = False
760
771
 
 
772
            if  (export_is_valid == True) and \
 
773
                    (export_data.has_key('soundfile')) :
 
774
                self._audio_in_path = export_data['soundfile']
 
775
                export_is_valid = True
 
776
                
 
777
 
761
778
            if (export_is_valid == True) and os.path.exists(_video_path) :
762
779
                try :
763
780
                    os.remove(_video_path) 
767
784
                    _serr =  _('Unable to erase : %s') % _err.filename
768
785
                    _serr = "%s \n %s" % (_serr,  _err.strerror)
769
786
                    raise L_EXCEP.LucioException, _serr
770
 
 
 
787
        
771
788
 
772
789
            if export_is_valid == True :
773
790
                # start yuv converter sub process
788
805
                        export_data['export_type'],
789
806
                        self._video_path,
790
807
                        self._data_queue,
791
 
                        self._export_gui_obj)
 
808
                        self._export_gui_obj,
 
809
                        self._audio_in_path)
792
810
                self._t_encoder.start()
793
811
            else :
794
812
                return (0, _video_path)
813
831
            self._clean_tmp_dir()
814
832
            try :
815
833
                os.remove(self._video_path ) 
816
 
                self.logger.debug("%s is removed" % self._video_path)
 
834
                self.debug("%s is removed" , self._video_path)
817
835
            except OSError, _err :
818
836
                _serr = _('Unable to erase : %s') % _err.filename
819
837
                _serr = "%s \n %s" % (_serr,  _err.strerror)
841
859
                _file_path = os.path.join(self.__tmp_dir, _file)
842
860
                try :
843
861
                    os.remove(_file_path) 
844
 
                    self.logger.debug("%s is removed" % _file_path)
 
862
                    self.debug("%s is removed" , _file_path)
845
863
                except OSError, _err :
846
864
                    _serr = _('Unable to erase : %s') % _err.filename
847
865
                    _serr = "%s \n %s" % (_serr,  _err.strerror)