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.
ffmpegthumbnailer
binary should be present on the PATH.
ffmpegthumbnailer git repository
gem install carrierwave-video-thumbnailer
Or add to your Gemfile:
gem 'carrierwave-video-thumbnailer'
If you need resize thumbnail add RMagick or MiniMagic
-
Install ffmpegthumbnailer
linux
sudo apt install ffmpegthumbnailer
MacOS
brew install ffmpegthumbnailer
-
Create migration for your model:
rails g migration add_video_to_your_model video:string
-
Generate uploader
rails generate uploader Video
-
Mount uploader in model
class YourModel < ApplicationRecord mount_uploader :video, VideoUploader end
-
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
-
Don't forget add parameter in controller
def post_params params.require(:post).permit(:title, :body, :video) end
-
Add image_tag to your view
<%= 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.
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 timehh: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 (readman ffmpegthumbnailer
for further explanations). - logger: an object behaving like Rails.logger (may be omitted).
For disable film stripes in thumbnail check strip to false
process thumbnail: [{format: 'png', quality: 10, size: 192, strip: false, logger: Rails.logger}]
Please read Code of Conduct and Contributing Guidelines for submitting pull requests to us.
We use SemVer for versioning. For the versions available, see the tags on this repository.
The changelog is here.
- Pavel Argentov - Initial work
See also the list of contributors who participated in this project.
This project is licensed under the MIT License.
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).