gpt4 book ai didi

ruby-on-rails - 使用回形针在 Rails 应用程序中上传时裁剪视频和音频文件

转载 作者:行者123 更新时间:2023-12-04 22:45:25 25 4
gpt4 key购买 nike

我想根据长度裁剪音频和视频以显示大约 30 秒的样本,同时保存原始音频或视频文件。

我在 Rails 中使用这个 gem Paperclip-FFMPEG为视频生成缩略图。

但我还想将视频裁剪到最大长度,并通过提取音频的前 30 秒来为音频生成示例音频。

我查看了文档,但无法在 Stackoverflow 上找到任何此类文档或问题。

有人知道如何使用 paperclip-ffmpeg 或其他 gem 来解决这个问题吗?

提前致谢。

最佳答案

对于回形针,您应该使用 ffmpeg 的以下命令来生成裁剪音频/视频:

ffmpeg -ss 0 -i file.mp3 -t 20 file.wav

看看 -t-ss 参数,它会做你想做的事:

-t duration

Restrict the transcoded/captured video sequence to the duration specified in seconds. hh:mm:ss[.xxx] syntax is also supported.

-ss position

Seek to given time position in seconds. hh:mm:ss[.xxx] syntax is also supported.

例如,ffmpeg -ss 0 -t 20 -i inputfile.mp3 -acodec copy outputfile.mp3

视频/音频从0-20秒开始

-ss 0 - Start at 0 seconds
-t 30 - Capture 30 seconds (from 0, so 0:00 - 0:30). If you want 1 minute of audio, use -t 60.
-acodec copy - Stream copy (re-mux) the audio instead of re-encode it.
file.mp3 - Input file
file.wav - output file

希望这能解决您的问题。

关于ruby-on-rails - 使用回形针在 Rails 应用程序中上传时裁剪视频和音频文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27080315/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com