From 32bf365c9cdef1d1c1a281e6780441c64b1d555f Mon Sep 17 00:00:00 2001 From: Omar Abdel-Wahab Date: Sun, 4 Jan 2015 00:09:46 +0200 Subject: [PATCH 01/12] Using the newer AV 0.8 --- paperclip-av-transcoder.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paperclip-av-transcoder.gemspec b/paperclip-av-transcoder.gemspec index 1dcebd9..394800e 100644 --- a/paperclip-av-transcoder.gemspec +++ b/paperclip-av-transcoder.gemspec @@ -26,5 +26,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency "coveralls" spec.add_dependency "paperclip", ">=2.5.2" - spec.add_dependency "av", ">= 0.7.1" + spec.add_dependency "av", ">= 0.8.0" end From 65274ab1ad4792ebeefb75b30df1de2671129d95 Mon Sep 17 00:00:00 2001 From: Christian Jeffries Date: Mon, 2 Mar 2015 12:09:52 +1100 Subject: [PATCH 02/12] The output hash now includes the geometry options --- .../paperclip_processors/transcoder.rb | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/lib/paperclip/paperclip_processors/transcoder.rb b/lib/paperclip/paperclip_processors/transcoder.rb index 9ebce7e..7ebeaea 100755 --- a/lib/paperclip/paperclip_processors/transcoder.rb +++ b/lib/paperclip/paperclip_processors/transcoder.rb @@ -14,10 +14,11 @@ def initialize file, options = {}, attachment = nil @cli = ::Av.cli @meta = ::Av.cli.identify(@file.path) @whiny = options[:whiny].nil? ? true : options[:whiny] - - @convert_options = options[:convert_options] + + @convert_options = set_convert_options(options) + @format = options[:format] - + @geometry = options[:geometry] unless @geometry.nil? modifier = @geometry[0] @@ -28,14 +29,16 @@ def initialize file, options = {}, attachment = nil @enlarge_only = @keep_aspect && modifier == '<' @shrink_only = @keep_aspect && modifier == '>' end - + @time = options[:time].nil? ? 3 : options[:time] @auto_rotate = options[:auto_rotate].nil? ? false : options[:auto_rotate] @pad_color = options[:pad_color].nil? ? "black" : options[:pad_color] - + + @convert_options[:output][:s] = format_geometry(@geometry) if @gemotry.present? + attachment.instance_write(:meta, @meta) if attachment end - + # Performs the transcoding of the +file+ into a thumbnail/video. Returns the Tempfile # that contains the new image/video. def make @@ -43,7 +46,7 @@ def make @cli.add_source @file dst = Tempfile.new([@basename, @format ? ".#{@format}" : '']) dst.binmode - + if @meta log "Transocding supported file #{@file.path}" @cli.add_source(@file.path) @@ -76,10 +79,21 @@ def make end dst end - + def log message Paperclip.log "[transcoder] #{message}" end + + def set_convert_options options + return options[:convert_options] if options[:convert_options].present? + options[:convert_options] = {output: {}} + return options[:convert_options] + end + + def format_geometry geometry + return unless geometry.present? + return geometry.gsub(/[#!<>)]/, '') + end end class Attachment From f5d60e7d2b4482ae921a0bd1da0240d7499a418c Mon Sep 17 00:00:00 2001 From: Omar Abdel-Wahab Date: Wed, 11 Mar 2015 13:04:44 +0200 Subject: [PATCH 03/12] Upgrading to av 0.8.1 --- lib/paperclip/av/transcoder/version.rb | 2 +- paperclip-av-transcoder.gemspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/paperclip/av/transcoder/version.rb b/lib/paperclip/av/transcoder/version.rb index a212f99..b99f404 100644 --- a/lib/paperclip/av/transcoder/version.rb +++ b/lib/paperclip/av/transcoder/version.rb @@ -1,7 +1,7 @@ module Paperclip module Av module Transcoder - VERSION = "0.6.2" + VERSION = "0.6.3" end end end diff --git a/paperclip-av-transcoder.gemspec b/paperclip-av-transcoder.gemspec index 394800e..20baf74 100644 --- a/paperclip-av-transcoder.gemspec +++ b/paperclip-av-transcoder.gemspec @@ -26,5 +26,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency "coveralls" spec.add_dependency "paperclip", ">=2.5.2" - spec.add_dependency "av", ">= 0.8.0" + spec.add_dependency "av", "~> 0.8.1" end From b8f777e3389fea1dfbbe7171837ae57b0adf5692 Mon Sep 17 00:00:00 2001 From: Omar Abdel-Wahab Date: Wed, 11 Mar 2015 13:10:19 +0200 Subject: [PATCH 04/12] Adding gem version badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 62896f0..eda9480 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ This is a replacement for ( https://github.com/owahab/paperclip-ffmpeg ). [![Coverage Status](https://coveralls.io/repos/ruby-av/paperclip-av-transcoder/badge.png?branch=master)](https://coveralls.io/r/ruby-av/paperclip-av-transcoder?branch=master) [![Code Climate](https://codeclimate.com/github/ruby-av/paperclip-av-transcoder/badges/gpa.svg)](https://codeclimate.com/github/ruby-av/paperclip-av-transcoder) [![Dependency Status](https://gemnasium.com/ruby-av/paperclip-av-transcoder.svg)](https://gemnasium.com/ruby-av/paperclip-av-transcoder) +[![Gem Version](https://badge.fury.io/rb/paperclip-av-transcoder.svg)](http://badge.fury.io/rb/paperclip-av-transcoder) ## Installation From 72d88916dfca1365b458ab8b24ee8b11113d3404 Mon Sep 17 00:00:00 2001 From: Sergey Margaritov Date: Wed, 18 Mar 2015 15:33:08 +0200 Subject: [PATCH 05/12] add seeking support for creating thumbnails of video --- lib/paperclip/paperclip_processors/transcoder.rb | 10 ++++++++++ spec/spec_helper.rb | 8 ++++++-- spec/transcoder/transcoder_spec.rb | 11 ++++++----- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/lib/paperclip/paperclip_processors/transcoder.rb b/lib/paperclip/paperclip_processors/transcoder.rb index 7ebeaea..b9d2c4b 100755 --- a/lib/paperclip/paperclip_processors/transcoder.rb +++ b/lib/paperclip/paperclip_processors/transcoder.rb @@ -52,6 +52,12 @@ def make @cli.add_source(@file.path) @cli.add_destination(dst.path) @cli.reset_input_filters + + if output_is_image? + @time = @time.call(@meta, @options) if @time.respond_to?(:call) + @cli.filter_seek @time + end + if @convert_options.present? if @convert_options[:input] @convert_options[:input].each do |h| @@ -94,6 +100,10 @@ def format_geometry geometry return unless geometry.present? return geometry.gsub(/[#!<>)]/, '') end + + def output_is_image? + !!@format.to_s.match(/jpe?g|png|gif$/) + end end class Attachment diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ed48510..1735ebf 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -41,6 +41,10 @@ class Document < ActiveRecord::Base ac: 2 } } + }, + thumb: { + format: 'jpg', + time: 0 } }, processors: [:transcoder] @@ -53,8 +57,8 @@ class Document < ActiveRecord::Base styles: { small: "100x100" }, - processors: [:transcoder, :thumbnail] - + processors: [:transcoder, :thumbnail] + do_not_validate_attachment_file_type :video do_not_validate_attachment_file_type :image end \ No newline at end of file diff --git a/spec/transcoder/transcoder_spec.rb b/spec/transcoder/transcoder_spec.rb index 3468168..33ff890 100644 --- a/spec/transcoder/transcoder_spec.rb +++ b/spec/transcoder/transcoder_spec.rb @@ -3,18 +3,19 @@ describe Paperclip::Transcoder do let(:supported) { File.new(Dir.pwd + '/spec/support/assets/sample.mp4') } let(:unsupported) { File.new(File.expand_path('spec/support/assets/image.png')) } - + let(:destination) { Pathname.new("#{Dir.tmpdir}/transcoder/") } - + describe "supported formats" do let(:subject) { Paperclip::Transcoder.new(supported) } let(:document) { Document.create(video: Rack::Test::UploadedFile.new(supported, 'video/mp4')) } - + describe ".transcode" do it { expect(File.exists?(document.video.path(:small))).to eq true } + it { expect(File.exists?(document.video.path(:thumb))).to eq true } end end - + describe "unsupported formats" do let(:subject) { Paperclip::Transcoder.new(unsupported) } let(:document) { Document.create(image: Rack::Test::UploadedFile.new(unsupported, 'image/png')) } @@ -22,5 +23,5 @@ it { expect(File.exists?(document.image.path(:small))).to eq true } end end - + end \ No newline at end of file From a2463aeaa5112907bbaddfc29e60702f745b9eb7 Mon Sep 17 00:00:00 2001 From: Sergey Margaritov Date: Mon, 23 Mar 2015 15:20:30 +0200 Subject: [PATCH 06/12] change dependency to av gem version 0.9+ --- lib/paperclip/av/transcoder/version.rb | 2 +- paperclip-av-transcoder.gemspec | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/paperclip/av/transcoder/version.rb b/lib/paperclip/av/transcoder/version.rb index b99f404..ce319b6 100644 --- a/lib/paperclip/av/transcoder/version.rb +++ b/lib/paperclip/av/transcoder/version.rb @@ -1,7 +1,7 @@ module Paperclip module Av module Transcoder - VERSION = "0.6.3" + VERSION = "0.6.4" end end end diff --git a/paperclip-av-transcoder.gemspec b/paperclip-av-transcoder.gemspec index 20baf74..c62aa5c 100644 --- a/paperclip-av-transcoder.gemspec +++ b/paperclip-av-transcoder.gemspec @@ -24,7 +24,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency "rails", ">= 4.0.0" spec.add_development_dependency "sqlite3" spec.add_development_dependency "coveralls" - + spec.add_dependency "paperclip", ">=2.5.2" - spec.add_dependency "av", "~> 0.8.1" + spec.add_dependency "av", "~> 0.9.0" end From d5c18eaa0b3f9ed4d8e6509e3d3217a2fec5675f Mon Sep 17 00:00:00 2001 From: Joshua Pearson Date: Wed, 8 Apr 2015 15:57:33 -0700 Subject: [PATCH 07/12] I'm not sure if this is causing any errors, but I'm pretty sure this is a spelling error --- lib/paperclip/paperclip_processors/transcoder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/paperclip/paperclip_processors/transcoder.rb b/lib/paperclip/paperclip_processors/transcoder.rb index b9d2c4b..01ee8d4 100755 --- a/lib/paperclip/paperclip_processors/transcoder.rb +++ b/lib/paperclip/paperclip_processors/transcoder.rb @@ -34,7 +34,7 @@ def initialize file, options = {}, attachment = nil @auto_rotate = options[:auto_rotate].nil? ? false : options[:auto_rotate] @pad_color = options[:pad_color].nil? ? "black" : options[:pad_color] - @convert_options[:output][:s] = format_geometry(@geometry) if @gemotry.present? + @convert_options[:output][:s] = format_geometry(@geometry) if @geometry.present? attachment.instance_write(:meta, @meta) if attachment end From 2b0af9dbaf8f0cda24d2c91e1f1a26f83a20ccb4 Mon Sep 17 00:00:00 2001 From: Igor Zubkov Date: Thu, 4 Jun 2015 10:13:46 +0300 Subject: [PATCH 08/12] Fix typo --- lib/paperclip/paperclip_processors/transcoder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/paperclip/paperclip_processors/transcoder.rb b/lib/paperclip/paperclip_processors/transcoder.rb index 01ee8d4..36b3f88 100755 --- a/lib/paperclip/paperclip_processors/transcoder.rb +++ b/lib/paperclip/paperclip_processors/transcoder.rb @@ -48,7 +48,7 @@ def make dst.binmode if @meta - log "Transocding supported file #{@file.path}" + log "Transcoding supported file #{@file.path}" @cli.add_source(@file.path) @cli.add_destination(dst.path) @cli.reset_input_filters From 1c9c74136016044bdc9a95db35d078a05b95ea84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joa=CC=83o=20Costa?= Date: Sun, 13 Dec 2015 22:34:58 +0000 Subject: [PATCH 09/12] Readds auto-rotate option --- lib/paperclip/paperclip_processors/transcoder.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/paperclip/paperclip_processors/transcoder.rb b/lib/paperclip/paperclip_processors/transcoder.rb index 36b3f88..d191ce6 100755 --- a/lib/paperclip/paperclip_processors/transcoder.rb +++ b/lib/paperclip/paperclip_processors/transcoder.rb @@ -56,6 +56,18 @@ def make if output_is_image? @time = @time.call(@meta, @options) if @time.respond_to?(:call) @cli.filter_seek @time + + if @auto_rotate && !@meta[:rotate].nil? + log "Adding rotation #{@meta[:rotate]}" + case @meta[:rotate] + when 90 + @convert_options[:output][:vf] = "'transpose=1'" + when 180 + @convert_options[:output][:vf] = "'vflip, hflip'" + when 270 + @convert_options[:output][:vf] = "'transpose=2'" + end + end end if @convert_options.present? From 98783a03641d143605e7d88382e0f077048c21e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joa=CC=83o=20Costa?= Date: Mon, 14 Dec 2015 12:01:29 +0000 Subject: [PATCH 10/12] Uses av filter_rotate instead --- lib/paperclip/paperclip_processors/transcoder.rb | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/lib/paperclip/paperclip_processors/transcoder.rb b/lib/paperclip/paperclip_processors/transcoder.rb index d191ce6..d67efea 100755 --- a/lib/paperclip/paperclip_processors/transcoder.rb +++ b/lib/paperclip/paperclip_processors/transcoder.rb @@ -56,18 +56,7 @@ def make if output_is_image? @time = @time.call(@meta, @options) if @time.respond_to?(:call) @cli.filter_seek @time - - if @auto_rotate && !@meta[:rotate].nil? - log "Adding rotation #{@meta[:rotate]}" - case @meta[:rotate] - when 90 - @convert_options[:output][:vf] = "'transpose=1'" - when 180 - @convert_options[:output][:vf] = "'vflip, hflip'" - when 270 - @convert_options[:output][:vf] = "'transpose=2'" - end - end + @cli.filter_rotate @meta[:rotate] if @auto_rotate && !@meta[:rotate].nil? end if @convert_options.present? From 47081726a92f1170a473b314e36e81e4cd9b8d46 Mon Sep 17 00:00:00 2001 From: Erik Rothoff Andersson Date: Thu, 4 Feb 2016 08:57:48 +0100 Subject: [PATCH 11/12] Show convert_options in README --- README.md | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index eda9480..062fb1e 100644 --- a/README.md +++ b/README.md @@ -45,13 +45,35 @@ This will produce: You may optionally add `_meta` to your model and it will get populated with information about the processed video. -The geometry parameters are: +### `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](https://ffmpeg.org/ffmpeg.html). + +For example, sending in the `-an` flag would look like this: + +```ruby +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 ) From 4aec85e791ad1a62ea04dcef50d9b1bc10059736 Mon Sep 17 00:00:00 2001 From: Jeremy Clemans Date: Thu, 21 Apr 2016 21:10:04 -0700 Subject: [PATCH 12/12] Adds more detailed instructions on how to get file meta data --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 062fb1e..6a2673c 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,17 @@ 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. -You may optionally add `_meta` to your model and it will get populated with information about the processed video. +### Meta Data + +Then paperclip-av-transcoder can optionally add uploaded file meta data to a database column for `_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`