如何使用 bash 命令或 Ruby 使用 ffmpeg 将 mp4 文件批量转换为 ogg [英] How to batch convert mp4 files to ogg with ffmpeg using a bash command or Ruby

查看:16
本文介绍了如何使用 bash 命令或 Ruby 使用 ffmpeg 将 mp4 文件批量转换为 ogg的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行的是 OSX,对视频转换一无所知.但是我有 200 个视频,它们都是 mp4 格式,无法在 Firefox 中播放.我需要将它们转换为 ogg 才能使用 html5 视频标签.

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.

这些文件位于文件夹结构中,因此很难一次处理一个文件.我希望 bash 命令或 Ruby 命令遍历所有子文件夹并找到所有 .mp4 并转换它们.

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.

我找到了一个关于如何使用 Google 执行此操作的参考:http://athmasagar.wordpress.com/2011/05/12/a-bash-script-to-convert-mp4-files-to-oggogv/

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

但不知道如何将其从 linux 转换为 osx.

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

推荐答案

虽然直接回答你的问题是这样的:

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;

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

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;

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

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.

这篇关于如何使用 bash 命令或 Ruby 使用 ffmpeg 将 mp4 文件批量转换为 ogg的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆