Extracting frames from video

Lijo Jose
This article discusses about golang wrapper for ffmpeg for extracting frames from video.

FFmpeg is a great software package a media developer should have. The kind of configurability this provides is uncomparable in media domain. Out of vast capabilities, this article discusses how one can extract frames from video.

  • The key idea in extracting the frames using ffmpeg involves specifiying the output file name. Here, we need to specify the filename with extendable naming pattern like %04d. This will extend the naming from 0001 to 9999 .
  • Next we need to specify the rate at which these frames to be generated. We use video filters available with ffmpeg. The filter we use is fps .

Below is the sample command to extract the frames.

ffmpeg -i <input file> -vf fps=3 <out-dir>/frame%04d.jpg

Go wrapper

For using the ffmpeg frame extraction programmatically, we need to write one wrapper. I chose Go as I want to put this in AWS Lambda Function with extra functionalities. (Will write about that later).

I forked go ffmpeg wrapper from https://github.com/yale8848/gffmpeg (I liked the builder pattern used here) and modified. The updated version is available https://github.com/lijo-jose/gffmpeg.

The complete usage is available here.

Lijo Jose

Written by

Lijo Jose

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade