[vlc-devel] [PATCH] [RFC] youtube.lua: read more available formats from the webpage

Steve Lhomme robux4 at ycbcr.xyz
Tue Sep 29 11:34:07 CEST 2020


It seems that "formats" is only providing 2 basic versions of the video in H264
in my tests: 720p and 360p
(https://www.youtube.com/watch?v=ISJMsVhY5Yk or https://www.youtube.com/watch?v=ISJMsVhY5Yk)
See https://pastebin.com/dL8R4Hqp

"adaptiveFormats" provide a lot more formats, including 8K AV1 ones.
That may cause some problems as the hardware may not be able to decode such
streams. We're probably missing some more refinements to select the best
resolution/bitrate that the hardware can handle. I would assume that's
something adaptive streaming is best suited to take care of. So maybe the
Youtube script should return an adaptive manifest and let the adaptive code
take care of it ? Is that even possible ?

To do that properly we may also have a list of codec profiles that the current
hardware (GPU) is capable of, probably in the form of a list of MIME types
similar to the ones used in adaptive streaming.

For now we may stick to H264 for wider compatibility but at least we should try
to get the highest resolution when possible. In the example above there's a
1080p version in H264.

The extra streams are video or audio only anyway. So they are not suitable on
their own. They would need to be combined just like in adaptive streaming.
---
 share/lua/playlist/youtube.lua | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/share/lua/playlist/youtube.lua b/share/lua/playlist/youtube.lua
index 32b6972370e..9d2ed376889 100644
--- a/share/lua/playlist/youtube.lua
+++ b/share/lua/playlist/youtube.lua
@@ -409,6 +409,17 @@ function parse()
                 end
 
                 -- New-style parameters
+                if not path then
+                    local adaptive_formats = string.match( line, '\\"adaptiveFormats\\":%[(.-)%]' )
+                    if adaptive_formats then
+                        vlc.msg.dbg( "Found new-style parameters for youtube adaptive video stream, parsing..." )
+                        -- FIXME: do this properly (see #24958)
+                        adaptive_formats = string.gsub( adaptive_formats, '\\(["\\/])', '%1' )
+                        adaptive_formats = string.gsub( adaptive_formats, "\\u0026", "&" )
+                        path = pick_stream( adaptive_formats, js_url )
+                    end
+                end
+
                 if not path then
                     local stream_map = string.match( line, '\\"formats\\":%[(.-)%]' )
                     if stream_map then
-- 
2.26.2



More information about the vlc-devel mailing list