簡體   English   中英

使用回形針在Rails應用程序中上傳時裁剪視頻和音頻文件

[英]Crop Video and Audio files when uploading in a Rails app using paperclip

我想根據長度裁剪音頻和視頻,以顯示大約30秒的樣本,並保存原始音頻或視頻文件。

我在Rails Paperclip-FFMPEG中使用此gem來生成視頻的縮略圖。

但是我還想將視頻裁剪到最大長度,並通過占用音頻的前30秒來為音頻生成示例音頻。

我查看了文檔,但在Stackoverflow上找不到任何文檔或類似問題。

有誰知道如何用回形針-ffmpeg或其他寶石做到這一點的解決方案?

提前致謝。

對於回形針,您應該使用以下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

希望這能解決您的問題。

我將上面的ffmpeg命令轉換為回形針擴展,希望它有用。

https://github.com/jentzheng/paperclip_audio_crop

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM