frame extraction with mplayer, possibly we have to use that

This commit is contained in:
j 2007-07-22 17:44:41 +00:00
parent f58ed28f01
commit e14b0aabcd

View file

@ -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