Error when uploading video to heroku - ruby-on-rails

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 :)

Related

URL issue: paperclip-av-transcoder

I am trying to implement paperclip-av-transcoder gem. I have checked everything but not able to find what I am doing wrong here. I'm writing steps which I have followed.
Added into gemfile
--> gem 'paperclip-av-transcoder'
Added into my model
--> has_attached_file :video_file, :styles => {
:medium => { :geometry => "640x480", :format => 'mp4' },
:thumb => { :geometry => "100x100#", :format => 'jpg', :time => 10 }
}, :processors => [:transcoder]
--> validates_attachment_content_type :video_file, :content_type => /\Avideo\/.*\Z/
created schema to add column name
"video_file_meta"
In my view file
video_tag(video.video_file.url, controls: true, autobuffer: true, size: "320x240")
I have checked video in public/system folder it is properly saved I am able to see that video there but I am not able to see that in my view file.
Video Url -> /system/videos/video_files/000/000/003/original/tingtong_464.mp4?1497851104
I am sharing screens to show how it looks in the browser.
Everything from my point is correct, except Paperclip requires at least one field in database - *_file_name (for you it's video_file_file_name), but you didn't added it and Paperclip can't construct url properly. Read more https://github.com/thoughtbot/paperclip#usage
Currently working model file code:
has_attached_file :video_file, :styles => {
:medium => { :geometry => "500x500", :format => 'jpg' },
:thumb => { :geometry => "100x100", :format => 'jpg' }
}, :processors => [:transcoder]
validates_attachment_content_type :video_file,
:content_type => [
"video/mp4",
"video/quicktime",
"video/3gpp",
"video/x-ms-wmv",
"video/mov",
"video/flv",
],
:message => "Sorry! We do not accept the attached file type"
I guess I am not resizing my video file in any other video format so it is working properly.

Paperclip AV Transcoder not working on remote server

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!

Paperclip and Amazon S3. Styled images can't be displayed, only downloaded. Original image is blank

Having some odd issues with paperclip, s3 and imagemagick.
The normal sized image will force an image download.
http://ads_honours_development.s3.amazonaws.com/assets/adverts/10/normal.jpg?1333899985
Meanwhile the original image is blank.
http://ads_honours_development.s3.amazonaws.com/assets/adverts/10/original.jpg?1333899985
Here is the model.
class Advert < ActiveRecord::Base
belongs_to :group
#paperclip
has_attached_file :photo, {
:styles => { :large => "512x512", :normal => "360x360", :small => "200x200", :tiny => "64x64", :thumbnail => "32x32" },
:convert_options => { :large => "-quality 86" },
:default_url => "/images/thumbnail/blank-recipe.png",
:url => ':s3_domain_url',
:path => 'assets/:class/:id/:style.:extension',
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/s3.yml",
:s3_permissions => 'public-read',
:s3_protocol => 'http'}
validates_attachment_presence :photo
end
Gem file is like:
gem 'aws-sdk'
gem 'paperclip', '~> 2.0'
I can't work out what I'm doing wrong here. Any help/suggestions?
UPDATE I've got this running on heroku as well and the exact same issue occurs, so it's not down to my development machines settings. I'm guessing the problem lies within Paperclip itself, my bucket setup or the amazon aws-sdk gem.
SECOND UPDATE Ok so all of these images load in IE, but not Chrome. What gives?
Maybe you have an extension running on chrome which is blocking the images? The link shows for me in Chrome only with adblock disabled.

Amazon S3 path or to_file wont work

Hey guys ive got the following code in my Model
require 'RMagick'
class Upload < ActiveRecord::Base
belongs_to :card
has_attached_file :photo,
:styles => {
:thumb => ["100x100", :jpg],
:pagesize => ["500x400", :jpg],
},
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:path => ":attachment/:id/:style.:extension",
:bucket => 'your_deck',
:default_style => :pagesize
attr_accessor :x1, :y1, :width, :height
def update_attributes(att)
scaled_img = Magick::ImageList.new(self.photo.path)
orig_img = Magick::ImageList.new(self.photo.path(:original))
scale = orig_img.columns.to_f / scaled_img.columns
args = [ att[:x1], att[:y1], att[:width], att[:height] ]
args = args.collect { |a| a.to_i * scale }
orig_img.crop!(*args)
orig_img.write(self.photo.path(:original))
self.photo.reprocess!
self.save
super(att)
end
end
This code works offline however when on Heroku with Amazon S3 it fails to work, ive tried the code with to_file and it also wont work
I get the following error
can't convert Array into String
I had the same problem and it's due to an update to paperclip. I'm surprised heroku are still using this gem version as it will surely affect all their users; I installed a previous version as a plugin and it's fine. Don't forget to remove the gem from your .gems file or specify the previous version in your gems manifest.

How to pass additional convert options to paperclip on Heroku?

class User < ActiveRecord::Base
has_attached_file :photo, :styles => { :square => "100%", :large => "100%" },
:convert_options => {
:square => "-auto-orient -geometry 70X70#",
:large => "-auto-orient -geometry X300" },
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:path => ":attachment/:id/:style.:extension",
:bucket => 'mybucket'
validates_attachment_size :photo,
:less_than => 5.megabyte
end
Works great on local machine, but gives me an error on Heroku: There was an error processing the thumbnail for stream.20143
The thing is I want to auto-orient photos before resizing, so they resized properly.
The only working variant now(thanks to jonnii) is resizing without auto-orient:
...
as_attached_file :photo, :styles => { :square => "70X70#", :large => "X300" },
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:path => ":attachment/:id/:style.:extension",
:bucket => 'mybucket'
...
How to pass additional convert options to paperclip on Heroku?
UPD
I discover, the trouble in "-auto-orient" option. It seems like this option is broken in version of ImageMagick used by Heroku. I created custom paperclip image processor inherited from paperclip's standard thumbnail:
module Paperclip
class Ao < Thumbnail
def transformation_command
super + " -auto-orient"
end
end
end
It works perfect on local machine, but fails on Heroku.
These are the sizes I use. They all work fine on heroku:
SIZES = {
:original => "640x480>",
:thumb => "150x150#",
:mini => "60x60#",
:micro => "30x30#"
}
Make sure your gem version of paperclip is the same as heroku's. You can specify the specific gem version in your .gems file and in your environment.rb to make sure they line up.
I'm not sure exactly why your convert_options are causing problems, but if I remember correctly paperclip uses ImageScience directly and your chosen options might be incompatible with the read only heroku file system.
If this is critical and you need an answer right now I'd raise a support ticket on heroku. If you get a response make sure you post it back here!

Resources