ts2mkv.py

changeset 26
361f76cd60ee
parent 25
078802773343
child 27
a2951f7c435e
equal deleted inserted replaced
25:078802773343 26:361f76cd60ee
216 if not option: 216 if not option:
217 option = tmp 217 option = tmp
218 else: 218 else:
219 if option != tmp: 219 if option != tmp:
220 failcount += 1 220 failcount += 1
221 if failcount > 12: 221 if failcount > 6:
222 print "!!! Crop detect is inconsistent" 222 print "!!! Crop detect is inconsistent"
223 self.info["msg_prepare"] += "WARNING: cropdetect >50% inconsistent over scan time, disabling autocrop\n" 223 self.info["msg_prepare"] += "WARNING: cropdetect inconsistent, disabling autocrop\n"
224 return None 224 return None
225 self.info["msg_prepare"] += "Crop detected: %s\n" % option 225 self.info["msg_prepare"] += "Crop detected: %s\n" % option
226 return option 226 return option
227 227
228 def __get_audiomap(self, info): 228 def __get_audiomap(self, info):
295 self.info["frames_total"] = round(self.info["frames_total"] * self.info["fps"], 0) 295 self.info["frames_total"] = round(self.info["frames_total"] * self.info["fps"], 0)
296 print "Input framerate: %f fps" % self.info["fps"] 296 print "Input framerate: %f fps" % self.info["fps"]
297 print "Total frames of input file: %i" % (self.info["frames_total"]) 297 print "Total frames of input file: %i" % (self.info["frames_total"])
298 298
299 299
300 def __get_ffmpeg_input_info(self, filename): 300 def __get_ffmpeg_input_info(self, filename, crop_minute = 5):
301 """ 301 """
302 Run ffmpeg for cropdetect and general input information 302 Run ffmpeg for cropdetect and general input information
303 """ 303 """
304 cmd = [ 304 cmd = [
305 "ffmpeg", "-hide_banner", 305 "ffmpeg", "-hide_banner",
306 "-ss 00:05:00", "-t 2", # search to 5 minutes, analyze 2 seconds 306 "-ss 00:%02i:00" % crop_minute, "-t 1", # search to 5 minutes, analyze 1 seconds
307 "-i %s" % filename, 307 "-i %s" % filename,
308 "-vf \"cropdetect=24:2:0\"", # detect black bar crop on top and bottom 308 "-vf \"cropdetect=24:2:0\"", # detect black bar crop on top and bottom
309 "-f null", "-" # no output file 309 "-f null", "-" # no output file
310 ] 310 ]
311 p = subprocess.Popen(shlex.split(" ".join(cmd)), \ 311 p = subprocess.Popen(shlex.split(" ".join(cmd)), \
406 cmd.append("-map %s" % v) 406 cmd.append("-map %s" % v)
407 self.info["msg_prepare"] += "Video Stream selected: Stream #%s\n" % v 407 self.info["msg_prepare"] += "Video Stream selected: Stream #%s\n" % v
408 408
409 flt = [] 409 flt = []
410 crop = self.get_crop_option() 410 crop = self.get_crop_option()
411 if not crop:
412 # load input file to get informations about
413 # scan to other position and try again
414 print "Scanning again for autocrop..."
415 self.info["msg_prepare"] += "Rescan autocrop on other position in input stream...\n"
416 self.__get_ffmpeg_input_info(fn["in"], 9)
417 crop = self.get_crop_option()
418
411 if crop: 419 if crop:
412 flt.append(crop) 420 flt.append(crop)
413 if self.config["scaledown"]: 421 if self.config["scaledown"]:
414 # -2 ensures division by two for codec 422 # -2 ensures division by two for codec
415 flt.append("scale='min(1280,iw)':-2'") 423 flt.append("scale='min(1280,iw)':-2'")
490 processor.config["scaledown"] = not args.ns 498 processor.config["scaledown"] = not args.ns
491 processor.config["rename"] = args.rename 499 processor.config["rename"] = args.rename
492 processor.config["overwrite"] = args.f 500 processor.config["overwrite"] = args.f
493 processor.config["firstaudio"] = args.fa 501 processor.config["firstaudio"] = args.fa
494 502
503 src = []
495 for srcstr in args.input: 504 for srcstr in args.input:
496 src = glob.glob(srcstr) 505 src.extend(glob.glob(srcstr))
497 for srcfile in src: 506 idx = 1
498 print "Processing: %s" % srcfile 507 for srcfile in src:
499 processor.load(srcfile) 508 print "\nProcessing file %i/%i: %s" % (idx, len(src), srcfile)
500 processor.convert() 509 processor.load(srcfile)
501 510 processor.convert()
502 511 idx += 1
512
513

mercurial