我想根据长度裁剪音频和视频,以显示大约30秒的样本,同时保存原始音频或视频文件。
我在Rails Paperclip-FFMPEG中使用这个gem来生成视频的缩略图。
但我还希望将视频裁剪为最大长度,并通过获取音频的前30秒为音频生成示例音频。
我查看了文档,但无法在Stackoverflow上找到任何类似的文档或问题。
有没有人知道如何使用paperclip-ffmpeg或其他宝石来解决这个问题?
提前致谢。
答案 0 :(得分: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
希望这能解决您的问题。
答案 1 :(得分:0)
我将上面的ffmpeg命令转换为回形针扩展名,希望这有用。