anxdpanic / plugin.video.youtube

Watch your favorite YouTube content on Kodi
https://ytaddon.panicked.xyz/forum
679 stars 111 forks source link

Add codec priority #833

Closed CasperMcFadden95 closed 2 months ago

CasperMcFadden95 commented 2 months ago

What Problem Does This Solve?

VP9 YouTube videos look better than h264 despite the lower bitrate. When watching a 1080p video or lower. It seems that this addon will either pick the vp9 or h264 video randomly. It would be nice to pick the best codec too if supported


Suggest a Solution (optional)

Autopick best video using AV1 (if supported) then VP9 (if supported) then h264 waterfall logic. I know "Enable H264 video" can be disabled in settings but videos won't always have a vp9 or av1 version and the video won't play.


Thanks for your hard work on this add-on.

MoojMidge commented 2 months ago

It seems that this addon will either pick the vp9 or h264 video randomly.

InputStream.Adaptive picks the streams based on the bandwidth and resolution rules that are configured in its settings, but this often results in a poorer quality stream being selected simply because it has a slightly higher bitrate.

Autopick best video using AV1 (if supported) then VP9 (if supported) then h264 waterfall logic.

This is already done in the plugin to overcome the limitation of just choosing the stream with the higher bitrate, however simply choosing the codec based on priority/preference will also result in poorer quality streams being selected, when better quality ones are available.

Instead, the comparative bitrate is assessed:

https://github.com/anxdpanic/plugin.video.youtube/blob/4ef1fc4c8cd044ae6c761bf3e37c2c8f9d011b2e/resources/lib/youtube_plugin/youtube/helper/video_info.py#L643

The bitrate of a H264 stream needs to be double the bitrate of an AV1 stream and 50% greater than a VP9 stream to be selected.

It is a fairly arbitrary qualitative distinction, but it was roughly based on the results of a number of video codec benchmarks that I could find published on the internet.

However those benchmarks results reflect the state of the encoders at the time the tests were done, and may not be valid for the encoding parameters used by YouTube, the encoding infrastructure in use, and will not be valid for all types of videos.

Regardless, it generally seems to work well. Do you have any examples where this doesn't end up choosing the best available stream?

I know "Enable H264 video" can be disabled in settings but videos won't always have a vp9 or av1 version and the video won't play.

Do you have an example link you can share?

CasperMcFadden95 commented 2 months ago

Thanks a lot @MoojMidge for your response. I've disabled h264 and so far so good. From my experience, vp9 always looks nicer than h264.

I know "Enable H264 video" can be disabled in settings but videos won't always have a vp9 or av1 version and the video won't play.

Do you have an example link you can share?

When a video has just been uploaded it may only have a h264 variant as the vp9 variant is still being encoded. AV1 variants seems to only be available for popular videos.

MoojMidge commented 2 months ago

I think there was a bug with setting the comparative bitrate for VP9 streams.

Can you check if better quality VP9 streams are correctly selected even when h264 streams are re-enabled in v7.0.9+beta.5?