Youtube stream for deepstream with python

• GeForce GTX 1660 Ti Mobile
• DeepStream 6.1
• Ubuntu 20.04
• GStreamer 1.16.2
• NVIDIA driver 510.47.03
• CUDA 11.6 Update 1

Can I get a youtube stream as input stream for deepstream? Are there any examples for python?

There is no youtube related example in deepstream.
Can you get the URL of the stream? Which codec does it use?

I want to parse this link

I can watch in terminal with gst by:

gst-launch-1.0 souphttpsrc is-live=true location="$(yt-dlp --get-url https://www.youtube.com/watch?v=RoVIM4BYbZ8)" ! decodebin ! videoconvert ! nvvideoconvert ! 'video/x-raw', format=NV12 ! nveglglessink

But when I add it like source, I have an error.
Code:

 def create_source_bin(self, index, uri):
        
        bin_name = "source-bin-%02d" % index
        print(bin_name)
        nbin = Gst.Bin.new(bin_name)
        if not nbin:
            sys.stderr.write(" Unable to create source bin \n")

        uri_decode_bin = Gst.ElementFactory.make("souphttpsrc", "souphttpsrc_0")
        if not uri_decode_bin:
            sys.stderr.write(" Unable to create uri decode bin \n")

        loc_str = '$(yt-dlp --get-url https://www.youtube.com/watch?v=RoVIM4BYbZ8)'
        uri_decode_bin.set_property('location', loc_str)
       
        Gst.Bin.add(nbin, uri_decode_bin)
        bin_pad = nbin.add_pad(Gst.GhostPad.new_no_target("src", Gst.PadDirection.SRC))
        if not bin_pad:
            sys.stderr.write(" Failed to add ghost pad in source bin \n")
            return None
        return nbin

Error:

(python3:33662): GStreamer-CRITICAL **: 16:36:58.899: gst_query_set_uri: assertion 'gst_uri_is_valid (uri)' failed
Error: gst-resource-error-quark: Error parsing URL. (5): gstsouphttpsrc.c(1463): gst_soup_http_src_build_message (): /GstPipeline:pipeline0/GstBin:source-bin-00/GstSoupHTTPSrc:souphttpsrc_0:
URL: $(yt-dlp --get-url https://www.youtube.com/watch?v=RoVIM4BYbZ8)
Exiting app

I can get url with bash:

echo $(yt-dlp --get-url https://www.youtube.com/watch?v=RoVIM4BYbZ8)
https://manifest.googlevideo.com/api/manifest/hls_playlist/expire/1672256307/ei/00asY4PxKMfR7gSf5pbYAQ/ip/85.234.35.135/id/RoVIM4BYbZ8.2/itag/96/source/yt_live_broadcast/requiressl/yes/ratebypass/yes/live/1/sgoap/gir%3Dyes%3Bitag%3D140/sgovp/gir%3Dyes%3Bitag%3D137/hls_chunk_host/rr8---sn-jvhnu5g-045e.googlevideo.com/playlist_duration/30/manifest_duration/30/spc/zIddbI3dgrlW-FqeIFYG6dPJygHQ0uo/vprv/1/playlist_type/DVR/initcwndbps/1783750/mh/1c/mm/44/mn/sn-jvhnu5g-045e/ms/lva/mv/m/mvi/8/pl/24/dover/11/pacing/0/keepalive/yes/fexp/24001373,24007246/mt/1672234364/sparams/expire,ei,ip,id,itag,source,requiressl,ratebypass,live,sgoap,sgovp,playlist_duration,manifest_duration,spc,vprv,playlist_type/sig/AOq0QJ8wRAIga0CxE7ffvCH6quvPcfbdCtmoBcnOF7Ooqa1llUcYCxQCIB6V4859D43XiO_fbFuqzF5lX9cYwddS3jOY1zKNnknY/lsparams/hls_chunk_host,initcwndbps,mh,mm,mn,ms,mv,mvi,pl/lsig/AG3C_xAwRAIgC5vX6MdaPbDIYL3NutWIiUpov4Qb9a-udG3M8gkhLycCICOjwYuqp22I_JXdwFPHLzTyB6Nlm5qL1dqe2puEkTdc/playlist/index.m3u8

When I paste this url to python function, that discribed higher, I have this:

Error: gst-stream-error-quark: Internal data stream error. (1): gstbasesrc.c(3072): gst_base_src_loop (): /GstPipeline:pipeline0/GstBin:source-bin-00/GstSoupHTTPSrc:souphttpsrc_0:
streaming stopped, reason not-linked (-1)
Exiting app

You may try instead:

import subprocess
loc_str = subprocess.check_output(['/usr/bin/yt-dlp', '--get-url', 'https://www.youtube.com/watch?v=RoVIM4BYbZ8'])

This is a good way to get the URL. But I have the same error.
My function:

    def create_source_bin(self, index, uri):

        bin_name = "source-bin-%02d" % index
        print(bin_name)
        nbin = Gst.Bin.new(bin_name)
        if not nbin:
            sys.stderr.write(" Unable to create source bin \n")

        uri_decode_bin = Gst.ElementFactory.make("souphttpsrc", "souphttpsrc_0")
        if not uri_decode_bin:
            sys.stderr.write(" Unable to create uri decode bin \n")

        loc_str = subprocess.check_output(
            ['yt-dlp', '--get-url', 'https://www.youtube.com/watch?v=RoVIM4BYbZ8'])
        uri_decode_bin.set_property('location', loc_str.decode("utf-8"))

        Gst.Bin.add(nbin, uri_decode_bin)
        bin_pad = nbin.add_pad(Gst.GhostPad.new_no_target("src", Gst.PadDirection.SRC))
        if not bin_pad:
            sys.stderr.write(" Failed to add ghost pad in source bin \n")
            return None
        return nbin

Error:

Error: gst-stream-error-quark: Internal data stream error. (1): gstbasesrc.c(3072): gst_base_src_loop (): /GstPipeline:pipeline0/GstBin:source-bin-00/GstSoupHTTPSrc:souphttpsrc_0:
streaming stopped, reason not-linked (-1)
Exiting app

If i don’t decode:

loc_str = subprocess.check_output(
            ['yt-dlp', '--get-url', 'https://www.youtube.com/watch?v=RoVIM4BYbZ8'])
        uri_decode_bin.set_property('location', loc_str)

My error:

(python3:136672): GStreamer-CRITICAL **: 09:59:48.879: gst_query_set_uri: assertion 'gst_uri_is_valid (uri)' failed
Error: gst-resource-error-quark: Error parsing URL. (5): gstsouphttpsrc.c(1463): gst_soup_http_src_build_message (): /GstPipeline:pipeline0/GstBin:source-bin-00/GstSoupHTTPSrc:souphttpsrc_0:
URL: b'https://manifest.googlevideo.com/api/manifest/hls_playlist/expire/1672318786/ei/4jqtY4WsA4rO7gSs0r3ACw/ip/85.234.35.135/id/RoVIM4BYbZ8.2/itag/96/source/yt_live_broadcast/requiressl/yes/ratebypass/yes/live/1/sgoap/gir%3Dyes%3Bitag%3D140/sgovp/gir%3Dyes%3Bitag%3D137/hls_chunk_host/rr2---sn-gvnuxaxjvh-2x1e.googlevideo.com/playlist_duration/30/manifest_duration/30/spc/zIddbFS7gk57NK-UWiPJED93DCZXcz8/vprv/1/playlist_type/DVR/initcwndbps/1855000/mh/1c/mip/85.237.57.85/mm/44/mn/sn-gvnuxaxjvh-2x1e/ms/lva/mv/m/mvi/2/pl/24/dover/11/pacing/0/keepalive/yes/fexp/24001373,24007246/mt/1672296752/sparams/expire,ei,ip,id,itag,source,requiressl,ratebypass,live,sgoap,sgovp,playlist_duration,manifest_duration,spc,vprv,playlist_type/sig/AOq0QJ8wRgIhANEACsphTt7TQwUFYNt6L36mFzTiVjcnjsDMigVVKTpJAiEAnT7_rPS5iOSEDgN2bnbkbC-NOXKARhYADdBrbMvMHtE%3D/lsparams/hls_chunk_host,initcwndbps,mh,mip,mm,mn,ms,mv,mvi,pl/lsig/AG3C_xAwRAIgWv-R5RHQiCFD8Eo9BwuBUax_Cz1tIiBi9Wk_ZWHUhVICIBZgEbUsaznXylg636rmK6bw89VQL_Hc79QVjpm3rg5N/playlist/index.m3u8\n'
Exiting app

If i am using

loc_str = subprocess.check_output(['youtube-dl', '--get-url', 'https://www.youtube.com/watch?v=RoVIM4BYbZ8'])

I have the same error

Please google the usage of souphttpsrc by yourself. souphttpsrc (gstreamer.freedesktop.org)

It is not a DeepStream issue.

Try using uridecodebin instead of soupĥttpsrc + decodebin:

uri_decode_bin = Gst.ElementFactory.make("uridecodebin", "uridecodebin_0")
...
uri_decode_bin.set_property('uri', loc_str.decode("utf-8"))

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.