bluenviron / mediamtx

Ready-to-use SRT / WebRTC / RTSP / RTMP / LL-HLS media server and media proxy that allows to read, publish, proxy, record and playback video and audio streams.
MIT License
11.91k stars 1.5k forks source link

Incompatibility with libcamera 0.1.0 and Raspberry Pi 5 #2581

Closed neutralvibes closed 1 month ago

neutralvibes commented 11 months ago

Which version are you using?

v1.2.0

Which operating system are you using?

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

aler9 commented 11 months ago

Hello, the server is compatible with only a version of libcamera at the time, and the current compatible version is 0.0.5.

It seems like Raspberry Pi maintainers are starting to unroll 0.1.0 on some OS-hardware combinations, but not on everyone.

Anyway, the majority of OSs currently run 0.0.5, so we can't perform the upgrade right now, but i'll keep this issue open in order to monitor the situation.

neutralvibes commented 11 months ago

I reported a bump in version a while ago that you thankfully were able to resolve quickly. I cannot remember how I previously got the version. Just in case I have somehow provided an incorrect version this time I thought I should provide info on how it was obtained.

libcamera-hello --version

Reports

libcamera-apps build: 7e4d3d71867f 22-08-2023 (10:57:38)
libcamera build: v0.1.0+52-a858d20b

Thanks for your help.

aler9 commented 11 months ago

We could quickly solve this issue too, but the problem is that i just checked the latest libcamera version on my Raspberry Pi, and it's still 0.0.5, so a full switch to 0.1.0 would cause problems to most users.

neutralvibes commented 11 months ago

I will use docker in meantime.

Topper69 commented 11 months ago

Hi, Raspbian OS has pushed libcamera 0.1.0+99-4a23664b version which brake the compatibility.

Extract of error logs :


Nov 07 21:23:08 baby mediamtx[6996]: [0:04:27.972403420] [6998]  WARN RPiSdn sdn.cpp:39 Using legacy SDN tuning - please consider moving SDN inside rpi.denoise
Nov 07 21:23:08 baby mediamtx[6996]: [0:04:27.978540965] [6998]  INFO RPI vc4.cpp:444 Registered camera /base/soc/i2c0mux/i2c@1/ov5647@36 to Unicam device /dev/media0 and ISP device /dev/media1
Nov 07 21:23:08 baby mediamtx[6996]: [0:04:27.980189092] [6996] ERROR RPI pipeline_base.cpp:166 Invalid sensor configuration request
Nov 07 21:23:08 baby mediamtx[6996]: [0:04:27.981955922] [6998] ERROR Camera camera.cpp:585 Removing camera while still in use
Nov 07 21:23:08 baby mediamtx[459]: 2023/11/07 21:23:08 ERR [path cam] [RPI Camera source] camera_create(): StreamConfiguration.validate() failed```
aler9 commented 11 months ago

Unfortunately libcamera version is still 0.0.5 on Raspberry Bullseye. If you need a server version that is compatible with libcamera 0.1.0, compile it from source by following instructions in the README, or use the Dockerized version, which is independent from libcamera.

Topper69 commented 11 months ago

I have fix the issue with the following code in camera.cpp line 192:

conf->transform = Transform::Identity;
if (params->h_flip) {
    conf->transform = Transform::HFlip; 
}
if (params->v_flip) {
    conf->transform = Transform::VFlip;
}
if  (params->v_flip && params->h_flip) {
     conf->transform = Transform::Rot180Transpose;
}
neutralvibes commented 11 months ago

Bookworm is the latest Raspberry distro. That may explain the issue.

kanehekili commented 11 months ago

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
lolorc commented 10 months ago

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
suosuo6 commented 10 months ago

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

masipcat commented 10 months ago

After applying the @Topper69 patch to a Raspberry Pi 5 (Bookworm), the create_camera function works as expected. However, since the Raspberry Pi 5 does not have a hardware video encoder, the encoder_create function fails. This is the log:

2023/12/06 19:39:56 INF MediaMTX v0.0.0
2023/12/06 19:39:56 INF configuration loaded from /home/jordi/mediamtx.yml
2023/12/06 19:39:56 INF [path cam] [RPI Camera source] started
2023/12/06 19:39:56 INF [RTSP] listener opened on :8554 (TCP), :8000 (UDP/RTP), :8001 (UDP/RTCP)
2023/12/06 19:39:56 INF [RTMP] listener opened on :1935
2023/12/06 19:39:56 INF [HLS] listener opened on :8888
2023/12/06 19:39:56 INF [SRT] listener opened on :8890 (UDP)
[1:30:45.141358142] [7124]  INFO Camera camera_manager.cpp:284 libcamera v0.1.0+118-563cd78e
[1:30:45.165242066] [7128]  INFO RPI pisp.cpp:653 libpisp version v1.0.2 fa44a258644a 22-11-2023 (21:59:22)
[1:30:45.341024932] [7128]  INFO RPI pisp.cpp:1112 Registered camera /base/axi/pcie@120000/rp1/i2c@88000/imx708@1a to CFE device /dev/media1 and ISP device /dev/media0 using PiSP variant BCM2712_C0
[1:30:45.341676454] [7124]  INFO Camera camera.cpp:1183 configuring streams: (0) 1920x1080-YUV420 (1) 1536x864-BGGR16_PISP_COMP1
[1:30:45.341833770] [7128]  INFO RPI pisp.cpp:1396 Sensor: /base/axi/pcie@120000/rp1/i2c@88000/imx708@1a - Selected sensor format: 1536x864-SBGGR10_1X10 - Selected CFE format: 1536x864-PC1B
2023/12/06 19:39:57 ERR [path cam] [RPI Camera source] encoder_create(): unable to open device
Topper69 commented 10 months ago

After applying the @Topper69 patch to a Raspberry Pi 5 (Bookworm), the create_camera function works as expected. However, since the Raspberry Pi 5 does not have a hardware video encoder, the encoder_create function fails. This is the log:

2023/12/06 19:39:56 INF MediaMTX v0.0.0
2023/12/06 19:39:56 INF configuration loaded from /home/jordi/mediamtx.yml
2023/12/06 19:39:56 INF [path cam] [RPI Camera source] started
2023/12/06 19:39:56 INF [RTSP] listener opened on :8554 (TCP), :8000 (UDP/RTP), :8001 (UDP/RTCP)
2023/12/06 19:39:56 INF [RTMP] listener opened on :1935
2023/12/06 19:39:56 INF [HLS] listener opened on :8888
2023/12/06 19:39:56 INF [SRT] listener opened on :8890 (UDP)
[1:30:45.141358142] [7124]  INFO Camera camera_manager.cpp:284 libcamera v0.1.0+118-563cd78e
[1:30:45.165242066] [7128]  INFO RPI pisp.cpp:653 libpisp version v1.0.2 fa44a258644a 22-11-2023 (21:59:22)
[1:30:45.341024932] [7128]  INFO RPI pisp.cpp:1112 Registered camera /base/axi/pcie@120000/rp1/i2c@88000/imx708@1a to CFE device /dev/media1 and ISP device /dev/media0 using PiSP variant BCM2712_C0
[1:30:45.341676454] [7124]  INFO Camera camera.cpp:1183 configuring streams: (0) 1920x1080-YUV420 (1) 1536x864-BGGR16_PISP_COMP1
[1:30:45.341833770] [7128]  INFO RPI pisp.cpp:1396 Sensor: /base/axi/pcie@120000/rp1/i2c@88000/imx708@1a - Selected sensor format: 1536x864-SBGGR10_1X10 - Selected CFE format: 1536x864-PC1B
2023/12/06 19:39:57 ERR [path cam] [RPI Camera source] encoder_create(): unable to open device

Have you tried to get the rasp5 camera videostream from gstreamer (to push the rtmp stream to mediamtx ) instead of the native raspberry pi camera support ?

masipcat commented 10 months ago

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
Topper69 commented 10 months ago

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 ?

masipcat commented 10 months ago

Worse for the delay ?

Yes, for the delay and freezes

Topper69 commented 10 months ago

Worse for the delay ?

Yes, for the delay and freezes

Strange.

try to tweak your gstreamer command. Take some inspiration from this one :

https://github.com/bluenviron/mediamtx/discussions/1425#discussion-4795897

aler9 commented 10 months ago

the Raspberry Pi 5 does not have a hardware video encoder

Thanks for reporting this news since it changes a lot of things. Performing a linear bump of libcamera is not enough anymore and a little reasoning is needed before improving the server in order to deal with the issue.

There are two separate problems, a technical one and a legal one.

The technical problem can be solved by embedding a software encoder into the server and using it as failback. Raspberry Pi employees wrote that they recommend performing software encoding on the new Pi, even though it consumes at least an entire core. Let's do like they say, even though it sounds particularly inadequate in the era of 8k videos.

Unfortunately embedding an H264 software encoder has legal implications, since H264 is covered by patents. Hardware encoders don't have this problem since the legal responsibility is on the hardware manufacturers, and that is why, for instance, Chrome supports H265 decoding if and only if there's an available hardware decoder, and the same applies to MediaMTX in case of H264 encoding.

My idea is to change the video codec of the RPI camera from H264 to AV1, which is royalty free, and embed an AV1 software encoder into the server. AV1 is supported by most browsers and by a relevant fraction of mobile devices, although the compatibility level is not the same as the one of H264. I can't imagine any other way.

CVasilakis commented 9 months ago

My idea is to change the video codec of the RPI camera from H264 to AV1

I would suggest to maintain the H264 option for backward compatibility with older devices and add option for AV1 for the newer devices.

Tdougherty350 commented 8 months ago

the Raspberry Pi 5 does not have a hardware video encoder

Thanks for reporting this news since it changes a lot of things. Performing a linear bump of libcamera is not enough anymore and a little reasoning is needed before improving the server in order to deal with the issue.

There are two separate problems, a technical one and a legal one.

The technical problem can be solved by embedding a software encoder into the server and using it as failback. Raspberry Pi employees wrote that they recommend performing software encoding on the new Pi, even though it consumes at least an entire core. Let's do like they say, even though it sounds particularly inadequate in the era of 8k videos.

Unfortunately embedding an H264 software encoder has legal implications, since H264 is covered by patents. Hardware encoders don't have this problem since the legal responsibility is on the hardware manufacturers, and that is why, for instance, Chrome supports H265 decoding if and only if there's an available hardware decoder, and the same applies to MediaMTX in case of H264 encoding.

My idea is to change the video codec of the RPI camera from H264 to AV1, which is royalty free, and embed an AV1 software encoder into the server. AV1 is supported by most browsers and by a relevant fraction of mobile devices, although the compatibility level is not the same as the one of H264. I can't imagine any other way.

Hello, Just my two cents. With the Lite version of Bookworm, the video encoders are not included. You either have to use the full desktop version of rasbian bookworm, or compile rpicam-aps to get the h264 encoders. Reference: https://forums.raspberrypi.com/viewtopic.php?t=361268

IgorWolkov commented 8 months ago

@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
JohnMcLear commented 8 months ago

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 $ 
kungeplay commented 7 months ago

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 $ 

I met this problem too.

xXAzazelXx commented 6 months ago

i get the same issue on pi5 with docker image, ERR [path cam] [RPI Camera source] camera_create(): selected camera is not available

Ataman commented 6 months ago

The current incompatibility issue with libcamera0.1.0 (and 0.2.0 for that matter) also causes problems on other systems if you're trying to use Picamera2 on the current Raspberry Pi OS (Bookworm). Currently, installing libcamera0 removes libcamera0.2 which python3-libcamera and picamera2 depends on. As it stands, we can only use MediaMTX or the Picamera2 python module on the same system.

The following packages will be REMOVED:
  libcamera-ipa libcamera0.2 python3-libcamera
The following NEW packages will be installed:
  libcamera0

I was testing a dual setup with MediaMTX for streaming and Picamera2 for taking still images with a Raspberry Pi Zero 2 running Bookworm but I'm putting this on hold for now.

yoyojacky commented 5 months ago

mine is Raspberry pi OS bootworm 64bit, application is openCV and I've tried to do :

sudo modprobe bcm2835-v4l2 

although I can see /dev/video0 but exeucte the python code to grap image from camera 0 - /dev/video0, I have nothing on the screen. my camera is CSI camera and i can detect it via

libcamera-hello --list-cameras 

it shows: 0: imx708 [4608x2592 10-bit RGGB]xxxxxx bf17198a82f626a2bfab215c56c5a934 and try to use picamera with no luck.

import cv2
from picamera.array import PiRGBArray
from picamera import PiCamera
import time

# Initialize the camera
camera = PiCamera()

# Set camera resolution (optional)
camera.resolution = (640, 480)

# Set camera framerate (optional)
camera.framerate = 32

# Initialize the video stream
rawCapture = PiRGBArray(camera, size=(640, 480))

# Allow the camera to warm up
time.sleep(0.1)

# Capture frames from the camera
for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
    # Grab the raw NumPy array representing the image
    image = frame.array

    # Perform image processing with OpenCV (e.g., display the image)
    cv2.imshow("Frame", image)

    # Clear the stream in preparation for the next frame
    rawCapture.truncate(0)

    # Check for key press to exit the loop
    key = cv2.waitKey(1) & 0xFF
    if key == ord("q"):
        break

# Release the camera resources
cv2.destroyAllWindows()

909b35f3290b52d1447c7fa1ebe2190f 9d6effa1d8424b17a9c02eede62c7930 How can I use CSI camera on Raspberry Pi 5 with OpenCV ?

kawogi commented 4 months ago

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?

krokosik commented 2 months ago

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;

krokosik commented 2 months ago

Regarding the encoder, would it be possible to implement it in the same way as rpicam-apps did? https://github.com/raspberrypi/rpicam-apps/commit/213b166b7e48b3fca0a4aa172baaa773f1dd280f

xXAzazelXx commented 1 month ago

omg , this worked for me https://gektor650.medium.com/comparing-video-stream-latencies-raspberry-pi-5-camera-v3-a8d5dad2f67b

aler9 commented 1 month ago

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).

github-actions[bot] commented 1 month ago

This issue is mentioned in release v1.9.0 🚀 Check out the entire changelog by clicking here