Changeset 1807

Show
Ignore:
Timestamp:
11/19/08 17:32:54 (16 months ago)
Author:
JensDiemer
Message:

VideoTools? updates.

Location:
CodeSnippets/VideoTools
Files:
3 added
6 modified

Legend:

Unmodified
Added
Removed
  • CodeSnippets/VideoTools

    • Property svn:ignore set to
      config.dat
  • CodeSnippets/VideoTools/eac3to.py

    r1799 r1807  
    55""" 
    66 
    7 import os, sys, glob, time, datetime, subprocess, logging 
     7import os, sys, glob, time, datetime, logging 
    88from pprint import pprint 
    99 
     
    1414from shared.config import VideoToolsConfig 
    1515from shared.tk_tools import askopenfilename2, askdirectory2, TkListbox 
    16 from shared.tools import make_slug, human_filesize 
     16from shared.tools import make_slug, human_filesize, subprocess2 
    1717 
    1818DEBUG = False 
     
    6060        self["vol_info"] = vol_info 
    6161        self["lable"] = vol_info[0] 
    62  
     62         
    6363    def debug(self): 
    6464        print "_"*79 
     
    8888        self["abs_path"] = abs_path # File path + filename 
    8989        self["stat"] = stat # os.stat 
    90  
     90         
    9191        self.cfg = cfg 
    9292 
     
    130130    def get_command(self, stream_selection): 
    131131        cmd = [self.cfg["eac3to"], self["abs_path"]] 
    132  
     132         
    133133        value_dict = {} 
    134134        for k,v in self["streams"].iteritems(): 
     
    136136            if v not in value_dict: 
    137137                value_dict[v] = [] 
    138  
     138         
    139139            value_dict[v].append(k) 
    140  
     140         
    141141#        pprint(value_dict) 
    142142 
     
    147147                        return True 
    148148                return False 
    149  
     149             
    150150            for stream_info in STREAMINFOS: 
    151151                if in_list(stream_txt, stream_info["txt_filter"]): 
    152152                    return stream_info["ext"] 
    153  
     153                 
    154154            raise RuntimeError( 
    155155                "No STREAMINFOS entry matched for '%s'" % stream_txt 
    156156            ) 
    157  
     157         
    158158        selected_streams = {} 
    159159        for stream_txt in stream_selection: 
     
    163163                print "Stream '%s' doesn't exist. Skip file." % stream_txt 
    164164                return 
    165  
     165             
    166166            file_ext = get_file_ext(stream_txt) 
    167  
     167             
    168168            for id in ids: 
    169169                filename = "%s - %i - %s%s" % ( 
     
    174174                ) 
    175175                out_filepath = os.path.join(self["out_path"], filename) 
    176  
     176                 
    177177                cmd.append("%i:" % id) 
    178178                cmd.append(out_filepath) 
    179  
     179                         
    180180        return cmd 
    181181 
     
    189189                print ">", line 
    190190            no, info = line.split(":",1) 
    191  
     191             
    192192            try: 
    193193                no = int(no) 
    194194            except ValueError: 
    195195                continue 
    196  
     196             
    197197            info = info.strip() 
    198  
     198             
    199199            self["streams"][no] = info 
    200  
     200  
    201201 
    202202    def get_stream_info(self): 
     
    216216            print "run '%s'..." % " ".join(cmd) 
    217217            process, output = subprocess2(cmd) 
    218  
     218             
    219219            f = file(self["eac3to_txt_path"], "w") 
    220220            f.write(output) 
    221221            f.close() 
    222  
     222             
    223223        return output 
    224224 
    225225    #------------------------------------------------------------------------- 
    226  
     226     
    227227    def debug(self): 
    228228        print "_"*79 
     
    250250    result = [] 
    251251    for drive in drives: 
     252        drive_letter = drive["letter"] 
    252253        try: 
    253             vol_info = win32api.GetVolumeInformation(drive.letter) 
     254            vol_info = win32api.GetVolumeInformation(drive_letter) 
    254255        except Exception, err: 
    255             #~ print "Skip drive '%s': %s" % (drive.letter, err) 
     256            print "Skip drive '%s': %s" % (drive_letter, err) 
    256257            continue 
    257258 
     
    273274        filetypes = [('M2TS File','*.m2ts')], 
    274275    ) 
    275  
     276     
    276277    vol_info = path.replace("\\", "_").replace(":","_") # Fallback 
    277278    for part in reversed(path.split(os.sep)[:-1]): 
     
    280281            vol_info = part 
    281282            break 
    282  
     283     
    283284    drive = Drive(os.path.splitdrive(path)[0], cfg) 
    284285    drive["stream_dir"] = os.path.split(path)[0] 
    285286    drive.set_vol_info((vol_info,)) 
    286  
     287     
    287288    drive.debug() 
    288  
     289     
    289290    drives = [drive,] 
    290  
     291     
    291292    cfg["last sourcedir"] = path 
    292  
     293     
    293294    return drives 
    294295 
     
    306307            print "Error: Path '%s' doesn't exist -> skip." % path 
    307308            continue 
    308  
     309         
    309310        glob_path = os.path.join(path, cfg["glob"]) 
    310311        print "Looking in", glob_path 
     
    313314        for abs_path in sorted(file_list): 
    314315            filename = os.path.basename(abs_path) 
    315  
     316             
    316317            stat = os.stat(abs_path) 
    317318 
     
    344345    for index, videofile in enumerate(videofiles): 
    345346        filesize = videofile["stat"].st_size 
    346  
     347         
    347348        line = "%s - %s" % (videofile["abs_path"], human_filesize(filesize)) 
    348349        item_list.append(line) 
    349  
     350         
    350351        if filesize>cfg["skip_size"]: 
    351352            activated.append(index) 
    352  
     353     
    353354#    size = stat.st_size 
    354355#    if size<cfg["skip_size"]: 
    355356#        # Skip small files 
    356 #        continue 
    357  
     357#        continue   
     358     
    358359    lb = TkListbox( 
    359360        title = "Please select", 
     
    364365    print "selected items:" 
    365366    pprint(lb.selection) # list of selected items. 
    366  
     367     
    367368    curselection = lb.curselection # tuple containing index of selected items 
    368     print "curselection:", curselection 
    369  
     369    print "curselection:", curselection       
     370         
    370371    new_list = [ 
    371372        item 
     
    380381 
    381382 
    382 def subprocess2(cmd): 
    383     print "_"*80 
    384     print "subprocess2():" 
    385     pprint(cmd) 
    386     print " -"*40 
    387     process = subprocess.Popen( 
    388         cmd, 
    389         stdout=subprocess.PIPE, 
    390         shell=True, 
    391     ) 
    392     output = "" 
    393     char_count = 0 
    394     while True: 
    395         char = process.stdout.read(1) 
    396         if char=="": 
    397             break 
    398  
    399         if char in ("\r", "\x08"): 
    400             continue 
    401  
    402         if char == "\n": 
    403             char_count = 0 
    404         else: 
    405             char_count += 1 
    406  
    407         output += char 
    408         sys.stdout.write(char) 
    409         if char_count>79: 
    410             sys.stdout.write("\n") 
    411             char_count = 0 
    412         sys.stdout.flush() 
    413  
    414     return process, output 
    415  
    416  
     383 
     384 
     385     
    417386def select_streams(videofiles): 
    418387    """ 
     
    426395            if not stream_txt in streams_txt: 
    427396                streams_txt.append(stream_txt) 
    428 # 
     397#     
    429398#    lb = TkListbox( 
    430399#        title = "Please select", 
     
    433402#    ) 
    434403#    print lb.selection 
    435  
     404     
    436405    selection = TkListbox( 
    437406        title = "Please select", 
     
    439408        items = streams_txt 
    440409    ).selection 
    441  
     410     
    442411    return selection 
    443412 
     
    445414    print "convert_streams():", videofile, stream_selection 
    446415    videofile.debug() 
    447  
    448  
    449  
    450  
    451 if __name__ == "__main__": 
     416     
     417     
     418 
     419 
     420if __name__ == "__main__":     
    452421    cfg = VideoToolsConfig() 
    453422    cfg.debug() 
    454  
     423     
    455424    if DEBUG: 
    456425        print "DEBUG!!!" 
     
    473442    # Select via Tk the files witch realy convert 
    474443    videofiles = select_videofiles(videofiles) 
    475  
     444     
    476445    if not videofiles: 
    477446        print "No stream files found -> abort, ok." 
     
    497466            print "ERROR: No streams found!" 
    498467            continue 
    499  
     468         
    500469 
    501470 
  • CodeSnippets/VideoTools/shared/tk_tools.py

    r1798 r1807  
    1717        sys.exit() 
    1818     
    19     return os.path.normpath(path) 
     19    if isinstance(path, tuple): 
     20        return [os.path.normpath(i) for i in path] 
     21    else: 
     22        return os.path.normpath(path) 
    2023 
    2124def askdirectory2(*args, **kwargs): 
  • CodeSnippets/VideoTools/shared/tools.py

    r1797 r1807  
    11# -*- coding: utf-8 -*- 
    22 
    3 import os, sys, string 
     3import os, sys, string, subprocess 
     4from pprint import pprint 
    45 
    56 
     
    7980 
    8081 
     82 
     83 
     84def subprocess2(cmd, debug=False): 
     85    """ 
     86    start a subprocess and display all output 
     87    """ 
     88    print "_"*80 
     89    print "subprocess2():" 
     90    pprint(cmd) 
     91    print " -"*40 
     92    if debug: 
     93        print "(Debug only, nothing would be started.)" 
     94        return 
     95    process = subprocess.Popen( 
     96        cmd, 
     97        stdout=subprocess.PIPE, 
     98        shell=True, 
     99    ) 
     100    output = "" 
     101    char_count = 0 
     102    while True: 
     103        char = process.stdout.read(1) 
     104        if char=="": 
     105            break 
     106 
     107        if char in ("\r", "\x08"): 
     108            continue 
     109         
     110        if char == "\n": 
     111            char_count = 0 
     112        else: 
     113            char_count += 1 
     114 
     115        output += char 
     116        sys.stdout.write(char) 
     117        if char_count>79: 
     118            sys.stdout.write("\n") 
     119            char_count = 0             
     120        sys.stdout.flush() 
     121 
     122    return process, output 
     123 
     124 
     125 
     126 
     127 
    81128if __name__ == "__main__": 
    82129    import doctest 
  • CodeSnippets/VideoTools/Templatemaker.py

    r1797 r1807  
    308308    print "rate value:", rate_value 
    309309     
    310     create_files(cfg, video_file_path, template, rate_value, x264_settings) 
     310    if len(sys.argv)>1: 
     311        for fn in sys.argv[1:]: 
     312            create_files(cfg, fn, template, rate_value, x264_settings) 
     313    else: 
     314        create_files(cfg, video_file_path, template, rate_value, x264_settings) 
    311315     
    312316    print " -- END -- " 
  • CodeSnippets/VideoTools/templates/bitrate - 2pass with fast-first-pass/x264 2pass with fast-first-pass.cmd

    r1788 r1807  
    1919set stats_file=${basename} x264.stats 
    2020 
    21 set out_file1=${basename} x264 ${rate_value}KBits pass1.mkv 
    2221set out_file2=${basename} x264 ${rate_value}KBits pass2.mkv 
    2322 
     
    3837:pass1 
    3938echo on 
    40 %x264% --pass 1 %firstpass% --bitrate %rate_value% --stats "%stats_file%" -o "%out_file1%" "%pass1_source%" 
     39%x264% --pass 1 %firstpass% --bitrate %rate_value% --stats "%stats_file%" -o NUL "%pass1_source%" 
    4140@echo off 
    4241