Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
731 views
in Technique[技术] by (71.8m points)

video - How to batch convert mp4 files to ogg with ffmpeg using a bash command or Ruby

I am running a OSX, don't know tons about video conversions. But I have like 200 videos that are all in mp4 format and won't play in Firefox. I need to convert them to ogg to use the html5 video tag.

These files live in a folder structure that makes it hard to do files one at a time. I would like the bash command or Ruby command to go through all child folders and find all .mp4's and convert them.

I found one reference of how to do this with Google: http://athmasagar.wordpress.com/2011/05/12/a-bash-script-to-convert-mp4-files-to-oggogv/

#!/bin/bash
for f in $(ls *mp4 | sed ‘s/(.*)..*/1/’)
do
ffmpeg -i $f.mp4 -acodec vorbis -vcodec libtheora $f.ogg
done

But have no idea how to convert this from linux to osx.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

While the direct answer to your question would be like this:

#!/bin/bash
MOVIES=~/Movies/
find "$MOVIES" -name '*.mp4' -exec sh -c 'ffmpeg -i "$0" -sameq "${0%%.mp4}.ogg"' {} ;
exit;

I think you might find better results using the VP8 or webm codec as it will give you much better results and is actually preferred in modern versions of Firefox. Given that, you should try this:

#!/bin/bash
MOVIES=~/Movies/
find "$MOVIES" -name '*.mp4' -exec sh -c 'ffmpeg -i "$0" -sameq "${0%%.mp4}.webm"' {} ;
exit;

Both of these methods WILL result in a loss of quality in your resulting videos as they are re-encoding the already encoded material and, in my opinion, even the webm codec is not nearly as good as a properly encoded MP4 using the h.264 codec.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...