ffmpeg /视频处理:使视频重复播放而不重复内容?

发布于 2025-01-18 04:50:39 字数 300 浏览 1 评论 0原文

假设我有一个大小为 20 MB、持续 30 秒的视频文件。

我想创建一个新的视频文件,该文件基本上由现有视频组成,重复 10 次。因此,新视频应持续 300 秒(5 分钟),并且每 30 秒包含相同的内容。

当然,我可以将该视频附加到自身 10 次,从而生成大约 200 MB 的文件。但这似乎非常多余,因为显然相同的内容有十倍。我希望有一种更智能的方法,即相同的 30 秒视频以某种方式被“引用”10 次。

常见的编码器或容器格式(例如 .mp4 或 .mkv 容器中的 h.264)是否支持此功能?有没有办法用 ffmpeg 来实现这一点?

Suppose I have a video file that is 20 MB in size and lasts 30 seconds.

I want to create a new video file that basically consists of the existing video, repeated 10 times. So the new video should last 300 seconds (5 minutes) and contain the same content every 30 seconds.

I could of course append this video to itself 10 times, resulting in a file of approximately 200 MB. But this seems very redundant, since obviously the same content is in there tenfold. I was hoping for a somewhat more intelligent approach, where the same 30 seconds of video is somehow 'referenced' 10 times over.

Do common encoders or container formats (say h.264 in a .mp4 or .mkv container) support this? And by any chance is there a way to pull this off with ffmpeg?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

执着的年纪 2025-01-25 04:50:39

有一个选项可以创建 M3U 播放列表文件 (playlist.m3u8) 重复同一文件 10 次。

示例:

创建 30 秒的合成视频(用于测试):

ffmpeg -y -f lavfi -i testsrc=size=192x108:rate=30 -f lavfi -i sine=frequency=400 -f lavfi -i sine=frequency=1000 -filter_complex "[1:a][2:a]amix=inputs=2" -vcodec libx264 -crf 17 -pix_fmt yuv420p -acodec aac -ar 44100 -t 30 input.mp4

假设 input.mp4 是您的 30 秒视频。


将 MP4 文件重新复用为 TS 容器格式(播放列表不适用于 MP4 文件):

ffmpeg -y -i input.mp4 -codec copy input.ts

创建一个名为 playlist.m3u8 的文本文件,其中包含以下内容:

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:30
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:30.00,
input.mp4
#EXTINF:30.00,
input.mp4
#EXTINF:30.00,
input.mp4
#EXTINF:30.00,
input.mp4
#EXTINF:30.00,
input.mp4
#EXTINF:30.00,
input.mp4
#EXTINF:30.00,
input.mp4
#EXTINF:30.00,
input.mp4
#EXTINF:30.00,
input.mp4
#EXTINF:30.00,
input.mp4
#EXT-X-ENDLIST

您可以播放 playlist .m3u8 文件适用于大多数视频播放器。


在大多数情况下,输入文件被分割成小片段(用于网络视频流):

ffmpeg -y -i input.mp4 -codec copy -f segment input%3d.ts

创建片段播放列表:

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:30
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:30.00,
input000.ts
#EXTINF:30.00,
input001.ts
#EXTINF:30.00,
input002.ts
#EXTINF:30.00,
input003.ts
#EXTINF:30.00,
input000.ts
#EXTINF:30.00,
input001.ts
#EXTINF:30.00,
input002.ts
#EXTINF:30.00,
input003.ts
#EXTINF:30.00,

...

#EXT-X-ENDLIST

播放列表解决方案是我能想到的唯一解决方案。
该格式主要用于 HTTP Live Streaming (HLS) 格式。
它与单个视频文件不同(例如在搜索方面)。

据我所知,使用 MP4 或 MKV 等经典视频容器是不可能的。

还有一个选项可以播放同一文件 10 次(可能不相关),例如:

ffplay -loop 10 input.mp4

There is an option to create an M3U playlist file (playlist.m3u8) that repeats the same file 10 times.

Example:

Create 30 seconds synthetic video (for testing):

ffmpeg -y -f lavfi -i testsrc=size=192x108:rate=30 -f lavfi -i sine=frequency=400 -f lavfi -i sine=frequency=1000 -filter_complex "[1:a][2:a]amix=inputs=2" -vcodec libx264 -crf 17 -pix_fmt yuv420p -acodec aac -ar 44100 -t 30 input.mp4

Assume input.mp4 is your 30 seconds video.


Re-mux the MP4 file to TS container format (the playlist is not going to work with MP4 file):

ffmpeg -y -i input.mp4 -codec copy input.ts

Create a text file named playlist.m3u8 with the following content:

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:30
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:30.00,
input.mp4
#EXTINF:30.00,
input.mp4
#EXTINF:30.00,
input.mp4
#EXTINF:30.00,
input.mp4
#EXTINF:30.00,
input.mp4
#EXTINF:30.00,
input.mp4
#EXTINF:30.00,
input.mp4
#EXTINF:30.00,
input.mp4
#EXTINF:30.00,
input.mp4
#EXTINF:30.00,
input.mp4
#EXT-X-ENDLIST

You can play playlist.m3u8 file with most video players.


In most cases the input file is splinted into small segments (used for Web video streaming):

ffmpeg -y -i input.mp4 -codec copy -f segment input%3d.ts

Creating playlist of segments:

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:30
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:30.00,
input000.ts
#EXTINF:30.00,
input001.ts
#EXTINF:30.00,
input002.ts
#EXTINF:30.00,
input003.ts
#EXTINF:30.00,
input000.ts
#EXTINF:30.00,
input001.ts
#EXTINF:30.00,
input002.ts
#EXTINF:30.00,
input003.ts
#EXTINF:30.00,

...

#EXT-X-ENDLIST

The playlist solution is the only solution I can think of.
The format is mostly used for HTTP Live Streaming (HLS) format.
It is not the same as having a single video file (in terms of seeking for example).

As far as I know it is not possible using classic video containers like MP4 or MKV.

There is also an option to play the same file 10 times (probably not relevant), for example:

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