Skip to content

Instantly share code, notes, and snippets.

@zenny
Forked from wwwins/c920.md
Created July 18, 2019 21:52
Show Gist options
  • Save zenny/55cdc06e71a261e3430a8a83c6c75612 to your computer and use it in GitHub Desktop.
Save zenny/55cdc06e71a261e3430a8a83c6c75612 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