{"id":1504,"date":"2015-04-10T23:52:30","date_gmt":"2015-04-10T23:52:30","guid":{"rendered":"http:\/\/178.62.237.127\/?p=1504"},"modified":"2020-01-23T13:25:18","modified_gmt":"2020-01-23T13:25:18","slug":"converting-recordings-to-mp3-in-elastix-and-updating-mysql-cdr-records","status":"publish","type":"post","link":"https:\/\/www.cyber-cottage.co.uk\/?p=1504","title":{"rendered":"Converting recordings to MP3 in FreePBX and updating mysql CDR records"},"content":{"rendered":"<p>In FreePBX users can listen to wav file recordings via the &#8220;Call Recordings&#8221; tab, This uses a field in the mysql cdr table to say where that recording is and what its called, They are now stored in year\/month\/day directory structure under \/var\/spool\/asterisk\/monitor so if the end user wants the recordings in mp3 format as many do its not just a case of converting them its also a case of updating the database.<\/p>\n<p>Luckily this is fairly straight forward, its just a case of doing a quick query and then converting the file and the updating the database. First you have to install lame, This can be done simply with yum then write a script.<\/p>\n<p>In FreePBX advanced settings, you need to enable &#8220;Display&#8221; and &#8220;Override&#8221; readonly settings and then add<\/p>\n<p><strong><em>\/usr\/local\/sbin\/postrecord.sh ^{CDR(linkedid)}<\/em> <\/strong>to &#8220;<label class=\"control-label\" for=\"MIXMON_POST\">Post Call Recording Script&#8221; settings<\/label><i class=\"fa fa-question-circle fpbx-help-icon\" data-for=\"MIXMON_POST\"><\/i><\/p>\n<p>The script I use is simple with a bit of basic logging.<\/p>\n<pre class=\"p1\">#!\/bin\/bash\n. postrecconfig.sh\ndate &gt;&gt; \/var\/log\/asterisk\/mp3.log\npcmwav=$(mysql -u$user -p$secret -s -N -D asteriskcdrdb&lt;&lt;&lt;\"select recordingfile from cdr where linkedid LIKE '$1' AND disposition = 'ANSWERED'  ORDER by calldate DESC LIMIT 1\");\nmp3=\"$(echo $pcmwav | sed s\/\".wav\"\/\".mp3\"\/)\"\nnice lame -b 16 -m m -q 9-resample  \"$path$pcmwav\" \"$path$mp3\" &gt;&gt; \/var\/log\/asterisk\/mp3.log\ntouch -r \"$path$pcmwav\" \"$path$mp3\" &gt;&gt; \/var\/log\/asterisk\/mp3.log\nmysql -u$user -p$secret -s -N -D asteriskcdrdb&lt;&lt;&lt;\"UPDATE cdr SET recordingfile='$mp3'  WHERE recordingfile = '$pcmwav'\" &gt;&gt; \/var\/log\/asterisk\/mp3.log\necho $pcmwav &gt;&gt; \/var\/log\/asterisk\/mp3.log\necho \"--------||-------\" &gt;&gt; \/var\/log\/asterisk\/mp3.log\ndate &gt;&gt; \/var\/log\/asterisk\/mp3.log\necho \"Done\" &gt;&gt; \/var\/log\/asterisk\/mp3.log\necho \"--------||-------\" &gt;&gt; \/var\/log\/asterisk\/mp3.log\nexit 1\n\nThe postrecconfig.sh file looks like\n\nuser=freepbxuser\nsecret=secret\nreceptemail=info@youremailaddress.com\nfile_age=35\ndy=$(date '+%Y')\ndm=$(date '+%m')\ndd=$(date '+%d')\npath=\/var\/spool\/asterisk\/monitor\/$dy\/$dm\/$dd\/\n\n\n\nAs can be seen it steps through entry by entry converting and updating the DB, This example is cron'd to run hourly but does not delete the original wav file, this would be done in a separate script run weekly to remove old files. The reason to keep them is so that a backup of the original is held for a period in case of errors.<\/pre>\n<p class=\"p1\">Hope this is of help to you and your users<\/p>\n<p class=\"p1\">\n","protected":false},"excerpt":{"rendered":"<p>In FreePBX users can listen to wav file recordings via the &#8220;Call Recordings&#8221; tab, This uses a field in the mysql cdr table to say where that recording is and what its called, They are now stored in year\/month\/day directory structure under \/var\/spool\/asterisk\/monitor so if the end user wants the recordings in mp3 format as [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2390,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"content-type":"","advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[89,11,6],"tags":[23,99,28,35,40,55,98,73,100],"class_list":["post-1504","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-elxsupport","category-knowledge","category-support-services","tag-asterisk","tag-cdr","tag-centrex","tag-elastix","tag-freepbx","tag-mysql","tag-smdr","tag-support","tag-technical"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.cyber-cottage.co.uk\/wp-content\/uploads\/2015\/04\/Screenshot-2020-01-23-at-13.18.17.png?fit=1222%2C790&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/p5daZy-og","jetpack_sharing_enabled":true,"jetpack_likes_enabled":false,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1504","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1504"}],"version-history":[{"count":4,"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1504\/revisions"}],"predecessor-version":[{"id":2391,"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1504\/revisions\/2391"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=\/wp\/v2\/media\/2390"}],"wp:attachment":[{"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1504"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1504"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1504"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}