# How to Switch video codec(vp9/vp8/h264) on the fly

**URL:** <https://mediasoup.discourse.group/t/how-to-switch-video-codec-vp9-vp8-h264-on-the-fly/5414>\
**Category:** mediasoup libraries\
**Created:** [August 9, 2023, 2:51pm UTC](https://mediasoup.discourse.group/t/how-to-switch-video-codec-vp9-vp8-h264-on-the-fly/5414 "2023-08-09T14:51:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![John](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@John](https://mediasoup.discourse.group/u/John)\
**Post date:** [August 9, 2023, 2:51pm UTC](https://mediasoup.discourse.group/t/how-to-switch-video-codec-vp9-vp8-h264-on-the-fly/5414/1 "2023-08-09T14:51:50Z")

</div>

I’m looking to implement real-time codec switching based on the user’s browser. My goal is to use the VP9 codec when a Chrome user initiates a call. However, if a Mozilla or Safari user joins the call, I intend to seamlessly transition the codec for Chrome participants to VP8. I’m curious if this is achievable using mediasoup and, if so, how I could go about 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:** [August 9, 2023, 3:49pm UTC](https://mediasoup.discourse.group/t/how-to-switch-video-codec-vp9-vp8-h264-on-the-fly/5414/2 "2023-08-09T15:49:13Z")

</div>

You close the Producer in client and server and then create another one specifying the desired codec.

---

<div class="post-metadata">

**Author:** ![John](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@John](https://mediasoup.discourse.group/u/John)\
**Post date:** [August 9, 2023, 5:06pm UTC](https://mediasoup.discourse.group/t/how-to-switch-video-codec-vp9-vp8-h264-on-the-fly/5414/3 "2023-08-09T17:06:53Z")

</div>

Thanks for the reply.  
Introducing a new producer could potentially lead to a slight degradation in the user experience, resulting in moments of a black stream lasting mere milliseconds.

---

<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:** [August 9, 2023, 6:09pm UTC](https://mediasoup.discourse.group/t/how-to-switch-video-codec-vp9-vp8-h264-on-the-fly/5414/4 "2023-08-09T18:09:51Z")

</div>

Unless you do a magic transition by not removing the former until the latter is ready.

Anyway, there is no way in WebRTC to dynamically change the codec in an ongoing stream.

---

<div class="post-metadata">

**Author:** ![copiltembel](https://avatars.discourse-cdn.com/v4/letter/c/e9a140/32.png) [@copiltembel](https://mediasoup.discourse.group/u/copiltembel)\
**Post date:** [August 9, 2023, 7:31pm UTC](https://mediasoup.discourse.group/t/how-to-switch-video-codec-vp9-vp8-h264-on-the-fly/5414/5 "2023-08-09T19:31:39Z")

</div>

A more “traditional” way that has been discussed on this forum and elsewhere is to have a re-encoder, possibly running close to the sfu. That way you don’t need to switch the producer’s codec, just re-encode into whatever you think it’s best for the consumer. See also [mediasoup :: Scalability](https://mediasoup.org/documentation/v3/scalability/)

---

<div class="post-metadata">

**Author:** ![John](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@John](https://mediasoup.discourse.group/u/John)\
**Post date:** [August 18, 2023, 2:30pm UTC](https://mediasoup.discourse.group/t/how-to-switch-video-codec-vp9-vp8-h264-on-the-fly/5414/6 "2023-08-18T14:30:05Z")

</div>

Hi @ibc,  
Is it possible to munging SDP within MediaSoup itself to switch codecs?
