Nikita Kazakov
Nikita Kazakov
~1 min read

Tags

I had to come up with a way to extract video metadata for work. I found Mediainfo to be a great fit.

It strips video and audio metadata from a video file. It provides metadata without downloading an entire video.

Install

Install the MediaInfo CLI first. I used the MacOS in development and Ubuntu setup in production.

Let’s use Brew to install it on a MacOS in development.

brew install media-info

Add the gem script for MediaInfo from rubygems.org to your Gemfile.

gem 'mediainfo', '~> 1.5'

Run bundle install to install. Let’s jump into the Rails Console and play around.

rails console
# add a video url
url = 'https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-mp4-file.mp4'
metadata = MediaInfo.from(url)
metadata = JSON.parse(metadata.to_json)

The metadata will be a Ruby hash.