From 28933b828137f6e4f692bc18f98fe1fe8ddc640a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Tronel?= Date: Tue, 28 Nov 2023 16:19:16 +0100 Subject: [PATCH] =?UTF-8?q?On=20g=C3=A8re=20le=20framerate=20de=20la=20vid?= =?UTF-8?q?=C3=A9o.=20On=20g=C3=A8re=20le=20cas=20o=C3=B9=20le=20d=C3=A9bu?= =?UTF-8?q?t=20et/ou=20la=20fin=20tombe=20sur=20une=20i-frame.=20On=20affi?= =?UTF-8?q?che=20les=20timestamps=20=C3=A0=20v=C3=A9rifier=20dans=20la=20v?= =?UTF-8?q?id=C3=A9o=20finale.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- removeads.py | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/removeads.py b/removeads.py index 3bc9c52..32c1872 100755 --- a/removeads.py +++ b/removeads.py @@ -194,6 +194,12 @@ def extractAllStreams(inputFile, begin, end, streams, filesPrefix, nbFrames, wid if stream['codec_type'] == 'video': print("Extracting video stream: %s" % stream) frameRate = stream['r_frame_rate'] + pattern = re.compile('^(?P[0-9]+)/(?P[0-9]+)$') + m = pattern.match(frameRate) + print(m) + if m != None: + frameRate = float(m['numerator']) / float(m['denominator']) + print(frameRate) sar = stream['sample_aspect_ratio'] dar = stream['display_aspect_ratio'] pixelFormat = stream['pix_fmt'] @@ -203,9 +209,9 @@ def extractAllStreams(inputFile, begin, end, streams, filesPrefix, nbFrames, wid colorPrimaries = stream['color_primaries'] codec = stream['codec_name'] extractPictures(inputFile=inputFile, begin=begin, nbFrames=nbFrames, prefix="%s-%d" % (filesPrefix, videoID), width=width, height=height) - inputParams.extend(['-i', '%s-%d-%%03d.ppm' % (filesPrefix, videoID)]) + inputParams.extend(['-framerate', '%f'%frameRate, '-i', '%s-%d-%%03d.ppm' % (filesPrefix, videoID)]) codecsParams.extend(['-c:v:%d' % videoID, codec, '-pix_fmt', pixelFormat, '-colorspace:v:%d' % videoID, colorSpace, '-color_primaries:v:%d' % videoID, colorPrimaries, - '-color_trc:v:%d' % videoID, colorTransfer, '-color_range:v:%d' % videoID, colorRange ]) + '-color_trc:v:%d' % videoID, colorTransfer, '-color_range:v:%d' % videoID, colorRange]) videoID=videoID+1 elif stream['codec_type'] == 'audio': print("Extracting audio stream: %s" % stream) @@ -472,6 +478,8 @@ def main(): # Pour chaque portion partnum = 0 mkvparts = [] + checks = [] + pos = timedelta() for ts1, ts2 in parts: # Trouver l'estampille de la trame 'I' la plus proche (mais postérieure) au début de la portion. @@ -501,13 +509,16 @@ def main(): headIFrameTS = timedelta(seconds=float(headIFrame['pts_time'])) tailIFrameTS = timedelta(seconds=float(tailIFrame['pts_time'])) + checks.append(pos+headIFrameTS-ts1) subparts = [] - head = extractAllStreams(inputFile=mkv, begin=ts1, end=headIFrameTS, nbFrames=nbHeadFrames, filesPrefix='part-%d-head' % (partnum), streams=streams, width=width, height=height) - subparts.append(head) + if nbHeadFrames > 0: + head = extractAllStreams(inputFile=mkv, begin=ts1, end=headIFrameTS, nbFrames=nbHeadFrames, filesPrefix='part-%d-head' % (partnum), streams=streams, width=width, height=height) + subparts.append(head) - tail = extractAllStreams(inputFile=mkv, begin=tailIFrameTS, end=ts2, nbFrames=nbTailFrames, filesPrefix='part-%d-tail' % (partnum), streams=streams, width=width, height=height) + if nbTailFrames > 0: + tail = extractAllStreams(inputFile=mkv, begin=tailIFrameTS, end=ts2, nbFrames=nbTailFrames, filesPrefix='part-%d-tail' % (partnum), streams=streams, width=width, height=height) # Creating MKV file that corresponds to current part between I-frames internal = open('part-%d-internal.mkv' % partnum, 'w') @@ -515,18 +526,27 @@ def main(): extractMKVPart(inputFile=mkv, outputFile=internal, begin=headIFrameTS, end=tailIFrameTS) subparts.append(internal) - subparts.append(tail) + if nbTailFrames > 0: + subparts.append(tail) part = mergeMKVs(inputs=subparts, outputName="part-%d.mkv" % partnum) mkvparts.append(part) + + pos = pos+tailIFrameTS-ts1 + + # We need to check the end also + checks.append(pos) nbParts = len(mkvparts) if nbParts > 1: - mergeMKVs(inputs=mvkparts, outputName=args.output) + mergeMKVs(inputs=mkvparts, outputName=args.outputFile) elif nbParts == 1: print("A single part") else: print("Nothing produced !") + for c in checks: + logger.info("Please check cut smoothness at: %s" % c) + if __name__ == "__main__": main()