Coder Social home page Coder Social logo

paperclip-av-transcoder's Introduction

Paperclip Transcoder

Audio/Video Transcoder for Paperclip using FFMPEG/Avconv.

This is a replacement for ( https://github.com/owahab/paperclip-ffmpeg ).

Status

Build Status Coverage Status Code Climate Dependency Status Gem Version

Installation

Add this line to your application's Gemfile:

gem 'paperclip-av-transcoder'

And then execute:

$ bundle

Or install it yourself as:

$ gem install paperclip-av-transcoder

Usage

In your model:

# app/models/user.rb
class User < ActiveRecord::Base
  has_attached_file :avatar, :styles => {
    :medium => { :geometry => "640x480", :format => 'flv' },
    :thumb => { :geometry => "100x100#", :format => 'jpg', :time => 10 }
  }, :processors => [:transcoder]
end

This will produce:

  1. A transcoded :medium FLV file with the requested dimensions if they will match the aspect ratio of the original file, otherwise, width will be maintained and height will be recalculated to keep the original aspect ration.
  2. A screenshot :thumb with the requested dimensions regardless of the aspect ratio.

Meta Data

Then paperclip-av-transcoder can optionally add uploaded file meta data to a database column for <your_attachment>_meta.

Example: Given a model called User with an attachment field named :avatar, create a new migration to add an avatar_meta column to the users table.

def change
  add_column :users, :avatar_meta, :data_type
end

You can use a data type of :json, :jsonb, :hstore or even just :string. Check what data types your database supports.

geometry

The geometry option has the following available modifiers:

  1. '!' - Keep the same aspect of the image/video, but with the passed dimesion.
  2. '#' - Pad the image/video.
  3. '<' - Enlarge the image/video.
  4. '>' - Shrink the image/video.

convert_options

The convert_options option lets you specify custom command line options to be sent to the ffmpeg command. The options are split into output and input, which define where in the pipeline they will be applied. Read more about which flags go where on the official documentation.

For example, sending in the -an flag would look like this:

has_attached_file :video, styles: {
  mobile: {
    format: "mp4",
    convert_options: {
      output: {
        an: nil # Remove audio track resulting in a silent movie, passing in nil results in `-an`,
        name: "value" # Results in `-name value` in the command line
      }
    }
  },
}

Contributing

  1. Fork it ( https://github.com/ruby-av/paperclip-av-transcoder/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

paperclip-av-transcoder's People

Contributors

owahab avatar joaoffcosta avatar attenzione avatar cjeffries avatar erkie avatar biow0lf avatar paulodealmeida avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.