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