【问题标题】:Crop Video and Audio files when uploading in a Rails app using paperclip使用回形针在 Rails 应用程序中上传时裁剪视频和音频文件
【发布时间】:2015-01-20 17:13:34
【问题描述】:

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

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

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

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

有没有人知道如何使用回形针-ffmpeg 或其他 gem 来解决这个问题?

提前致谢。

【问题讨论】:

    标签: ruby-on-rails file-upload ffmpeg paperclip


    【解决方案1】:

    我把上面的ffmpeg命令转换成了回形针扩展,希望对你有用。

    https://github.com/jentzheng/paperclip_audio_crop

    【讨论】:

      【解决方案2】:

      使用回形针,您应该使用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
      

      希望这能解决您的问题。

      【讨论】:

      • 谢谢让我试试这个
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-13
      • 2015-06-26
      • 2011-07-24
      • 1970-01-01
      • 2013-10-16
      • 1970-01-01
      • 2018-04-29
      相关资源
      最近更新 更多