Paperclip thumbnail generation uses magic?

65 views
Skip to first unread message

Walter Lee Davis

unread,
Jun 12, 2013, 11:15:50 AM6/12/13
to rubyonra...@googlegroups.com
I have been using CarrierWave for file uploads on a site which needs to accept a really wide range of different movie formats, stills, PDFs... And I have been struggling with making thumbnails of certain formats. After much yak-shaving with ffmpeg and imagemagick and Rmagick, I finally decided to do a little spike app with nothing but Paperclip. I set up the simplest thing that could possibly work:

has_attached_file :blob, :styles => { :thumb => ["320x320>", :png], :large => ["1500x1500>", :png] }

And no matter what format (within reason) I pass to it, I get a nicely formed PNG format thumbnail and large preview image. PSD, PDF, TIFF, MOV, M4V -- it Just Works™. And I cannot figure out how it is doing this, despite reading through the source code for quite a while.

The reason why I need to access the magic is that while I am getting a nice thumbnail from any movie format I pass in, I am getting the very first frame of the movie (usually black) rather than a few seconds into the clip. In my CarrierWave converter, I had a custom offset time defined for this. But I cannot see where Paperclip is defining what to do with a video to generate a PNG image so I can alter this default.

There are tons of examples on SO and the Web in general, showing how to create a custom video thumbnailer and transcoder, but I would like to avoid rebuilding this wheel that Paperclip seems to have hewn out of pure Elven magick.

Thanks in advance,

Walter

Jim Ruther Nill

unread,
Jun 12, 2013, 11:58:21 AM6/12/13
to rubyonra...@googlegroups.com
I haven't seen the paperclip code but I think you can look at the preprocessors used by default by paperclip.
You usually see logs when paperclip does some processing using rmagick which may be a clue as to what
part of the lib you want to look at.



--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/87E1CB56-F23E-4EF2-A760-9F6D6A2C0B74%40wdstudio.com?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.





--
-------------------------------------------------------------
visit my blog at http://jimlabs.heroku.com

Jason Fleetwood-Boldt

unread,
Jun 12, 2013, 12:21:01 PM6/12/13
to rubyonra...@googlegroups.com
you may want to put this into something that loads when you app loads, like initializers/paperclip.rb

Paperclip.options[:log] = true

Walter Lee Davis

unread,
Jun 12, 2013, 12:23:56 PM6/12/13
to rubyonra...@googlegroups.com
Thanks, that's good advice. The console told the tale. It appears as though ImageMagick is delegating to ffmpeg, and the convert function that Paperclip generates in their thumbnail operation tacks a [0] to the end of the filename to get it to use the first frame. I need to do some more digging, but it appears as though I can just put a different number in there for movies. It seems as though all file types are getting the [0] treatment, not just movies, so I don't want to start looking for frame 10 in a TIFF...

Walter

On Jun 12, 2013, at 11:58 AM, Jim Ruther Nill wrote:

> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAJ8y7Vdt3BKPzFd%2BzQDsLnNA2G0%2BY2d0pa9fc4RQFVVH6kLuhA%40mail.gmail.com?hl=en-US.
Reply all
Reply to author
Forward
0 new messages