# Using diffrent codecs for video and screen share

**URL:** <https://mediasoup.discourse.group/t/using-diffrent-codecs-for-video-and-screen-share/679>\
**Category:** mediasoup libraries\
**Created:** [March 24, 2020, 10:15pm UTC](https://mediasoup.discourse.group/t/using-diffrent-codecs-for-video-and-screen-share/679 "2020-03-24T22:15:53Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![erlichmen](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/erlichmen/32/269_2.png) [@erlichmen](https://mediasoup.discourse.group/u/erlichmen)\
**Post date:** [March 24, 2020, 10:15pm UTC](https://mediasoup.discourse.group/t/using-diffrent-codecs-for-video-and-screen-share/679/1 "2020-03-24T22:15:53Z")

</div>

I want to send (on the same transport) webcam video using h264 (to take advantage of HW acceleration) and screen share using VP8 (since it looks better).  
I managed to “trick” chrome to use h264 as the first option (for the webcam) but what I really want is the ability to control the payloadType which will be used to encode each stream.

Is that even possible?

---

<div class="post-metadata">

**Author:** ![ibc](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/ibc/32/1540_2.png) [@ibc](https://mediasoup.discourse.group/u/ibc)\
**Post date:** [March 24, 2020, 10:27pm UTC](https://mediasoup.discourse.group/t/using-diffrent-codecs-for-video-and-screen-share/679/2 "2020-03-24T22:27:49Z")

</div>

> [@erlichmen](#):
>
> I managed to “trick” chrome to use h264 as the first option (for the webcam)

Why a trick? You don’t need to do any trick for that, just set H264 (with proper configuration) in the Router `mediaCodecs` as first codec and Chrome will use it without any trick.

> [@erlichmen](#):
>
> but what I really want is the ability to control the payloadType which will be used to encode each stream.

This is a good feature to have, but it’s not done yet (it requires lot of work in client side).

However, you can do this:

- Set both H264 and VP8 codecs in the mediasoup Router `mediaCodecs`.
- Create 2 mediasoup-client `Device` instances in your client app (one for webcam and audio, another one just for sending screen sharing).
- In the first one, before calling `device1.load({ routerRtpCapabilities })`, mangle the Router `rtpCapabilities` and put VP8 as first video codec.
- In the second one, before calling `device2.load({ routerRtpCapabilities })`, mangle the Router `rtpCapabilities` and put H264 as first video codec.
- Then create transports, etc.

---

<div class="post-metadata">

**Author:** ![erlichmen](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/erlichmen/32/269_2.png) [@erlichmen](https://mediasoup.discourse.group/u/erlichmen)\
**Post date:** [March 25, 2020, 8:09am UTC](https://mediasoup.discourse.group/t/using-diffrent-codecs-for-video-and-screen-share/679/3 "2020-03-25T08:09:10Z")

</div>

The problem with two devices is that currently we have (mediasoup) device=user model, extending that a user can have multiple devices will required a lot of refactoring.

If you point me in the right direction I don’t mind publishing a PR to support that.

---

<div class="post-metadata">

**Author:** ![ibc](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/ibc/32/1540_2.png) [@ibc](https://mediasoup.discourse.group/u/ibc)\
**Post date:** [March 25, 2020, 8:29am UTC](https://mediasoup.discourse.group/t/using-diffrent-codecs-for-video-and-screen-share/679/4 "2020-03-25T08:29:11Z")

</div>

Adding the ability to select a codec for each Producer in the same sendTransport would also require a huge refactor in mediasoup-client. IMHO more than a refactor in your app for each user to hold two devices.

> [@erlichmen](#):
>
> If you point me in the right direction I don’t mind publishing a PR to support that.

This is complex and I cannot give any guidance due to its complexity. This is a good to have feature but we need time to do it.

---

<div class="post-metadata">

**Author:** ![ibc](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/ibc/32/1540_2.png) [@ibc](https://mediasoup.discourse.group/u/ibc)\
**Post date:** [March 25, 2020, 10:19pm UTC](https://mediasoup.discourse.group/t/using-diffrent-codecs-for-video-and-screen-share/679/5 "2020-03-25T22:19:45Z")

</div>

> [@mediasoup-client 3.6.0 released with per Producer codec selection](https://mediasoup.discourse.group/t/mediasoup-client-3-6-0-released-with-per-producer-codec-selection/686):
>
> mediasoup-client 3.6.0 has been released. It comes with the ability to choose a desired codec per Producer. Sometimes it’s useful to use, for instance, H264 for webcam and VP8 for screen sharing. This is now possible. More info: [https://mediasoup.org/documentation/v3/tricks/#using-a-different-video-codec-in-each-producer](https://mediasoup.org/documentation/v3/tricks/#using-a-different-video-codec-in-each-producer)

[Donations](https://mediasoup.org/sponsors/#become-a-sponsor) are welcome 😉

---

<div class="post-metadata">

**Author:** ![erlichmen](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/erlichmen/32/269_2.png) [@erlichmen](https://mediasoup.discourse.group/u/erlichmen)\
**Post date:** [March 26, 2020, 7:52am UTC](https://mediasoup.discourse.group/t/using-diffrent-codecs-for-video-and-screen-share/679/6 "2020-03-26T07:52:07Z")

</div>

Even if I spend every second of the day I wouldn’t have made the change you suggested to my application 🙂

Good feature! passing the donation link to finance (It’s a big corp so it will take some time)

---

<div class="post-metadata">

**Author:** ![ibc](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/ibc/32/1540_2.png) [@ibc](https://mediasoup.discourse.group/u/ibc)\
**Post date:** [March 26, 2020, 10:26am UTC](https://mediasoup.discourse.group/t/using-diffrent-codecs-for-video-and-screen-share/679/7 "2020-03-26T10:26:23Z")

</div>

Great 🙂

Please remember using the feature with mediasoup-client 3.6.2 (a bug was fixed yesteday). I’m using it right now and it works fine.
