From 9f489d306b847fb9f1f2f97f58448eff8a020bd2 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Mon, 19 Jan 2009 11:45:28 +1100 Subject: [PATCH] add oxposterframe, create 8 line timeline --- bin/oxposterframe | 59 +++++++++++++++++++++++++++++++++++++++++++++++ oxgst/timeline.py | 17 ++++++++++---- setup.py | 1 + 3 files changed, 72 insertions(+), 5 deletions(-) create mode 100755 bin/oxposterframe diff --git a/bin/oxposterframe b/bin/oxposterframe new file mode 100755 index 0000000..98960e2 --- /dev/null +++ b/bin/oxposterframe @@ -0,0 +1,59 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# vi:si:et:sw=4:sts=4:ts=4 +# GPL 2008 + +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', '--size', dest='size', help='scale image to size') + parser.add_option('-p', '--pos', dest='pos', help='frame position in seconds, float') + 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() + video = Video(opts.input) + timestamp = int(float(opts.pos) * gst.SECOND) + + frame = video.frame(timestamp) + if frame: + width = frame.size[0] + height = frame.size[1] + if opts.size: + if width > height: + width = int(int(opts.size) * (float(width) / height)) + height = int(opts.size) + width = width - width % 2 + ox = abs(height - width) / 2 + oy = 0 + else: + height = int(int(opts.size) * (float(height) / width)) + width = int(opts.size) + height = height - height % 2 + ox = 0 + oy = abs(height - width) / 2 + frame = frame.resize((width, height), Image.ANTIALIAS) + + frame = frame.crop((ox, oy, int(opts.size) + ox, oy + int(opts.size))) + frame.save(opts.output) + diff --git a/oxgst/timeline.py b/oxgst/timeline.py index f7446d1..2fd4bfa 100644 --- a/oxgst/timeline.py +++ b/oxgst/timeline.py @@ -138,16 +138,23 @@ def createTimelineMultiline(timeline_prefix, width=600, height=16): width = duration - (lines - 1) * lineWidth box = ((0, offset , width, offset + timlelineHeight)) i.paste(timelineColor, box) - timeline_file = '%s.timeline.overview.png' % (timeline_prefix) + timeline_file = '%s.overview.png' % (timeline_prefix) i.save(timeline_file, 'PNG') + timeline8_file = '%s.overview.8.png' % (timeline_prefix) + if lines < 8: + i.save(timeline8_file, 'PNG') + else: + i.crop((0,0,lineWidth, 8 * lineHeight)).save(timeline8_file, 'PNG') + + def makeTimelineByFramesPerPixel(timeline_prefix, frames_per_pixel, inpoint=0, outpoint=0, height=16): pos = 0 input_scale = 25 - timeline_file = '%s.timeline.%s.png' % (timeline_prefix, width) + timeline_file = '%s.pixels.%s.png' % (timeline_prefix, width) if outpoint > 0: - timeline_file = '%s.timeline.%s.%d-%d.png' % (timeline_prefix, width, inpoint, outpoint) + timeline_file = '%s.pixels.%s.%d-%d.png' % (timeline_prefix, width, inpoint, outpoint) timeline = loadTimeline(timeline_prefix) duration = timeline.size[0] @@ -170,9 +177,9 @@ def makeTimelineByFramesPerPixel(timeline_prefix, frames_per_pixel, inpoint=0, o def makeTimelineOverview(timeline_prefix, width, inpoint=0, outpoint=0, duration=-1, height=16): input_scale = 25 - timeline_file = '%s.timeline.%s.png' % (timeline_prefix, width) + timeline_file = '%s.overview.%s.png' % (timeline_prefix, width) if outpoint > 0: - timeline_file = '%s.timeline.%s.%d-%d.png' % (timeline_prefix, width, inpoint, outpoint) + timeline_file = '%s.overview.%s.%d-%d.png' % (timeline_prefix, width, inpoint, outpoint) timeline = loadTimeline(timeline_prefix) duration = timeline.size[0] diff --git a/setup.py b/setup.py index b21b1bd..6fdd037 100644 --- a/setup.py +++ b/setup.py @@ -11,6 +11,7 @@ setup(name="oxtools", 'bin/oxinfo', 'bin/oxframe', 'bin/oxposter', + 'bin/oxposterframe', 'bin/oxtimeline', ], packages = [