I recently had an issue with flash videos being corrupted on a project. I decided to use FFmpeg to try to open the file automatically and generate a thumbnail. My reasoning was that if I could open the file with FFmpeg than it probably wasn't corrupt. Read more...
FFmpeg is a command line utility typically used for transcoding video or generating thumbnails for the flash FLV format so it is the ideal utility for this. We start by compiling it on OS X Leopard.
Obtaining the sources
I used git to obtain the sources. I highly suggest you check it out and this guide assumes you already have the git command line utilities installed.
Downloading
Start by opening terminal and running the following commands:
cd ~/Desktop git clone git://git.mplayerhq.hu/ffmpeg/ cd ffmpeg git clone git://git.mplayerhq.hu/libswscale/
This should download the sources for the latest version of FFmpeg from the git repository.
Compiling
./configure --disable-vhook --enable-shared --disable-mmx
* Note: This doesn't compile in support for any audio codecs or anything specific. Check out Stephen Jungles more detailed FFmpeg install tutorial if you require that.
Compiling Continued
Now all we need to do is compile the configuration. This can take a few minutes. It took around 5 on my macbook pro.
make sudo make install
Testing
You can see if FFmpeg has installed correctly by typing the following:
$ ffmpeg --version FFmpeg version git-1e63b35, Copyright (c) 2000-2008 Fabrice Bellard, et al. configuration: --disable-vhook --enable-shared --disable-mmx libavutil 49.11. 0 / 49.11. 0 libavcodec 52. 0. 0 / 52. 0. 0 libavformat 52.22. 1 / 52.22. 1 libavdevice 52. 1. 0 / 52. 1. 0 built on Sep 29 2008 11:46:55, gcc: 4.0.1 (Apple Inc. build 5465)
If you see this output you should be good to go!
Generating A Thumbnail from FLV
Now it's time to generate a thumbnail from the FLV file in question. I did a little bit of google searching and came up with a simple command line option via FlashComGuru. Type:
ffmpeg -i video.flv -an -ss 00:00:05 -an -r 1 -vframes 1 -y thumbnail_%d.jpg
In my case, the corrupt videos will output something like this:
video.flv: Unknown format
And there you have it. A simple way to test for corrupt FLV videos. Next up, I will write a rake script that will batch through a queue of videos testing for corruption.