So, I’ve been hacking around with different methods for getting stills from video files via the command line. This is part of a larger project I’m working on, but I figured I’d document what I’ve come up with to hopefully make things easier for folks in the future.
Click the link for more…
So, first off, if you’re not working on a Mac OSX / OSX Server platform, your options are pretty limited. You’re pretty much guaranteed to end up using something related to ffmpeg, unless you go for commercial software.
In my case, this needs to happen via some interaction with a php script, so the easiest approach is to use the ffmpeg-php extension. This is actually a very cool extension, though it’s rather fiddly to get installed right. You can get all sorts of information about a video, and extract whatever information you need.
A few downsides present themselves though. First off, ffmpeg is what we might fairly call “patent encumbered.” Because nobody is paying the MPEG-LA for use of the mpeg codecs, ffmpeg is in violation of any number of patents. Now, you’re fairly unlikely to be personally harmed for using it, but it’s important to be aware of the legality.
Next, and more pressing, ffmpeg is terrible for doing frame grabs. You get lots of control, but it gets slower as a linear function of how far into the video you need to seek. It almost seems like it converts every frame of the video up to and including your target frame. On my 2ghz g5, it can do a grab of the first frame of a video instantly, but grabbing a frame from 10 minutes in can take up to 60 seconds. That’s unacceptable. I need to poke in the code a bit more to get a better sense of why that’s happening – it happens with both the CVS and stable branch, no matter how I compile it.
As best as I can tell, if you’re on a non-Mac platform, that’s really the only free way to do it. So let’s move on to the Mac options.
First, you can use applescript (via osacript) to make Quicktime do it for you. You’ll need QT Pro. This may be a good option for very low volume uses where you can monitor the display. Unfortunately, my experience with applescript and Quicktime is that things often go awry. Further, you’re limited to performing one operation at a time, which is tough to do when you’re deal with web access. You’d need to create a backend to do batch processing at intervals – no fun!
Next, you can use the QT_Tools software. This is a very lightweight set of applications which make calls into the Quicktime API. If you’re looking to learn the Quicktime API, these are actually pretty helpful too. The source is available, but developer support is limited.
Semi-related, you should take a look at the movtoy4m software. It also uses the Quicktime API via the command line to do simple video processing. It’s pretty helpful for pulling basic information. It is essentially abandoned at this point.
So that’s where I’m at. I think for my solution, I’ll end up using the QT_Tools route. I’m somewhat tempted to learn how to write a php extension and just code my own PHP-Quicktime ext. I get the feeling though that this wouldn’t be nearly as easy as it seems. Perhaps I’ll just make some very stripped down binaries I can call from within PHP.
Anyone have a fantastic option that I haven’t thought of?