oxtimeline/bin/oxframe

59 lines
1.7 KiB
Text
Raw Normal View History

2009-01-18 08:39:14 +00:00
#!/usr/bin/python
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
# GPL 2008
2009-06-21 19:42:10 +00:00
import gobject
gobject.threads_init()
2009-01-18 08:39:14 +00:00
import os
import sys
from optparse import OptionParser
import pygst
pygst.require("0.10")
import gst
import Image
root = os.path.join(os.path.abspath(os.path.dirname(__file__)), '..')
if os.path.exists(os.path.join(root, 'oxgst')):
sys.path.insert(0, root)
from oxgst import Video
if __name__ == '__main__':
width = None
height = None
size = None
parser = OptionParser()
parser.add_option('-x', '--width', dest='width', help='scale image to given width')
parser.add_option('-y', '--height', dest='height', help='scale image to given height')
2009-01-18 23:43:30 +00:00
parser.add_option('-p', '--pos', dest='pos', help='frame position in seconds, float')
2009-01-18 08:39:14 +00:00
parser.add_option('-i', '--input', dest='input', help='video input')
parser.add_option('-o', '--output', dest='output', help='path to save frame to, jpg, png supported')
(opts, args) = parser.parse_args()
if None in (opts.input, opts.output, opts.pos):
parser.print_help()
sys.exit()
if opts.width:
width = int(opts.width)
if opts.height:
height = int(opts.height)
video = Video(opts.input)
timestamp = int(float(opts.pos) * gst.SECOND)
frame = video.frame(timestamp)
if frame:
if width:
height = int(float(frame.size[1])/frame.size[0] * width)
height = height + height%2
size = (width, height)
elif height:
width = int(float(frame.size[0])/frame.size[1] * height)
width = width + width%2
size = (width, height)
if size:
frame = frame.resize(size, Image.ANTIALIAS)
frame.save(opts.output)