From ceabbed29feadadda108622a576953ac514e24d5 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Thu, 22 Apr 2010 11:14:04 +0300 Subject: [PATCH] add oxposterframe, decode one frame more --- Makefile | 3 +-- oxframe.c | 2 +- oxposterframe | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 3 deletions(-) create mode 100755 oxposterframe diff --git a/Makefile b/Makefile index 0da8749..f6a81c5 100644 --- a/Makefile +++ b/Makefile @@ -26,8 +26,7 @@ ${PROG}: ${SRC} install: ${PROG} ${INSTALL} -c -m 555 -o root -g bin ${PROG} ${BINDIR} - test -d ${MAN1DIR} || ${INSTALL} -d -o root ${MAN1DIR} - ${INSTALL} -c -m 444 -o root -g bin ${MAN} ${MAN1DIR} + ${INSTALL} -c -m 555 -o root -g bin oxposterframe ${BINDIR} clean: -@rm -f ${PROG} *~ core *.core diff --git a/oxframe.c b/oxframe.c index 968ec51..628b01c 100644 --- a/oxframe.c +++ b/oxframe.c @@ -224,7 +224,7 @@ int main (int argc, char * argv[]) { } oggplay_set_data_callback(player, dump_frame_callback, NULL); - max_num = ((1<< granuleshift) - 1); + max_num = 1 << granuleshift; offset = 1000* max_num * fps_denom / fps_num; //ogg_int64_t duration = oggplay_get_duration(player); diff --git a/oxposterframe b/oxposterframe new file mode 100755 index 0000000..821636a --- /dev/null +++ b/oxposterframe @@ -0,0 +1,66 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# vi:si:et:sw=4:sts=4:ts=4 +# GPL 2010 + +import os +import sys +from optparse import OptionParser +import subprocess +import tempfile + +import Image + + +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() + + f, fname = tempfile.mkstemp(suffix='.png') + cmd = ['oxframe', '-i', opts.input, '-o', fname, '-p', opts.pos] + p = subprocess.Popen(cmd + ['-x', opts.size, ]) + p.wait() + frame = Image.open(fname) + width = frame.size[0] + height = frame.size[1] + if height > width: + p = subprocess.Popen(cmd + ['-y', opts.size, ]) + p.wait() + frame = Image.open(fname) + width = frame.size[0] + height = frame.size[1] + + if opts.size: + size = opts.size + else: + size = min(width, height) + + 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) + if os.path.exists(fname): + os.unlink(fname)