2018-07-06 11:18:15 +00:00
|
|
|
#!/usr/bin/python3
|
2010-04-22 08:14:04 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vi:si:et:sw=4:sts=4:ts=4
|
|
|
|
# GPL 2010 <j@mailb.org>
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
from optparse import OptionParser
|
|
|
|
import subprocess
|
|
|
|
import tempfile
|
|
|
|
|
2018-07-06 11:18:15 +00:00
|
|
|
from PIL import Image
|
2010-04-22 08:14:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
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]
|
2010-04-23 18:47:26 +00:00
|
|
|
p = subprocess.Popen(cmd)
|
2010-04-22 08:14:04 +00:00
|
|
|
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
|
2018-07-06 11:18:15 +00:00
|
|
|
ox = int(abs(height - width) / 2)
|
2010-04-22 08:14:04 +00:00
|
|
|
oy = 0
|
|
|
|
else:
|
|
|
|
height = int(int(opts.size) * (float(height) / width))
|
|
|
|
width = int(opts.size)
|
|
|
|
height = height - height % 2
|
|
|
|
ox = 0
|
2018-07-06 11:18:15 +00:00
|
|
|
oy = int(abs(height - width) / 2)
|
2010-04-22 08:14:04 +00:00
|
|
|
|
|
|
|
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)
|
2010-04-23 18:47:26 +00:00
|
|
|
|