ruby-av / paperclip-av-transcoder

Audio/Video Transcoder for Paperclip using FFMPEG/Avconv
MIT License
136 stars 83 forks source link

Video Skewed (does not maintain aspect ratio) #31

Open zreitano opened 9 years ago

zreitano commented 9 years ago

The video uploaded does not maintain aspect ratio. In the readme it says, " '!' - Keep the same aspect of the image/video, but with the passed dimesion."

My goal is to be able to be able to have the video returned in a square (while maintaining the aspect ratio). Cropping from the center would be ideal, as well.

Any help would be greatly appreciated. I included my code below.

Here is a link to a skewed 500x500! video of my puppy: http://s3.amazonaws.com/pivotdevelopment/posts/videos/102/square.mp4?1440617576

Here is the non-skewed version for comparison: http://s3.amazonaws.com/pivotdevelopment/posts/videos/103/square.mp4?1440617933

class Video < Post

  Paperclip.interpolates :id do |attachment, style|
    attachment.instance.id
  end

  #basename/extension is paperclip interpolation from attachment, can write own interpolations as needed

  # have to link /usr/local/bin to the linuxbrew version of ffmpeg
  has_attached_file :video,  path: "/posts/videos/:id/:style.:extension",
  :styles => {
    :square => {:geometry => "500x500!", :format => 'mp4', :streaming => true }
  },
  :processors => [:transcoder]

  validates_attachment :video, :presence => true,
                               :content_type => { content_type: ["video/mp4", "video/mov", "video/mpeg","video/mpeg4", "video/quicktime"] }

  def video_url
    video = self.video
    if video.present?
      return video.url(:square)
    end
  end

end
attenzione commented 9 years ago

Currently it's not possible to crop video at all. You can pad video with #, but not crop. I have the same problem 2 years ago, so forked paperclip-ffmpeg and made a crop instead of pad. You can try https://github.com/attenzione/paperclip-ffmpeg for now. But i think this behaviour should be implemented in this gem, too.

zreitano commented 9 years ago

Thank you! And agreed. But even # doesn't pad the video for me. And it returns the exact same video as 500x500 (without the hashtag).

Any ideas?

 has_attached_file :video,  path: "/posts/videos/:id/:style.:extension",
  :styles => {
    :square => {:geometry => "500x500#", :format => 'mp4', :streaming => true }
  },
  :processors => [:transcoder]
attenzione commented 9 years ago

possibly this gem is not finished yet, for padding.

wingrunr21 commented 9 years ago

The geometry options are actually totally ignored in this version of the gem. You can see here that the various options are extracted but they are never passed to the output. The only thing the output sees is a sanitized geometry setting which causes the backend to resize to the requested height/width.