Paperclip thumbnail generation uses magic?

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,


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 may want to put this into something that loads when you app loads, like initializers/paperclip.rb

Paperclip.options[:log] = true

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...