Convert yesterdays wavs to mp3

Status
Not open for further replies.

DigitalDaz

Administrator
Staff member
Sep 29, 2016
3,038
556
113
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
 

DigitalDaz

Administrator
Staff member
Sep 29, 2016
3,038
556
113
Just tested on a live box that I had just backed up first and it seems to work just fine :)
 

taptech

Member
Mar 6, 2017
50
10
8
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!!
 

DigitalDaz

Administrator
Staff member
Sep 29, 2016
3,038
556
113
FusionPBX just looks on the file system, it will look for multiple extensions, mp3, wav, ogg I think too
 

taptech

Member
Mar 6, 2017
50
10
8
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.
 

KonradSC

Active Member
Mar 10, 2017
166
98
28
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
 
  • Like
Reactions: DigitalDaz

brickrat

New Member
Sep 3, 2018
12
0
1
42
Just a question
If the recordings are converted to .mp3 will it still be available (playable and able to download) in cdr module?
 

DigitalDaz

Administrator
Staff member
Sep 29, 2016
3,038
556
113
Yes they are but now also, the path is stored in the DB so paths will need to be updated too.
 

brickrat

New Member
Sep 3, 2018
12
0
1
42
Thnx for the response. Maybe s symlink to converted file location.
I will try that and give feedback here
 

screwloose

Member
Feb 5, 2017
49
9
8
40
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]
 

kp123

New Member
Feb 6, 2017
19
1
3
43
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]
 

DigitalDaz

Administrator
Staff member
Sep 29, 2016
3,038
556
113
You should also be able to use sudo to avoid the password for the db
 

skyiax

New Member
Aug 30, 2019
3
2
3
38
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
 
  • Like
Reactions: ad5ou

clive18

New Member
Sep 26, 2019
1
0
1
54
Hi.
Thanks for the script which I use, and seems to work well.
I have a strange issue where the recordings seem to be deleted aprox 3 months after they were recorded.

Do you think this may have something to do with this script?

Thanks

-I am answering myself... There is a script that runs a cronjob as follows:
/etc/cron.daily/fusionpbx-maintenance

This script removes recordings older than 90 days.

Hope this helps anyone else having the same issue. ! :)
 
Last edited:

taptech

Member
Mar 6, 2017
50
10
8
Check to see if the maintenance script is deleting them. I can't remember if it is default or not, but I have my system set to delete recordings, voicemails, and CDR's after a set amount of time.
 

Adrian Fretwell

Well-Known Member
Aug 13, 2017
1,382
364
83
If you have a default install, you will have a shell script in /etc/cron.daily/ called fusionpbx-maintenance. Below is an extract of this
shell script showing the part that is deleting your recordings after three months:
Code:
#delete call recordings older than 90 days
if [ .$switch_package = .true ]; then
    find /var/lib/freeswitch/recordings/*/archive/*  -name '*.wav' -mtime +90 -exec rm {} \;
    find /var/lib/freeswitch/recordings/*/archive/*  -name '*.mp3' -mtime +90 -exec rm {} \;
else
    find /usr/local/freeswitch/recordings/*/archive/*  -name '*.wav' -mtime +90 -exec rm {} \;
    find /usr/local/freeswitch/recordings/*/archive/*  -name '*.mp3' -mtime +90 -exec rm {} \;
fi
psql --host=127.0.0.1 --username=fusionpbx -c "delete from v_call_recordings WHERE call_recording_date < NOW() - INTERVAL '90 days'"
 
  • Like
Reactions: pleide

roger_roger

Member
Oct 12, 2016
198
19
18
69
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 have replaced lame with ffmpeg and convert to OPUS. The quality seems better and the files are smaller.
 
Status
Not open for further replies.