Skip to content

Instantly share code, notes, and snippets.

@gatlin

gatlin/twitch

Created Apr 26, 2020
Embed
What would you like to do?
Stream arbitrary video files to twitch via gstreamer
#!/usr/bin/env bash
###
# Usage
###
# twitch <path-to-file>
PATH_TO_TWITCH_KEY="$HOME/.config/twitch.key"
if [ ! -f "$HOME/.config/twitch.key" ]; then
echo "Please write your twitch key to $PATH_TO_TWITCH_KEY"
exit 1
fi
TWITCH_KEY=$(cat $PATH_TO_TWITCH_KEY)
FILE_PATH="$1"
if [ -z "$FILE_PATH" ]; then
echo "Please specify a file to stream."
exit 1
fi
gst-launch-1.0 --gst-debug-level=2 \
filesrc location="$FILE_PATH" ! \
qtdemux name=demux \
demux.video_0 ! \
queue ! \
decodebin ! \
videoconvert ! \
x264enc threads=0 bitrate=400 tune=zerolatency key-int-max=30 ! \
queue ! \
flvmux name=flvmux ! \
queue ! \
rtmpsink location="rtmp://live-fra.twitch.tv/app/$TWITCH_KEY" \
demux.audio_0 ! \
queue ! \
decodebin ! \
audioconvert ! \
audioresample ! \
avenc_aac ! \
flvmux.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment