use extract_frame from pad.ma

This commit is contained in:
j 2008-07-03 18:40:06 +02:00
parent ba183e2dfd
commit 5f9a4ab588
2 changed files with 154 additions and 164 deletions

View File

@ -169,7 +169,7 @@ def extract_still(movie_file, png_file, inpoint):
inpoint = time2ms(inpoint) inpoint = time2ms(inpoint)
extractClipScript = abspath(join(dirname(__file__), "tools/extract_frame.py")) extractClipScript = abspath(join(dirname(__file__), "tools/extract_frame.py"))
cmd = '''%s "%s" "%s" %s 0 -1''' % (extractClipScript, movie_file, png_file, inpoint) cmd = '''%s "%s" "%s" %s 0 -1''' % (extractClipScript, movie_file, png_file, inpoint)
run_command(cmd.encode('utf-8')) run_command(cmd.encode('utf-8'), 100)
def extract_poster_still(movie_file, png_file, inpoint): def extract_poster_still(movie_file, png_file, inpoint):
ext = movie_file.split('.')[-1] ext = movie_file.split('.')[-1]

View File

@ -1,7 +1,7 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vi:si:et:sw=2:sts=2:ts=2 # vi:si:et:sw=4:sts=4:ts=4
# GPL written 2008 by j@pad.ma # GPL 2008
import gobject import gobject
gobject.threads_init() gobject.threads_init()
@ -22,9 +22,8 @@ class ExtractFrame:
duration = 0 duration = 0
height = 0 height = 0
width = 128 width = 128
def __init__(self, videofile, frame, frame_pos, width=128, height=0): def __init__(self, videofile, frame, frame_pos, width=128):
self.width = width self.width = width
self.height = height
self.frame_file = frame self.frame_file = frame
self.frame_pos = frame_pos self.frame_pos = frame_pos
self.mainloop = gobject.MainLoop() self.mainloop = gobject.MainLoop()
@ -114,15 +113,10 @@ class ExtractFrame:
self.bus.post(gst.message_new_eos(self.pipeline)) self.bus.post(gst.message_new_eos(self.pipeline))
def scaleto(self, width, height): def scaleto(self, width, height):
if self.width:
height = int(self.width / (float(width) / height)) height = int(self.width / (float(width) / height))
height = height - height % 2 height = height - height % 2
self.height = height
return (self.width, height) return (self.width, height)
else:
width = int(self.height * (float(width) / height))
width = width - width % 2
return (width, self.height)
def get_audio_info_cb(self, sink, buffer, pad): def get_audio_info_cb(self, sink, buffer, pad):
caps = sink.sink_pads().next().get_negotiated_caps() caps = sink.sink_pads().next().get_negotiated_caps()
@ -137,7 +131,6 @@ class ExtractFrame:
self.info["width"] = s['width'] self.info["width"] = s['width']
self.info["height"] = s['height'] self.info["height"] = s['height']
self.info["framerate"] = float(s['framerate']) self.info["framerate"] = float(s['framerate'])
self.info["pixel-aspect-ratio"] = "%d:%d" % (s['pixel-aspect-ratio'].num, s['pixel-aspect-ratio'].denom)
self.video.disconnect(self.video_cb) self.video.disconnect(self.video_cb)
def demux_pad_added(self, element, pad, bool): def demux_pad_added(self, element, pad, bool):
@ -170,7 +163,7 @@ class ExtractFrame:
def quit(self): def quit(self):
if self.frame_img: if self.frame_img:
if self.frame_size: if self.frame_size
img = self.frame_img.resize(self.frame_size, Image.ANTIALIAS) img = self.frame_img.resize(self.frame_size, Image.ANTIALIAS)
else: else:
img = self.frame_img img = self.frame_img
@ -187,14 +180,11 @@ class ExtractFrame:
if __name__ == "__main__": if __name__ == "__main__":
import sys import sys
width = 128 width = 128
height = 0
inputFile = sys.argv[1] inputFile = sys.argv[1]
outputFile = sys.argv[2] outputFile = sys.argv[2]
offset = int(float(sys.argv[3]) * gst.MSECOND) offset = int(float(sys.argv[3]) * gst.MSECOND)
if len(sys.argv) > 4: if len(sys.argv) > 4:
width = int(sys.argv[4]) width = int(sys.argv[4])
if len(sys.argv) > 5: f = ExtractFrame(inputFile, outputFile, offset, width)
height = int(sys.argv[5])
f = ExtractFrame(inputFile, outputFile, offset, width, height)
f.run() f.run()