No commit activity in last 3 years
No release in over 3 years
There's a lot of open issues
Lets you make video thumbnails in carrierwave via ffmpegthumbnailer
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.0
>= 0
~> 0.8
~> 2.4
~> 0.8

Runtime

 Project Readme

carrierwave-video-thumbnailer

Build Status Maintainability Reviewed by Hound

A thumbnailer plugin for Carrierwave. It mixes into your uploader setup and makes easy thumbnailing of your uploaded videos. This software is quite an alpha right now so any kind of OpenSource collaboration is welcome.

Sponsored by Evrone

Demo

demo image

Getting Started

Prerequisites

ffmpegthumbnailer binary should be present on the PATH.

ffmpegthumbnailer git repository

Installation

gem install carrierwave-video-thumbnailer

Or add to your Gemfile:

gem 'carrierwave-video-thumbnailer'

If you need resize thumbnail add RMagick or MiniMagic

Usage

  1. Install ffmpegthumbnailer

    linux

     sudo apt install ffmpegthumbnailer
    

    MacOS

     brew install ffmpegthumbnailer  
    
  2. Create migration for your model:

     rails g migration add_video_to_your_model video:string
    
  3. Generate uploader

     rails generate uploader Video
    
  4. Mount uploader in model

     class YourModel < ApplicationRecord
       mount_uploader :video, VideoUploader
     end
    
  5. Update your uploader

    In your Rails app/uploaders/video_uploader.rb:

    class VideoUploader < CarrierWave::Uploader::Base
        include CarrierWave::Video  # for your video processing
        include CarrierWave::Video::Thumbnailer
        
        storage :file
        
        def store_dir
          "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
        end
        
        version :thumb do
          process thumbnail: [{format: 'png', quality: 10, size: 192, strip: true, logger: Rails.logger}]
        
          def full_filename for_file
            png_name for_file, version_name
          end
        end
        
        def png_name for_file, version_name
          %Q{#{version_name}_#{for_file.chomp(File.extname(for_file))}.png}
        end
    end

    For resize thumbnail add version:

        class VideoUploader < CarrierWave::Uploader::Base
           include CarrierWave::MiniMagick
        
           ...
        
           version :small_thumb, from_version: :thumb do
             process resize_to_fill: [20, 200]
           end
     
        end
  6. Don't forget add parameter in controller

      def post_params
        params.require(:post).permit(:title, :body, :video)
      end
  7. Add image_tag to your view

    erb example
     <%= image_tag(@post.video.thumb.url, alt: 'Video') if @post.video? %>
    

Runs ffmpegthumbnailer with CLI keys provided by your configuration or just uses quite a reasonable ffmpegthumbnailer's defaults.

Thumbnailer Options

The options are passed as a hash to the thumbnail processing callback as shown in the example. The options may be, according to ffmpegthumbnailer's manual:

  • format: 'jpg' or 'png' ('jpg' is the default).
  • quality: image quality (0 = bad, 10 = best) (default: 8) only applies to jpeg output
  • size: size of the generated thumbnail in pixels (use 0 for original size) (default value: 128 and keep initial aspect ratio).
  • strip: movie film strip decoration (defaults to false).
  • seek: time to seek to (percentage or absolute time hh:mm:ss) (default: 10)
  • square: if set to true ignore aspect ratio and generate square thumbnail.
  • workaround: if set to true runs ffmpegthumbnailer in some safe mode (read man ffmpegthumbnailer for further explanations).
  • logger: an object behaving like Rails.logger (may be omitted).
film stripes

For disable film stripes in thumbnail check strip to false

process thumbnail: [{format: 'png', quality: 10, size: 192, strip: false, logger: Rails.logger}]

Contributing

Please read Code of Conduct and Contributing Guidelines for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Changelog

The changelog is here.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License.

Acknowledgments

Huge Thanks to Rachel Heaton (https://github.com/rheaton) whose carrierwave-video gem has inspired me (and where I've borrowed some code as well).