There is a Swiss army knife of video handling that’s called ffmpeg. A real workhorse. See examples of what it can do. Those are 19 real-world use-cases for this command-line tool.
ffmpeg’s website says:
FFmpeg is a complete, cross-platform solution to record, convert and stream audio and video.
It might sound smug, but it’s quite true. “Complete.” Here is a short, reconstructed snapshot of how me and some friends used it, a few weeks ago.
One night, a while ago, me and friends at recreational programming collective Forskningsavdelningen got a very well-defined and fun problem to solve. “Send a video to this custom-built screen over the Net.” And the inventor added “I’ll be done receiving the bytes you send me in, say 10 minutes.”
Frantic activity on our side. Us? Yes, me and Jonas.
Should we build a video player plugin? We looked at building plugins for VLC. Hmm. Would take us more than one night. Hard. Then ffmpeg came on the table; my friend was right in just assuming that there’d be some option to extract frames from a video. So, we went to the documentation. A flag “-f” meant “apply a filter”.
An aside: Creating a film from a series of images
ffmpeg -f image2 -i foo-%03d.jpeg -r 28 -s 96x54 foo.avi
- Use the image2 filter to create a video from a bunch of still images
- The existing images have names that match the form foo-001.jpeg, foo-002.jpeg, and so forth
- The framerate of the created video should be 28 frames per second
- The resulting video should be 96 pixels wide and 54 pixels tall
- The output video is named foo.avi
Pretty soon we were using Ruby to factor out configuration. When we knew that ffmpeg was able to do the video frame-grabbing, we said “let’s create random data, to have something to send over the Net”. Borrowing code from a snippet website, we skipped reading the API for the UDP Socket library.
Trying it, we actually got pixels sent to the screen. “But we don’t know if it’s our noise.”
Then, the task of reading the image files began. We had begun with JPEG. Difficult format, much compression. Then, PNG. Hmm. Still compressed. RAW didn’t exist. But, snooping around at the Cats Who Code article about ffmpeg tricks, we found this pearl of wisdom:
The following image formats are also availables : PGM, PPM, PAM, PGMYUV, JPEG, GIF, PNG, TIFF, SGI.
Wikipedia explains PPM. Wonderful format. From there on out, it was a walk in the park – apart from wrangling with Ruby strings for a confusing bit.
Well, this was an incomplete and belated recap – I am not the BBC. – but I wanted to share it with you, anyway. The kind of fast-paced fun Forskningsavdelningen can provide is hard to get elsewhere.