Last active
June 19, 2025 09:49
-
-
Save toshvelaga/df2daecf212efc6d86380891108a884d to your computer and use it in GitHub Desktop.
stream to twitch and youtube RTMP destinations using FFmpeg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ffmpeg = child_process.spawn('ffmpeg', [ | |
// the input | |
'-i', | |
'-', | |
// video codec config: low latency, adaptive bitrate, | |
// list of presets: https://trac.ffmpeg.org/wiki/Encode/H.264 | |
// tune zerolatency is good for fast encoding and low-latency streaming | |
// g:v 60 ==> https://www.reddit.com/r/ffmpeg/comments/redaa2/while_livestreaming_to_youtube_using_ffmpeg_i_get/ | |
'-c:v', | |
'libx264', | |
'-preset', | |
'veryfast', | |
'-tune', | |
'zerolatency', | |
'-g:v', | |
'60', | |
// audio codec config: 2 channels of audio, audio sampling rate of 44100, bitrate 64 kbits | |
'-c:a', | |
'aac', | |
'-strict', | |
'-2', | |
'-ar', | |
'44100', | |
'-b:a', | |
'64k', | |
//force to overwrite | |
// this is probably not needed | |
'-y', | |
// used for audio sync | |
'-use_wallclock_as_timestamps', | |
'1', | |
'-async', | |
'1', | |
// output to twitch's RTMP server in an flv container | |
'-f', | |
'flv', | |
twitchRtmpUrl, | |
// video codec config: low latency, adaptive bitrate | |
'-c:v', | |
'libx264', | |
'-preset', | |
'veryfast', | |
'-tune', | |
'zerolatency', | |
// audio codec config | |
'-c:a', | |
'aac', | |
'-strict', | |
'-2', | |
'-ar', | |
'44100', | |
'-b:a', | |
'64k', | |
//force to overwrite | |
'-y', | |
// used for audio sync | |
'-use_wallclock_as_timestamps', | |
'1', | |
'-async', | |
'1', | |
// output to youtube's RTMP server in an flv container | |
'-f', | |
'flv', | |
youtubeRtmpUrl | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment