twitch-ffmpeg: stream through ffmpeg on twitch
Go to: https://dev.twitch.tv/console/apps
{
"client_id": "g719ehxq9xieaiandwcphpcv613cws",
"client_secret": "vek7nwmh53klnrtj7zpizj53q99f56"
}
#!/usr/bin/env python3
# -*- coding: utf-8 -*
from src.TwitchFfmpeg import TwitchFfmpeg
tf = TwitchFfmpeg('/home/projects/twitch-ffmpeg/config')
tf.Api.setTokenFromCode()
Your nick from twitch, for example: sithtal https://twitch.tv/sithtal
Go to: https://dashboard.twitch.tv/u/{your_channel}/settings/stream for example: https://dashboard.twitch.tv/u/sithtal/settings/stream
COPY Primary Stream key
Go to: https://stream.twitch.tv/ingests/ and get desired end point server url without {stream_key}, for example: rtmp://mad01.contribute.live-video.net/app/
Open twitch_channel.json and replace values, for example:
{
"channel": "sithtal",
"key": "live_123456789_ABCDEFGHGIJKLMNOPQRS1aBCdEFGH2i",
"server": "rtmp://mad01.contribute.live-video.net/app/"
}
The TOKEN expires, to refresh token create a cron to refresh it
#!/usr/bin/env python3
# -*- coding: utf-8 -*
from src.TwitchFfmpeg import TwitchFfmpeg
tf = TwitchFfmpeg('/home/projects/twitch-ffmpeg/config')
tf.Api.refreshToken()
#!/usr/bin/env python3
# -*- coding: utf-8 -*
from src.TwitchFfmpeg import TwitchFfmpeg
tf = TwitchFfmpeg('/home/projects/twitch-ffmpeg/config')
tf.Api.setStreamTitle('THIS IS A TEST')
#!/usr/bin/env python3
# -*- coding: utf-8 -*
from src.TwitchFfmpeg import TwitchFfmpeg
tf = TwitchFfmpeg('/home/projects/twitch-ffmpeg/config')
tf.Api.setStreamTitle('Dragoi Bola 18')
tf.streamFile('/home/zital/Bideoak/dragoi_bola/db/018.mp4')
#!/usr/bin/env python3
# -*- coding: utf-8 -*
from src.TwitchFfmpeg import TwitchFfmpeg
tf = TwitchFfmpeg('/home/projects/twitch-ffmpeg/config')
tf.Api.setStreamTitle('Dragoi Bola 1,2,3,4,5 atalak')
tf.streamVideoList('/home/zital/scripts/bash/twitch/db.list')
db.list
file '/home/zital/Bideoak/dragoi_bola/db/001.mp4'
file '/home/zital/Bideoak/dragoi_bola/db/002.mp4'
file '/home/zital/Bideoak/dragoi_bola/db/003.mp4'
file '/home/zital/Bideoak/dragoi_bola/db/004.mp4'
file '/home/zital/Bideoak/dragoi_bola/db/005.mp4'
It's a possibility to make and custom filter for ffmpeg creating a file with ffmpeg custom arguments, for example: twitch_ffmpeg_custom.json
[
"/usr/bin/ffmpeg ",
"-safe 0 ",
"-re ",
"-i $1 ",
"-r hd720 ",
"-r 60 ",
"-f flv "
]
IMPORTANT Add space after each argument
Code example:
#!/usr/bin/env python3
# -*- coding: utf-8 -*
from src.TwitchFfmpeg import TwitchFfmpeg
tf = TwitchFfmpeg('/home/projects/twitch-ffmpeg/config')
tf.Api.setStreamTitle('CUSTOM')
tf.stream('/home/zital/scripts/bash/twitch/db.list', 'custom')
-re: real time output -f flv: flv as output container
FPS: 30/60 FPS RESOLUTION: 1280x720 or 1980x1080
To stream optimally is required to encode before as desired params, otherwise the CPU will be working harder.
Example, the video is 1080/60 and we are going to encode at 720/30, first:
ffmpeg -i input.mp4 -s hd720 -r 30 output.mp4