On gère le framerate de la vidéo. On gère le cas où le début et/ou la fin tombe sur une i-frame. On affiche les timestamps à vérifier dans la vidéo finale.
This commit is contained in:
34
removeads.py
34
removeads.py
@@ -194,6 +194,12 @@ def extractAllStreams(inputFile, begin, end, streams, filesPrefix, nbFrames, wid
|
|||||||
if stream['codec_type'] == 'video':
|
if stream['codec_type'] == 'video':
|
||||||
print("Extracting video stream: %s" % stream)
|
print("Extracting video stream: %s" % stream)
|
||||||
frameRate = stream['r_frame_rate']
|
frameRate = stream['r_frame_rate']
|
||||||
|
pattern = re.compile('^(?P<numerator>[0-9]+)/(?P<denominator>[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']
|
sar = stream['sample_aspect_ratio']
|
||||||
dar = stream['display_aspect_ratio']
|
dar = stream['display_aspect_ratio']
|
||||||
pixelFormat = stream['pix_fmt']
|
pixelFormat = stream['pix_fmt']
|
||||||
@@ -203,9 +209,9 @@ def extractAllStreams(inputFile, begin, end, streams, filesPrefix, nbFrames, wid
|
|||||||
colorPrimaries = stream['color_primaries']
|
colorPrimaries = stream['color_primaries']
|
||||||
codec = stream['codec_name']
|
codec = stream['codec_name']
|
||||||
extractPictures(inputFile=inputFile, begin=begin, nbFrames=nbFrames, prefix="%s-%d" % (filesPrefix, videoID), width=width, height=height)
|
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,
|
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
|
videoID=videoID+1
|
||||||
elif stream['codec_type'] == 'audio':
|
elif stream['codec_type'] == 'audio':
|
||||||
print("Extracting audio stream: %s" % stream)
|
print("Extracting audio stream: %s" % stream)
|
||||||
@@ -472,6 +478,8 @@ def main():
|
|||||||
# Pour chaque portion
|
# Pour chaque portion
|
||||||
partnum = 0
|
partnum = 0
|
||||||
mkvparts = []
|
mkvparts = []
|
||||||
|
checks = []
|
||||||
|
pos = timedelta()
|
||||||
|
|
||||||
for ts1, ts2 in parts:
|
for ts1, ts2 in parts:
|
||||||
# Trouver l'estampille de la trame 'I' la plus proche (mais postérieure) au début de la portion.
|
# 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']))
|
headIFrameTS = timedelta(seconds=float(headIFrame['pts_time']))
|
||||||
tailIFrameTS = timedelta(seconds=float(tailIFrame['pts_time']))
|
tailIFrameTS = timedelta(seconds=float(tailIFrame['pts_time']))
|
||||||
|
|
||||||
|
checks.append(pos+headIFrameTS-ts1)
|
||||||
|
|
||||||
subparts = []
|
subparts = []
|
||||||
|
|
||||||
head = extractAllStreams(inputFile=mkv, begin=ts1, end=headIFrameTS, nbFrames=nbHeadFrames, filesPrefix='part-%d-head' % (partnum), streams=streams, width=width, height=height)
|
if nbHeadFrames > 0:
|
||||||
subparts.append(head)
|
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
|
# Creating MKV file that corresponds to current part between I-frames
|
||||||
internal = open('part-%d-internal.mkv' % partnum, 'w')
|
internal = open('part-%d-internal.mkv' % partnum, 'w')
|
||||||
@@ -515,18 +526,27 @@ def main():
|
|||||||
extractMKVPart(inputFile=mkv, outputFile=internal, begin=headIFrameTS, end=tailIFrameTS)
|
extractMKVPart(inputFile=mkv, outputFile=internal, begin=headIFrameTS, end=tailIFrameTS)
|
||||||
subparts.append(internal)
|
subparts.append(internal)
|
||||||
|
|
||||||
subparts.append(tail)
|
if nbTailFrames > 0:
|
||||||
|
subparts.append(tail)
|
||||||
|
|
||||||
part = mergeMKVs(inputs=subparts, outputName="part-%d.mkv" % partnum)
|
part = mergeMKVs(inputs=subparts, outputName="part-%d.mkv" % partnum)
|
||||||
mkvparts.append(part)
|
mkvparts.append(part)
|
||||||
|
|
||||||
|
pos = pos+tailIFrameTS-ts1
|
||||||
|
|
||||||
|
# We need to check the end also
|
||||||
|
checks.append(pos)
|
||||||
|
|
||||||
nbParts = len(mkvparts)
|
nbParts = len(mkvparts)
|
||||||
if nbParts > 1:
|
if nbParts > 1:
|
||||||
mergeMKVs(inputs=mvkparts, outputName=args.output)
|
mergeMKVs(inputs=mkvparts, outputName=args.outputFile)
|
||||||
elif nbParts == 1:
|
elif nbParts == 1:
|
||||||
print("A single part")
|
print("A single part")
|
||||||
else:
|
else:
|
||||||
print("Nothing produced !")
|
print("Nothing produced !")
|
||||||
|
|
||||||
|
for c in checks:
|
||||||
|
logger.info("Please check cut smoothness at: %s" % c)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user