Blog

Video encoding processor for CarrierWave, more options and background processing

Tips how to tackle with video processing.

As previously promised, here are some more tips how to tackle with video processing. Streamio FFMPEG has a bunch of useful options. You can specify, for example frame rate, resolution, bitrate, codecs and many other by simply passing an options hash to transcoding. This time I wanted to change the previous code a little bit, add some options and include latest rails goodies as ActiveJob and Enumerable.

So let’s get started:

First, I have added an enum field for processing status to have some information about the uploaded file. It was introduced in Rails 4.1. It's an attribute where database values are integers, but you can use them by name. For example:

You can learn more about enums here.

The updated post model will now look like this:

In the modified processor I have added some ffmpeg transcoding options, which modify how uploaded video will look like. I have also added job for ActiveJob library. This feature was included in Rails 4.2. Previously, when you were creating a job for background processing it may look different depending on which queueing backend you have used (sidekiq, delayedjob, sucker_punch etc.). Now on you can create a job and change the background processor in initializer without adding any changes to your job file.

More about ActiveJob can be found here.

In the job I have also added an option of taking a screenshot from uploaded movie and printing the progress of the current uploading. However, this is only for demonstration purposes because in the current shape it will only print progress in a background worker log, which may be only helpful with debugging on localhost.

And don’t forget to add an ActiveJob initializer (config/initializers/active_job.rb) where you specify which background engine you are using. In my case it’s sidekiq.

Photo by: unsplash.com

Check our latest product - it's based on our experience of managing over 50-people strong company. The tool we're missing as a small company and not an enterprise.

humadroid.io is an employee and performance management software. It's an unique tool allowing everyone to be in the loop - by having up to date info about co-workers, time-off, benefits, assets, helping with one-on-ones, being a go-to place for company-wide announcements.

Check out humadroid.io
Top

Contact us

* Required fields

The controller of your personal data provided via this contact form is Prograils sp. z o.o., with a registered seat at Sczanieckiej 9A/10, 60-215 Poznań. Your personal data will be processed in order to respond to your inquiries and for our marketing purposes (e.g. when you ask us for our post-development, maintenance or ad hoc engagements for your app). You have the rights to: access your personal data, rectify or erase your personal data, restrict the processing of your personal data, data portability and to object to the processing of your personal data. Learn more.

Notice

We do not track you online. We use only session cookies and anonymous identifiers for the purposes specified in the cookie policy. No third-party trackers.

I understand
Elo Mordo!Elo Mordo!