# Modifying transcoding in asterisk

**URL:** <https://community.asterisk.org/t/modifying-transcoding-in-asterisk/78579>\
**Category:** Asterisk General\
**Created:** [February 16, 2019, 12:55am UTC](https://community.asterisk.org/t/modifying-transcoding-in-asterisk/78579 "2019-02-16T00:55:56Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![vubtrong](https://avatars.discourse-cdn.com/v4/letter/v/8491ac/32.png) [@vubtrong](https://community.asterisk.org/u/vubtrong)\
**Post date:** [February 16, 2019, 12:55am UTC](https://community.asterisk.org/t/modifying-transcoding-in-asterisk/78579/1 "2019-02-16T00:55:56Z")

</div>

Hi,

I see the following transcoding done for channel Dahdi/1-1 from _alaw_ to _slin48_

Name: DAHDI/1-1  
…  
NativeFormats: (alaw)  
WriteFormat: slin48  
ReadFormat: slin48  
WriteTranscode: Yes (slin@48000)-\>(slin@8000)-\>(alaw@8000)  
ReadTranscode: Yes (alaw@8000)-\>(slin@8000)-\>(slin@48000)

I would like to suppress the transcoding altogether so that only alaw is used.

Any thoughts on how to do this? Much thanks!

---

<div class="post-metadata">

**Author:** ![david551](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@david551](https://community.asterisk.org/u/david551)\
**Post date:** [February 16, 2019, 9:41am UTC](https://community.asterisk.org/t/modifying-transcoding-in-asterisk/78579/2 "2019-02-16T09:41:13Z")

</div>

We would need details of the other channel involved and the dialplan in order understand why lan48 was involved at all.

---

<div class="post-metadata">

**Author:** ![vubtrong](https://avatars.discourse-cdn.com/v4/letter/v/8491ac/32.png) [@vubtrong](https://community.asterisk.org/u/vubtrong)\
**Post date:** [February 16, 2019, 5:32pm UTC](https://community.asterisk.org/t/modifying-transcoding-in-asterisk/78579/3 "2019-02-16T17:32:57Z")

</div>

Here are the details …

This is comms between two asterisk system using IAX …

First we are going to a Dahdi channel then to asterisk. (Note: the digital audio audio when it arrives at the Dahdi channel is encoded in alaw.) In so doing, we get the following transcoding as detailed above …

_Name: DAHDI/1-1_  
_…_  
_NativeFormats: (alaw)_  
_WriteFormat: slin48_  
_ReadFormat: slin48_  
_WriteTranscode: Yes (slin@48000)-\>(slin@8000)-\>(alaw@8000)_  
_ReadTranscode: Yes (alaw@8000)-\>(slin@8000)-\>(slin@48000)_

From there, we go from one asterisk system to another using the opus codec and IAX. This is the transcoding that we see …

_Name: IAX2/ua\_vip-12603_  
_NativeFormats: (opus)_  
_WriteFormat: slin48_  
_ReadFormat: slin48_  
_WriteTranscode: Yes (slin@48000)-\>(opus@48000)_  
_ReadTranscode: Yes (opus@48000)-\>(slin@48000)_

The part of the dialplan that concerns this is straightforward:  
_[globals]_  
_FEATURES\_LIST=PttOn#PttOff#J7#J8#J9#J0_

_[general]_  
_autofallthrough=no_

_[inbound]_

_; ask the VIP where to route calls to 4-digit extensions_

\_exten =\> \_XXXX,1,Set(\__DYNAMIC\_FEATURES=${FEATURES\_LIST})_  
\_exten =\> _XXXX,n,Answer()_  
\_exten =\> _XXXX,n,Dial(DAHDI/1)_  
\_exten =\> _XXXX,n,Hangup()_

Finally, here are relevant parts of codecs.conf, pjsip.conf and iax.conf:

codecs.conf:

_[opus8]_  
_type=opus_  
_signal=voice_  
_max\_playback\_rate=8000_  
_fec=yes_

pjsip.conf:  
_;================================ TRANSPORTS ==_  
_; Our primary transport definition for UDP communication behind NAT._  
_[simpletransport]_  
_type = transport_  
_protocol = udp_  
_bind = 0.0.0.0_  
_; NAT settings_  
_;local\_net = 10.0.0.0/8_  
_;external\_media\_address = 203.0.113.1_  
_;external\_signaling\_address = 203.0.113.1_

_;=================================================_  
_; remote-dial_  
_;=================================================_  
_[remote-dial]_  
_type=endpoint_  
_context=inbound_  
_transport=simpletransport_  
_disallow=all_  
_allow=opus8:60_  
_;allow=alaw, ulaw_  
_aors=remote-dial_  
_ice\_support=no_  
_rtp\_timeout=15_

_[remote-dial]_  
_type=aor_  
_;So that registration can happen from anywhere_  
_remove\_existing=yes_  
_max\_contacts=1_

_[remote-dial]_  
_type=identify_  
_endpoint=remote-dial_  
_match=uav_

iax.conf:  
_[general]_  
_autokill=yes_

_; Listener Addresses_  
_;_  
_; Use the ‘bindaddr’ and ‘bindport’ options to specify on which address and port_  
_; the IAX2 channel driver will listen for incoming requests._  
_;_  
_;_

_bindport=4569 ; The default port to listen on_

_bindaddr=192.168.40.198_

_bandwidth=low_

_;_  
_; You can also fine tune codecs here using “allow” and “disallow” clauses with_  
_; specific codecs. Use “all” to represent all formats._  
_;_  
_;allow=all_  
_;disallow=g723.1_  
_disallow=all_  
_allow=opus8:60_  
_;_

_;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;_  
_; Jitter Buffer_  
_;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;_

_jitterbuffer=yes_  
_maxjitterbuffer=200_

_;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;_  
_; IAX2 Encryption_  
_;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;_

_; trunkfreq sets how frequently trunk messages are sent in milliseconds. This_  
_; value is 20ms by default, which means the trunk will send all the data queued_  
_; to it in the past 20ms. By increasing the time between sending trunk messages,_  
_; the trunk’s payload size will increase as well. Note, depending on the size_  
_; set by trunkmtu, messages may be sent more often than specified. For example_  
_; if a trunk’s message size grows to the trunkmtu size before 20ms is reached_  
_; that message will be sent immediately. Acceptable values are between 10ms and_  
_; 1000ms._  
_;_  
_trunkfreq=40 ; How frequently to send trunk msgs (in ms). This is 20ms by_  
\_ ; default.\_

_; Should we send timestamps for the individual sub-frames within trunk frames?_  
_; There is a small bandwidth use for these (less than 1kbps/call), but they_  
_; ensure that frame timestamps get sent end-to-end properly. If both ends of_  
_; all your trunks go directly to TDM, and your trunkfreq equals the frame_  
_; length for your codecs, you can probably suppress these. The receiver must_  
_; also support this feature, although they do not also need to have it enabled._  
_;_  
_trunktimestamps=yes_

_register =\> [ground\_vip:12345678@192.168.40.201](mailto:ground_vip:12345678@192.168.40.201)_

_[ua\_vip]_  
_type=friend_  
_host=192.168.40.201_  
_trunk=yes_  
_secret=12345678_  
_;context=iax\_incoming_  
_context=inbound_  
_disallow=all_  
_allow=opus8:60_

Thank you for looking into this!!!

---

<div class="post-metadata">

**Author:** ![david551](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@david551](https://community.asterisk.org/u/david551)\
**Post date:** [February 16, 2019, 6:19pm UTC](https://community.asterisk.org/t/modifying-transcoding-in-asterisk/78579/4 "2019-02-16T18:19:22Z")

</div>

Are you using any of originate, call files and local channels?

---

<div class="post-metadata">

**Author:** ![vubtrong](https://avatars.discourse-cdn.com/v4/letter/v/8491ac/32.png) [@vubtrong](https://community.asterisk.org/u/vubtrong)\
**Post date:** [February 16, 2019, 7:08pm UTC](https://community.asterisk.org/t/modifying-transcoding-in-asterisk/78579/5 "2019-02-16T19:08:33Z")

</div>

Pjsip for local channel…

---

<div class="post-metadata">

**Author:** ![david551](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@david551](https://community.asterisk.org/u/david551)\
**Post date:** [February 16, 2019, 8:37pm UTC](https://community.asterisk.org/t/modifying-transcoding-in-asterisk/78579/6 "2019-02-16T20:37:20Z")

</div>

A local channel is not the same as a pjsip channel. The reason I asked is that local channels and originate can result in the call being set up with codecs that match neither end point.

---

<div class="post-metadata">

**Author:** ![vubtrong](https://avatars.discourse-cdn.com/v4/letter/v/8491ac/32.png) [@vubtrong](https://community.asterisk.org/u/vubtrong)\
**Post date:** [February 16, 2019, 10:04pm UTC](https://community.asterisk.org/t/modifying-transcoding-in-asterisk/78579/7 "2019-02-16T22:04:52Z")

</div>

Then we are not using local channels …

---

<div class="post-metadata">

**Author:** ![vubtrong](https://avatars.discourse-cdn.com/v4/letter/v/8491ac/32.png) [@vubtrong](https://community.asterisk.org/u/vubtrong)\
**Post date:** [February 16, 2019, 10:06pm UTC](https://community.asterisk.org/t/modifying-transcoding-in-asterisk/78579/8 "2019-02-16T22:06:22Z")

</div>

We are not using originate, call files, nor local channels …

---

<div class="post-metadata">

**Author:** ![jcolp](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/jcolp/32/8848_2.png) [@jcolp](https://community.asterisk.org/u/jcolp)\
**Post date:** [February 18, 2019, 11:02am UTC](https://community.asterisk.org/t/modifying-transcoding-in-asterisk/78579/9 "2019-02-18T11:02:11Z")

</div>

Based on your information one side is using opus and the other alaw, there has to be a transcoding path for that scenario. If that’s not the scenario then you’ll need to provide further information and clarify.

---

<div class="post-metadata">

**Author:** ![vubtrong](https://avatars.discourse-cdn.com/v4/letter/v/8491ac/32.png) [@vubtrong](https://community.asterisk.org/u/vubtrong)\
**Post date:** [February 18, 2019, 9:44pm UTC](https://community.asterisk.org/t/modifying-transcoding-in-asterisk/78579/10 "2019-02-18T21:44:53Z")

</div>

Yes, there is transcoding that is going on between alaw and opus, but with slin48000 as the intermediary encoding format.

As background info, audio enters the dahdi channel on one asterisk as alaw and then gets transcoded to slin8000 and finally to slin48000.

Then it gets sent via IAX to a second asterisk but with opus specified for the IAX trunk. So there is another transcoding … from slin48000 to opus48000.

Problem is we are limited to narrowband between the two asterisks so we need the final encoding to be opus8000.

Here are the details:  
**On the 1st asterisk:**  
_Name: DAHDI/1-1_  
_NativeFormats: (alaw)_  
_WriteFormat: slin48_  
_ReadFormat: slin48_  
_WriteTranscode: Yes (slin@48000)-\>(slin@8000)-\>(alaw@8000)_  
_ReadTranscode: Yes (alaw@8000)-\>(slin@8000)-\>(slin@48000)_

**From there, we go to the second asterisk via IAX and opus.**  
This is the transcoding that we see for the IAX trunk from the 1st asterisk.  
_Name: IAX2/ua\_vip-12603_  
_NativeFormats: (opus)_  
_WriteFormat: slin48_  
_ReadFormat: slin48_  
_WriteTranscode: Yes (slin@48000)-\>(opus@48000)_  
_ReadTranscode: Yes (opus@48000)-\>(slin@48000)_

My questions are:  
How can I prevent the transcoding from alaw to slin in the first place so that I can go directly from alaw to opus8000?

However, if the alaw format data must be transcoded to slin first, how do I stop it at slin8000 so that I can transcode from slin8000 to opus8000 (for the IAX trunk)?

Thank you for your help.

---

<div class="post-metadata">

**Author:** ![david551](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@david551](https://community.asterisk.org/u/david551)\
**Post date:** [February 18, 2019, 11:09pm UTC](https://community.asterisk.org/t/modifying-transcoding-in-asterisk/78579/11 "2019-02-18T23:09:51Z")

</div>

Sorry I missed the point originally.

My suspicion is that the bit rate is a constraint applied to the codec, not a different codec. I think the translation path code probably only determines translations based on the codec name, so has to assume the maximum possible settings for the codec.

Chances are that the code has been written so that it only knows how to encode Opus from 48kHz signed linear, so you would probably have to rewrite the translation code (is the Opus codec module open source?)

I wouldn’t expect there to be a direct translation form G.711 A-Law to anything other than 8kHz signed linear. That translation is going to have to be done to make the maths straightforward, when going to any of the complex codecs.

What confused me originally, and still confuses me, is why the translation is split across the bridge. I would have expected the whole translation to be done on the outgoing side for the direction. However, that doesn’t change the fact that there will be multiple steps in the translation.

---

<div class="post-metadata">

**Author:** ![jcolp](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/jcolp/32/8848_2.png) [@jcolp](https://community.asterisk.org/u/jcolp)\
**Post date:** [February 18, 2019, 11:30pm UTC](https://community.asterisk.org/t/modifying-transcoding-in-asterisk/78579/12 "2019-02-18T23:30:10Z")

</div>

The codec\_opus module only supports a 48kHz output and input.

---

<div class="post-metadata">

**Author:** ![vubtrong](https://avatars.discourse-cdn.com/v4/letter/v/8491ac/32.png) [@vubtrong](https://community.asterisk.org/u/vubtrong)\
**Post date:** [February 18, 2019, 11:54pm UTC](https://community.asterisk.org/t/modifying-transcoding-in-asterisk/78579/13 "2019-02-18T23:54:26Z")

</div>

Thank you for your help David! 😀

---

<div class="post-metadata">

**Author:** ![vubtrong](https://avatars.discourse-cdn.com/v4/letter/v/8491ac/32.png) [@vubtrong](https://community.asterisk.org/u/vubtrong)\
**Post date:** [February 18, 2019, 11:57pm UTC](https://community.asterisk.org/t/modifying-transcoding-in-asterisk/78579/14 "2019-02-18T23:57:12Z")

</div>

Thank you jcolp! 😀
