Add a new option to not take into account sequences that are shorter than a certain threshold.
This commit is contained in:
24
removeads.py
24
removeads.py
@@ -17,6 +17,8 @@ from tqdm import tqdm, trange
|
||||
from select import select
|
||||
from math import floor, ceil, log
|
||||
from shutil import copyfile, which
|
||||
import hexdump
|
||||
|
||||
|
||||
# Useful SPS/PPS discussion
|
||||
# TODO: improve situation of SPS and PPS header mismatch when merging MVK with mkvmerge to remove warnings.
|
||||
@@ -1092,12 +1094,18 @@ def main():
|
||||
parser.add_argument("-o", "--output", dest='outputFile', type=str, required=True, help="Output MKV file to produce.")
|
||||
parser.add_argument("-p", "--part", dest='parts', nargs='+', required=False, action='append', metavar="hh:mm:ss[.mmm]-hh:mm:ss[.mmm]", help="Extract this exact part of the original file.")
|
||||
parser.add_argument("-k", "--keep", action='store_true', help="Do not cleanup temporary files after processing.")
|
||||
parser.add_argument("--safe", action='store_true', help="Suppress headers and trailers to only keep safe parts of the movie.")
|
||||
parser.add_argument("-t", "--threshold", action='store', type=int, help="Suppress headers and trailers that are smaller than the threshold.")
|
||||
parser.add_argument("-f", "--fusion", action='store_true', help="Collapse the trailer of a part with the header of the next (when it makes sense).")
|
||||
parser.add_argument("--dump-memory", action='store_true', dest='dump', help="For debug purpose, dump all memory mapping of headers (and trailers) before (after) each part. They are kept in memory only otherwise.")
|
||||
parser.add_argument("-s","--srt", action='store_true', dest='srt', help="Dump subtitles ")
|
||||
|
||||
args = parser.parse_args()
|
||||
logger.debug("Arguments: %s" % args)
|
||||
|
||||
if args.threshold == None:
|
||||
args.threshold = 0
|
||||
|
||||
allOptionalTools, paths = checkRequiredTools()
|
||||
|
||||
# Flatten args.parts
|
||||
@@ -1252,7 +1260,7 @@ def main():
|
||||
|
||||
subparts = []
|
||||
|
||||
if nbHeadFrames > 0:
|
||||
if nbHeadFrames > args.threshold:
|
||||
# We extract all frames between the beginning upto the frame that immediately preceeds the I-frame.
|
||||
head = extractAllStreams(ffmpeg=paths['ffmpeg'], ffprobe=paths['ffprobe'], inputFile=mkv, begin=ts1, end=headIFrameTS, nbFrames=nbHeadFrames-1, filesPrefix='part-%d-head' % (partnum), streams=streams, width=width, height=height, temporaries=temporaries, dumpMemFD=args.dump)
|
||||
# Change private codec data of the new file so that it is the same as the one of the original movie
|
||||
@@ -1269,17 +1277,21 @@ def main():
|
||||
extractMKVPart(mkvmerge=paths['mkvmerge'], inputFile=mkv, outputFile=internal, begin=headIFrameTS, end=tailIFrameTS)
|
||||
subparts.append(internal)
|
||||
|
||||
if nbTailFrames > 0:
|
||||
if nbTailFrames > args.threshold:
|
||||
# We extract all frames between the I-frame (including it) upto the end.
|
||||
tail = extractAllStreams(ffmpeg=paths['ffmpeg'], ffprobe=paths['ffprobe'], inputFile=mkv, begin=tailIFrameTS, end=ts2, nbFrames=nbTailFrames, filesPrefix='part-%d-tail' % (partnum), streams=streams, width=width, height=height, temporaries=temporaries, dumpMemFD=args.dump)
|
||||
# Change private codec data of the new file so that it is the same as the one of the original movie
|
||||
changeCodecPrivateData(paths['mkvinfo'], tail, codecData)
|
||||
subparts.append(tail)
|
||||
|
||||
logger.info('Merging: %s' % subparts)
|
||||
part = mergeMKVs(inputs=subparts, outputName="part-%d.mkv" % partnum)
|
||||
mkvparts.append(part)
|
||||
temporaries.append(part)
|
||||
if not args.fusion:
|
||||
logger.info('Merging: %s' % subparts)
|
||||
part = mergeMKVs(inputs=subparts, outputName="part-%d.mkv" % partnum)
|
||||
mkvparts.append(part)
|
||||
temporaries.append(part)
|
||||
else:
|
||||
logging.error("Not yet implemented")
|
||||
exit(-1)
|
||||
|
||||
pos = pos+tailIFrameTS-ts1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user