【问题标题】:gstreamer uri vs files: Cannot play local video filegstreamer uri vs文件:无法播放本地视频文件
【发布时间】:2019-01-14 13:17:02
【问题描述】:

我是 gstreamer 的新手,并试图在我的基于 NVIDIA Jetson ARM 的板上使用它进行一些 GPU 加速视频解码。我在网上找到了一些创建 gstreamer 管道的 python 代码,我试图用它来熟悉自己。创建管道的代码如下:

def new_pipeline(self, mediauri):

    pipeline = Gst.Pipeline()

    if (not pipeline):
        print ('Failed to create pipeline')
        exit (-1)

    # Create bus to get events from GStreamer pipeline
    bus = pipeline.get_bus()
    self.bus.append(bus)
    bus.add_signal_watch()
    bus.connect('message::error', self.on_error)

    # This is needed to make the video output in our DrawingArea:
    bus.enable_sync_message_emission()
    bus.connect('sync-message::element', self.on_sync_message)

    # Create GStreamer elements
    decodebin = Gst.ElementFactory.make('uridecodebin', 'decodebin')
    videosink = Gst.ElementFactory.make('nveglglessink', 'videosink')

    if (not decodebin or not videosink):
        print ('Failed to create uridecodebin and/or nveglglessink')
        exit(-1)

    # Set properties
    decodebin.set_property('uri', mediauri)
    videosink.set_property('create-window', False)

    # Add elements to the pipeline
    pipeline.add(decodebin)
    pipeline.add(videosink)

    decodebin.connect("pad-added", self.decodebin_pad_added)

    return pipeline

完整的项目可以在这里找到 (https://github.com/kulve/gst-multiwindow)

现在,每当我尝试从本地文件创建管道时,都会出现错误:

on_error(): (GError('Invalid URI "testfile.avi".',), 'gsturidecodebin.c(1373): gen_source_element (): /GstPipeline:pipeline0/GstURIDecodeBin:decodebin')

我感觉这个错误是因为本地文件不是有效的 uri。我尝试将其作为file://testfile.avi 传递,但这也不起作用,返回could not open resource for reading 错误。

此代码是否有可能帮助我播放本地视频文件的更改?

【问题讨论】:

    标签: python gstreamer


    【解决方案1】:

    要播放的文件/URI 应通过“uri”属性设置。这必须是绝对 URI,不允许使用相对文件路径。

    例如:

    文件.avi在/home/user/Downloads,那么:

    uri=file:///home/user/Downloads/file.avi

    【讨论】:

      【解决方案2】:

      URI 必须以 URI Tag 开头,如 http、tcp、rtsp、file。 然后 : 和资源的最后位置。

      For Ex : for file /home/Desktop/a.avi
                   URI : file:/home/Desktop/a.avi
            For RTSP,
        URI : rtsp://<IP>:<PORT>/<PATH>
                 ex: rtsp://192.168.1.1/test
      

      【讨论】:

        【解决方案3】:

        您只提供文件名作为输入。 URI 属性将标准 URI 作为输入。此外,uridecodebin 不支持仅相对 URI。正确的 URI 是这样的:

        file://localhost/absolute/path/to/file
        

        或者如果您想删除主机名(注意附加的斜杠):

        file:///absolute/path/to/file
        

        一些解析器足够智能,也可以解析相对路径(uridecodebin 不支持这一点)。在您的情况下,它可以被指定为:

        file:./testfile.avi
        

        有关File URI scheme的更多详细信息。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2013-08-02
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多