ts2mkv.py

changeset 34
344802cf307d
parent 30
6eaf5e9c6968
equal deleted inserted replaced
33:83bcb5931ee3 34:344802cf307d
199 def get_crop_option(self): 199 def get_crop_option(self):
200 """ 200 """
201 parse the ffmpeg analyze output cropdetect lines 201 parse the ffmpeg analyze output cropdetect lines
202 returns None or valid crop string for ffmpeg video filter 202 returns None or valid crop string for ffmpeg video filter
203 """ 203 """
204 if not self.config["cropdetect"]:
205 return None
204 lines = filter_lines(self.info["msg_ffmpeg"], "[Parsed_cropdetect").split("\n") 206 lines = filter_lines(self.info["msg_ffmpeg"], "[Parsed_cropdetect").split("\n")
205 option = None 207 option = None
206 failcount = 0 208 failcount = 0
207 for line in lines: 209 for line in lines:
208 tmp = line[line.find(" crop="):].strip() 210 tmp = line[line.find(" crop="):].strip()
209 # crop=1920:804:0:138 211 # crop=1920:804:0:138
210 if len(tmp.split(":")) != 4: 212 if len(tmp.split(":")) != 4:
211 print "Warning, invalid cropdetect: %s" % tmp 213 print "Warning, invalid cropdetect: %s" % tmp
212 return None 214 return None
213 if tmp.split(":")[2] != "0": 215 try:
214 print "!!! X crop detected, disabling autocrop (%s)" % tmp 216 if int(tmp.split(":")[2]) > 4:
215 self.info["msg_prepare"] += "WARNING: cropdetect suggested X crop, disabling autocrop\n" 217 print "!!! X crop detected, disabling autocrop (%s)" % tmp
218 self.info["msg_prepare"] += "WARNING: cropdetect suggested X crop, disabling autocrop\n"
219 return None
220 except ValueError:
221 print "invalid crop x shift value, ignoring autocrop"
216 return None 222 return None
217 #print "DEBUG: " + tmp 223 #print "DEBUG: " + tmp
218 if not option: 224 if not option:
219 option = tmp 225 option = tmp
220 else: 226 else:
488 help='h264 crf (default 19)') 494 help='h264 crf (default 19)')
489 parser.add_argument('--tune', default='film', \ 495 parser.add_argument('--tune', default='film', \
490 help='ffmpeg tune preset [film, animation] (default is film)') 496 help='ffmpeg tune preset [film, animation] (default is film)')
491 parser.add_argument('--ns', action='store_true', default=False, \ 497 parser.add_argument('--ns', action='store_true', default=False, \
492 help='no rescaling (default is scale to 720p)') 498 help='no rescaling (default is scale to 720p)')
499 parser.add_argument('--nc', action='store_true', default=False, \
500 help='no crop detection')
493 parser.add_argument('-f', action='store_true', default=False, \ 501 parser.add_argument('-f', action='store_true', default=False, \
494 help='force overwrite of existing file') 502 help='force overwrite of existing file')
495 parser.add_argument('--fa', action='store_true', default=False, \ 503 parser.add_argument('--fa', action='store_true', default=False, \
496 help='force use first audio stream') 504 help='force use first audio stream')
497 parser.add_argument('--rename', action='store_true', default=False, \ 505 parser.add_argument('--rename', action='store_true', default=False, \
504 help='one or more files, glob style syntax') 512 help='one or more files, glob style syntax')
505 513
506 args = parser.parse_args() 514 args = parser.parse_args()
507 processor = ts2mkv(crf=args.crf, tune=args.tune) 515 processor = ts2mkv(crf=args.crf, tune=args.tune)
508 processor.config["scaledown"] = not args.ns 516 processor.config["scaledown"] = not args.ns
517 processor.config["cropdetect"] = not args.nc
509 processor.config["rename"] = args.rename 518 processor.config["rename"] = args.rename
510 processor.config["overwrite"] = args.f 519 processor.config["overwrite"] = args.f
511 processor.config["firstaudio"] = args.fa 520 processor.config["firstaudio"] = args.fa
512 processor.config["dryrun"] = args.dryrun 521 processor.config["dryrun"] = args.dryrun
513 522

mercurial