如何在 OS X 中使用 shell 脚本以编程方式将 FLV 视频文件转换为 MP4?
我想批量转换包含数百个 FLV 文件的目录,以便每个文件都有一个 MP4 等效文件。我正在尝试通过编写 shell 脚本并从终端运行它来自动化此过程。我该如何去做呢?大多数可用的说明适用于使用 ffmpeg 的 Linux,但我认为 OS X 没有它。谢谢。
I want to batch convert a directory containing hundreds of FLV files so that each file has a MP4 equivalent. I'm trying to automate this process by writing a shell script and running it from the Terminal. How do I go about doing that? Most of the instructions available are for Linux using ffmpeg but I think OS X doesn't have it. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可以通过 Homebrew 或 MacPorts。使用 Homebrew 安装 ffmpeg 的命令是
brew install ffmpeg
;同样,使用 MacPorts 安装 ffmpeg 的命令是 sudo port install ffmpeg 。安装 ffmpeg 后,这里有一个用于转换文件的简单(并且有些幼稚)脚本。您可能需要添加更多标志,具体取决于您所需的选项。只需制作将上述脚本放入可执行文件的任何文件(例如,
chmod a+x path/to/convert_all_to_mp4.sh
)并通过其完全限定路径调用它或将包含它的目录添加到 PATH 环境变量中,并按您指定的名称调用脚本。You can install ffmpeg via Homebrew or MacPorts. The commnd to install ffmpeg with Homebrew is
brew install ffmpeg
; similarly, the command to install ffmpeg with MacPorts issudo port install ffmpeg
. Once you've installed ffmpeg, here is a simple (and somewhat naive) script for converting the files. You may need to add more flags, depending on your desired options.Just make whatever file you put the script above in executable (for example,
chmod a+x path/to/convert_all_to_mp4.sh
) and invoke it by its fully qualified path or add the directory containing it to the PATH environment varaible and invoke the script by the name you gave it.使用 ffmpeg 将 FLV 转换为 MP4
目标:使用 Bash 脚本将多个 Adobe Flash Video (FLV) 文件转换为 MP4。
我的环境:
MAC OS X 10.5.8、Terminal v.240.2、Bash v.3.2.17(此解决方案应适用于大多数 Apple Mac 系统)。
语言:
bash
描述:
该脚本将搜索指定位置中的所有 FLV 文件,遍历每个文件,将它们转换为等效的 MP4 视频,并将它们放置在子目录 MP4-yymmdd-HHMMSS 中。 在此过程中生成的日志文件放置在该子目录中的log目录中。
先决条件:
下载 ffmpeg 二进制文件并将其放置在
/usr/local/bin
目录中。我的代码基于 Jan 在trick77.com 上的博客。详情请参阅“参考资料”。
从“Bash 脚本”部分下载我的 bash 脚本。
我的代码说明
Limitations:
Only processes videos with the FLV1 and H264 codecs.
用法:
示例:
输出:
MP4-yymmdd-HHMMSS 子目录中的 mp4 文件
日志:
转换flv-to-mp4.log.txt - 程序日志
ffmpeg-yyyymmdd-HHMMSS.log.txt - 每个转换文件的 ffmpeg 二进制日志
ffmpeg.log.txt ; - 以上所有 ffmpeg 日志的编译
元数据.csv ; - 每个视频文件的元数据
讨论:
在我的第一次尝试中,我无法使用
-copy
ffmpeg 选项将视频转换为 FLV1 视频流。相反,我需要使用以下 ffmpeg 选项:-strictexperimental -b:a 64k
这意味着转换不会因小错误而停止,并且它使用 64k 音频比特率转换。
使用
-copy
选项只会重新混合输入视频,因此速度很快。否则,ffmpeg 将对文件进行转码,这会花费相当长的时间。该脚本将确定使用哪个选项。关键代码片段:
位置:
示例日志文件:
元数据日志文件:
结论:
完整的解决方案已在从 YouTube 下载的 73 个 FLV 文件上成功进行了测试。转码 34 个文件和重新混合 39 个文件花了 8 分钟,平均大小为 11MB。
Bash 脚本:
convert-flv-to-mp4.sh
参考文献:< /strong>
FFmpeg 二进制文件下载
FFmpeg 官方文档
如何在 Mac 上将 .flv Flash 视频转换为 .mp4
扩展性:
如果您有任何 FLV 文件包含 FLV1 或 H264 以外的视频流(例如 VP6、FLV4),请添加带有指向您的视频文件的链接的注释,我将更新我的代码来处理它。
Conversion from FLV to MP4 using ffmpeg
Aim: Convert multiple Adobe Flash Video (FLV) files to MP4 using a Bash script.
My Environment:
MAC OS X 10.5.8, Terminal v.240.2, Bash v.3.2.17 (This solution should work with most Apple Mac systems).
Language:
bash
Description:
This script will search for all FLV files in the specified location, iterate through each one, converting them to an equivalent MP4 video and place them in the sub-directory MP4-yymmdd-HHMMSS. Log files generated during the process are placed in the log directory within this sub-directory.
Prerequisites:
Download the ffmpeg binary and place in the
/usr/local/bin
directory.My code is based on Jan's blog on trick77.com. See "References" for details.
Download my bash script from the "Bash Script" section.
Explanation of my code
ffmpeg -i [file]
.Limitations:
Only processes videos with the FLV1 and H264 codecs.
Usage:
Example:
Output:
mp4 files in the MP4-yymmdd-HHMMSS subdirectory
Logs:
convert-flv-to-mp4.log.txt - program log
ffmpeg-yyyymmdd-HHMMSS.log.txt - ffmpeg binary log for each file converted
ffmpeg.log.txt - compilation of all the above ffmpeg logs
metadata.csv - metadata for each video file
Discussion:
In my first attempt, I was not able to convert videos with the FLV1 video stream using the
-copy
ffmpeg option. Instead, I needed to use the following ffmpeg options:-strict experimental -b:a 64k
This means that the conversion doesn't halt on minor errors and that it uses 64k audio bit rate conversion.
Using the
-copy
option just remuxes the input video and hence is fast. Otherwise, ffmpeg will transcode the file, which takes considerably longer. This script will determine which option to use.Key snippet of code:
where:
Example log file:
Metadata log file:
Conclusion:
A complete solution was successfully tested on 73 FLV files downloaded from youtube. It took 8 minutes to transcode 34 files and remux 39 files, on average 11MB in size.
Bash Script:
convert-flv-to-mp4.sh
References:
FFmpeg Binary Download
FFmpeg Official Documentation
How to convert .flv Flash video to .mp4 on the Mac
Extensibility:
If you have any FLV files that have a video stream other than FLV1 or H264, e.g. VP6, FLV4, add a comment with a link to your video file and I will update my code to handle it.
您可以使用 VLC
http://wiki.videolan.org/Transcode#Transcoding_with_the_Command_Prompt
you can do it with VLC
http://wiki.videolan.org/Transcode#Transcoding_with_the_Command_Prompt
另一种选择是MPEG Streamclip,它具有非常好的批处理功能。
Another alternative is MPEG Streamclip which has a really good batch function.