Streaming to twitch.tv
Twitch.tv is a popular RTMP-based streaming service. As so, this page serve as a list of solutions for streaming to Twitch.tv. Use cases may include streaming games, Linux desktop, etc.
Twitch Broadcast Requirements
From Twitch.tv support:
- Video Requirements
- Codec: H.264 (x264)
- Mode: Strict CBR
- Keyframe Interval: 2 seconds
- Audio Requirements
- Codec: AAC-LC, Stereo or Mono
- Maximum bit rate: 160 kbps
- Sampling frequency: any Note: Support for the MP3 codec has been deprecated
- Other Requirements
- Not listed on their page is a requirement of the Y'UV420p pixel format, as Y'UV444 is not widely supported just yet.
GUI solutions
- Open Broadcaster Software (obs-studio) is a popularly used streaming program. Alpha Linux builds (obs-studio-gitAUR) are also available for compiling & testing.
- Castawesome (castawesomeAUR) is a Gtk3 frontend for ffmpeg streaming with builtin Twitch.tv support.
- SimpleScreenRecorder (lib32-simplescreenrecorder) can be configured to stream to Twitch:
- The container needs to be set to FLV
- RTMP URL needs to be put in the 'save as' field
- make sure 'separate file per segment' is unchecked
- video codec set to libx264 (NOT H.264)
- set the bitrate to a reasonable value, such as 2000 kbps
- in the custom option field, enter
preset=fast,minrate=2000,maxrate=2000,bufsize=2000,keyint=60
- Note: The value of 'minrate', 'maxrate' and 'bufsize' should be equal to the bit rate.
CLI solutions
FFmpeg
The following solutions make use of FFmpeg for streaming to Twitch.tv.
Shell script method
Shell script for streaming to Twitch.tv using FFmpeg. It supports streaming of both desktop and OpenGL elements. The script can be called by running stream-to-twitch path/to/stream_key
into a shell, being the key securely stored with pass. The script is as follows:
Note: Depending on your internet upload speed, you may need to modify the FFmpeg parameters. use the breakdown list for reference.
Parameter | Description |
---|---|
ffmpeg | The converter |
sets logging level output | |
forces input to be from x11grab | |
sets a specific image size from input source, given by variable $RES_INPUT | |
sets framerate to be the value equal to $FPS | |
sets size of the data to analyze to get stream information | |
gets input, in this case its pulling in screen :0.0 from x11. Can be adjusted, e.g. -i :0.0+500,100 to start at screenpos 500/100 | |
forces input to be from PulseAudio | |
selects the speakers' sink ID | |
-i "${AUDIO_INPUT_MIC}" | selects the microphone's sink ID |
apply filter to microphone for reducing noise and merge audio streams | |
-map 0:v | maps video stream |
maps audio stream | |
forces format to FLV | |
sets audio channels to 2 | |
sets audio rate | |
sets video codec to libx264 | |
specifies that the video bitrate is to be changed. the value of the bitrate is set by $CBR | |
sets pixel format to Y'UV420p. Otherwise by default Y'UV444 is used and is incompatible with Twitch | |
sets a specific image size for output, given by variable $RES_OUTPUT | |
-preset "{$QUALITY}" | sets the preset compression quality and speed |
sets audio codec to use AAC | |
-threads 0 | sets CPU threads to start, 0 autostarts threads based on CPU cores |
This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.