防止“膨胀”的ffmpeg视频编码策略低质量视频
我们正在尝试构建一个基于 php 的视频共享网站,允许用户上传自己的内容。
我们需要将所有这些视频转换为中等质量的 mp4 视频文件,以便最终通过 FlowPlayer 进行流式传输。
我们的代码是这样的(例如 flv):
system("ffmpeg -i $vidPath -pass 1 -ab 64k -ar 44100 -ac 1 -vcodec flv -b 1500k -cmp 3 -subcmp 3 -mbd 2 $flvPath");
问题是这会将任何类型的 1 分钟视频转换为 10 MB 文件。如果它是高质量的 1 分钟视频,则会转换为 10 MB 文件 - 这很棒。但是,如果它是低质量视频,例如只有 2 MB,它仍然会被转换为 10 MB 文件!
我应该采取什么策略/方法,以便上传的视频的大小是“上限”,但相同长度的较低质量视频不会“膨胀”到相同的大小!
We're trying to build a php based video sharing site that allows users to upload their own content.
We need to convert all these videos into a medium-quality mp4 video file for eventual streaming through FlowPlayer.
Our code is something like this (example for flv):
system("ffmpeg -i $vidPath -pass 1 -ab 64k -ar 44100 -ac 1 -vcodec flv -b 1500k -cmp 3 -subcmp 3 -mbd 2 $flvPath");
The problem is that this converts any type of 1 minute video into a 10 MB file. If its a high quality 1 minute video, that gets converted to a 10 MB file - which is great. However, if its a low-quality video, say of just 2 MB, it will still get converted to a 10 MB file!!
What strategy / method should I adopt so that uploaded videos are "upper bound" in size, but lower quality videos of the same length dont get "inflated" to the same size!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您正在使用
-b
标志来强制比特率。当您使用-minrate
和-maxrate
标志时会发生什么,如文档中列出的而不是设置特定的比特率?另一个有趣的选项是 -fs,它设置最大文件大小。如果您可以在编码之前确定视频的长度,则可以根据该长度找出合适的上限。
It looks like you're using the
-b
flag to force a bitrate. What happens when you use the-minrate
and-maxrate
flags, as listed in the documentation instead of setting a specific bitrate?Another interesting option is
-fs
, which sets a maximum file size. If you can determine the length of the video before encoding it, you can figure out what a good upper limit would be based on that length.