Convert yesterdays wavs to mp3

Status
Not open for further replies.

tjfayaz

New Member
Apr 20, 2021
15
1
3
46
Hi I've implemented as per above including the sql update to change the record_name from .wav to .mp3 as well as se the correct permissions etc. So now I have all recordings in the same location correctly converted to mp3 (with .mp3 extension). The problem I have is the front-end call detail records page links no longer work, so I cannot play or download recordings. Clicking to download results in a white screen and playback just stalls. If i put the wav file back then it works again.

It seems like there is something more than just to convert the wav's to mp3 and change this one field record_name since the system is still trying to look for .wav. Any ideas? I'm using v 4.5.23 of FusionPBX.
 
Last edited:

roger_roger

Member
Oct 12, 2016
198
19
18
69
Hi I've implemented as per above including the sql update to change the record_name from .wav to .mp3 as well as se the correct permissions etc. So now I have all recordings in the same location correctly converted to mp3 (with .mp3 extension). The problem I have is the front-end call detail records page links no longer work, so I cannot play or download recordings. Clicking to download results in a white screen and playback just stalls. If i put the wav file back then it works again.

It seems like there is something more than just to convert the wav's to mp3 and change this one field record_name since the system is still trying to look for .wav. Any ideas? I'm using v 4.5.23 of FusionPBX.
You need to update the v_xml_cdr record to reflect that the file is now an mp3 file instad of a wav file. Add this to your script in the loop that updates the v_call_recordings record:

psql --host=127.0.0.1 --username=fusionpbx -t -c "update v_xml_cdr set record_name = replace(record_name, '.wav', '.mp3') where xml_cdr_uuid = '$BNAME'"
 
  • Like
Reactions: tjfayaz

tjfayaz

New Member
Apr 20, 2021
15
1
3
46
You need to update the v_xml_cdr record to reflect that the file is now an mp3 file instad of a wav file. Add this to your script in the loop that updates the v_call_recordings record:

psql --host=127.0.0.1 --username=fusionpbx -t -c "update v_xml_cdr set record_name = replace(record_name, '.wav', '.mp3') where xml_cdr_uuid = '$BNAME'"
worked perfectly that is just what I was looking for. Thanks Roger :)
 
  • Like
Reactions: roger_roger

rabbidiesel

Member
Aug 28, 2020
32
5
8
9x9tech.com
Hi,

This script works great, and it updates the "Call Recording" app.
The problem I am having is that I cant get the CDR's to update.
When I add
psql --host=127.0.0.1 --username=fusionpbx -t -c "update v_xml_cdr set record_name = replace(record_name, '.wav', '.mp3') where xml_cdr_uuid = '$BNAME'
to the script I get this error
ERROR: invalid input syntax for type uuid: ""
LINE 1: ...replace(record_name, '.wav', '.mp3') where xml_cdr_uuid = ''

Can anyone advise?

Thanx,
 

roger_roger

Member
Oct 12, 2016
198
19
18
69
Hi,

This script works great, and it updates the "Call Recording" app.
The problem I am having is that I cant get the CDR's to update.
When I add

to the script I get this error


Can anyone advise?

Thanx,
You're missing a double quote at the end of the line - try this:

psql --host=127.0.0.1 --username=fusionpbx -t -c "update v_xml_cdr set record_name = replace(record_name, '.wav', '.opus') where xml_cdr_uuid = '$BNAME'"
 

roger_roger

Member
Oct 12, 2016
198
19
18
69
You're missing a double quote at the end of the line - try this:

psql --host=127.0.0.1 --username=fusionpbx -t -c "update v_xml_cdr set record_name = replace(record_name, '.wav', '.opus') where xml_cdr_uuid = '$BNAME'"
My bad - in the examle I gave you, replace opus with mp3. We convert to opus.
 

Adrian Fretwell

Well-Known Member
Aug 13, 2017
1,412
376
83
Is your script setting the shell variable $BNAME correctly?

For what it's worth, I do this slightly differently without referencing a variable in the SQL statement. This method makes the assumption that the file conversion completed successfully as there is no connection between the conversion loop and the SQL statement, but it does mean the script makes only two SQL queries, not one for each file. This job is run once after midnight (about 1am). Field names are correct as of FusionPBX v4.5.11.

Code:
#!/bin/sh
#settings
export PGPASSWORD="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
db_host=127.0.0.1
db_port=5432

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
                        chown www-data:www-data $DIRYESTERDAY/$bname.mp3
                done
                rm $DIRYESTERDAY/*.wav
        fi
done

#echo "converting records to show .mp3 not .wav"
psql --host=127.0.0.1 --username=fusionpbx -c "update v_call_recordings set call_recording_name = replace(call_recording_name, '.wav', '.mp3') from v_xml_cdr where call_recording_name = record_name and record_name is not NULL and DATE_TRUNC('day', to_timestamp(start_epoch)) = CURRENT_DATE - INTERVAL '1 day'"
psql --host=127.0.0.1 --username=fusionpbx -c "update v_xml_cdr set record_name = replace(record_name, '.wav', '.mp3') where record_name is not NULL and DATE_TRUNC('day', to_timestamp(start_epoch)) = CURRENT_DATE - INTERVAL '1 day'"
 
  • Like
Reactions: pleide

roger_roger

Member
Oct 12, 2016
198
19
18
69
Is your script setting the shell variable $BNAME correctly?

For what it's worth, I do this slightly differently without referencing a variable in the SQL statement. This method makes the assumption that the file conversion completed successfully as there is no connection between the conversion loop and the SQL statement, but it does mean the script makes only two SQL queries, not one for each file. This job is run once after midnight (about 1am). Field names are correct as of FusionPBX v4.5.11.

Code:
#!/bin/sh
#settings
export PGPASSWORD="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
db_host=127.0.0.1
db_port=5432

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
                        chown www-data:www-data $DIRYESTERDAY/$bname.mp3
                done
                rm $DIRYESTERDAY/*.wav
        fi
done

#echo "converting records to show .mp3 not .wav"
psql --host=127.0.0.1 --username=fusionpbx -c "update v_call_recordings set call_recording_name = replace(call_recording_name, '.wav', '.mp3') from v_xml_cdr where call_recording_name = record_name and record_name is not NULL and DATE_TRUNC('day', to_timestamp(start_epoch)) = CURRENT_DATE - INTERVAL '1 day'"
psql --host=127.0.0.1 --username=fusionpbx -c "update v_xml_cdr set record_name = replace(record_name, '.wav', '.mp3') where record_name is not NULL and DATE_TRUNC('day', to_timestamp(start_epoch)) = CURRENT_DATE - INTERVAL '1 day'"
I like this version and I'm sure it runs much faster.
 

rabbidiesel

Member
Aug 28, 2020
32
5
8
9x9tech.com
Is your script setting the shell variable $BNAME correctly?

For what it's worth, I do this slightly differently without referencing a variable in the SQL statement. This method makes the assumption that the file conversion completed successfully as there is no connection between the conversion loop and the SQL statement, but it does mean the script makes only two SQL queries, not one for each file. This job is run once after midnight (about 1am). Field names are correct as of FusionPBX v4.5.11.

Code:
#!/bin/sh
#settings
export PGPASSWORD="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
db_host=127.0.0.1
db_port=5432

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
                        chown www-data:www-data $DIRYESTERDAY/$bname.mp3
                done
                rm $DIRYESTERDAY/*.wav
        fi
done

#echo "converting records to show .mp3 not .wav"
psql --host=127.0.0.1 --username=fusionpbx -c "update v_call_recordings set call_recording_name = replace(call_recording_name, '.wav', '.mp3') from v_xml_cdr where call_recording_name = record_name and record_name is not NULL and DATE_TRUNC('day', to_timestamp(start_epoch)) = CURRENT_DATE - INTERVAL '1 day'"
psql --host=127.0.0.1 --username=fusionpbx -c "update v_xml_cdr set record_name = replace(record_name, '.wav', '.mp3') where record_name is not NULL and DATE_TRUNC('day', to_timestamp(start_epoch)) = CURRENT_DATE - INTERVAL '1 day'"
Thank you so much.

This worked like a charm.
 

Andyd358

Member
Aug 23, 2018
243
8
18
55
UK
I know this is an old thread but how would i go about converting all previous recordings (Lots of them)?
 

rabbidiesel

Member
Aug 28, 2020
32
5
8
9x9tech.com
I know this is an old thread but how would i go about converting all previous recordings (Lots of them)?
Hi,

first, I use the maintenance script to make sure the I don’t have any recordings over 90 days. That’s my policy. So when I went ahead and did this manually, I only had to do it 90 times.

What I did is change “yesterday” to “2 days ago” in the 4 spots on the script, then I ran the script. After it finished, I changed “2 days ago” to “3 days ago” and ran the script again. Etc ec

I used vim because I was able to do find and replace.

I am sure someone can update the script to do it in one shot, but I am not that someone. :)

Hope this helped.
 
  • Like
Reactions: Andyd358
Status
Not open for further replies.