mediamtx icon indicating copy to clipboard operation
mediamtx copied to clipboard

Native Raspberry Pi Camera: Can't achieve specified framerate with rpiCameraMode

Open giano574 opened this issue 2 years ago • 0 comments

Which version are you using?

v0.20.4

Which operating system are you using?

  • [ ] Linux amd64 standard
  • [ ] Linux amd64 Docker
  • [ ] Linux arm64 standard
  • [ ] Linux arm64 Docker
  • [x] 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

I'm trying to achieve the supported 18 FPS of my Arducam 16 MP Autofocus camera when selecting the 3840:2160 sensor mode with rtsp-simple-server using the native Raspberry Pi Camera support, but it seems like rtsp-simple-server maxes out at around 12.3-12.7 FPS. Lowering the framerate below 12 works as expected.

I've tried running libcamera-vid -t 30000 --vflip --width 1920 --height 1080 --mode 3840:2160:10:P --codec mjpeg --framerate 18 -o fps_test.mjpeg to verify that 18 FPS is possible to achive, and counting the frames with ffprobe, I get:

ffprobe -v error -select_streams v:0 -count_frames -show_entries stream=nb_read_frames -print_format csv fps_test.mjpeg
stream,532

which is 532 frames/30 seconds ≈ 17.7 FPS

Running rtsp-simple-server with the config:

readBufferCount: 1024
###############################################
# HLS parameters

# Disable support for the HLS protocol.
hlsDisable: no
hlsAddress: :8888
hlsAlwaysRemux: yes
hlsVariant: mpegts
hlsSegmentCount: 30
hlsSegmentDuration: 30s
hlsPartDuration: 200ms
hlsSegmentMaxSize: 100M

paths:
  stream:
    source: rpiCamera
    rpiCameraCamID: 0
    rpiCameraWidth: 1920
    rpiCameraHeight: 1080
    rpiCameraHFlip: true
    rpiCameraVFlip: true
    rpiCameraBrightness: 0
    rpiCameraContrast: 1
    rpiCameraSaturation: 1
    rpiCameraSharpness: 1
    rpiCameraExposure: normal
    rpiCameraAWB: auto
    rpiCameraDenoise: auto
    rpiCameraShutter: 4000
    rpiCameraMetering: centre
    rpiCameraGain: 7
    rpiCameraEV: 0
    rpiCameraROI:
    rpiCameraTuningFile:
    rpiCameraMode: "3840:2160:10:P"
    rpiCameraFPS: 18
    rpiCameraIDRPeriod: 9
    rpiCameraBitrate: 8000000
    rpiCameraProfile: main
    rpiCameraLevel: "4.1"

and downloading the segments, I get between 370 and 380 frames:

ffprobe -v error -select_streams v:0 -count_frames -show_entries stream=nb_read_frames -print_format csv seg0.ts
stream,378

which is ~12.3-12.7 FPS (because the segments are ~30 seconds long). Originally I had readBufferCount set to 512, but tried increasing it to 1024 with no luck.

If, however, I remove rpiCameraMode: "3840:2160:10:P" from the configuration and set rpiCameraFPS to 30, I get 909 frames/30 seconds = 30.3 FPS. So it seems like the implementation of rpiCameraMode is different than the one in libcamera-vid making it slower/not able to keep up?

Describe how to replicate the issue

  1. Use the configuration from above.
  2. Start rtsp-simple-server.
  3. Check the frame count of a few segments and verify that the count is lower than expected.

Did you attach the server logs?

no

Did you attach a network dump?

no

giano574 avatar Dec 12 '22 14:12 giano574