Skip to content

Instantly share code, notes, and snippets.

@toshvelaga
Last active June 19, 2025 09:49
Show Gist options
  • Save toshvelaga/df2daecf212efc6d86380891108a884d to your computer and use it in GitHub Desktop.
Save toshvelaga/df2daecf212efc6d86380891108a884d to your computer and use it in GitHub Desktop.
stream to twitch and youtube RTMP destinations using FFmpeg
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