Many customers on Linux select to stream to Twitch on Linux utilizing the Open broadcaster instrument. Not everybody likes this instrument, and a few want for an alternate. You possibly can watch Twitch streams with out utilizing a browser, and you may use a easy bash script stream to Twitch.

Should you use a VPN with Twitch, you’ll have to allow it individually.

Set up FFmpeg Encoding Instrument

Streaming to Twitch from the Linux command line runs with the assistance of the FFmpeg encoding instrument. Earlier than we go any additional on this tutorial, you’ll want to put in it in your Linux PC. Open up a terminal window and enter the next. To set up FFmpeg, you should be working Ubuntu, Debian, Arch Linux, Fedora or OpenSUSE. Should you aren’t working certainly one of these Linux distributions, you’ll be able to construct and set up the FFmpeg encoding software program instantly from the web site here.

Ubuntu

sudo apt set up ffmpeg

Debian

sudo apt-get set up ffmpeg

Arch Linux

sudo pacman -S ffmpeg

Fedora

sudo dnf set up ffmpeg

OpenSUSE

sudo zypper set up ffmpeg

Now that the encoding instrument is put in, run it within the terminal to make certain that all the things is working accurately. FFmpeg doesn’t want file encoding to run. In a terminal, strive:

ffmpeg --help

Verify that the assistance web page launches accurately, and sort clear to erase the terminal.

Modify Bashrc

Z

The encoder instrument is put in and dealing. The subsequent step is to arrange the Twitch streaming alias on the system. To create the streaming alias, you’ll want to change the bashrc file. This file holds a variety of totally different command variables for every person. The bashrc file works on a per-user foundation, so every person that desires to make use of this command to stream to Twitch should comply with the method under.

Begin off by backing up the bashrc file. This can make sure that any edits or errors could be undone if you wish to delete the streaming command. Create a backup by making a replica of the file:

mkdir ~/bashrc-backup

cp ~/.bashrc ~/bashrc-backup/.bashrc-bak

With the backup taken care of, begin the modifying. Open up bashrc within the terminal. DO NOT USE ROOT, you would by chance edit the foundation person’s bashrc file as an alternative of your individual, which might be a mistake.

nano ~/.bashrc

Paste the next code on the very finish of the bashrc file. Perceive you could have to undergo this code and edit it to fit your wants. Particularly, the resolutions, threads, high quality, CBR,  and and many others.

Observe: don’t fill out your stream key in bashrc, as it’s unsafe. This script asks for the important thing each time you stream for security sake.

 streaming() {
     INRES="1920x1080" # enter decision
     OUTRES="1920x1080" # output decision
     FPS="15" # goal FPS
     GOP="30" # i-frame interval, must be double of FPS, 
     GOPMIN="15" # min i-frame interval, must be equal to fps, 
     THREADS="2" # max 6
     CBR="1000k" # fixed bitrate (must be between 1000k - 3000k)
     QUALITY="ultrafast"  # one of many many FFMPEG preset
     AUDIO_RATE="44100"
     STREAM_KEY="$1" # use the terminal command Streaming streamkeyhere to stream your video to twitch or justin
     SERVER="live-sjc" # twitch server in California, see  to alter 
     
     ffmpeg -f x11grab -s "$INRES" -r "$FPS" -i :0.0 -f alsa -i pulse -f flv -ac 2 -ar $AUDIO_RATE 
       -vcodec libx264 -g $GOP -keyint_min $GOPMIN -b:v $CBR -minrate $CBR -maxrate $CBR -pix_fmt yuv420p
       -s $OUTRES -preset $QUALITY -tune movie -acodec libmp3lame -threads $THREADS -strict regular 
       -bufsize $CBR "rtmp://$SERVER.twitch.tv/app/$STREAM_KEY"
 }

When the code is in bashrc, save the Nano textual content editor with Ctrl + O, and exit it with Ctrl + X.

Streaming

To stream to Twitch instantly from the command line, open up a terminal and use the new streaming command arrange in bashrc. You will need to know your Twitch stream key. Log into Twitch, go to the dashboard and discover your streaming key.

If the secret’s arrange accurately, streaming from the command line ought to work like this:

streaming streamkey

To give up streaming, press “Q” and it ought to finish, because the stream is utilizing FFmpeg. If the button doesn’t work, power the script to give up with Ctrl + Z.

Stream Script

If getting into a stream key again and again will get exhausting, contemplate making a stream script. Take into account that doing it will expose your key to anybody else that has entry to your PC. To create the script, open terminal and enter the next instructions.

First, use echo so as to add the shebang. A shebang lets the Bash interpreter know what sort of script it’s about to run, the atmosphere, and many others.

Observe: don’t transfer the script from your house folder! It depends on the streaming script inside bashrc. Should you transfer it to different locations within the file system that don’t have the right permissions, it could not work accurately.

echo "#!/bin/bash" > ~/stream-script.sh

Subsequent, copy your streaming command and use echo to put in writing it into the script.

echo "streaming streamkey" >> ~/stream-script.sh

Lastly, replace the permissions of the script, in order that the system will enable it to run accurately. With out this, the script might fail.

sudo chmod +x stream-script.sh

Run the script with:

./stream-script.sh

or

sh stream-script.sh

Stop the script with or Ctrl + Z.



Source link

Share.
Leave A Reply

Exit mobile version