The progress bar for pictures extraction are now counted in number of pictures.

This commit is contained in:
Frédéric Tronel
2023-12-01 16:47:15 +01:00
parent ed0494b540
commit cf4850c8dc

View File

@@ -356,10 +356,11 @@ def extractPictures(inputFile, begin, nbFrames, width=640, height=480):
# "P6\nWIDTH HEIGHT\n255\n"
headerLen=2+1+ceil(log(width, 10))+1+ceil(log(height, 10))+1+3+1
logger.debug('Header length: %d' % headerLen)
length = (width*height*3+headerLen)*nbFrames
imageLength = width*height*3+headerLen
length = imageLength*nbFrames
logger.debug("Estimated length: %d" % length)
pg = trange(length)
pg = trange(nbFrames)
images = bytes()
with Popen(['ffmpeg', '-loglevel', 'quiet' ,'-y', '-ss', '%s'%begin, '-i', '/proc/self/fd/%d' % infd, '-s', '%dx%d'%(width, height), '-vframes', '%d'%nbFrames, '-c:v', 'ppm', '-f', 'image2pipe', '/proc/self/fd/%d' % fdw ], stdout=PIPE, close_fds=False) as ffmpeg:
while ffmpeg.poll() == None:
@@ -367,11 +368,11 @@ def extractPictures(inputFile, begin, nbFrames, width=640, height=480):
# fds, _, _ = select([fdr, ffmpeg.stdout], [], [], .1)
fds, _, _ = select([fdr], [], [], .1)
if fdr in fds:
buf = os.read(fdr, 1000000)
buf = os.read(fdr, imageLength)
# print("Read %d bytes of image. ffmpeg finished: %s" % (len(buf), ffmpeg.poll()))
if len(buf) == 0:
break
pg.update(len(buf))
pg.update(len(buf)/imageLength)
images=images+buf
if ffmpeg.stdout in fds:
for line in TextIOWrapper(ffmpeg.stdout, encoding="utf-8"):
@@ -383,11 +384,11 @@ def extractPictures(inputFile, begin, nbFrames, width=640, height=480):
while True:
fd, _, _ = select([fdr], [], [], .1)
if fd != []:
buf = os.read(fdr, 1000000)
buf = os.read(fdr, imageLength)
# print("Read %d bytes of image" % len(buf))
if len(buf) == 0:
break
pg.update(len(buf))
pg.update(len(buf)/imageLength)
images=images+buf
else:
# Nothing more to read