Created
September 27, 2012 05:13
-
-
Save Knio/3792271 to your computer and use it in GitHub Desktop.
Resize GOPRO images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dir=${1-.} | |
fps=${2-48} | |
if [ ! -s times.sub ] | |
then | |
find . -path "*/$dir/???GOPRO/GOPR????.JPG" -printf '%p\n' | sort | python `dirname $0`/subs.py > times.sub | |
fi | |
mplayer "mf://$dir/???GOPRO/GOPR????.JPG" -mf w=1920:h=1080:fps=$fps:type=jpg -ao null -benchmark -vo yuv4mpeg:file=>(x264 --demuxer y4m --crf 21 --preset fast --muxer mkv --output GOPRO.MKV -) -vf scale=1920:-3,flip,mirror,crop=1920:1080:0:0,pp=al -sub times.sub | |
# mplayer "mf://$dir/???GOPRO/GOPR????.JPG" -mf w=1280:h=720:fps=$fps:type=jpg -ao null -benchmark -vo yuv4mpeg:file=>(x264 --demuxer y4m --crf 21 --preset fast --muxer mkv --output GOPRO.MKV -) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from subprocess import * | |
j = os.path.join | |
GOPRO_ROOT = 'E:\\DCIM\\' | |
TEMP = 'E:\\TEMP\\' | |
input_files = [] | |
for path, dirs, files in os.walk(GOPRO_ROOT): | |
for i in files: | |
if not i.endswith('.JPG'): | |
continue | |
input_files.append(j(path, i)) | |
try: os.mkdir(TEMP) | |
except: pass | |
try: os.mkdir(j(TEMP, 'resize')) | |
except: pass | |
output_files = [] | |
def go(): | |
while 1: | |
i = None | |
try: | |
i = input_files.pop() | |
except IndexError: | |
return | |
o = j(TEMP, 'resize', os.path.basename(i)) | |
output_files.append(o) | |
if os.path.isfile(o): | |
continue | |
print i, o | |
call(['convert', i, '-flip', '-flop', '-resize', '1280x960', o], shell=True) | |
import threading | |
threads = [threading.Thread(target=go) for i in xrange(10)] | |
for i in threads: i.start() | |
for i in threads: i.join() | |
print 'Done resizing' | |
output_files.sort() | |
TEMP = 'T:\\TEMP\\' | |
YUV = j(TEMP, 'out.yuv') | |
MP4 = j(TEMP, 'out.mp4') | |
f = open(YUV, 'wb') | |
p = Popen(['K:\\SOFTWARE\\tools\\mjpeg\\jpeg2yuv.exe'] + '-f 25 -I p -R 0'.split(), stdin=PIPE, stdout=PIPE) | |
def w(): | |
while 1: | |
d = p.stdout.read(1024 * 1024) | |
f.write(d) | |
if not d: | |
break | |
t = threading.Thread(target=w) | |
t.start() | |
p.stdin.write('\n'.join(output_files)) | |
p.stdin.close() | |
t.join() | |
print 'Write YUV' | |
call(('K:\\SOFTWARE\\TOOLS\\z264.exe --input-res 1280x960 --fps 25 -o %s %s --pass 1' % (MP4, YUV)).split()) | |
call(('K:\\SOFTWARE\\TOOLS\\z264.exe --input-res 1280x960 --fps 25 -o %s %s --pass 2' % (MP4, YUV)).split()) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dir=${1-.} | |
out=${2-$dir/processed} | |
if [ ! -d $out ] | |
then | |
mkdir $out; | |
fi | |
for i in `find $dir -name 'GOPR*.JPG' -type f -printf '%p\\n' | sort` | |
do | |
echo $i; | |
if [ ! -d $out/`dirname $i` ] | |
then | |
mkdir -p $out/`dirname $i` | |
fi | |
if [ ! -s $out/$i ] | |
then | |
convert $i -flip -flop -resize 1280x720^ -gravity North -extent 1280x720 +contrast -unsharp 0x32x0.3x0 -normalize $out/$i | |
fi | |
done | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import re | |
import os | |
import os.path as p | |
import threading | |
from subprocess import * | |
def call(cmd): | |
p = Popen(cmd, stdin=PIPE, stdout=PIPE, shell=True) | |
out, err = p.communicate(None) | |
ret = p.returncode | |
if ret: | |
raise Exception(ret) | |
return out | |
def main(): | |
os.makedirs('resize') | |
files = call("find * -name 'GOPR*.JPG' -type f -printf '%p\\n'").split() | |
files.sort() | |
cmds = [] | |
done = [] | |
r = re.compile('^(\d\d\d)GOPRO/GOPR(\d\d\d\d).JPG$') | |
for f in files: | |
m = r.match(f) | |
if not m: | |
print 'skipping %s' % f | |
continue | |
out = 'resize/%s%s.JPG' % (m.group(1), m.group(2)) | |
cmds.append('convert %s -flip -flop -resize 1280x720^ -gravity North -extent 1280x720 %s' % (f, out)) | |
threads = [] | |
for thread in xrange(4): | |
def go(): | |
while 1: | |
try: | |
i = cmds.pop(0) | |
except IndexError: | |
return | |
print i | |
call(i) | |
done.append(i) | |
t = threading.Thread(target=go) | |
t.start() | |
threads.append(t) | |
for t in threads: | |
t.join() | |
print 'Resized %d files' % len(done) | |
print 'Encoding video..' | |
call( | |
'mplayer "mf://resize/*.JPG" -mf w=1280:h=720:fps=10:type=jpg ' | |
'-ao null -benchmark -vo yuv4mpeg:file=>(' | |
'x264 --demuxer y4m --crf 20 --preset faster ' | |
'--muxer mkv --output test.mkv -)') | |
print 'Done' | |
if __name__ == '__main__': | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import time | |
print('[BEGIN]') | |
i=0 | |
while 1: | |
try: | |
fname = raw_input() | |
except EOFError: | |
break | |
ts = os.stat(fname).st_mtime | |
st = time.localtime(ts) | |
s = time.strftime('%A %B %d %Y %H:%M.%S', st) | |
print('{%d}{%d}%s' % (i, i+1, s)) | |
i += 1 | |
print('[END]') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment