您可以将一个 1 分钟的剪辑从一个较大的文件中拼接出来,而不进行转码吗?

发布于 2024-08-10 04:00:59 字数 168 浏览 5 评论 0原文

我有一个网站,允许人们上传各种格式(avi、mp4、mkv 和 flv)的大型视频文件。我需要从已上传的较大文件中生成 1 分钟的“样本”,并且该样本需要与原始文件具有相同的格式、相同的帧尺寸和比特率。有没有办法简单地将文件的一部分剪切到新文件中?最好使用 ffmpeg(如果 ffmpeg 不可能,则使用任何其他工具)。

I have a site that allows people to upload large video files in various formats (avi, mp4, mkv and flv). I need to generate a 1 minute "sample" from the larger file that has been uploaded, and the sample needs to be in the same format, have the same frame dimensions and bit-rate as the original file. Is there a way to simply cut out a section of the file into a new file? Preferably in ffmpeg (or any other tool if ffmpeg is impossible).

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

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

发布评论

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

评论(4

ぽ尐不点ル 2024-08-17 04:00:59

首先,您需要了解视频文件的实际工作原理。这里有一组教程解释了这一点: 过于简单互联网视频指南

然后,您可以尝试各种可能有助于切出样本的工具。一种是 flvtool(如果您的输入是 FLV)或 FFmpeg。使用 FFmpeg,您可以指定开始时间和停止时间,它会尝试剪切您所要求的内容(但它必须找到最近的关键帧来开始切片)。

下面是 FFmpeg 命令,用于读取名为 input.flv 的文件,开始播放视频 15 秒,然后剪切接下来的 60 秒,但保留音频代码和视频编解码器的相同参数,并将其写入输出文件:

ffmpeg -i input.flv -ss 15 -t 60 -acodec copy -vcodec copy output.flv

最后,如果您愿意,您可以用 C 或 C++(使用 FFmpeg 的 libav 库)或 Java(使用 Xuggler) 以编程方式执行此操作,但这对于您的用例来说非常先进。

First you'll want to understand how video files actually work. Here's a set of tutorials explaining that: Overly Simplistic Guide to Internet Video.

Then, you can try a variety of tools that may help with slicing out a sample. One is flvtool (if your input is FLV) or FFmpeg. With FFmpeg you can specify a start time and stop time, and it will attempt to cut out just what you ask for (but it will have to find the nearest key-frame to begin slicing at).

Here's the FFmpeg command to read a file called input.flv, start 15 seconds into the video, and then cut out the next 60 seconds, but otherwise keep the same parameters for the audio code and video codec, and write it to an output file:

ffmpeg -i input.flv -ss 15 -t 60 -acodec copy -vcodec copy output.flv

Finally if you want you can write computer code in C or C++ (using FFmpeg's libav libraries) or Java (using Xuggler) to programatically do this, but that's pretty advanced for your use case.

何止钟意 2024-08-17 04:00:59

如果您像我一样在保持自动和视频同步方面遇到问题,以下内容可能会有所帮助(在另一个网站上找到):

ffmpeg -sameq -i file.flv -ss 00:01:00 -t 00:00:30 -ac 2 -r 25 -copyts output.flv

If you are having problems keeping auto and video synced up as I was, the following may help (found on another website):

ffmpeg -sameq -i file.flv -ss 00:01:00 -t 00:00:30 -ac 2 -r 25 -copyts output.flv
幸福丶如此 2024-08-17 04:00:59

正如 Evan 指出的,已接受答案中的方法可能会导致 A/V 同步丢失。然而,他的解决方案不正确,因为 -sameq 已被删除。

正如 https://trac.ffmpeg.org/wiki/Seeking 中所述 - ss 选项应该出现在 -i 之前而不是之后。这为我解决了这个问题。

As Evan notes, the approach in the accepted answer can result in loss of A/V sync. However his solution is not correct because -sameq was removed.

As stated at https://trac.ffmpeg.org/wiki/Seeking the -ss option should come before -i not after. This fixed the issue for me.

奢望 2024-08-17 04:00:59

下一个选项是使用 -fs 开关。示例:

ff -i ip.mkv -fs 500M -c copy ~/Movies/reservoir/carbohydrates.mkv

从选定的源中提取 500 兆字节(500×1000×1000 字节 +“复用开销”)。
–基于文件大小,正如您所见,

One love。和尊重。

Next option is to use -fs switch. Example:

ff -i ip.mkv -fs 500M -c copy ~/Movies/reservoir/carbohydrates.mkv

Extract 500 megabytes (500×1000×1000 bytes + ‘muxing overhead’) off selected source.
–based on filesize, as you can tell

One love. And respect.

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