Skip to content

Instantly share code, notes, and snippets.

@gatlin
Created April 26, 2020 22:53
Show Gist options
  • Select an option

  • Save gatlin/986a5610b0b4cd6c0ba0ea00d536dead to your computer and use it in GitHub Desktop.

Select an option

Save gatlin/986a5610b0b4cd6c0ba0ea00d536dead to your computer and use it in GitHub Desktop.

Revisions

  1. gatlin created this gist Apr 26, 2020.
    39 changes: 39 additions & 0 deletions twitch
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    #!/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.