Create Thumbnail Images from Flash Video FLVs Folder with Bash Script

I’ve had the problem that I wanted to show a list of Flash videos in a Flex application and I want to show a sample picture of each video. As I have got only the videos stored in a folder and have no jpegs of them, I want to generate those sample jpegs, one for each video in the folder. Thus, I found quite a lot of blog entries that show you how you can create an image from a Flash video with the Open Source tool ffmpeg.

As I want to do this not for a single file but for a whole folder, I have written a bash script, that renders out a frame of each FLV video into a jpeg and saves them into a folder called thumbnails of the folder in which it is lying.

So here is the bash script:

1
2
3
4
5
6
7
8
9
10
11
12
#!/bin/bash
 for FILENAME in *.flv
 do
   if test -f "$FILENAME"; then
     echo "Create thumbnail of $FILENAME"
     ffmpeg -i "$FILENAME" -ss 00:00:01.00 -vcodec mjpeg -vframes 1 \ 
         -f image2 ./thumbnails/"$FILENAME".jpg
     #cp $FILENAME ~/test1/
   else
       echo "File $FILENAME not existing."
   fi
 done

Download bash script as a file.

If you are under Mac OS X (or any other Unix system that supports bash scripts) you will have to save and extract this file in the folder where your FLV files are in and then cd to it in the Terminal and make it executable:

chmod u+x createFlvThumbnailsInCurrentFolder.sh

and then execute it in that folder:

./createFlvThumbnailsInCurrentFolder.sh

If there is nothing happening you maybe have to create the folder thumbnails on your own:

mkdir thumbnails

The script should be able to cope with blanks in filenames. However, there are some letters in filenames (like ‘/’) that it cannot cope with. But you will see, which images are missing in the thumbnails folder and can then appropriately rename those files.

Please be so kind to post improvements of the script in the comments.

Cheers!

(Script is under Creative Commons Attribution 2.5 License)

Published by Johannes Luderschmidt

About this blog