上传的视频和streamio-ffmpeg

时间:2016-08-22 02:26:04

标签: ruby-on-rails ffmpeg

我正在尝试使用我的Rails应用程序中的streamio-ffmpeg将上传的视频文件直接转换为gif。

如何通过streamio-ffmpeg直接读取上传的视频(ActionDispatch :: Http :: UploadedFile对象)?

我尝试了以下尝试失败:

movie = FFMPEG::Movie.new(params[:video])
TypeError: can't convert ActionDispatch::Http::UploadedFile to IO (ActionDispatch::Http::UploadedFile#to_io gives Tempfile)


movie = FFMPEG::Movie.new(params[:video].open)
TypeError: no implicit conversion of File into String

movie = FFMPEG::Movie.new(params[:video].read)
ArgumentError: invalid byte sequence in UTF-8


File.open(params[:video].path) do |file|
  movie = FFMPEG::Movie.new(file)
  options = {frame_rate: '10', duration: '00:00:6.000'}
  movie.transcode("test.gif", options)
end
TypeError: no implicit conversion of File into String

1 个答案:

答案 0 :(得分:0)

movie = FFMPEG::Movie.new(params[:video].tempfile.path)