#!/usr/bin/ruby require 'readline' require 'fileutils' o = ARGV[0] f = "/home/jgwong/tmp/disposable/runonce/temp-video-keyframes.mp4" t = "/home/jgwong/tmp/disposable/runonce/temp-video.mp4" identify = "mplayer -vo null -ao null -frames 0 -identify " ss = 0 endpos = 1 run = true #print "Finding out FPS... " # #a = `ffmpeg -i #{o} 2>&1` # #if a =~ /, ([0-9\.]+?) fps/m # fps = $1 # puts "#{fps}" #else # puts "FAILED!" # exit #end # #if ARGV[1] == 'no' FileUtils.cp o, f #else # puts "Reencoding for keyframes, please wait patiently..." # STDOUT.flush # `mencoder #{o} -idx -nosound -fps #{fps} -ofps 24 -ovc x264 -x264encopts keyint=10:bitrate=10500 -o "#{f}" 2>&1` #end `mplayer -vo x11 #{f}` while run endpos = ss + 1 #`ffmpeg -ss #{ss} -t 1 -i "#{f}" -vcodec copy -an -y #{t}` `mencoder -ss #{ss} -endpos 1 -of lavf -lavfopts format=mp4 -ovc copy -nosound "#{f}" -o "#{t}" 2>&1` `mplayer -vo x11 #{t}` i = `#{identify} #{t}` i =~ /ID_LENGTH=(.+?)\n/m puts "Duration: #{$1}" a = Readline.readline("(#{ss}) =>", true) if a == 'q' ss -= 0.5 elsif a == 'w' ss += 0.5 elsif a == 'a' ss -= 0.1 elsif a == 's' ss += 0.1 elsif a == 'z' ss -= 0.01 elsif a == 'x' ss += 0.01 elsif a == 'all' `mplayer -vo x11 #{f}` elsif a == 'quit' run = false elsif a == 'save' FileUtils.cp t, o puts "Video saved. #{o}" puts run = false else ss = a.to_f end ss = 0 if ss < 0 end