Changeset 1807
- Timestamp:
- 11/19/08 17:32:54 (16 months ago)
- Location:
- CodeSnippets/VideoTools
- Files:
-
- 3 added
- 6 modified
-
. (modified) (1 prop)
-
AC3downconvert.cmd (added)
-
AC3downconvert.py (added)
-
eac3to.py (modified) (25 diffs)
-
shared/tk_tools.py (modified) (1 diff)
-
shared/tools.py (modified) (2 diffs)
-
Templatemaker.cmd (added)
-
Templatemaker.py (modified) (1 diff)
-
templates/bitrate - 2pass with fast-first-pass/x264 2pass with fast-first-pass.cmd (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
CodeSnippets/VideoTools
-
Property
svn:ignore set
to
config.dat
-
Property
svn:ignore set
to
-
CodeSnippets/VideoTools/eac3to.py
r1799 r1807 5 5 """ 6 6 7 import os, sys, glob, time, datetime, subprocess,logging7 import os, sys, glob, time, datetime, logging 8 8 from pprint import pprint 9 9 … … 14 14 from shared.config import VideoToolsConfig 15 15 from shared.tk_tools import askopenfilename2, askdirectory2, TkListbox 16 from shared.tools import make_slug, human_filesize 16 from shared.tools import make_slug, human_filesize, subprocess2 17 17 18 18 DEBUG = False … … 60 60 self["vol_info"] = vol_info 61 61 self["lable"] = vol_info[0] 62 62 63 63 def debug(self): 64 64 print "_"*79 … … 88 88 self["abs_path"] = abs_path # File path + filename 89 89 self["stat"] = stat # os.stat 90 90 91 91 self.cfg = cfg 92 92 … … 130 130 def get_command(self, stream_selection): 131 131 cmd = [self.cfg["eac3to"], self["abs_path"]] 132 132 133 133 value_dict = {} 134 134 for k,v in self["streams"].iteritems(): … … 136 136 if v not in value_dict: 137 137 value_dict[v] = [] 138 138 139 139 value_dict[v].append(k) 140 140 141 141 # pprint(value_dict) 142 142 … … 147 147 return True 148 148 return False 149 149 150 150 for stream_info in STREAMINFOS: 151 151 if in_list(stream_txt, stream_info["txt_filter"]): 152 152 return stream_info["ext"] 153 153 154 154 raise RuntimeError( 155 155 "No STREAMINFOS entry matched for '%s'" % stream_txt 156 156 ) 157 157 158 158 selected_streams = {} 159 159 for stream_txt in stream_selection: … … 163 163 print "Stream '%s' doesn't exist. Skip file." % stream_txt 164 164 return 165 165 166 166 file_ext = get_file_ext(stream_txt) 167 167 168 168 for id in ids: 169 169 filename = "%s - %i - %s%s" % ( … … 174 174 ) 175 175 out_filepath = os.path.join(self["out_path"], filename) 176 176 177 177 cmd.append("%i:" % id) 178 178 cmd.append(out_filepath) 179 179 180 180 return cmd 181 181 … … 189 189 print ">", line 190 190 no, info = line.split(":",1) 191 191 192 192 try: 193 193 no = int(no) 194 194 except ValueError: 195 195 continue 196 196 197 197 info = info.strip() 198 198 199 199 self["streams"][no] = info 200 200 201 201 202 202 def get_stream_info(self): … … 216 216 print "run '%s'..." % " ".join(cmd) 217 217 process, output = subprocess2(cmd) 218 218 219 219 f = file(self["eac3to_txt_path"], "w") 220 220 f.write(output) 221 221 f.close() 222 222 223 223 return output 224 224 225 225 #------------------------------------------------------------------------- 226 226 227 227 def debug(self): 228 228 print "_"*79 … … 250 250 result = [] 251 251 for drive in drives: 252 drive_letter = drive["letter"] 252 253 try: 253 vol_info = win32api.GetVolumeInformation(drive .letter)254 vol_info = win32api.GetVolumeInformation(drive_letter) 254 255 except Exception, err: 255 #~ print "Skip drive '%s': %s" % (drive.letter, err)256 print "Skip drive '%s': %s" % (drive_letter, err) 256 257 continue 257 258 … … 273 274 filetypes = [('M2TS File','*.m2ts')], 274 275 ) 275 276 276 277 vol_info = path.replace("\\", "_").replace(":","_") # Fallback 277 278 for part in reversed(path.split(os.sep)[:-1]): … … 280 281 vol_info = part 281 282 break 282 283 283 284 drive = Drive(os.path.splitdrive(path)[0], cfg) 284 285 drive["stream_dir"] = os.path.split(path)[0] 285 286 drive.set_vol_info((vol_info,)) 286 287 287 288 drive.debug() 288 289 289 290 drives = [drive,] 290 291 291 292 cfg["last sourcedir"] = path 292 293 293 294 return drives 294 295 … … 306 307 print "Error: Path '%s' doesn't exist -> skip." % path 307 308 continue 308 309 309 310 glob_path = os.path.join(path, cfg["glob"]) 310 311 print "Looking in", glob_path … … 313 314 for abs_path in sorted(file_list): 314 315 filename = os.path.basename(abs_path) 315 316 316 317 stat = os.stat(abs_path) 317 318 … … 344 345 for index, videofile in enumerate(videofiles): 345 346 filesize = videofile["stat"].st_size 346 347 347 348 line = "%s - %s" % (videofile["abs_path"], human_filesize(filesize)) 348 349 item_list.append(line) 349 350 350 351 if filesize>cfg["skip_size"]: 351 352 activated.append(index) 352 353 353 354 # size = stat.st_size 354 355 # if size<cfg["skip_size"]: 355 356 # # Skip small files 356 # continue 357 357 # continue 358 358 359 lb = TkListbox( 359 360 title = "Please select", … … 364 365 print "selected items:" 365 366 pprint(lb.selection) # list of selected items. 366 367 367 368 curselection = lb.curselection # tuple containing index of selected items 368 print "curselection:", curselection 369 369 print "curselection:", curselection 370 370 371 new_list = [ 371 372 item … … 380 381 381 382 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 417 386 def select_streams(videofiles): 418 387 """ … … 426 395 if not stream_txt in streams_txt: 427 396 streams_txt.append(stream_txt) 428 # 397 # 429 398 # lb = TkListbox( 430 399 # title = "Please select", … … 433 402 # ) 434 403 # print lb.selection 435 404 436 405 selection = TkListbox( 437 406 title = "Please select", … … 439 408 items = streams_txt 440 409 ).selection 441 410 442 411 return selection 443 412 … … 445 414 print "convert_streams():", videofile, stream_selection 446 415 videofile.debug() 447 448 449 450 451 if __name__ == "__main__": 416 417 418 419 420 if __name__ == "__main__": 452 421 cfg = VideoToolsConfig() 453 422 cfg.debug() 454 423 455 424 if DEBUG: 456 425 print "DEBUG!!!" … … 473 442 # Select via Tk the files witch realy convert 474 443 videofiles = select_videofiles(videofiles) 475 444 476 445 if not videofiles: 477 446 print "No stream files found -> abort, ok." … … 497 466 print "ERROR: No streams found!" 498 467 continue 499 468 500 469 501 470 -
CodeSnippets/VideoTools/shared/tk_tools.py
r1798 r1807 17 17 sys.exit() 18 18 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) 20 23 21 24 def askdirectory2(*args, **kwargs): -
CodeSnippets/VideoTools/shared/tools.py
r1797 r1807 1 1 # -*- coding: utf-8 -*- 2 2 3 import os, sys, string 3 import os, sys, string, subprocess 4 from pprint import pprint 4 5 5 6 … … 79 80 80 81 82 83 84 def 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 81 128 if __name__ == "__main__": 82 129 import doctest -
CodeSnippets/VideoTools/Templatemaker.py
r1797 r1807 308 308 print "rate value:", rate_value 309 309 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) 311 315 312 316 print " -- END -- " -
CodeSnippets/VideoTools/templates/bitrate - 2pass with fast-first-pass/x264 2pass with fast-first-pass.cmd
r1788 r1807 19 19 set stats_file=${basename} x264.stats 20 20 21 set out_file1=${basename} x264 ${rate_value}KBits pass1.mkv22 21 set out_file2=${basename} x264 ${rate_value}KBits pass2.mkv 23 22 … … 38 37 :pass1 39 38 echo 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%" 41 40 @echo off 42 41