Convert yesterdays wavs to mp3

DigitalDaz

Administrator
Staff member
Use with caution, not well tested, give us some feedback please. This will iterate through each domain. The lame settings I have chosen give great quality with good compression.

If you have not installed it already:

Code:
apt-get install lame
Code:
#!/bin/sh
for DIRECTORY in /var/lib/freeswitch/recordings/*/; do
        DIRYESTERDAY=/var/lib/freeswitch/recordings/`basename "$DIRECTORY"`/archive/`date -d "yesterday" +%Y/%b/%d`
        if [ -d "$DIRYESTERDAY" ]; then
                for WAVFILE in /var/lib/freeswitch/recordings/`basename "$DIRECTORY"`/archive/`date -d 'yesterday' +%Y/%b/%d`/*.wav; do
                        bname=`basename $WAVFILE .wav`
                        lame -b 16 -m m -q 8 $WAVFILE $DIRYESTERDAY/$bname.mp3 >> /dev/null
                done
                rm $DIRYESTERDAY/*.wav
        fi
done
chown -R www-data:www-data /var/lib/freeswitch/recordings
Add a cron job for just after midnight or another convenient time eg:

Code:
5 0 * * * /bin/bash /root/convert_wav_to_mp3.sh >/dev/null 2>&1
Obviously, you need to be using the default fusionpbx recording location.

Don't forget to make your script executable with chmod +x
 
I've found that for the call recordings, as long as only the file extension is changed on the recording, FusionPBX doesn't seem to care if it is *.wav or *.mp3, which is fantastic. I am not sure if this holds true for recordings across the board though, such as IVR. It looks like this script would convert all of them. Digi, does FusionPBX also ignore the file type for these other recordings?

Also- Thank You!!
 
Just wanted to note- with the new style of CDR which I believe now requires the file extension, this will result in the record buttons disappearing in the CDR as it can no longer find *.wav file.
 
Updated for v_call_recordings table in the newer versions of fusion. Make sure you put the write IP for your database.

Code:
#!/bin/sh
for DIRECTORY in /var/lib/freeswitch/recordings/*/; do
        DIRYESTERDAY=/var/lib/freeswitch/recordings/`basename "$DIRECTORY"`/archive/`date -d "yesterday" +%Y/%b/%d`
        if [ -d "$DIRYESTERDAY" ]; then
                for WAVFILE in /var/lib/freeswitch/recordings/`basename "$DIRECTORY"`/archive/`date -d 'yesterday' +%Y/%b/%d`/*.wav; do
                        bname=`basename $WAVFILE .wav`
                        lame -b 16 -m m -q 8 $WAVFILE $DIRYESTERDAY/$bname.mp3 >> /dev/null
                done
                rm $DIRYESTERDAY/*.wav
                psql --host=127.0.0.2 --username=fusionpbx -t -c "UPDATE v_call_recordings SET call_recording_name = '$bname.mp3' WHERE call_recording_name = '$bname.wav' and call_recording_path = '$DIRYESTERDAY'"
        fi
done
chown -R www-data:www-data /var/lib/freeswitch/recordings
 
I had to make a mod to the code to make my DB connect with out a password.

Code:
#!/bin/sh
export PGPASSWORD="YourFusionpbxDBPasswordHere"
for DIRECTORY in /var/lib/freeswitch/recordings/*/; do
        DIRYESTERDAY=/var/lib/freeswitch/recordings/`basename "$DIRECTORY"`/archive/`date -d "yesterday" +%Y/%b/%d`
        if [ -d "$DIRYESTERDAY" ]; then
                for WAVFILE in /var/lib/freeswitch/recordings/`basename "$DIRECTORY"`/archive/`date -d 'yesterday' +%Y/%b/%d`/*.wav; do
                        bname=`basename $WAVFILE .wav`
                        lame -b 16 -m m -q 8 $WAVFILE $DIRYESTERDAY/$bname.mp3 >> /dev/null
                done
                rm $DIRYESTERDAY/*.wav
                psql --host=127.0.0.1 --username=fusionpbx -t -c "UPDATE v_call_recordings SET call_recording_name = '$bname.mp3' WHERE call_recording_name = '$bname.wav' and call_recording_path = '$DIRYESTERDAY'"
        fi
done
chown -R www-data:www-data /var/lib/freeswitch/recordings
[/QUOTE]
 
I had to make a mod to the code to make my DB connect with out a password.

Code:
#!/bin/sh
export PGPASSWORD="YourFusionpbxDBPasswordHere"
for DIRECTORY in /var/lib/freeswitch/recordings/*/; do
        DIRYESTERDAY=/var/lib/freeswitch/recordings/`basename "$DIRECTORY"`/archive/`date -d "yesterday" +%Y/%b/%d`
        if [ -d "$DIRYESTERDAY" ]; then
                for WAVFILE in /var/lib/freeswitch/recordings/`basename "$DIRECTORY"`/archive/`date -d 'yesterday' +%Y/%b/%d`/*.wav; do
                        bname=`basename $WAVFILE .wav`
                        lame -b 16 -m m -q 8 $WAVFILE $DIRYESTERDAY/$bname.mp3 >> /dev/null
                done
                rm $DIRYESTERDAY/*.wav
                psql --host=127.0.0.1 --username=fusionpbx -t -c "UPDATE v_call_recordings SET call_recording_name = '$bname.mp3' WHERE call_recording_name = '$bname.wav' and call_recording_path = '$DIRYESTERDAY'"
        fi
done
chown -R www-data:www-data /var/lib/freeswitch/recordings
[/QUOTE]

Line psql.... in loop for ... done


Code:
#!/bin/sh
export PGPASSWORD="YourFusionpbxDBPasswordHere"
for DIRECTORY in /var/lib/freeswitch/recordings/*/; do
        DIRYESTERDAY=/var/lib/freeswitch/recordings/`basename "$DIRECTORY"`/archive/`date -d "yesterday" +%Y/%b/%d`
        if [ -d "$DIRYESTERDAY" ]; then
                for WAVFILE in /var/lib/freeswitch/recordings/`basename "$DIRECTORY"`/archive/`date -d 'yesterday' +%Y/%b/%d`/*.wav; do
                        bname=`basename $WAVFILE .wav`
                        lame -b 16 -m m -q 8 $WAVFILE $DIRYESTERDAY/$bname.mp3 >> /dev/null

               psql --host=127.0.0.1 --username=fusionpbx -t -c "UPDATE v_call_recordings SET call_recording_name = '$bname.mp3' WHERE call_recording_name = '$bname.wav' and call_recording_path = '$DIRYESTERDAY'"
     
                done
                rm $DIRYESTERDAY/*.wav
               
        fi
done
chown -R www-data:www-data /var/lib/freeswitch/recordings
[/QUOTE][/QUOTE]
 
Guys, how are you?

Well I'll try to run this script but unsuccessfully, so decide to debug.

I will post here my script with my changes that worked in recent versions.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#! / bin / sh
export PGPASSWORD = "*************"
for DIRECTORY in / var / lib / freeswitch / recordings / * /; of
DIRYESTERDAY = / var / lib / freeswitch / recordings / `basename" $ DIRECTORY "` / archive / `LANG = en_us_88591; date -d "yesterday" +% Y /% b /% d`
if [-d "$ DIRYESTERDAY"]; then
for WAVFILE in / var / lib / freeswitch / recordings / `basename" $ DIRECTORY "` / archive / `LANG = en_us_88591; date -d 'yesterday' +% Y /% b /% d` / *. wav; of
bname = `basename $ WAVFILE .wav`
lame -b 16 -m m -q 8 $ WAVFILE $ DIRYESTERDAY / $ bname.mp3 >> / dev / null

psql --host = 127.0.0.1 --username = fusionpbx -t -c "UPDATE v_xml_cdr SET record_name = '$ bname.mp3' WHERE record_name = '$ bname.wav'"

done
rm $ DIRYESTERDAY / *. wav

fi
done
chown -R www-data: www-data / var / lib / freeswitch / recordings

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


This table that is in the previous post had not found it, I looked in the database and the file name is v_xml_cdr.

I made the update in the bank and the conversation with lame, ready the file appeared in php.


I hope I collaborated,


In Brazil we like to collaborate to make the application even better.


Thanks