Skip to content

Generate an RTMP stream from video files for ingestion by a twitch.tv endpoint

License

Notifications You must be signed in to change notification settings

mulekick/stream-from-the-shell

Repository files navigation

GitHub package.json version GitHub License Last Commit Docker Image Size Docker Pulls

Stream on twitch.tv from the shell

Important : make sure that whatever you're streaming is compliant with twitch.tv's terms of service and community guidelines.

Prerequisites

1 - Install the program

# install ffmpeg if necessary (required for video sources preparation)
dpkg-query -l ffmpeg > /dev/null 2>&1 || sudo apt-get install ffmpeg

# clone the repository
git clone https://github.com/mulekick/stream-from-the-shell

# cd into the cloned repository
cd stream-from-the-shell

# create container name configuration file (lower / uppercase letters, numbers and dashes allowed)
echo "STREAMING_CONTAINER_SAMPLE_NAME" > .container.name

# create endpoint configuration file (append your stream key to whatever URL you selected)
echo "rtmp://{TWITCH_ENDPOINT_ID}.contribute.live-video.net/app/{YOUR_STREAM_KEY}" > .twitch.endpoint

# pull the docker image
docker image pull mulekick/stream-from-the-shell:latest

2 - Prepare videos to stream

  • Select some videos you want to broadcast and add them to video.sources/.video.sources.list :
# sample .video.sources.list file (all containers formats, resolutions, framerates etc ... are permitted)
# you can write comments into this file as well using the bash syntax
# always use absolute paths and enclose in single quotes as in the following examples :
'/home/myusername/video files/series/breaking bad season 1/season 1 episode 1.mp4'
'/home/myusername/video files/series/breaking bad season 1/season 1 episode 2.mp4'
'/home/myusername/video files/series/breaking bad season 1/season 1 episode 3.mp4'
# etc ...
# IMPORTANT NOTE : FILE PATHS MUST NOT CONTAIN SINGLE QUOTES, RENAME IF NECESSARY 
  • Once done, run npm run prepare to format your videos sources and ready them up for streaming.
  • You can run ./utils/prepare.sources.sh to the same effect if you don't have npm installed.
  • Formatted video files will be saved in .flv format in video.sources.

Note : It is best to not store anything in video.sources besides the sources list and the processed files.

3 - Stream on twitch.tv from the shell

  • You're all set up now, so run npm run stream or ./commands.sh stream to start your twitch.tv stream.
  • Once the docker container has started, run npm run console or ./commands.sh console.
  • At this stage, the streaming console should show on your TTY and display the 40 program slots :

live streaming console

4 - Broadcast your videos on stream

  • Congrats ! Your stream is now live on twitch.tv and will loop 24/7 over the 40 available program slots.
  • Any formatted video file copied to stream.queue will be queued to be broadcasted on stream.
  • Each queued file will show up in the TTY console with its slot number, start time, title and duration.
# IMPORTANT : COPY FORMATTED VIDEO FILES TO THE STREAM QUEUE ONE AT A TIME
# if you copy multiple files at once, only the first one will be added
cp "video.sources/beaking_bad_season_1_episode_1.flv" stream.queue/.
# IMPORTANT : ALWAYS WAIT FOR THE COPIED VIDEO TO APPEAR IN THE CONSOLE BEFORE COPYING THE NEXT ONE
# it is even better to wait a few seconds between copy operations, especially when working with large videos
cp "video.sources/beaking_bad_season_1_episode_2.flv" stream.queue/.
# etc ...
cp "video.sources/beaking_bad_season_1_episode_3.flv" stream.queue/.
# ...
  • Once the video has been transcoded into the outgoing stream, its slot is reset and becomes available again.

5 - Restream an ongoing stream

  • You can also use the program to restream an ongoing live stream by typing the following command :
# pass the url to the master playlist of the live stream you want to restream
npm run restream "https://video.website/live-stream-master-playlist.m3u8"

# if you don't have npm installed
./commands.sh restream "https://video.website/live-stream-master-playlist.m3u8"

6 - Once done, stop the stream

  • The stream can be stopped at any point by running npm run stop or ./commands.sh stop.
  • Twitch.tv may automatically terminate the stream after 48 hours (I'm unable to 100% confirm that).
  • As a result, if twitch.tv terminates the stream, the streaming container will exit and have to be restarted.

About

Generate an RTMP stream from video files for ingestion by a twitch.tv endpoint

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published