Why not wrap avconv and ffmpeg using the Python sh module[1]? I was kind of curious about the problem myself so I did an implementation of the thumbnail extraction using ffprobe and ffmpeg (attached).[2]
[1] python-pbs pre-jessie, python-sh in jessie and sid https://github.com/amoffat/sh [2] based on this answer from SU: http://superuser.com/a/821680 On Sat, Mar 21, 2015 at 3:20 AM, Etienne Millon <m...@emillon.org> wrote: > * Brian May <br...@microcomaustralia.com.au> [150321 11:07]: >> I need to be able to generate a thumbnail of designated size and >> also tell what the width and height in pixels of the video; Being >> able to scale the video would be even better, but optional, I >> currently use avconv to do this. > > You should be able to get metadata using python-enzyme ; not sure > about what's best to actually extract the thumbnail. > > -- > Etienne Millon > > > -- > To UNSUBSCRIBE, email to debian-python-requ...@lists.debian.org > with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org > Archive: https://lists.debian.org/20150321102055.GA3789@klow >
from sh import ffmpeg,ffprobe import sys import json movie = sys.argv[1] frames = int(sys.argv[2]) videometadata = ffprobe("-v", "quiet", "-print_format", "json", "-show_format", "-show_streams", movie) videometadata = json.loads(videometadata.stdout) duration = float(videometadata['format']['duration']) print "Generating %d thumbnails for %s" % (frames,movie) for x in range(1,frames+1): timepoint = int( (x - 0.5) * duration / frames) print " Extracting thumbnail %d/%d @ %d" % (x,frames,timepoint) ffmpeg('-y', '-v', 'quiet', '-ss', timepoint, '-i', '%s' % movie, '-vframes', '1', 'image%d.jpg' % x)