EmmonsNet

Geek Stuff

Home Software Linux FFmpeg and BASH: A way to impress the ladies and be the envy of your friends!
FFmpeg and BASH: A way to impress the ladies and be the envy of your friends! PDF Print E-mail
Written by Frank Emmons   
Tuesday, 04 August 2009 22:15

bash consoleWant to show off some mad bash skills while impressing hot babes and being the envy of your friends?

Then have a look at the bash goodness I laid on my linux neophyte friend. About about an hour ago he wanted to convert a whole directory of home videos (stored .wmv format) into .flv and thumbnails for upload to his site.

He had the option of using WinFF. But after playing with it for a while he realized it could not make thumbnails for him. So he called me to help.

First I showed him how to generate a thumbnail for each video file, then create flash versions of each of the videos using for loops and ffmpeg.


From the command line:

cd <directory where all of the videos are stored>


To create the thumbnails:

for f in *.wmv; do ffmpeg -y -i "$f" -f image2 -ss 10 -vframes 1 -an "${f%.wmv}.jpg"; done


To create the .flv video files:

for f in *.wmv; do ffmpeg -i "$f" "${f%.wmv}.flv"; done


NOTE: You really want to create the thumbnails from the original video files. Creating thumbnails from .flv files makes for images that are tiled and not very pretty.

What is really going on with those commands? Well lets take look at the first one a piece at a time.

for f in *.wmv;


This for portion 'for' of the loop. What we are really doing is telling our shell that for each file we find that matches the pattern '*.wmv' in the current directory (or file that ends with .wmv) we want to execute the following command on it. And that command is:

do ffmpeg -y -i "$f" -f image2 -ss 10 -vframes 1 -an "${f%.wmv}.jpg";


Here is where we are calling 'ffmpeg'. For the particulars you can check out the ffmpeg man page. Basically we are telling ffmpeg to capture the first frame of the video and turn it into a .jpg thumbnail image. Then finally:

done

We are telling the shell we are done when it runs out of files that match the pattern in the 'for' portion of the statement.

This was something I threw together in less than five minutes. But the first time I attempted to get a for loop to work in bash, it took about an hour to get it right.

 

Disclaimer: the commands within this posting may not impress hot babes or make your friends green with envy. You will more than likely have to be content with that soft and quiet swell of pride knowing that there is one more productive thing you can do without the aid of a mouse.

Last Updated on Tuesday, 04 August 2009 22:50
 
Share/Save/Bookmark