Skip to content

Instantly share code, notes, and snippets.

@Yasushi
Created May 22, 2009 03:49
Show Gist options
  • Save Yasushi/115917 to your computer and use it in GitHub Desktop.
Save Yasushi/115917 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby -Kn
fn=ARGV[0].to_s
bn=fn.sub(/\.flv$/,'')
vn="#{$$}_track1.h264"
an="#{$$}_track2.aac"
out="#{bn}.mp4"
fps=ARGV[1]
if not File.exists? fn
puts "#{fn} not found"
exit
end
if File.exists? out
puts "#{out} already exists"
exit
end
if !fps
if /\x09framerate\x00(.{8})/=~IO.read(fn, 1024)
fps = $1.unpack("G")[0]
else
puts "fps read error(#{Regexp.last_match})"
exit
end
end
if /[0-9]{2}(\.[0-9]+)?/ !~ fps.to_s
puts "invalid fps(#{fps})"
exit
end
system("ffmpeg","-i",fn,"-vcodec","copy","-vbsf","h264_mp4toannexb","-an",vn)
system("ffmpeg","-i",fn,"-vn","-acodec","copy",an)
system("MP4Box","-add",vn,"-add",an,"-fps",fps.to_s,out)
File.unlink(vn,an)
__END__
ffmpeg -i "$fn" -vcodec copy -vbsf h264_mp4toannexb -an "$vn"
ffmpeg -i "$fn" -vn -acodec copy "$an"
MP4Box -add "$vn" -add "$an" -fps $fps "$out"
rm -v "$vn" "$an"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment