The progress bar for pictures extraction are now counted in number of pictures.
This commit is contained in:
13
removeads.py
13
removeads.py
@@ -356,10 +356,11 @@ def extractPictures(inputFile, begin, nbFrames, width=640, height=480):
|
|||||||
# "P6\nWIDTH HEIGHT\n255\n"
|
# "P6\nWIDTH HEIGHT\n255\n"
|
||||||
headerLen=2+1+ceil(log(width, 10))+1+ceil(log(height, 10))+1+3+1
|
headerLen=2+1+ceil(log(width, 10))+1+ceil(log(height, 10))+1+3+1
|
||||||
logger.debug('Header length: %d' % headerLen)
|
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)
|
logger.debug("Estimated length: %d" % length)
|
||||||
|
|
||||||
pg = trange(length)
|
pg = trange(nbFrames)
|
||||||
images = bytes()
|
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:
|
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:
|
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, ffmpeg.stdout], [], [], .1)
|
||||||
fds, _, _ = select([fdr], [], [], .1)
|
fds, _, _ = select([fdr], [], [], .1)
|
||||||
if fdr in fds:
|
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()))
|
# print("Read %d bytes of image. ffmpeg finished: %s" % (len(buf), ffmpeg.poll()))
|
||||||
if len(buf) == 0:
|
if len(buf) == 0:
|
||||||
break
|
break
|
||||||
pg.update(len(buf))
|
pg.update(len(buf)/imageLength)
|
||||||
images=images+buf
|
images=images+buf
|
||||||
if ffmpeg.stdout in fds:
|
if ffmpeg.stdout in fds:
|
||||||
for line in TextIOWrapper(ffmpeg.stdout, encoding="utf-8"):
|
for line in TextIOWrapper(ffmpeg.stdout, encoding="utf-8"):
|
||||||
@@ -383,11 +384,11 @@ def extractPictures(inputFile, begin, nbFrames, width=640, height=480):
|
|||||||
while True:
|
while True:
|
||||||
fd, _, _ = select([fdr], [], [], .1)
|
fd, _, _ = select([fdr], [], [], .1)
|
||||||
if fd != []:
|
if fd != []:
|
||||||
buf = os.read(fdr, 1000000)
|
buf = os.read(fdr, imageLength)
|
||||||
# print("Read %d bytes of image" % len(buf))
|
# print("Read %d bytes of image" % len(buf))
|
||||||
if len(buf) == 0:
|
if len(buf) == 0:
|
||||||
break
|
break
|
||||||
pg.update(len(buf))
|
pg.update(len(buf)/imageLength)
|
||||||
images=images+buf
|
images=images+buf
|
||||||
else:
|
else:
|
||||||
# Nothing more to read
|
# Nothing more to read
|
||||||
|
|||||||
Reference in New Issue
Block a user