cybercampbell
07-21-2007, 06:47 PM
Ok...I've been trying to do this with a shell script but I've been advised to use perl as I have some requirements that are a little more involved....I'm hoping someone can help as I don't know Perl at all...although I'm intermediate in PHP.
this is what I have as a shell script...it works but doesn't do everything I need.
#!/bin/bash
cd /var/www/vhosts/path/to/directory/and/files
for f in $( find . -name "*.mov" -o -name "*.mpeg" -o -name "*.mpg" -o -name "*.mp4" -o -name "*.wmv" -o -name "*.3gp" ) ; do ffmpeg -i $f -s 384x240 -b 700000 -r 25 -acodec mp3 -ar 44100 -ab 128 -f flv `echo $f | sed "s/\.[^.]*$//"`.flv ; done
for f in $( find . -name "*.wav" -o -name "*.aif" -o -name "*.sd2" -o -name "*.wma" ) ; do ffmpeg -i $f -acodec mp3 -ar 44100 -ab 128 `echo $f | sed "s/\.[^.]*$//"`.mp3 ; done
This script goes through a chosen directory plus all subdirectories and converts all video format files to .flv and audio format files to .mp3
I'm executing a linux command using ffmpeg to do this. this part I do know.
This works fine but I need to make this a Perl script and add the following features:
1. I need to have it work with files and folders with spaces in the name.
2. I need it to check if the .flv or .mp3 already exists and if not then convert the file...if so then just move on the the next file.
3. I would like the script to save all actions in some sort of 'converted log' file so I can see what it did exactly.
4. and lastly id like to have it handle any problems in a better way eg. if for some reason it can't convert the file or the conversion fails...it should save the error and path/filename in an 'error log' being different file to the 'converted log'. and also not stop the script(like it does now) if there is a problem then it just logs it and moves on to the next file.
Note: it has to save the new .flv or .mp3 with the same filename
eg:
mymovie.mp4 ....becomes......mymovie.flv
mysong.wav....becomes......mysong.mp3
any advice on this would be greatly appreciated.
Cheers
C
this is what I have as a shell script...it works but doesn't do everything I need.
#!/bin/bash
cd /var/www/vhosts/path/to/directory/and/files
for f in $( find . -name "*.mov" -o -name "*.mpeg" -o -name "*.mpg" -o -name "*.mp4" -o -name "*.wmv" -o -name "*.3gp" ) ; do ffmpeg -i $f -s 384x240 -b 700000 -r 25 -acodec mp3 -ar 44100 -ab 128 -f flv `echo $f | sed "s/\.[^.]*$//"`.flv ; done
for f in $( find . -name "*.wav" -o -name "*.aif" -o -name "*.sd2" -o -name "*.wma" ) ; do ffmpeg -i $f -acodec mp3 -ar 44100 -ab 128 `echo $f | sed "s/\.[^.]*$//"`.mp3 ; done
This script goes through a chosen directory plus all subdirectories and converts all video format files to .flv and audio format files to .mp3
I'm executing a linux command using ffmpeg to do this. this part I do know.
This works fine but I need to make this a Perl script and add the following features:
1. I need to have it work with files and folders with spaces in the name.
2. I need it to check if the .flv or .mp3 already exists and if not then convert the file...if so then just move on the the next file.
3. I would like the script to save all actions in some sort of 'converted log' file so I can see what it did exactly.
4. and lastly id like to have it handle any problems in a better way eg. if for some reason it can't convert the file or the conversion fails...it should save the error and path/filename in an 'error log' being different file to the 'converted log'. and also not stop the script(like it does now) if there is a problem then it just logs it and moves on to the next file.
Note: it has to save the new .flv or .mp3 with the same filename
eg:
mymovie.mp4 ....becomes......mymovie.flv
mysong.wav....becomes......mysong.mp3
any advice on this would be greatly appreciated.
Cheers
C