Skip to content

Instantly share code, notes, and snippets.

@wwwins
Last active December 8, 2022 09:37
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save wwwins/c345cb24c13d00b2b71c7290fc0b3d21 to your computer and use it in GitHub Desktop.
Save wwwins/c345cb24c13d00b2b71c7290fc0b3d21 to your computer and use it in GitHub Desktop.
live streaming from raspberry pi with logitech usb c920

video stream(v4l2-ctl)

v4l2-ctl --list-devices
mmal service 16.1 (platform:bcm2835-v4l2):
        /dev/video0

HD Pro Webcam C920 (usb-3f980000.usb-1.2):
        /dev/video1
v4l2-ctl --list-formats-ext
...
Index       : 4
Type        : Video Capture
Pixel Format: 'H264' (compressed)
Name        : H264
        Size: Stepwise 16x16 - 2592x1944 with step 2/2
...
v4l2-ctl --help-stream
v4l2-ctl --set-fmt-video=width=1920,height=1080,pixelformat="H264" -d /dev/video1
v4l2-ctl -d /dev/video1 --stream-mmap=4 --stream-to=- |nc -l -k -v 2222

ffmpeg

ffmpeg -r 30 -use_wallclock_as_timestamps 1 -copytb 0 -f v4l2 -video_size 1920x1080 -vcodec h264 -i /dev/video1 -vcodec copy -f flv - |nc -l -k -v 2222

play video

mplayer -fps 200 ffmpeg://tcp://raspberrypi.local:2222

audio stream

arecord -D plughw:0,0 -f cd |nc -l -k -v 2222

play audio(sox)

nc raspberrypi.local 2222 | play -

pi3+c920 live A/V stream to fb

# size=1280x720
# first input: video(v4l2)
# second input: audio(alsa)
v4l2-ctl --set-fmt-video=width=1280,height=720,pixelformat="H264" -d /dev/video1
v4l2-ctl -d /dev/video1 --stream-mmap=4 --stream-to=- | ffmpeg -f h264 -vcodec h264 -i pipe:0 -f alsa -ac 2 -i hw:0,0 -force_key_frames 00:00:00.000 -r 30 -acodec aac -b:a 128k -vcodec copy -f flv "rtmp:/rtmp-api.facebook.com:80/rtmp/"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment