使用paperclip在Rails应用程序中上传视频和音频文件时如何裁剪?

3
我希望能够根据时长裁剪音频和视频,以展示大约30秒的示例,并保存原始音频或视频文件。我正在Rails中使用这个宝石Paperclip-FFMPEG为视频生成缩略图。但我还想将视频剪裁到最大长度,并通过取音频的前30秒来生成样本音频。我查看了文档,但无法在Stackoverflow上找到任何类似的文档或问题。有人知道如何使用paperclip-ffmpeg或其他宝石解决这个问题吗?谢谢。
2个回答

4
使用纸夹,您应该使用以下命令的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

希望这可以解决您的问题。

谢谢,让我试一试。 - Encore PTL

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接