Twitch is a platform that offers a live video streaming service owned by Amazon, this platform has become one of the most popular to share video game video streaming, including eSports streaming, and other video game related events. Site content can be viewed live or on demand.
To be able to stream video on linux we have some tools, but we forget the simplest and it is from the terminalIn this post I will share with you a method to be able to stream to Twitch from our terminal.
Previous requirements
To be able to broadcast on Twitch we will lean on from FFmpeg which is already known by many thanks to its wide range of utility, for this we must open a terminal and execute the following command:
sudo apt install ffmpeg
Simply to make sure it was installed successfully, let's run this command:
ffmpeg --help
Where they will receive an answer with all the parameters for the tool.
Modifying bashrc
Now we must make some modifications to our bashrc file, in which we will add an alias for the transmission.
It is important to remember that the bashrc file works per user, so if more than one user of your system is going to use this function, you must add the following to your bashrc file.
Before adding or modifying, we are going to make a backup copy of our file, for this on the terminal we are going to execute the following command:
mkdir ~/bashrc-backup
cp ~ / .bashrc ~ / bashrc-backup / .bashrc-bak
Already with our backup of the file, we can proceed to edit it safely, we only have to execute the following command:
nano ~/.bashrc
Note: you must not edit as root or with superuser permissions.
We must add the following to the end of the file:
streaming() { INRES="1920x1080" # input resolution OUTRES="1920x1080" # output resolution FPS="15" # target FPS GOP="30" # i-frame interval, should be double of FPS, GOPMIN="15" # min i-frame interval, should be equal to fps, THREADS="2" # max 6 CBR="1000k" # constant bitrate (should be between 1000k - 3000k) QUALITY="ultrafast" # one of the 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 http://bashtech.net/twitch/ingest.php to change 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 film -acodec libmp3lame -threads $THREADS -strict normal \ -bufsize $CBR "rtmp://$SERVER.twitch.tv/app/$STREAM_KEY" }
In this vWe can edit the resolution, quality, audio and other settings of transmission according to our need or capacity of our equipment and network connection. So you should take a few minutes for it.
The values can be calculated with the help of estimators, the links are eThis one that OBS provides us, and this other that I found on the net. It is essential that they also know the upload speed of their network since it is one of the most influential factors in the quality of the transmission, you can know it with this tool.
We will only not add our transmission key, this will be requested every time we run the script.
Once the configurations have been made, we proceed to save the changes in the Nano text editor with Ctrl + O and exit it with Ctrl + X.
Streaming to Twitch from the terminal
Now to run the script, just write the following command on the terminal:
streaming streamkey
With this they must already know the password provided by Twitch, if not, they should simply go to this link where they will get it.
Already with it simply configure it and you must start the stream to Twitch Correctly.
To exit the stream, press "Q" and it should end, as the stream uses FFmpeg. If the Q button doesn't work, try getting the quit script with Ctrl + C or Ctrl + Z.