减少相同格式的视频大小并减少帧大小

发布于 2024-10-08 07:28:06 字数 115 浏览 9 评论 0原文

这个问题可能是非常基本的

有没有办法减少有损压缩(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

作业与我同在 2024-10-15 07:28:07

有一个适用于 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

掌心的温暖 2024-10-15 07:28:07

我发现自己最近也想这样做,所以我创建了一个名为 Shrinkwrap 的工具,它使用 FFmpeg 对视频进行转码,同时保留尽可能多的原始元数据(包括文件修改时间戳)。

您可以将其作为 docker 容器运行:

docker run -v /path/to/your/videos:/vids bennetimo/shrinkwrap \
--input-extension mp4 --ffmpeg-opts crf=22,preset=fast /vids

其中:

  • /path/to/your/videos/ 是您想要播放视频的位置
    Convert
  • --input-extension 是你想要处理的视频类型,这里 .mp4
  • --ffmpeg-opts 是你想要用来自定义转码的任意 FFmpeg 选项

然后它将递归地查找与扩展名并将它们全部转码为带有 -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:

docker run -v /path/to/your/videos:/vids bennetimo/shrinkwrap \
--input-extension mp4 --ffmpeg-opts crf=22,preset=fast /vids

Where:

  • /path/to/your/videos/ is where the videos are that you want to
    convert
  • --input-extension is the type of videos you want to process, here .mp4
  • --ffmpeg-opts is any arbitrary FFmpeg options you want to use to customise the transcode

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!

二智少女 2024-10-15 07:28:07
ffmpeg -i <input.mp4> -b:v 2048k -s 1000x600 -fs 2048k -vcodec mpeg4 -acodec copy <output.mp4>
  • -i 输入文件

  • -b:v 输出视频的视频比特率(以千字节为单位)(您必须尝试)

  • -s 输出视频的尺寸

  • -fs 输出视频的FILESIZE(以千字节为单位)

  • -vcodec videocodec(使用 ffmpeg -codecs 列出所有可用的编解码器)

  • -acodec 用于输出视频的音频编解码器(仅复制音频流,请勿修改)
ffmpeg -i <input.mp4> -b:v 2048k -s 1000x600 -fs 2048k -vcodec mpeg4 -acodec copy <output.mp4>
  • -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)

  • -acodec audio codec for output video (only copy the audiostream, don't temper)
简单气质女生网名 2024-10-15 07:28:06

ffmpeg 提供此功能。您需要做的就是运行类似的命令

ffmpeg -i <inputfilename> -s 640x480 -b 512k -vcodec mpeg1video -acodec copy <outputfilename>

对于较新版本的 ffmpeg,您需要将 -b 更改为 -b:v:

ffmpeg -i <inputfilename> -s 640x480 -b:v 512k -vcodec mpeg1video -acodec copy <outputfilename>

将输入视频文件转换为视频使用 MPEG 1 视频编解码器并仅复制原始音频流,大小为 640 x 480,比特率为 512 kbps。当然,您可以插入所需的任何值,并调整大小和比特率,以实现您正在寻找的质量/大小权衡。 中还描述了许多其他选项

文档 Run ffmpeg -formatsffmpeg -codecs 获取所有可用格式和编解码器的列表。如果您不必为最终输出指定特定的编解码器,则可以使用 H.264 等最先进的编解码器以最小的质量损失实现更好的压缩比。

ffmpeg provides this functionality. All you need to do is run someting like

ffmpeg -i <inputfilename> -s 640x480 -b 512k -vcodec mpeg1video -acodec copy <outputfilename>

For newer versions of ffmpeg you need to change -b to -b:v:

ffmpeg -i <inputfilename> -s 640x480 -b:v 512k -vcodec mpeg1video -acodec copy <outputfilename>

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 or ffmpeg -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.

╰沐子 2024-10-15 07:28:06

如果您想保持相同的屏幕尺寸,可以考虑使用 crf 因子:https://trac.ffmpeg.org/ wiki/Encode/H.264

这是对我有用的命令:(在 mac 上,您需要添加 -strict -2 才能使用 aac 音频编解码器。

ffmpeg -i input.mp4 -c:v libx264 -crf 24 -b:v 1M -c:a aac output.mp4

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.

ffmpeg -i input.mp4 -c:v libx264 -crf 24 -b:v 1M -c:a aac output.mp4
半﹌身腐败 2024-10-15 07:28:06

使用 H.264 编解码器,您可以选择不同的预设,而不是选择固定比特率,如 https 中所述://trac.ffmpeg.org/wiki/x264EncodingGuide。我还在 KeyJ 的博客上找到了视频编码器比较 (存档版本)是一本有趣的读物,它将 H.264 与 Theora 等进行了比较。

以下是我尝试过的各种选项的比较。录制的视频最初大小为673M,使用RecordMyScreen在iPad上拍摄。它的时长约为20分钟,分辨率为1024x768(视频的一半是空白的,所以我将其裁剪为768x768)。为了减小尺寸,我将分辨率降低到480x480。没有音频。

结果,采用相同的 1024x768 作为基础(并应用裁剪、缩放和过滤器):

  • 没有特殊选项:95M (编码时间:1分19秒)。
  • 仅添加-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):

  • With no special options: 95M (encoding time: 1m19s).
  • With only -b 512k added, the size dropped to 77M (encoding time: 1m17s).
  • With only -preset veryslow (and no -b), it became 70M (encoding time: 6m14s)
  • With both -b 512k and -preset veryslow, the size becomes 77M (100K smaller than just -b 512k).
  • With -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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文