减少相同格式的视频大小并减少帧大小
这个问题可能是非常基本的
有没有办法减少有损压缩(WMV,MPEG)格式的帧大小/速率,以获得更小的视频,更小的尺寸,具有相同的格式。
是否有任何开源或专有的 API 可以实现这一点?
This question might be very basic
Is there a way to reduce the frame size/rate of Lossy compressed (WMV, MPEG) format, to get a smaller video, of lesser size, with same format.
Are there any open source or proprietary apis for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
有一个适用于 Mac 和 Mac 的应用程序。 Windows 调用 Handbrake,我知道这不是命令行的东西,而是为了快速打开文件 - 选择输出文件格式和文件格式。粗略的输出大小,同时保留视频的大部分优点,那么这很好,它只是 ffmpeg 最佳状态的图形视图......
它确实支持那些顽固的文本输入者的命令行输入。
https://handbrake.fr/downloads.php
There is an application for both Mac & Windows call Handbrake, i know this isn't command line stuff but for a quick open file - select output file format & rough output size whilst keeping most of the good stuff about the video then this is good, it's a just a graphical view of ffmpeg at its best ...
It does support command line input for those die hard texters..
https://handbrake.fr/downloads.php
我发现自己最近也想这样做,所以我创建了一个名为 Shrinkwrap 的工具,它使用 FFmpeg 对视频进行转码,同时保留尽可能多的原始元数据(包括文件修改时间戳)。
您可以将其作为 docker 容器运行:
其中:
Convert
然后它将递归地查找与扩展名并将它们全部转码为带有
-tc
后缀的同名文件。有关更多配置选项、GoPro 预设等,请参阅自述文件。
希望这对某人有帮助!
I found myself wanting to do this too recently, so I created a tool called Shrinkwrap that uses FFmpeg to transcode videos, while preserving as much of the original metadata as possible (including file modification timestamps).
You can run it as a docker container:
Where:
convert
Then it will recursively find all of the video files that match the extension and transcode them all into files of the same name with a
-tc
suffix.For more configuration options, presets for GoPro etc, see the readme.
Hope this helps someone!
-i 输入文件
-b:v 输出视频的视频比特率(以千字节为单位)(您必须尝试)
-s 输出视频的尺寸
-fs 输出视频的FILESIZE(以千字节为单位)
-vcodec videocodec(使用
ffmpeg -codecs
列出所有可用的编解码器)-i input file
-b:v videobitrate of output video in kilobytes (you have to try)
-s dimensions of output video
-fs FILESIZE of output video in kilobytes
-vcodec videocodec (use
ffmpeg -codecs
to list all available codecs)ffmpeg 提供此功能。您需要做的就是运行类似的命令
对于较新版本的 ffmpeg,您需要将
-b
更改为-b:v
:将输入视频文件转换为视频使用 MPEG 1 视频编解码器并仅复制原始音频流,大小为 640 x 480,比特率为 512 kbps。当然,您可以插入所需的任何值,并调整大小和比特率,以实现您正在寻找的质量/大小权衡。 中还描述了许多其他选项
文档 Run
ffmpeg -formats
或ffmpeg -codecs
获取所有可用格式和编解码器的列表。如果您不必为最终输出指定特定的编解码器,则可以使用 H.264 等最先进的编解码器以最小的质量损失实现更好的压缩比。ffmpeg provides this functionality. All you need to do is run someting like
For newer versions of ffmpeg you need to change
-b
to-b:v
:to convert the input video file to a video with a size of 640 x 480 and a bitrate of 512 kilobits/sec using the MPEG 1 video codec and just copying the original audio stream. Of course, you can plug in any values you need and play around with the size and bitrate to achieve the quality/size tradeoff you are looking for. There are also a ton of other options described in the documentation
Run
ffmpeg -formats
orffmpeg -codecs
for a list of all of the available formats and codecs. If you don't have to target a specific codec for the final output, you can achieve better compression ratios with minimal quality loss using a state of the art codec like H.264.如果您想保持相同的屏幕尺寸,可以考虑使用 crf 因子:https://trac.ffmpeg.org/ wiki/Encode/H.264
这是对我有用的命令:(在 mac 上,您需要添加
-strict -2
才能使用 aac 音频编解码器。If you want to keep same screen size, you can consider using crf factor: https://trac.ffmpeg.org/wiki/Encode/H.264
Here is the command which works for me: (on mac you need to add
-strict -2
to be able to use aac audio codec.使用 H.264 编解码器,您可以选择不同的预设,而不是选择固定比特率,如 https 中所述://trac.ffmpeg.org/wiki/x264EncodingGuide。我还在 KeyJ 的博客上找到了视频编码器比较 (存档版本)是一本有趣的读物,它将 H.264 与 Theora 等进行了比较。
以下是我尝试过的各种选项的比较。录制的视频最初大小为673M,使用RecordMyScreen在iPad上拍摄。它的时长约为20分钟,分辨率为1024x768(视频的一半是空白的,所以我将其裁剪为768x768)。为了减小尺寸,我将分辨率降低到480x480。没有音频。
结果,采用相同的 1024x768 作为基础(并应用裁剪、缩放和过滤器):
-b 512k
,大小就下降到77M(编码时间:1分17秒)。-preset veryslow
(并且没有-b
),它变成了70M(编码时间:6m14s)-b 512k
和-preset veryslow
,大小变为77M(比仅仅-b 512k
小100K)。-preset veryslow -crf 28
,我得到了一个 39M 的文件,花了 5 分 47 秒(对我来说没有视觉质量差异)。N=1,所以对结果持保留态度并进行自己的测试。
Instead of chosing fixed bit rates, with the H.264 codec, you can also chose a different preset as described at https://trac.ffmpeg.org/wiki/x264EncodingGuide. I also found Video encoder comparison at KeyJ's blog (archived version) an interesting read, it compares H.264 against Theora and others.
Following is a comparison of various options I tried. The recorded video was originally 673M in size, taken on an iPad using RecordMyScreen. It has a duration of about 20 minutes with a resolution of 1024x768 (with half of the video being blank, so I cropped it to 768x768). In order to reduce size, I lowered the resolution to 480x480. There is no audio.
The results, taking the same 1024x768 as base (and applying cropping, scaling and a filter):
-b 512k
added, the size dropped to 77M (encoding time: 1m17s).-preset veryslow
(and no-b
), it became 70M (encoding time: 6m14s)-b 512k
and-preset veryslow
, the size becomes 77M (100K smaller than just-b 512k
).-preset veryslow -crf 28
, I get a file of 39M which took 5m47s (with no visual quality difference to me).N=1, so take the results with a grain of salt and perform your own tests.