Converting recorded wav calls to mp3

The file_age variable was in one of the two files I used to compile the code. I was not sure what it did, and since I do not fully understand the code, I left it. I have since commented it out.

If I am to understand your second comment. The purging is the changing of the cdr log. Correct?

As for the script not affecting the call connection time. I understand that it should not affect this but as soon as I disabled the post recording script the issue of call connection lag was no longer present. When I re-enable this conversion calls start to take nearly 90 seconds to connect.

1 Like

I have no idea why as that script should have no impact on the dialplan until “hangup”. Perhaps a copy of a call from the “full” log would helpfully provide timestamps to possibly show any delays,

I will comment though that you call the script with ^{ARG3}, again why? , your post is not actually a complete working script as there is no initial hash/bang line apparent, $dtpath is neither apparently defined and I would not run any command through nice yet.

Perhaps you could post the script in it’s entirety.

The purging could be good for deleting recordings over 365 day to conserve disk space and remain compliant, deleting the cdr records really won’t save any space though.

1 Like

I also have a script that i would like to run after a call is recorded. If I call the script manually it works fine, /usr/sbin/./convert_wav2mp3 but if I put that in Advanced settings “Post Call Recording Script” not only does it not run but it also stops the call from being recorded, what would be the proper entry in “Post Call Recording Script” to call that script.

gary.

1 Like

your script needs to runnable by the asterisk user, I suggest you put it in /var/lib/asterisk/bin and then

chmod -R asterisk:asterisk /var/lib/asterisk/bin

2 Likes

Thanks dicko for your reply, I moved the script to the location you suggested, and made asterisk:asterisk and executable I can still run the script from cammand line ./convert_wav2mp3 and it works, but can not get it to run from “Post Call Recording Script” what command do I need to place into that field.

Gary.

1 Like

/var/lib/asterisk/bin/convert_wav2mp3 argument1 . . etc.

2 Likes

dicko,

I did what you said in this post and converting the wav files to mp3 works like a dream. even verified it actually runs

== MixMonitor close filestream (mixed)
== Executing [/var/lib/asterisk/bin/convert_recordings.sh]
== End MixMonitor Recording DAHDI/25-1

had 573MB of recordings and after converted it was 57MB

2 Likes

Excellent, gotta love an OS that does exactly what you want, (if you understand how it does it :slight_smile: ) .

1 Like

I agree with you 100%

1 Like

Shame people are not the same…

Very nice little script,
gonna have to use that I think, Cheers.

Hv.

1 Like

It works flawless. I put the script into /var/lib/asterisk/bin and then change the ownership and then added
/var/lib/asterisk/bin/convert_wav2mp3.sh to the Post Call Recordings section of Advanced Settings.

What are all all the variables used for in Post Call Recordings.

1 Like

You will likely only need the ones mentioned in the “hover over help”, filename, path and format.

1 Like

I just put on the Line for Post Call Recordings /var/lib/asterisk/bin/convert_wav2mp3.sh

and everything works. The Help does not explain it very well lol

1 Like

Which bit of

“An optional script to be run after the call is hangup. You can include channel and MixMon variables like ${CALLFILENAME}, ${MIXMON_FORMAT} and ${MIXMON_DIR}. To ensure that you variables are properly escaped, use the following notation: ^{MY_VAR}”

is not helpful ?

1 Like

What would be the purposes of using them?

${CALLFILENAME} is the filename of the recording?

{MIXMON_FORMAT : format of audio file?

1 Like

it is your choice what argument1 is but it might simplistically be ^{MIXMON_DIR}^{CALLFILENAME}.^{MIXMON_FORMAT}

1 Like

OH ok I got it now derrrrrrrrrrrrrrrrrrrrrrrrrrrrrv

:slight_smile:

1 Like

Just want to thank you all. You are my heroes. I was able to take a customer with 80 gb (3 months) of recordings and shrink it down to 16 gb. This solves our disk problems for past and future calls.

Thanks again!

2 Likes

I know this is an old post but I had to submit my 2 cents. First of all jhayes and dicko, I can’t thank either of you enough for your knowledge and direction. Using your scripts I was able to convert my client’s database of 2.7 million recordings to a reasonable size, and implement a long term storage strategy. You guys saved me a ton of time, and I can’t thank you guys enough. If you’re ever in Phoenix send me a message and the beers are on me!

Thanks guys,

Greg

2 Likes

Since this is the #1 Google result for this topic, I’m posting this here

I used the ideas from the scripts posted here to write a cleaner script with some improvements. Enjoy!

Notes:

  • LAME is automatically installed on the latest FreePBX distros, otherwise you can compile and install manually
  • You can change the LAME encoding parameters to better suit your needs
  • You need to specify the MySQL root password (or whatever user you like). Root password is blank by default (BTW, change it!)

EDIT: thanks to dicko for some improvements!

[code]#!/bin/bash

Save script as /var/lib/asterisk/bin/wav2mp3.sh and then:

chown asterisk:asterisk /var/lib/asterisk/bin/wav2mp3.sh

chmod +x /var/lib/asterisk/bin/wav2mp3.sh

Configure FreePBX postrecording script as: /var/lib/asterisk/bin/wav2mp3.sh ^{CALLFILENAME} ^{UNIQUEID}

Wait 3 seconds before we start

sleep 3

The default path for the recordings includes the current date

dy=$(date ‘+%Y’)
dm=$(date ‘+%m’)
dd=$(date ‘+%d’)

Path where recordings are stored, including trailing slash

dtpath=/var/spool/asterisk/monitor/$dy/$dm/$dd/

If the WAV file is 44 bytes long, delete it and exit. These are empty audio files that are generated

for example when a ring group or queue rings multiple extensions. This has been reported multiple

times, most recent bug report is https://issues.freepbx.org/browse/FREEPBX-13370

if [ $(wc -c < “$dtpath$1.wav” | cut -d ’ ’ -f1) -eq 44 ]; then
rm -f "$dtpath$1.wav"
exit 0
fi

Use LAME for the MP3 conversion, on a low priority process

nice lame -b 32 -m m “$dtpath$1.wav” “$dtpath$1.mp3”

If the conversion was successful, update CDR database and delete WAV file

if [ $? -eq 0 ]; then
mysql -u root -p’rootpassword’ -s -D asteriskcdrdb -e "UPDATE cdr SET recordingfile = ‘$1.mp3’ WHERE uniqueid = ‘$2’"
rm -f "$dtpath$1.wav"
else
exit 1
fi[/code]

1 Like