Friday, September 28, 2018

How does the YouTube android app select video codec?

Leave a Comment

I have enabled stats for nerds option in YouTube android app and played the same video in "Vivo V9" and "Nexus 5" device.

Vivo V9 : It played the video in WebM format which is basically "VP8 or VP9" codec.

Nexus 5 : It played the video in MP4 format which is basically "H264 or H265" codec.

So, based on the device YouTube app selects video codec.

Question : How does it do ? I know internally it uses ExoPlayer for playing video but ExoPlayer by default doesn't give functionality.

1 Answers

Answers 1

Different codecs may require different licences, which can cost much. Moreover codecs can be both software and hardware. There is no problem with many SW codecs but as name states HW codecs require specific chip which also increases cost and occupy space. That's why there is big variety between device manufactures and even between two devices from the same manufacturer. They just simply want to cut costs.

It's very common that one device has only a subset of most popular codecs and even if it has let's say both VP8 and H264 then one of them can be HW codec while other can be SW codec in which case usually HW codec will be preferred. YouTube (here I mean youtube.com not YouTube app) serves videos in different formats, so the device can choose optimal codec for it's capabilities.

Now as to choosing the right codec YouTube app can use MediaCodec API from Android. Please check e.g. this and / or it even can provide it's own SW codecs, so I would say that the behavior is platform dependent.

Last things are corner cases e.g. something can be played / recorded in background e.g. camera is turned on and screen recording happens while using YouTube app. Again it depends on device but HW codecs have limitations to the number of media codec instances and in such corner case it's possible that even if device has some HW codec YouTube app may be forced to choosing SW codec.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment