steveseguin / raspberry_ninja

Publish or capture VDO.Ninja streams with Python (Raspberry Pi, Linux, Mac, Windows WSL)
https://raspberry.ninja
143 stars 28 forks source link

Raspiberry Pi Zero 2 W - FrameRate Issues #43

Open sayeghsa opened 1 month ago

sayeghsa commented 1 month ago

Hello,

I am working on a small project where I have a small camera plugged into a Raspi Pi Zero 2 W and would like to stream that camera to a local host webpage.

OS: Latest Bookworm 32 Bit Lite Camera: Spec for 30 FPS is MJPEG 640x480 Photos below show the command used and the camera used.

When the camera is plugged into my PC, the FPS is 30 with 640 by 480 Resolution.

Do you guys think its the codec used or should I try a different board? I want this to be handheld eventually so it cannot be a larger board like a nvidia jetson.

Thank you! Capture1 Capture2 Capture3 Capture4

steveseguin commented 1 month ago

You can try using a different codec. --rpi --h264 maybe

You can reduce the bitrate, to see if that helps at all; maybe try 400-kbps instead of 2500, just for testing. It will look like crap, but maybe there is a packet loss issue.

If you do use a software encoder, openh264 or x264 might be faster than vp8. The preset I think for x264 is 1, which is ultrafast, https://gstreamer.freedesktop.org/documentation/x264/index.html?gi-language=c#GstX264EncPreset --- if you can get 640x480p30 working well with that, you can try to increase the bitrate or increase the preset value to get better quality.

Also try a different browser for playback; if using Firefox, try Chrome instead, and vice versa.

You can try to switch from MJPEG to YUV, which will limit the frame rate to 10-fps, but it won't need to handle any MJPEG then. This normally isn't an issue though, so it would be mainly for testing.

Adding &buffer=4000 to the view link might help with buffer, if there is an issue there.

You can also try with leaving a CPU core available for wifi or mjpeg; eg: isolcpus=0 , essentially play around with restricting the encoder to fewer CPU cores, to see if that helps elsewhere. If the wifi is getting bogged down, it might be dropping packets. https://github.com/steveseguin/raspberry_ninja/tree/main/raspberry_pi

I recall getting 1080p30 with a Raspberry Pi zero 2 W, but it was a bit janky. I found it more reliable at 720p30, although I don't recall trying it with USB MJPEG -- i was instead using the CSI port with a arducam or something.