Use a raspberry pi as an ip or udp camera

Its fairly easy this is a simple way to turn on your camera on a raspberry Pi using rpicam-tools. This is a very quick simple and cheap way to add a security camera, remote monitoring of equipment or a pet, or a camera on a pet, anything that comes to mind. For myself this will be to watch for the over voltage / somethings terribly wrong with my power connections i'm going to burn up red light of death on my video cards. A note on this if you ever see this red light blinking on your video card re-seat your power connectors or use another one. Maybe it's a short in the wires or they are bent at an angle that it doesn't like as this was my case with the larger video cards the wiring tends to get bent at a right angle harder than they like without making a harness to hold them at the correct angle, of course don't use the same pigtail or daisy chained connector across all the ports its just going to melt.
To start as with any Raspberry Pi installation the usual baseline.
sudo apt update && sudo apt upgrade
That's really all the work, rpicam-tools should be installed by default on a standard Raspberry Pi image. To test lets run the standard hello world.
rpicam-hello
if you are using a desktop installation you should probably see a preview image, but more than likely for this type of use its a command line only installation or connecting through ssh to be used as a network camera so you will see the frame output in the console.
zero@zero1:~ $ rpicam-hello
[138:05:08.601690899] [41284] INFO Camera camera_manager.cpp:326 libcamera v0.5.1+100-e53bdf1f
[138:05:08.677037438] [41289] WARN RPiSdn sdn.cpp:40 Using legacy SDN tuning - please consider moving SDN inside rpi.denoise
[138:05:08.682786134] [41289] INFO RPI vc4.cpp:440 Registered camera /base/soc/i2c0mux/i2c@1/ov5647@36 to Unicam device /dev/media2 and ISP device /dev/media0
[138:05:08.683006029] [41289] INFO RPI pipeline_base.cpp:1107 Using configuration file '/usr/share/libcamera/pipeline/rpi/vc4/rpi_apps.yaml'
Made DRM preview window
Preview window unavailable
Mode selection for 1296:972:12:P
SGBRG10_CSI2P,640x480/0 - Score: 3296
SGBRG10_CSI2P,1296x972/0 - Score: 1000
SGBRG10_CSI2P,1920x1080/0 - Score: 1349.67
SGBRG10_CSI2P,2592x1944/0 - Score: 1567
Stream configuration adjusted
[138:05:08.689300975] [41284] INFO Camera camera.cpp:1205 configuring streams: (0) 1296x972-YUV420/sYCC (1) 1296x972-SGBRG10_CSI2P/RAW
So we know its working but whats the point of single images unless we are doing something like image recognition, we need video so FFMpeg.
sudo apt install ffmpeg
and then we run again. Lets skip saving to a file and just go straight into streaming since thats the goal. So we want to make a udp stream available to another machine running vlc.
my video machine is 192.168.0.115 so pick a random port (5 numbers to be safe)
rpicam-vid -t 0 -n --codec libav --libav-format mpegts -o udp://192.168.0.115:11111
Looks like its working but, another error
Stream configuration adjusted
[140:03:33.815559740] [43384] INFO Camera camera.cpp:1205 configuring streams: (0) 640x480-YUV420/SMPTE170M (1) 640x480-SGBRG10_CSI2P/RAW
[140:03:33.816239689] [43387] INFO RPI vc4.cpp:615 Sensor: /base/soc/i2c0mux/i2c@1/ov5647@36 - Selected sensor format: 640x480-SGBRG10_1X10 - Selected unicam format: 640x480-pGAA
ERROR: *** Unrecognised codec libav ***
Since this is a minimal install with no desktop we need to add the codecs
sudo apt install libavcodec-dev libavdevice-dev libavformat-dev libswresample-dev
Now we run and still the error persists? Figured this should work but since this is again a minimal install it doesn't have all of the requirements for the camera. so we need the full package
sudo apt install libcamera-apps
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following package was automatically installed and is no longer required:
rpicam-apps-lite
Notice this will replace the standard rpicam-apps-lite. now we run again.
rpicam-vid -t 0 -n --codec libav --libav-format mpegts -o udp://192.168.0.115:11111
[149:17:33.757875735] [44909] INFO Camera camera_manager.cpp:326 libcamera v0.5.1+100-e53bdf1f
[149:17:33.824614600] [44912] WARN RPiSdn sdn.cpp:40 Using legacy SDN tuning - please consider moving SDN inside rpi.denoise
[149:17:33.830363160] [44912] INFO RPI vc4.cpp:440 Registered camera /base/soc/i2c0mux/i2c@1/ov5647@36 to Unicam device /dev/media2 and ISP device /dev/media0
[149:17:33.830550244] [44912] INFO RPI pipeline_base.cpp:1107 Using configuration file '/usr/share/libcamera/pipeline/rpi/vc4/rpi_apps.yaml'
Mode selection for 640:480:12:P
SGBRG10_CSI2P,640x480/0 - Score: 1000
SGBRG10_CSI2P,1296x972/0 - Score: 1287
SGBRG10_CSI2P,1920x1080/0 - Score: 1636.67
SGBRG10_CSI2P,2592x1944/0 - Score: 1854
Stream configuration adjusted
[149:17:33.933692249] [44909] INFO Camera camera.cpp:1205 configuring streams: (0) 640x480-YUV420/SMPTE170M (1) 640x480-SGBRG10_CSI2P/RAW
[149:17:33.934446678] [44912] INFO RPI vc4.cpp:615 Sensor: /base/soc/i2c0mux/i2c@1/ov5647@36 - Selected sensor format: 640x480-SGBRG10_1X10 - Selected unicam format: 640x480-pGAA
[h264_v4l2m2m @ 0x55aa646cb0] <<< v4l2_encode_init: fmt=179/0
[h264_v4l2m2m @ 0x55aa646cb0] Using device /dev/video11
[h264_v4l2m2m @ 0x55aa646cb0] driver 'bcm2835-codec' on card 'bcm2835-codec-encode' in mplane mode
[h264_v4l2m2m @ 0x55aa646cb0] requesting formats: output=YU12 capture=H264
Output #0, mpegts, to 'udp://192.168.0.115:11111':
Stream #0:0: Video: h264, drm_prime(tv, smpte170m/smpte170m/bt709), 640x480, q=2-31, 200 kb/s, 30 fps, 30 tbr, 1000k tbn
So the stream is running. now on the target machine in VLC in a new window open a network stream to the address

And we get our result

Now we have streaming video and its perfectly good to go for this purpose.