From e14b0aabcd1fe2b8df2191114994af8000eaee45 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sun, 22 Jul 2007 17:44:41 +0000 Subject: [PATCH] frame extraction with mplayer, possibly we have to use that --- oxdbarchive/tools/extract_poster_still.py | 50 +++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/oxdbarchive/tools/extract_poster_still.py b/oxdbarchive/tools/extract_poster_still.py index f8c9db5..ea45220 100644 --- a/oxdbarchive/tools/extract_poster_still.py +++ b/oxdbarchive/tools/extract_poster_still.py @@ -5,6 +5,7 @@ # import os import time +import shutil import gobject gobject.threads_init() @@ -99,6 +100,55 @@ class PosterStill: self.width = width return (self.width, self.height) +class PosterStillMplayer: + length = 0 + height = 0 + def __init__(self, videofile, png='', nseconds=-1, height=128): + import warnings + warnings.filterwarnings("ignore", "tempnam") + + self.height = height + self.videofile = videofile + self.png_frame = png + + framedir = os.tempnam() + os.mkdir(framedir) + os.chdir(framedir) + mplayer_options = '' + mplayer_options += " '%s'" % self.videofile + mplayer_options += " -ss '%s' -frames 2" % self.msec2time(nseconds) + mplayer_options += " -vo png " + mplayer_options += " -ao null" + mplayer = "mplayer %s >/dev/null 2>&1" % mplayer_options + + #execute mplayer + os.system (mplayer.encode('utf-8')) + #get a last decoded frame + files = os.listdir(framedir) + if files: + #scale and save it + self.scaleImage(files[-1]) + shutil.rmtree(framedir) + + def msec2time(self, msec): + import time + msec_string = "%s" % msec + ms = ",%s" % msec_string[-3:] + sec = float(msec) / 1000 + return time.strftime("%H:%M:%S", time.gmtime(sec)) + ms + + def scaleImage(self, tmpImage): + img = Image.open(tmpImage) + output_d = self.scaleto(i.size[0], i.size[1]) + img = img.resize(output_d, Image.ANTIALIAS) + img.save(self.png_frame) + + def scaleto(self, width, height): + width = int(self.height * (float(width) / height)) + width = width - width%2 + self.width = width + return (self.width, self.height) + if __name__ == "__main__": import sys height = 128