Changeset 19f68114ed66d3e613ac582097a372e399f4af17
- Timestamp:
- 07/29/11 14:02:28 (10 months ago)
- Children:
- 7cebbdb62a64026be49de41d00e78e6af5cedef2, 3a775b411f35b86eb3571e5ee1847dbfa4067f9c
- Parents:
- 70076a735ad14f19763a31ed1f6e806027043cba
- git-committer:
- Luper Rouch <luper.rouch@…> (07/29/11 14:02:28)
- File:
-
- 1 edited
-
utils/avi2mkv/src/avi2mkv/__init__.py (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
utils/avi2mkv/src/avi2mkv/__init__.py
r70076a7 r19f6811 1 1 import os 2 2 import os.path as op 3 import re 3 4 import subprocess 4 5 import argparse … … 9 10 10 11 11 def mux_ avi(args):12 def mux_file(args): 12 13 """ 13 14 Mux an avi and its subtitles (if any) in a mkv file. … … 36 37 else: 37 38 subtitles_file = None 38 # Run mkvmerge 39 args = [ 40 "mkvmerge", 41 "-o", output_file, 42 "--quiet", 43 "--forced-track", "0:no", 44 "--compression", "0:none", 45 "--forced-track", "1:no", 46 "--compression", "1:none", 47 "-a", "1", 48 "-d", "0", 49 "-S", 50 "-T", 51 "--no-global-tags", 52 "--no-chapters", 53 input_file 54 ] 39 # Build mkvmerge args 40 args = ["mkvmerge", "-o", output_file] 41 for track in list_tracks(input_file): 42 args += ["--compression", "%d:none" % track] 55 43 if subtitles_file is not None: 44 args += ["-S", input_file] 56 45 out_fd = tempfile.NamedTemporaryFile() 57 46 subrip.clean_srt(open(subtitles_file, "rt"), out_fd) … … 59 48 args += [ 60 49 "--sub-charset", "0:%s" % options.charset, 61 "--forced-track", "0:no",62 50 "--compression", "0:none", 63 "-s", "0",64 "-D",65 "-A",66 "-T",67 "--no-global-tags",68 "--no-chapters",69 51 out_fd.name, 70 "--track-order", "0:0,0:1,1:0"71 52 ] 72 53 else: 73 args += [ "--track-order", "0:0,0:1"]54 args += [input_file] 74 55 kwargs = {} 75 56 if not options.quiet: … … 77 58 (input_file, output_file)) 78 59 else: 60 args += ["--quiet"] 79 61 fnull = open(os.devnull, "w") 80 62 kwargs["stdout"] = fnull 81 63 kwargs["stderr"] = fnull 64 # Run mkvmerge 65 if options.verbose: 66 sys.stdout.write("mkvmerge command line:\n%s\n" % " ".join(args)) 82 67 try: 83 68 subprocess.check_call(args, **kwargs) … … 85 70 sys.stderr.write("Error muxing '%s', mkvmerge exited with error " 86 71 "code %s\n" % (input_file, err.returncode)) 72 73 74 def list_tracks(filename): 75 """ 76 List and return track IDs in *filename* with ``mkvmerge --identify``. 77 """ 78 process = subprocess.Popen(["mkvmerge", "--identify", filename], 79 stdout=subprocess.PIPE, stderr=subprocess.PIPE) 80 stdout, stderr = process.communicate() 81 track_pattern = re.compile("Track ID ([0-9]+):") 82 ids = [] 83 for line in stdout.splitlines(): 84 match = track_pattern.match(line) 85 if match: 86 ids.append(int(match.group(1))) 87 return ids 87 88 88 89 … … 100 101 help="output directory (default is to create the new files in the " 101 102 "same directory as the input files)") 103 parser.add_argument("--force", "-f", action="store_true", default=False, 104 help="force overwrite of existing files") 102 105 parser.add_argument("--quiet", "-q", action="store_true", default=False, 103 106 help="be quiet") 104 parser.add_argument("-- force", "-f", action="store_true", default=False,105 help=" force overwrite of existing files")107 parser.add_argument("--verbose", action="store_true", default=False, 108 help="be verbose") 106 109 args = parser.parse_args() 107 110 # Run jobs 108 111 pool = multiprocessing.Pool(args.num_jobs) 109 pool.map(mux_ avi, [(f, args) for f in args.input_files])112 pool.map(mux_file, [(f, args) for f in args.input_files])
Note: See TracChangeset
for help on using the changeset viewer.
