ruby-on-railswindowsvideocarrierwaveffmpegthumbnailer

ffmpegthumbnailer on Windows 10 [Ruby on Rails]


Hi I recently startet a Ruby on Rails project on a Windows 10 x64 machine. In this project I've got an uploadform with Carrierwave to upload some videofiles. To get a thumbnail from the uploaded videos I want to use the carrierwave-video-thumbnailer gem.

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

I already installed FFMPEG on my computer. As I understood correctly, to use the gem I need to install FFMPEGthumbnailer to, but i can't figure out how I can install it on a windows machine. (Just found installation guides for Linux and OS X) Did I miss something?

In my uploader file i've got following code:

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

By now the videos are being uploaded succesfully but without thumbnail and without error code.


Solution

  • You may be fighting an uphill battle. ffmpegthumbnailer doesn't appear to officially support Windows. However, it looks like at least one person managed to get it to compile in Cygwin. From 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!

    You can find releases here: https://github.com/dirkvdb/ffmpegthumbnailer/releases

    ††Since the project has been migrated to GitHub this link is broken and I have no idea which revision of moviedecoder.cpp this link corresponds to. Maybe the version tagged 2.0.7 is a good bet?

    Supposing that works for you, once you've compiled it (and confirmed that it works by testing it on the command line) you need to make sure carrierwave-video-thumbnailer knows where to find the executable, either by making sure it's in your $PATH or setting the FFMpegThumbnailer.binary option. I think it'd look something like this:

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

    Note that I haven't tested any of this and your mileage will vary.