How can I automatically convert all MP4 files to FLV with ffmpeg?

CIF picture CIF · Dec 20, 2010 · Viewed 7.5k times · Source

How can I automatically convert all MP4 files to FLV in a specific folder?

ffmpeg -i VID00002.MP4 -ar 44100 test.flv

Is there a way to queue these tasks, assuming that I don't know the file names?

If I need to run any scripts (I'm familiar with Python), how can I do that?

Answer

OV Web Solutions picture OV Web Solutions · Jul 13, 2011

You can do this fairly easy within the terminal, given you have ffmpeg installed. In your terminal, enter the following:

$>cd /your/path/to/videos
$>for i in *.mp4; do ffmpeg -i $i -ar 44100 $i.flv; done

The second command simply iterates through each mp4 file and assigns the filename to '$i'. You then call ffmpeg using $i as the input and output filename. For the output, you simply add the extension, in this case $i.flv. So, if your filename is 'video.mp4', it will output as 'video.mp4.flv'.

Hope this helps.