snapcrafters / obs-studio

This is a community-supported modified build of OBS Studio.
https://snapcraft.io/obs-studio
118 stars 35 forks source link

[Bug]: Unable to open RTSP-stream via gstreamer #188

Open fpostema opened 7 months ago

fpostema commented 7 months ago

What happened?

I really like OBS-Studio. Very professional software! I have a NDI-camera that is working perfectly. But I have some problems with an IP-camera. I'm trying to display a RTSP-stream from a webcam with low latency. I use the gstreamer plugin, because the "Media Source" is working but results in large latency. When I use gstreamer from the command-line gst-launch-1.0 rtspsrc location="rtsp://admin:1234@192.168.1.150/live/0/h264.sdp" latency=0 buffer-mode=auto ! decodebin ! autovideosink it works perfectly. Almost no latency. When I try the same with the gstreamer-plugin inside OBS Studio, I use the following pipeline: rtspsrc location="rtsp://admin:1234@192.168.1.150/live/0/h264.sdp" latency=0 buffer-mode=auto ! decodebin ! video. But that doesn't work. The stream is not displayed. I also tried the pipeline uridecodebin uri=rtsp://admin:1234@192.168.1.150/live/0/h264.sdp ! decodebin ! video. but that also didn't work. I have activated all permissions in "Ubuntu Software"

What should have happened?

The stream should be displayed with almost no latency

Output of snap info $snap_name

name:      obs-studio
summary:   Free and open source software for live streaming and screen recording
publisher: Snapcrafters✪
store-url: https://snapcraft.io/obs-studio
license:   GPL-2.0
description: |
  OBS Studio is software designed for capturing, compositing, encoding, recording, and streaming
  video content, efficiently.

  **NOTE: This is a community-supported modified build of OBS Studio; please file issues on the
  Snapcrafters GitHub:  https://github.com/snapcrafters/obs-studio/issues**

  **Batteries included**

  The snap of OBS studio comes pre-loaded with some extra features:

    * Supports **nvenc (NVIDIA) and VA-API (AMD & Intel) accelerated video encoding**.
    * **Advanced Scene Switcher** plugin; an automated scene switcher
    * **Browser** plugin; CEF-based OBS Studio browser plugin
    * **Directory Watch Media** plugin; filter you can add to a media source to load the oldest or
    newest file in a directory.
    * **Dynamic Delay** plugin; filter for dynamic delaying a video source.
    * **Freeze Filter** plugin; freeze a source using a filter.
    * **GStreamer** plugins; feed GStreamer launch pipelines into OBS Studio and use GStreamer
    encoder elements.
    * **Move Transition** plugin; move sources to a new position during a scene transition.
    * **NDI** plugin; Network A/V via NewTek's NDI.
    * **RGB Levels** plugin; simple filter to adjust RGB levels.
    * **Source Switcher** plugin; to switch between a list of sources.
    * **StreamFX** plugin; collection modern effects filters and transitions.
    * **Text Pango** plugin; Provides a text source rendered using Pango with multi-language
    support, emoji support, vertical rendering and RTL support.
    * **Transition Matrix** plugin; customize Any -> One or One -> One scene transitions.
    * **Waveform** plugin; audio visualization using fftw.
    * **Websockets** plugin; remote-control OBS Studio through WebSockets.

  **Connecting Interfaces**

  For the best experience, you'll want to connect the following interfaces.

     sudo snap connect obs-studio:alsa
     sudo snap connect obs-studio:audio-record
     sudo snap connect obs-studio:avahi-control
     sudo snap connect obs-studio:camera
     sudo snap connect obs-studio:jack1
     sudo snap connect obs-studio:kernel-module-observe

  **NDI**

  If you want to use the NDI plugin you'll need to connect the Avahi Control interface.

     snap connect obs-studio:avahi-control

  **Virtual Camera**

  Starting with OBS 26.1.0, Virtual Camera support is integrated. Here's how to install and
  configure `v4l2loopback`:

     sudo snap connect obs-studio:kernel-module-observe
     sudo apt -y install v4l2loopback-dkms v4l2loopback-utils
     echo "options v4l2loopback devices=1 video_nr=13 card_label='OBS Virtual Camera'   
     exclusive_caps=1" | sudo tee /etc/modprobe.d/v4l2loopback.conf
     echo "v4l2loopback" | sudo tee /etc/modules-load.d/v4l2loopback.conf
     sudo modprobe -r v4l2loopback
     sudo modprobe v4l2loopback devices=1 video_nr=13 card_label='OBS Virtual Camera'
     exclusive_caps=1

  **NOTE!** Using `video_nr` greater than 64 will not work.

  **Removable Storage**

  To access content on external storage, connect to the removable-media plug:

     snap connect obs-studio:removable-media

  **3rd Party plugins**

  To install pre-compiled plugins, download and extract the plugin to
  `~/snap/obs-studio/current/.config/obs-studio/plugins/`.

  This is how the Input Overlay plugin looks when correctly installed:

     /home/username/snap/obs-studio/current/.config/obs-studio/plugins/
     └── input-overlay
         ├── bin
         │   └── 64bit
         │       └── input-overlay.so
         └── data
             └── locale
                 ├── de-DE.ini
                 ├── en-US.ini
                 └── ru-RU.ini

  If you want to use the Input Overlay plugin, you'll also need to connect the joystick interface:

     snap connect obs-studio:joystick

  **NOTE: This is a community-supported modified build of OBS Studio; please file issues on the
  Snapcrafters GitHub:  https://github.com/snapcrafters/obs-studio/issues**
commands:
  - obs-studio
snap-id:      6uLU2MJmBURfLNz4rmL4WT2CmtVULE2u
tracking:     latest/stable
refresh-date: yesterday at 16:04 CET
channels:
  latest/stable:    30.0.0 2023-11-25 (1294) 599MB -
  latest/candidate: 29.1.3 2023-10-18 (1291) 423MB -
  latest/beta:      ↑                              
  latest/edge:      30.0.0 2023-12-22 (1296) 606MB -
installed:          30.0.0            (1294) 599MB -

Output of snap connections $snap_name

Interface                 Plug                                 Slot                            Notes
alsa                      obs-studio:alsa                      :alsa                           manual
audio-playback            obs-studio:audio-playback            :audio-playback                 -
audio-record              obs-studio:audio-record              :audio-record                   -
avahi-control             obs-studio:avahi-control             :avahi-control                  manual
browser-support           obs-studio:browser-support           :browser-support                -
camera                    obs-studio:camera                    :camera                         -
content[gnome-42-2204]    obs-studio:gnome-42-2204             gnome-42-2204:gnome-42-2204     -
content[gtk-3-themes]     obs-studio:gtk-3-themes              gtk-common-themes:gtk-3-themes  -
content[icon-themes]      obs-studio:icon-themes               gtk-common-themes:icon-themes   -
content[sound-themes]     obs-studio:sound-themes              gtk-common-themes:sound-themes  -
desktop                   obs-studio:desktop                   :desktop                        -
desktop-legacy            obs-studio:desktop-legacy            :desktop-legacy                 -
gsettings                 obs-studio:gsettings                 :gsettings                      -
hardware-observe          obs-studio:hardware-observe          :hardware-observe               manual
home                      obs-studio:home                      :home                           -
jack1                     obs-studio:jack1                     :jack1                          manual
joystick                  obs-studio:joystick                  :joystick                       manual
kernel-module-observe     obs-studio:kernel-module-observe     :kernel-module-observe          manual
network                   obs-studio:network                   :network                        -
network-bind              obs-studio:network-bind              :network-bind                   -
opengl                    obs-studio:opengl                    :opengl                         -
password-manager-service  obs-studio:password-manager-service  :password-manager-service       manual
process-control           obs-studio:process-control           :process-control                manual
pulseaudio                obs-studio:pulseaudio                :pulseaudio                     -
raw-usb                   obs-studio:raw-usb                   :raw-usb                        manual
removable-media           obs-studio:removable-media           :removable-media                manual
screen-inhibit-control    obs-studio:screen-inhibit-control    :screen-inhibit-control         -
screencast-legacy         obs-studio:screencast-legacy         :screencast-legacy              manual
system-observe            obs-studio:system-observe            :system-observe                 manual
unity7                    obs-studio:unity7                    :unity7                         -
upower-observe            obs-studio:upower-observe            :upower-observe                 -
wayland                   obs-studio:wayland                   :wayland                        -
x11                       obs-studio:x11                       :x11                            -

Output of snap version

snap    2.61.1
snapd   2.61.1
series  16
ubuntu  22.04
kernel  6.2.0-1016-lowlatency

Relevant log output

[  382.491168] audit: type=1400 audit(1708095653.746:70): apparmor="DENIED" operation="bind" class="net" profile="snap.obs-studio.obs-studio" pid=4514 comm="obs" family="unix" sock_type="dgram" protocol=0 requested_mask="bind" denied_mask="bind" addr="@2F636F6D2F6F627370726F6A65637420343531342033302E302E3020286C696E757829000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
[  383.583698] audit: type=1400 audit(1708095654.839:71): apparmor="DENIED" operation="bind" class="net" profile="snap.obs-studio.obs-studio" pid=4514 comm="obs" family="unix" sock_type="stream" protocol=0 requested_mask="bind" denied_mask="bind" addr="@/com/obsproject/vkcapture"
[  385.208548] audit: type=1400 audit(1708095656.464:72): apparmor="DENIED" operation="open" class="file" profile="snap.obs-studio.obs-studio" name="/sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service/app.slice/snap.obs-studio.obs-studio-4cec3178-71e8-46db-bda2-1194b8a4ca30.scope/memory.max" pid=4514 comm="ndir:reconn" requested_mask="r" denied_mask="r" fsuid=1000 ouid=1000

Teminal output of app

0:00:01.084975981  4514 0x7f7bac000f90 ERROR                default gstrtspconnection.c:1102:gst_rtsp_connection_connect_with_response_usec: failed to connect: GDBus.Error:org.freedesktop.portal.Error.NotAllowed: This call is not available inside the sandbox
0:00:01.085218307  4514 0x7f7bac000f90 ERROR                rtspsrc gstrtspsrc.c:5238:gst_rtsp_conninfo_connect:<rtspsrc0> Could not connect to server. (Generic error)
0:00:01.085509119  4514 0x7f7bac000f90 WARN                 rtspsrc gstrtspsrc.c:8130:gst_rtspsrc_retrieve_sdp:<rtspsrc0> error: Failed to connect. (Generic error)
0:00:01.085949998  4514 0x7f7bac000f90 WARN                 rtspsrc gstrtspsrc.c:8216:gst_rtspsrc_open:<rtspsrc0> can't get sdp
0:00:01.086307678  4514 0x7f7bac000f90 WARN                 rtspsrc gstrtspsrc.c:8877:gst_rtspsrc_play:<rtspsrc0> failed to open stream
0:00:01.086672327  4514 0x7f7bac000f90 WARN                 rtspsrc gstrtspsrc.c:6227:gst_rtspsrc_loop:<rtspsrc0> we are not connected
error: [obs-gstreamer] GStreamer Source: Could not open resource for reading and writing.
<...>
[tcp @ 0x7f7ab4003e00] Connection to tcp://192.168.1.150:554?timeout=30000000 failed: No route to host
warning: MP: Failed to open media: 'rtsp://admin:1234@192.168.1.150/live/0/mjpeg.sdp'
warning: [Media Source 'Media Source']: Disconnected. Reconnecting...
[tcp @ 0x7f7a940e5180] Connection to tcp://192.168.1.150:554?timeout=30000000 failed: No route to host
fpostema commented 7 months ago

Using this post I managed to switch apparmor from enforce-mode into complain-mode for snap.obs-studio.obs-studio. This removes the apparmor protection from obs-studio and removes the apparmor="DENIED" entries from the log. This is not a nice solution, but a workaround.

The remaining problem now is (Terminal output):

default gstrtspconnection.c:1102:gst_rtsp_connection_connect_with_response_usec: failed to connect: GDBus.Error:org.freedesktop.portal.Error.NotAllowed: This call is not available inside the sandbox

I have no clue how to fix this.