ffmpegthumbnailer Windows 10 [Ruby Rails]

ffmpegthumbnailer on Windows 10 [Ruby on Rails]

您好,我最近在 Windows 10 x64 机器上的 Rails 项目上启动了一个 Ruby。 在这个项目中,我有一个带有 Carrierwave 的上传表单来上传一些视频文件。 要从上传的视频中获取缩略图,我想使用 carrierwave-video-thumbnailer gem.

https://rubygems.org/gems/carrierwave-video-thumbnailer

我已经在我的电脑上安装了 FFMPEG。 正如我理解的那样,要使用 gem 我需要安装 FFMPEGthumbnailer,但我不知道如何在 windows 机器上安装它。 (刚刚找到 Linux 和 OS X 的安装指南) 我错过了什么?

在我的上传文件中,我有以下代码:

class VideoUploader < CarrierWave::Uploader::Base

  # Include RMagick or MiniMagick support:
  # include CarrierWave::RMagick
  # include CarrierWave::MiniMagick

  include CarrierWave::Video::Thumbnailer

  version :thumbail do
    process thumbnail: [{format: 'jpg', quality: 8, size: 360, logger: Rails.logger}]
    def full_filename for_file
      jpg_name for_file, version_name
    end
  end
  def jpg_name for_file, version_name
    %Q{#{version_name}_#{for_file.chomp(File.extname(for_file))}.jpg}
  end

  storage :file

  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

  def extension_white_list
    %w(mp4)
  end

  def filename 
    if original_filename 
      @name ||= Digest::MD5.hexdigest(File.dirname(current_path))
      "#{@name}.#{file.extension}"
    end
  end
end

至此视频上传成功,但没有缩略图,也没有错误代码。

您可能正在打一场艰苦的战斗。 ffmpegthumbnailer 似乎没有正式支持 Windows。然而,看起来至少有一个人设法让它在 Cygwin 中编译。来自 this issue thread:

I managed to compile it...

  1. download fffmpegthumbnailer 2.0.6

  2. apply the two patches here : https://github.com/dirkvdb/ffmpegthumbnailer/issues/78

  3. download a working version of moviedecoder.cpp†† : http://code.google.com/p/ffmpegthumbnailer/source/browse/trunk/libffmpegthumbnailer/moviedecoder.cpp?r=225

    replace it in libffmpegthumbnailer folder

  4. download ffmpeg here : http://www.ffmpeg.org/

  5. extract and put the folders starting with lib to the lib folder in cygwin root folder

  6. ./configure then make and make install

  7. enjoy!

您可以在这里找到版本:https://github.com/dirkvdb/ffmpegthumbnailer/releases

††由于项目已经迁移到GitHub,这个link被破坏了,我不知道moviedecoder.cpp this link corresponds to. Maybe the version tagged 2.0.7的哪个版本是一个不错的选择吗?

假设它对你有用,一旦你编译了它(并通过在命令行上测试它确认它可以工作)你需要确保 carrierwave-video-thumbnailer 知道在哪里可以找到可执行文件,或者通过确保它在您的 $PATH 中或设置 FFMpegThumbnailer.binary 选项。我认为它看起来像这样:

CarrierWave::Video::Thumbnailer::FFMpegThumbnailer.binary = "C:/path/to/ffmpegthumbnailer.exe"

请注意,我还没有测试过任何这些,你的里程会有所不同。