Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does the YouTube android app select video codec?

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.

like image 776
Manish Patwari Avatar asked Sep 18 '18 20:09

Manish Patwari


People also ask

What codec does YouTube uses?

YouTube encodes all videos with the VP9 codec, but for some reason displays H. 264 for low view count videos. YouTube deploys the AV1 codec at much, much lower view counts than reported below.

What is Android video codec?

mp4, which is a popular video format for Android, there are video codecs for Android and audio codecs for Android. Usually, the job of a codec is to compress a set of data (video or audio) for storage and later decompress it for playback or viewing. Codecs are different from containers and file formats.

What is the best video codec for Android?

Hands down, the best video format for Android in 2022 is MP4. Almost all Android phones can play MP4 videos in their native video player. However, the default player also supports many other formats.

How do I fix codec not supported on Android?

Quick solution. The easiest way to fix not supported audio or video codec error on Android is using the VLC Media Player app. VLC comes with extended codecs to play files such as MKV, MOV, WMV, etc. However, other ways exist to play the video in the native Android player.


1 Answers

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.

Edit: Starting from Android Q there is also new API which lets you to easily differentiate between SW and HW codecs. Take a look at this.

like image 185
LLL Avatar answered Oct 19 '22 10:10

LLL