mediamtx: Incompatibility with libcamera 0.1.0 and Raspberry Pi 5

Which version are you using?

v1.2.0

Which operating system are you using?

  • Linux amd64 standard
  • Linux amd64 Docker
  • Linux arm64 standard
  • Linux arm64 Docker
  • Linux arm7 standard
  • Linux arm7 Docker
  • Linux arm6 standard
  • Linux arm6 Docker
  • Windows amd64 standard
  • Windows amd64 Docker (WSL backend)
  • macOS amd64 standard
  • macOS amd64 Docker
  • Other (please describe)

Describe the issue

Description mediamtx fails to work after apt-get upgrade

Libcamera: v0.1.0+52-a858d20b

Describe how to replicate the issue

sudo apt-get update && sudo apt-get upgrade-y

Did you attach the server logs?

/dev/shm/rtspss-embeddedexe-1698423452247192666: error while loading shared libraries: libcamera.so.0.0: cannot open shared object file: No such file or directory

yes

Did you attach a network dump?

no

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 3
  • Comments: 33 (7 by maintainers)

Commits related to this issue

Most upvoted comments

new libcamera changes related to transform pushed to bookworm 😉

~/mediamtx/internal/protocols/rpicamera/exe $ make
g++ -Ofast -Werror -Wall -Wextra -Wno-unused-parameter -Wno-unused-result -std=c++17 $(pkg-config --cflags libcamera) -c camera.cpp -o camera.o
camera.cpp:37:18: error: ‘Transform’ has not been declared in ‘libcamera’
   37 | using libcamera::Transform;
      |                  ^~~~~~~~~

I was able to compile against libcamera 0.2.0 (part of current RasbperryPi OS, Bookworm) by removing these lines. Would it be possible to provide a compile-time switch to be able to compile against the current version rather than manually patching the code?

It there an estimate on how long mediamtx will be dependent on 0.0.5 or 0.1.0 before migrating to 0.2.0?

In 1.2.1 I had to create library links in bookworm to get it running:

/lib/aarch64-linux-gnu # :
 ln -s libcamera.so.0.1 libcamera.so.0.0
 ln -s libcamera-base.so.0.1 libcamera-base.so.0.0

@masipcat, I tried your solution

paths:
  # example:
  cam:
    runOnInit: bash -c 'libcamera-vid -t 0 --codec yuv420 --width 1280 --height 720 --inline --listen -o - | ffmpeg -f rawvideo -pix_fmt yuv420p -s:v 1280x720 -i /dev/stdin -c:v libx264 -preset ultrafast -tune zerolatency -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH'
    runOnInitRestart: yes

and it works for my Raspberry Pi 5 (Raspberry Pi OS (64-bit)). It takes up to 5 seconds to start the stream, then it streams with a subsecond delay to my laptop over wifi. It even works for two cameras.

My script with tiny improvements:

paths:
 cam1:
   runOnInit: bash -c 'rpicam-vid -t 0 --camera 0 --nopreview --codec yuv420 --width 1280 --height 720 --inline --listen -o - | ffmpeg -f rawvideo -pix_fmt yuv420p -s:v 1280x720 -i /dev/stdin -c:v libx264 -preset ultrafast -tune zerolatency -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH'
   runOnInitRestart: yes
 cam2:
   runOnInit: bash -c 'rpicam-vid -t 0 --camera 1 --nopreview --codec yuv420 --width 1280 --height 720 --inline --listen -o - | ffmpeg -f rawvideo -pix_fmt yuv420p -s:v 1280x720 -i /dev/stdin -c:v libx264 -preset ultrafast -tune zerolatency -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH'
   runOnInitRestart: yes

new libcamera changes related to transform pushed to bookworm 😉

~/mediamtx/internal/protocols/rpicamera/exe $ make
g++ -Ofast -Werror -Wall -Wextra -Wno-unused-parameter -Wno-unused-result -std=c++17 $(pkg-config --cflags libcamera) -c camera.cpp -o camera.o
camera.cpp:37:18: error: ‘Transform’ has not been declared in ‘libcamera’
   37 | using libcamera::Transform;
      |                  ^~~~~~~~~
camera.cpp: In function ‘bool camera_create(const parameters_t*, camera_frame_cb, camera_t**)’:
camera.cpp:192:11: error: ‘class libcamera::CameraConfiguration’ has no member named ‘transform’
  192 |     conf->transform = Transform::Identity;
      |           ^~~~~~~~~
camera.cpp:192:23: error: ‘Transform’ has not been declared
  192 |     conf->transform = Transform::Identity;
      |                       ^~~~~~~~~
camera.cpp:194:15: error: ‘class libcamera::CameraConfiguration’ has no member named ‘transform’
  194 |         conf->transform = Transform::HFlip * conf->transform;
      |               ^~~~~~~~~
camera.cpp:194:27: error: ‘Transform’ has not been declared
  194 |         conf->transform = Transform::HFlip * conf->transform;
      |                           ^~~~~~~~~
camera.cpp:194:52: error: ‘class libcamera::CameraConfiguration’ has no member named ‘transform’
  194 |         conf->transform = Transform::HFlip * conf->transform;
      |                                                    ^~~~~~~~~
camera.cpp:197:15: error: ‘class libcamera::CameraConfiguration’ has no member named ‘transform’
  197 |         conf->transform = Transform::VFlip * conf->transform;
      |               ^~~~~~~~~
camera.cpp:197:27: error: ‘Transform’ has not been declared
  197 |         conf->transform = Transform::VFlip * conf->transform;
      |                           ^~~~~~~~~
camera.cpp:197:52: error: ‘class libcamera::CameraConfiguration’ has no member named ‘transform’
  197 |         conf->transform = Transform::VFlip * conf->transform;
      |                                                    ^~~~~~~~~
make: *** [Makefile:46: camera.o] Error 1

raspberry pi5 bookworm camera v3 docker docker run --rm -it --network=host --privileged --tmpfs /dev/shm:exec -v /run/udev:/run/udev:ro -e MTX_PATHS_CAM_SOURCE=rpiCamera bluenviron/mediamtx:latest-rpi 2023/11/28 13:39:58 INF MediaMTX v1.3.1 2023/11/28 13:39:58 INF configuration loaded from /mediamtx.yml 2023/11/28 13:39:58 INF [path cam] [RPI Camera source] started 2023/11/28 13:39:58 INF [RTSP] listener opened on :8554 (TCP), :8000 (UDP/RTP), :8001 (UDP/RTCP) 2023/11/28 13:39:58 INF [RTMP] listener opened on :1935 2023/11/28 13:39:58 INF [HLS] listener opened on :8888 2023/11/28 13:39:58 INF [WebRTC] listener opened on :8889 (HTTP), :8189 (ICE/UDP) 2023/11/28 13:39:58 INF [SRT] listener opened on :8890 (UDP) [0:32:34.424405642] [13] INFO Camera camera_manager.cpp:297 libcamera v0.0.5+83-bde9b04f 2023/11/28 13:39:59 ERR [path cam] [RPI Camera source] camera_create(): selected camera is not available [0:32:39.569273539] [19] INFO Camera camera_manager.cpp:297 libcamera v0.0.5+83-bde9b04f 2023/11/28 13:40:04 ERR [path cam] [RPI Camera source] camera_create(): selected camera is not available

MediaMTX now supports serving the Raspberry Pi Camera feed on both Raspberry Pi OS Bookworm and Bullseye (because dependencies have been embedded inside the server) and on the Raspberry Pi 5 (because a H264 software encoder was added as failback).

Libcamera 0.3.0 has been pushed to bookworm and removed transform altogether. In order to compile from source, you need to use the new orientation enumeration. Replace the lines by @Topper69 with:

conf->orientation = Orientation::Rotate0;
if (params->h_flip) {
      conf->orientation = Orientation::Rotate0Mirror;
}
if (params->v_flip) {
      conf->orientation = Orientation::Rotate180Mirror;
}
if  (params->v_flip && params->h_flip) {
      conf->orientation = Orientation::Rotate180;
}

And replace using libcamera::Transform; with using libcamera::Orientation;

If I run apt-get install libcamera0 on Pi5 it somehow kills my GUI… I can still ssh into the pi.

pi@raspberrypi:~/Downloads $ ./mediamtx 
2024/01/27 16:14:23 INF MediaMTX v1.5.0
2024/01/27 16:14:23 INF configuration loaded from /home/pi/Downloads/mediamtx.yml
2024/01/27 16:14:23 INF [path cam] [RPI Camera source] started
2024/01/27 16:14:23 INF [RTSP] listener opened on :8554 (TCP), :8000 (UDP/RTP), :8001 (UDP/RTCP)
2024/01/27 16:14:23 INF [RTMP] listener opened on :1935
2024/01/27 16:14:23 INF [HLS] listener opened on :8888
2024/01/27 16:14:23 INF [WebRTC] listener opened on :8889 (HTTP), :8189 (ICE/UDP)
2024/01/27 16:14:23 INF [SRT] listener opened on :8890 (UDP)
[0:04:25.785510356] [6691]  INFO Camera camera_manager.cpp:297 libcamera v0.0.5+83-bde9b04f
2024/01/27 16:14:23 ERR [path cam] [RPI Camera source] camera_create(): selected camera is not available

Before I had libcamera-hello --list-cameras but obviously this has now gone

pi@raspberrypi:~/Downloads $ dmesg  | grep video
[    3.196991] videodev: Linux video capture interface: v2.00
[    3.294898] rpivid 1000800000.codec: Device registered as /dev/video19
[    3.308074] pispbe 1000880000.pisp_be: input device node registered as /dev/video20
[    3.318090] pispbe 1000880000.pisp_be: tdn_input device node registered as /dev/video21
[    3.329244] rp1-cfe 1f00128000.csi: Registered [rp1-cfe-csi2_ch0] node id 0 successfully as /dev/video0
[    3.329463] rp1-cfe 1f00128000.csi: Registered [rp1-cfe-embedded] node id 1 successfully as /dev/video1
[    3.329494] pispbe 1000880000.pisp_be: stitch_input device node registered as /dev/video22
[    3.329574] pispbe 1000880000.pisp_be: hog_output device node registered as /dev/video23
[    3.329633] pispbe 1000880000.pisp_be: output0 device node registered as /dev/video24
[    3.329690] pispbe 1000880000.pisp_be: output1 device node registered as /dev/video25
[    3.329701] rp1-cfe 1f00128000.csi: Registered [rp1-cfe-csi2_ch2] node id 2 successfully as /dev/video2
[    3.329754] pispbe 1000880000.pisp_be: tdn_output device node registered as /dev/video26
[    3.329887] rp1-cfe 1f00128000.csi: Registered [rp1-cfe-csi2_ch3] node id 3 successfully as /dev/video3
[    3.330112] rp1-cfe 1f00128000.csi: Registered [rp1-cfe-fe_image0] node id 4 successfully as /dev/video4
[    3.330153] pispbe 1000880000.pisp_be: stitch_output device node registered as /dev/video27
[    3.330226] pispbe 1000880000.pisp_be: config device node registered as /dev/video28
[    3.330361] rp1-cfe 1f00128000.csi: Registered [rp1-cfe-fe_image1] node id 5 successfully as /dev/video5
[    3.330508] rp1-cfe 1f00128000.csi: Registered [rp1-cfe-fe_stats] node id 6 successfully as /dev/video6
[    3.330621] rp1-cfe 1f00128000.csi: Registered [rp1-cfe-fe_config] node id 7 successfully as /dev/video7
[    3.330624] pispbe 1000880000.pisp_be: input device node registered as /dev/video29
[    3.330688] pispbe 1000880000.pisp_be: tdn_input device node registered as /dev/video30
[    3.331160] pispbe 1000880000.pisp_be: stitch_input device node registered as /dev/video31
[    3.331227] pispbe 1000880000.pisp_be: hog_output device node registered as /dev/video32
[    3.331290] pispbe 1000880000.pisp_be: output0 device node registered as /dev/video33
[    3.331348] pispbe 1000880000.pisp_be: output1 device node registered as /dev/video34
[    3.331405] pispbe 1000880000.pisp_be: tdn_output device node registered as /dev/video35
[    3.331461] pispbe 1000880000.pisp_be: stitch_output device node registered as /dev/video36
[    3.331520] pispbe 1000880000.pisp_be: config device node registered as /dev/video37

mediamtx.yml includes

paths:
  cam:
    source: rpiCamera

as per docs

I have no rpicam-vid command available

pi@raspberrypi:~/Downloads $ cat /etc/os-release 
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
pi@raspberrypi:~/Downloads $ 

Now I was trying something like this:

paths:
  # example:
  cam:
    runOnInit: bash -c 'libcamera-vid -t 0 --codec yuv420 --width 1280 --height 720 --inline --listen -o - | ffmpeg -f rawvideo -pix_fmt yuv420p -s:v 1280x720 -i /dev/stdin -c:v libx264 -preset ultrafast -tune zerolatency -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH'
    runOnInitRestart: yes

It works, but I observe 2-3 seconds delay and frequent freezes… Do you think switching to GStreamer would improve performance?

EDIT:

I tried using gstreamer and it’s worse than using ffmpeg. Maybe I’m configuring something wrong?

    runOnInit: gst-launch-1.0 -v libcamerasrc ! "video/x-raw,width=1280,height=720,framerate=2/1" ! videoconvert ! x264enc speed-preset=ultrafast tune=zerolatency byte-stream=true bitrate=3000 threads=2 ! rtspclientsink location=rtsp://localhost:$RTSP_PORT/$MTX_PATH

Worse for the delay ?