generator: add progressbar (closes #1)
This commit is contained in:
14
generator
14
generator
@@ -21,7 +21,8 @@ Options:
|
|||||||
from docopt import docopt
|
from docopt import docopt
|
||||||
from moviepy.editor import VideoFileClip
|
from moviepy.editor import VideoFileClip
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
import glob, os, random, sys, shutil, math, tempfile
|
from click import progressbar
|
||||||
|
import glob, os, random, shutil, math, tempfile
|
||||||
|
|
||||||
|
|
||||||
TMP_FRAMES_PATH = tempfile.mkstemp()[1]
|
TMP_FRAMES_PATH = tempfile.mkstemp()[1]
|
||||||
@@ -40,14 +41,13 @@ def generate_video_thumbnail(args):
|
|||||||
def generate_frames(videoFileClip, interval, outputPrefix, size):
|
def generate_frames(videoFileClip, interval, outputPrefix, size):
|
||||||
print "Extracting", int(videoFileClip.duration / interval), "frames"
|
print "Extracting", int(videoFileClip.duration / interval), "frames"
|
||||||
frameCount = 0
|
frameCount = 0
|
||||||
for i in range(0, int(videoFileClip.duration), interval):
|
with progressbar(range(0, int(videoFileClip.duration), interval)) as items:
|
||||||
extract_frame(videoFileClip, i, outputPrefix, size, frameCount)
|
for i in items:
|
||||||
frameCount += 1
|
extract_frame(videoFileClip, i, outputPrefix, size, frameCount)
|
||||||
print " Frames extracted."
|
frameCount += 1
|
||||||
|
print "Frames extracted."
|
||||||
|
|
||||||
def extract_frame(videoFileClip, moment, outputPrefix, size, frameCount):
|
def extract_frame(videoFileClip, moment, outputPrefix, size, frameCount):
|
||||||
sys.stdout.write(".")
|
|
||||||
sys.stdout.flush()
|
|
||||||
output = outputPrefix + ("%05d.png" % frameCount)
|
output = outputPrefix + ("%05d.png" % frameCount)
|
||||||
videoFileClip.save_frame(output, t=int(moment))
|
videoFileClip.save_frame(output, t=int(moment))
|
||||||
resize_frame(output, size)
|
resize_frame(output, size)
|
||||||
|
|||||||
Reference in New Issue
Block a user