Paperclip AV Transcoder not working on remote server - ruby-on-rails

I am able to upload videos locally. The videos are processed using paperclip and all the meta data is saved correctly, as well. When I tried to upload a video using our remote server, I received the error:
Av::UnableToDetect (Unable to detect any supported library)
I have installed ffmpeg using LinuxBrew. It says everything is installed correctly (checking which brew and which ffmpeg, as well as checking if the gem is appropriately installed).
When I have styling in my model for the video (which is what enables the meta information to be stored and to have control over how the video is uploaded) it doesn't work remotely.
has_attached_file :video, path: "/posts/:id/:style.:extension",
:styles => {
:medium => { :geometry => "493x877", :format => 'flv' },
:thumb => { :geometry => "100x100#", :format => 'jpg', :time => 10 },
# :mobile => {:geometry => "640X480", :format => 'mp4', :streaming => true}
}, :processors => [:transcoder]
However, when I remove this from my model and have:
has_attached_file :video, path: "/posts/:id/:style.:extension"
The video is uploaded to S3 (without the data or styling that I need).
Any help would be greatly appreciated. I think AV is having trouble finding ffmpeg but I am not sure why or how to go about fixing it. Thanks in advance for any advice.

I had the same issue just this past week - Try this!
Video model:
has_attached_file :video, styles: {
:medium => {
:geometry => "640x480",
:format => 'mp4'
},
:thumb => { :geometry => "160x120", :format => 'jpeg', :time => 10}
}, :processors => [:transcoder]
validates_attachment_content_type :video, content_type: /\Avideo\/.*\Z/
Make sure you already bundled:
gem 'paperclip', '~> 4.3.1'
gem 'aws-sdk', '< 2.0'
gem 'paperclip-av-transcoder'
gem "paperclip-ffmpeg", "~> 1.2.0"
Run the paperclip migration:
rails g paperclip model video
Be sure to add in post_controller.rb:
private
def bscenes_params
params.require(:post).permit(:video)
end
Upload form:
<%= f.file_field :video %>
Show page:
<%= video_tag bscene.video.url(:medium), controls: true, style: "max-width: 100%;" %>
At this point you should get this error:
Av::UnableToDetect (Unable to detect any supported library):
For Mac
Go to your terminal and type in:
brew options ffmpeg
Then run the following to install ffmpeg:
For older versions of brew recipe:
brew install ffmpeg --with-fdk-aac --with-ffplay --with-freetype --with-frei0r --with-libas
For newer versions of brew recipe:
brew install ffmpeg --with-fdk-aac --with-sdl2 --with-freetype --with-frei0r --with-libass
For Linux Mint / Ubuntu / Debian based Linux
Open a terminal (Ctrl + Alt + T) and execute following commands one by one to install ffmpeg.
sudo add-apt-repository ppa:mc3man/trusty-media
sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install ffmpeg
At this point Video uploads will work locally
Now for remote uploads you will need to setup https://devcenter.heroku.com/articles/buildpacks
This should now bring you to your error
Av::UnableToDetect (Unable to detect any supported library)
You will need to create a Procfile in the root of your app directory more information about Procfile here: https://devcenter.heroku.com/articles/procfile
touch Procfile
Hope this helps!

Related

Heroku ffmpeg buildpacks for video uploads

Is there a proper way to get heroku ffmpeg installed and running so that my users can upload videos in my rails app?
Tried the Heroku references on the topic which led to my app running the heroku error check logs page...
I know there has to be some installation I have to pass but don't seems to find anything on it - Please help with links or ideas :)
users can upload videos
We've had it working on Heroku before; we used paperclip-ffmpeg (which is now paperclip-av-transcoder) with the actual Paperclip gem.
Whilst I can't provide any information about the buildpacks, I can share how we were able to get video uploading working on Heroku...
#app/models/attachment.rb
class Attachment < ActiveRecord::Base
has_attached_file :attachment,
styles: { thumb: { geometry: "100x100#", format: 'jpg', time: 10}, medium: { geometry: "300x300#", format: 'jpg', time: 10} },
processors: [ :transcoder ]
end
As long as the paperclip-av-transcoder gem installs (ensure you've got it in your Gemfile), this should allow you to store the videos - and images - you need.
Got heroku Video uploads to work!
Video model:
has_attached_file :video, styles: {
:medium => {
:geometry => "640x480",
:format => 'mp4'
},
:thumb => { :geometry => "160x120", :format => 'jpeg', :time => 10}
}, :processors => [:transcoder]
validates_attachment_content_type :video, content_type: /\Avideo\/.*\Z/
Make sure you already bundled:
gem 'paperclip', '~> 4.3.1'
gem 'aws-sdk', '< 2.0'
gem 'paperclip-av-transcoder'
Run the paperclip migration:
rails g paperclip model video
Be sure to add in post_controller.rb:
private
def bscenes_params
params.require(:post).permit(:video)
end
Upload form:
<%= f.file_field :video %>
Show page:
<%= video_tag bscene.video.url(:medium), controls: true, style: "max-width: 100%;" %>
At this point you should get this error:
Av::UnableToDetect (Unable to detect any supported library):
Go to your terminal and type in:
brew options ffmpeg
Then run the following to install ffmpeg:
brew install ffmpeg --with-fdk-aac --with-ffplay --with-freetype --with-frei0r --with-libas
At this point video uploads will work locally
Now for remote uploads you will need to setup https://devcenter.heroku.com/articles/buildpacks
After setting up Heroku buildpacks you may get an error:
Av::UnableToDetect (Unable to detect any supported library)
You will need to create a Procfile in the root of your app directory more information about Procfile here: https://devcenter.heroku.com/articles/procfile
touch Procfile
Hope this helps!

Error when uploading video to heroku

I am using the paperclip and paperclip-av-transcoder in my rails app and I have gotten to the point where I can upload videos locally. But when I try it in heroku I get this error. Av::UnableToDetect (Unable to detect any supported library):
I may have to add something to make it work with s3 but I had it working with images earlier so everything should be setup for s3.
This is the code in my model
class Classvideo < ActiveRecord::Base
belongs_to :user
has_attached_file :video, :styles => {
:medium => {:geometry => "640x480", :format => 'flv'},
:thumb => { :geometry => "100x100#", :format => 'jpg', :time => 10 }
}, :processors => [:transcoder]
validates_attachment_content_type :video, :content_type => ["video/mp4", "video.mov", "video/mpeg","video/mpeg4", "image/jpg", "image/jpeg"]
end
Ok, you just need to install ffmpeg
For example on OS-X: http://www.renevolution.com/how-to-install-ffmpeg-on-mac-os-x/
And then on heroku https://elements.heroku.com/buildpacks/shunjikonishi/heroku-buildpack-ffmpeg
I had the same issue just this past week - Try this!
Video model:
has_attached_file :video, styles: {
:medium => {
:geometry => "640x480",
:format => 'mp4'
},
:thumb => { :geometry => "160x120", :format => 'jpeg', :time => 10}
}, :processors => [:transcoder]
validates_attachment_content_type :video, content_type: /\Avideo\/.*\Z/
Make sure you already bundled:
gem 'paperclip', '~> 4.3.1'
gem 'aws-sdk', '< 2.0'
gem 'paperclip-av-transcoder'
gem "paperclip-ffmpeg", "~> 1.2.0"
Run the paperclip migration:
rails g paperclip model video
Be sure to add in post_controller.rb:
private
def bscenes_params
params.require(:post).permit(:video)
end
Upload form:
<%= f.file_field :video %>
Show page:
<%= video_tag bscene.video.url(:medium), controls: true, style: "max-width: 100%;" %>
At this point you should get this error:
Av::UnableToDetect (Unable to detect any supported library):
Go to your terminal and type in:
brew options ffmpeg
Then run the following to install ffmpeg:
brew install ffmpeg --with-fdk-aac --with-ffplay --with-freetype --with-frei0r --with-libass --with-libvo-aacenc --with-libvorbis --with-libvpx --with-opencore-amr --with-openjpeg --with-opus --with-rtmpdump --with-schroedinger --with-speex --with-theora --with-tools
Restart your server and try to upload a video now! Hope this helps - Happy coding :)

mongoid-paperclip: Photo is not recognized by the 'identify' command

I'm migrating from Active Record to Mongoid, and this paperclip stuff used to work fine. I'm using Ubuntu 12.04.
I've got this code in my mongoid document:
has_mongoid_attached_file :photo,
:styles => {
:thumb => "60x60",
:small => "100x100",
:medium => "300x200",
:large => "600x400"
},
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/s3.yml",
:path => "#{Rails.env}/merc:attachment/:id/:style.:extension",
:url => ":s3_alias_url",
:bucket => '%^&*&^'
I have the rmagick gem installed and the command_path pointing to where the various imagemagick commands are -> '/usr/bin'.
I'm using Unicorn as my webserver, and I have verified that identiy and convert are available by putting this in my view:
<%= `which convert` %>
<%= `echo $PATH` %>
But alas, when I try to upload the image I get :
Photo /tmp/qdoba20121005-27609-1m3kq9c.jpg is not recognized by the
'identify' command. Photo /tmp/qdoba20121005-27609-1m3kq9c.jpg is not
recognized by the 'identify' command. Photo
/tmp/qdoba20121005-27609-1m3kq9c.jpg is not recognized by the
'identify' command. Photo /tmp/qdoba20121005-27609-1m3kq9c.jpg is
not recognized by the 'identify' command.
Seemingly one for every one of the styles I have defined.
I've confirmed that the file exists, and I can run identify on the file from the commandline.
Any help will be appreciated. Thanks!
There is a recent update to the Cocaine gem that is breaking the imagemagick filenames for a lot of people - check it out because rolling back Cocaine to the previous version may help.
See here:
https://github.com/thoughtbot/paperclip/issues/1038

Paperclip does NOT create my specified thumbnails. What am I missing?

I'm using ruby 1.9.2, rails 3.0.8, paperclip 2.3.11.
I installed imagemagick some time ago using macports. To find the version I used:
convert -version
Version: ImageMagick 6.5.6-1 2009-10-01 Q8 OpenMP http://www.imagemagick.org
Copyright: Copyright (C) 1999-2009 ImageMagick Studio LLC
In my model I'm setting:
class Sketch < ActiveRecord::Base
has_attached_file :image, :style => {:ipad => "786x1024>", :iphone => "320x480>"}, :default_style => :ipad, :whiny_thumbnails => true
has_many :comments
end
When I upload my image, the original size is uploaded but the thumbnails are never created. Even though I set whiny_thumbnails to true, I don't see any error output.
What else do I need to do?
Ultimately I want to deploy on Heroku, so I prefer not to use any configuration methods that are not compatible with Heroku.
The key for is :styles not :style.
has_attached_file :image, :styles => {:ipad => "786x1024>", :iphone => "320x480>"}, :default_style => :ipad, :whiny_thumbnails => true
^

Rails Paperclip image compression compared to what Page Speed produces

I've set up paperclip in rails and everything is working hunky-dory (i actually had to google that...:).
I've noticed however that Page Speed tells me I could losslessly compress my thumbnail and large images (the ones that paperclip produces) further. Is there an option I can put into my model which does this? I've noticed that mod_deflate doesn't compress images (I'm using Firefox).
You can add compression to paperclip processing using the paperclip-compression gem.
In your Gemfile:
gem "paperclip-compression", "~> 0.1.1"
(of course run bundle install)
In your model:
has_attached_file :avatar,
:styles => { :medium => "300x300>", :thumb => "100x100>" },
:processors => [:thumbnail, :compression]
"jpegtran works by rearranging the compressed data (DCT coefficients), without ever fully decoding the image. Therefore, its transformations are lossless"
Note: if you are running on heroku, you'll need jpegtran, and optipng binaries added to your application. Here's a good article on running binaries on heroku.
You should do your own testing on various JPEG compression levels but I've noticed that I can bump ImageMagicks quality setting down to 75 and still not see any noticeable difference - with about a 30-40% file size savings.
My model looks like:
has_attached_file :photo,
:styles => {
:"185x138" => {
:geometry => "185x138>"
} },
:convert_options => {
:all => "-auto-orient",
:"185x138" => "-quality 75",
-quality 75 is for ImageMagick. If you're using a different processor you will need to adjust accordingly.
What about FFMPEG or AVCONV?
sudo apt-get install ffmpeg/avconv
= initializer
Paperclip.options[:command_path] = "/usr/bin/" # see `which ffmpeg`
= Modal
after_save :compress_with_ffmpeg
def compress_with_ffmpeg
[:thumb, :original, :medium].each do |type|
img_path = self.avtar.path(type)
Paperclip.run("ffmpeg", " -i #{img_path} #{img_path}")
end
end

Resources