Video Upload/Processing with Ruby on Rails

Existing Architecture with Carrierwave GEM

# Carrierwave
gem 'carrierwave-video'
gem 'carrierwave-video-thumbnailer'
gem 'carrierwave_backgrounder'
gem 'streamio-ffmpeg', '~> 2.0.0'
# Delayed job used by carrierwave_backgrounder
gem 'delayed_job_active_record'
basic architecture for the video upload process

The Issue I faced

Correctly encoded video
vertically pressed video
PROCESSED_DEFAULTS = {
resolution: '500x400',
preserve_aspect_ratio: :height.
video_codec: 'libx264', # H.264/MPEG-4 AVC video codec
constant_rate_factor: '30', # GOP Size
frame_rate: '25', # frame rate
audio_codec: 'aac', # AAC audio codec
audio_bitrate: '64k', # Audio bitrate
audio_sample_rate: '44100' # Audio sampling frequency
}

What is FFMPEG ?

sudo apt-get update

sudo apt-get install ffmpeg
ffmpeg -version
ffmpeg -i some-video.mp4 -filter:v "scale='min(640,iw)':min'(480,ih)':force_original_aspect_ratio=decrease,pad=640:480:(ow-iw)/2:(oh-ih)/2" output.mp4
"scale='min(640,iw)':min'(480,ih)':force_original_aspect_ratio=decrease,pad=640:480:(ow-iw)/2:(oh-ih)/2"

What I did to fix the issue

version :rescaled do
process :encode
end
require 'streamio-ffmpeg'

--

--

Developer ❤️ JS

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store