Skip to content

Instantly share code, notes, and snippets.

@anisyanka
Last active February 23, 2024 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anisyanka/6b716fa051021752b0fc7e91322166f9 to your computer and use it in GitHub Desktop.
Save anisyanka/6b716fa051021752b0fc7e91322166f9 to your computer and use it in GitHub Desktop.
RPI video stream camera how to

Install gstreamer

sudo apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgstreamer-plugins-bad1.0-dev gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-qt5 gstreamer1.0-pulseaudio

More info here - https://gstreamer.freedesktop.org/documentation/installing/on-linux.html?gi-language=c

List video devices

0. Just check the camera was initialized with no errors

dmesg | grep 16MP

Output:

[    3.331850] usb 1-1.2: Product: 16MP USB Camera
[    3.336472] usb 1-1.2: Manufacturer: 16MP Camera Mamufacture
[   10.805018] usb 1-1.2: Found UVC 1.00 device 16MP USB Camera (32e4:0298)
[   10.825348] input: 16MP USB Camera: 16MP USB Camer as /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2:1.0/input/input0

1. Using v4l2

sudo apt-get install v4l-utils
v4l2-ctl --list-devices

Get device info

1. Using media-ctl

sudo media-ctl --device /dev/media4 -p

2. Using v4l2-ctl

v4l2-ctl Command Examples in Linux - https://www.thegeekdiary.com/v4l2-ctl-command-examples-in-linux/ Get all info

sudo v4l2-ctl --device=/dev/video0 --all

Get supported pixel formats

sudo v4l2-ctl -d /dev/video0 --list-formats

List supported video formats, FPS and resolutions of a specific video device

sudo v4l2-ctl --list-formats-ext --device /dev/video0

Capture photo from USB camera

1. Using fswebcam

fswebcam -r 4656х3496 --no-banner image1.jpg

More info here - https://raspberrypi-guide.github.io/electronics/using-usb-webcams

2. Using v4l2-ctl

v4l2-ctl --device path/to/video_device --set-fmt-video=width=width,height=height,pixelformat=MJPG --stream-mmap --stream-to=path/to/output.jpg --stream-count=1

Show video stream from camera

1. Using motion

0. sudo apt-get install modion
1. create separate user to escape permossion denied error - https://raspberrypi.stackexchange.com/questions/78715/motion-daemon-var-log-motion-motion-log-permission-denied
2. Google default config file for your version of motion. Change parameters which you need here - sudo nano /etc/motion/motion.conf
3. For better performance use this - https://raspberrypi.stackexchange.com/questions/106078/very-slow-with-motion-server-raspberry-pi-b
4. Setup camera setting here - /etc/motion/camera1-dist.conf
5. sudo service motion start

More info:

2. Using Gstreamer

Start UDP stream from RPI

HOST=192.168.1.101
PORT=5602

gst-launch-1.0 -v v4l2src device=/dev/video0 ! image/jpeg,width=1920,height=1080,type=video,framerate=30/1 ! jpegdec ! videoscale ! videoconvert ! x264enc tune=zerolatency ! rtph264pay ! udpsink host=$HOST port=$PORT

Show the stream on host:

PORT=5602

gst-launch-1.0 udpsrc port=$PORT caps = "application/x-rtp, media=video, clock-rate=90000, encoding-name=H264, payload=96" ! rtph264depay ! avdec_h264 ! autovideosink

Setup a camera device

1. Using media-ctl

sudo media-ctl --device /dev/media4 --set-v4l2 '"Input 1":0[fmt:MJPG/1920x1080@1/30]'. <---- DON'T WORK

2. Using v4l2-ctl

sudo v4l2-ctl -d /dev/video0 --set-fmt-video=width=4656,height=3496,pixelformat=MJPG -p 10

-p 10 means 10fps

Work with Gstreamer

https://www.marcusfolkesson.se/blog/v4l2-and-media-controller/ https://gist.github.com/anselmobattisti/ddab81f9485c5479d6c784d2813bc28e https://gist.github.com/hum4n0id/cda96fb07a34300cdb2c0e314c14df0a#send-a-webcam-with-h264-rtp-streamjetson-nano

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment