6

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.

4

2 回答 2

8

虽然您的问题的直接答案是这样的:

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

我认为您可能会使用VP8 或 webm 编解码器找到更好的结果,因为它会给您带来更好的结果,并且实际上是现代版本的 Firefox 的首选。鉴于此,你应该试试这个:

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

这两种方法都会导致您生成的视频质量下降,因为它们正在重新编码已经编码的材料,而且在我看来,即使是 webm 编解码器也远不如使用 h.264 正确编码的 MP4编解码器。

于 2012-05-28T02:24:24.553 回答
6

这是使用 Ruby,假设您使用的 ffmpeg 是正确的:

Dir.glob("**/*.mp4").each do |filename|
  new_filename = File.join(
    File.dirname(filename),
    "#{File.basename(filename, ".mp4")}.ogg")
  `ffmpeg -i "#{filename}" -acodec vorbis -vcodec libtheora "#{new_filename}"`
end

Dir.glob 以"**/*.mp4"递归方式匹配子目录中带有 .mp4 扩展名的所有文件。

于 2012-05-26T16:26:42.617 回答