frame extraction with mplayer, possibly we have to use that
This commit is contained in:
parent
f58ed28f01
commit
e14b0aabcd
1 changed files with 50 additions and 0 deletions
|
@ -5,6 +5,7 @@
|
||||||
#
|
#
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
import shutil
|
||||||
|
|
||||||
import gobject
|
import gobject
|
||||||
gobject.threads_init()
|
gobject.threads_init()
|
||||||
|
@ -99,6 +100,55 @@ class PosterStill:
|
||||||
self.width = width
|
self.width = width
|
||||||
return (self.width, self.height)
|
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__":
|
if __name__ == "__main__":
|
||||||
import sys
|
import sys
|
||||||
height = 128
|
height = 128
|
||||||
|
|
Loading…
Reference in a new issue