Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

initial commit

  • Loading branch information...
commit c22d161cd39c2aedda72af0a80a2bca5bb8fba2e 0 parents
@iamsolarpowered authored
20 MIT-LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2009 Ben Shymkiw
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
59 README.rdoc
@@ -0,0 +1,59 @@
+=Videoclip
+
+Videoclip is a video transcoding processor for Thoughbot's Paperclip plugin.
+It allows you to easily transcode/resize video using FFMPEG.
+
+*WARNING*: This is still experimental. Use at your own risk!
+
+For the time being, transcoding is done before the object is saved.
+If there's an error, you'll get a warning similar to if the object failed validation.
+Obviously, it would be nicer if transcoding were passed off to a queue instead.
+Stay tuned.
+
+==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 .
+
+==Usage
+
+Usage is similar to image styles in Paperclip:
+
+ class Episode < ActiveRecord::Base
+ has_attached_file :video,
+ :styles => {
+ :mov => {:geometry => '320x240', :format => 'mov'},
+ :avi => {:geometry => '320x240', :format => 'avi'}
+ },
+ :processors => [:transcode]
+ end
+
+The <tt>:processors => [:transcode]</tt> bit is crucial.
+
+<tt>:format</tt> should be the extension of the output file. FFMPEG will attempt to
+use some sensible defaults based on the extension.
+
+You can also pass in <tt>:options => 'FFMPEG OPTIONS'</tt> if you like. See
+http://ffmpeg.mplayerhq.hu/ffmpeg-doc.html#SEC8 for details. For example:
+
+ has_attached_file :video,
+ :styles => {
+ :low_quality => {:format => 'flv', :options => '-vb 300k'},
+ :high_quality => {:format => 'flv', :options => '-vb 800k'}
+ },
+ :processors => [:transcode]
+
+==Go Easy
+
+This is my first publicly released plugin. I hope you find it helpful!
+
+==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.
23 Rakefile
@@ -0,0 +1,23 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
+desc 'Test the videoclip plugin.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.libs << 'test'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+desc 'Generate documentation for the videoclip plugin.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'Videoclip'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
1  init.rb
@@ -0,0 +1 @@
+require File.join(File.dirname(__FILE__), "lib", "transcode")
1  install.rb
@@ -0,0 +1 @@
+# Install hook code here
37 lib/transcode.rb
@@ -0,0 +1,37 @@
+module Paperclip
+
+ class Transcode < Processor
+
+ def initialize file, options = {}, attachment = nil
+ @file = file
+ @geometry = options[:geometry]
+ @format = options[:format]
+ @options = options[:options]
+ @current_format = File.extname(@file.path)
+ @basename = File.basename(@file.path, @current_format)
+ end
+
+ def make
+ dst = Tempfile.new([@basename, @format].compact.join("."))
+
+ cmd = []
+ cmd << "ffmpeg"
+ cmd << "-i \"#{File.expand_path(@file.path)}\""
+ cmd << "-s #{@geometry}" if @geometry
+ cmd << @options if @options
+ cmd << "-y"
+ cmd << "\"#{File.expand_path(dst.path)}\""
+ cmd = cmd.join(' ')
+
+ begin
+ success = system cmd
+ rescue
+ raise PaperclipError, "There was an error transcoding #{@basename} to #{@format}"
+ end
+
+ dst
+ end
+
+ end
+
+end
4 tasks/videoclip_tasks.rake
@@ -0,0 +1,4 @@
+# desc "Explaining what the task does"
+# task :videoclip do
+# # Task goes here
+# end
3  test/test_helper.rb
@@ -0,0 +1,3 @@
+require 'rubygems'
+require 'active_support'
+require 'active_support/test_case'
8 test/videoclip_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class VideoclipTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
1  uninstall.rb
@@ -0,0 +1 @@
+# Uninstall hook code here
Please sign in to comment.
Something went wrong with that request. Please try again.