Skip to content

Instantly share code, notes, and snippets.

@TobiX
Created April 18, 2021 10:15
Show Gist options
  • Save TobiX/b39be139b4227b925f923c4370c2241e to your computer and use it in GitHub Desktop.
Save TobiX/b39be139b4227b925f923c4370c2241e to your computer and use it in GitHub Desktop.
Simple script to stream "Webcam" input to Twitch
#!/bin/sh
INDEV="/dev/v4l/by-id/usb-MACROSILICON_USB3._0_capture-video-index0"
INRES="1920x1080" # input resolution
FPS="30" # target FPS
GOP="$((FPS * 2))"
THREADS="2"
CBR="6000k"
STREAM_KEY="XXX"
if [ "$1" = live ]
then
target="rtmp://fra02.contribute.live-video.net/app/$STREAM_KEY"
else
target="output.flv"
fi
ffmpeg \
-f v4l2 -input_format mjpeg -framerate "$FPS" -video_size "$INRES" \
-hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i "$INDEV" \
-f alsa -i "hw:CARD=MS2109,DEV=0" \
-vf 'scale_vaapi=format=nv12' \
-codec:v h264_vaapi -b:v "$CBR" -profile:v main -g "$GOP" -bufsize "$CBR" \
-codec:a aac -threads "$THREADS" -strict normal \
-f flv "$target"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment