videoclip
videoclip copied to clipboard
A video transcoding processor for Thoughbot's Paperclip plugin. Requires FFMPEG.
=Videoclip
Videoclip is a video transcoding processor for Thoughbot's Paperclip plugin. It allows you to easily transcode/resize video using FFMPEG.
==Installation
script/plugin install git://github.com/thoughtbot/paperclip.git script/plugin install git://github.com/iamsolarpowered/videoclip.git
You'll also need FFMPEG installed, which isn't always straight-forward. Sometimes it's downright frustrating. FFMPEG needs to be compiled with any codecs you want to use (many of which aren't open source).
If you're using Ubuntu, this link should help https://wiki.ubuntu.com/ffmpeg . On a Mac, using Mac Ports, you should be able to install everything necessary with: sudo port install ffmpeg +lame +libogg +vorbis +faac +faad +xvid +x264 +a52 +gpl
==Usage
Usage is similar to image styles in Paperclip:
class Episode < ActiveRecord::Base has_attached_file :video, :styles => { :mov => {:size => '600x400', :format => 'mov'}, :avi => {:size => '600x400', :format => 'avi'}, :thumbnail => {:size => '150x100', :format => 'jpg', :disable_audio => true, :rate => 1, :video_frames => 1, :force_format => 'image2'} }, :processors => [:transcode] end
The :processors => [:transcode] bit is crucial.
:format is the only required parameter, and should be the extension of the output file. FFMPEG will attempt to use some sensible defaults based on the extension.
See the wiki for a full list of options, or check out the +ffmpeg_options+ method in lib/transcode.rb.
You can also pass in additional arguments with :options => 'FFMPEG OPTIONS' if you like. See http://ffmpeg.mplayerhq.hu/ffmpeg-doc.html#SEC8 for details. For example:
has_attached_file :video, :styles => { :default_channel => {:format => 'flv', :options => '-tvstd NTSC'}, :alternate_channel => {:format => 'flv', :options => '-vc 2 -tvstd NTSC'} }, :processors => [:transcode]
How about another example? This will convert the uploaded video to a .mov with h.264 compression. (Beware, I haven't actually tested this. It might not come out well.)
has_attached_file :video, :styles => { :mov => { :format => 'mov', :video_codec => 'libx264', :audio_codec => 'libmp3lame', :bitrate => '500k', :video_bitrate => '408k', :audio_bitrate => '92k' } }, :processors => [:transcode]
==Limiations
-
For the time being, transcoding is done before the object is saved. If there's an error, you'll get a warning similar to what you'd see if the object failed validation. Obviously, it would be nicer if transcoding were passed off to a queue instead. Stay tuned.
-
2-pass encoding isn't supported (yet).
-
I highly doubt it'll work on Windows. If you've got a Windows box and a bit of patience, let me know.
==License
Released under the MIT license. Copyright (c) 2009 Ben Shymkiw. A copy of the MIT license can be found in the MIT-LICENSE file.
==Misc.
This is my first publicly released plugin. If you have any suggestions, comments, or if you find a bug, please drop me a line.