Created
May 22, 2009 03:49
-
-
Save Yasushi/115917 to your computer and use it in GitHub Desktop.
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/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