开发者

How to show video clip in a list with Ruby on Rails.

开发者 https://www.devze.com 2022-12-10 21:39 出处:网络
I have uploaded videos but when I see them in list, I would like to see a snapshot or clip of the video. Is there a way to display a list vide开发者_StackOverflowos like this?You can use ffmpeg to gen

I have uploaded videos but when I see them in list, I would like to see a snapshot or clip of the video. Is there a way to display a list vide开发者_StackOverflowos like this?


You can use ffmpeg to generate images from a video.

You'll find here a tutorial allowing you to use Paperclip to upload a video and FFMpeg to make a thumbnail out of it.

In that tutorial, what's interesting for making the thumbnail is the make method.
Which generates a ffmpeg command and executes it.

You'll find informations about that command alone here.


When you upload videos & images with Paperclip, it uses a processor to create different variations of the file

The processor depends on the type of file, and will typically be imagemagick if you're working with images, and ffmpeg if you're working with video

The way this works is that Paperclip will handle the file upload, and then send to the various processor to change. That's how you can generate the thumbnails with imagemagick, or the video thumbnail with ffmpeg


paperclip-ffmpeg

FFMpeg will be the best way to create a video thumbnail, and you can actually put it to work by installing the paperclip-ffmpeg gem

Here is some live code showing how this works (you basically just have to call the :ffmpeg processor:

 has_attached_file :attachment,
                styles:          lambda { |a| a.instance.is_image? ? {:small => "x200>", :medium => "x300>", :large => "x400>"}  : {:thumb => { :geometry => "100x100#", :format => 'jpg', :time => 10}, :medium => { :geometry => "300x300#", :format => 'jpg', :time => 10}}},
                :processors => lambda { |a| a.is_video? ? [ :ffmpeg ] : [ :thumbnail ] }

    def is_video?
            attachment.instance.attachment_content_type =~ %r(video)
    end

    def is_image?
            attachment.instance.attachment_content_type =~ %r(image)
    end

If you need some more help with this (obviously the question was a long time ago), please let me know!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号