livestreaming to twitch using ffmpeg
See original GitHub issueHi there. I have a webRTC application that I am trying to add livestreaming to. I am trying to set up a small test where I can livestream to twitch using puppeteer-stream and ffmpeg. It seems as if I am only sending data to twitch right before the script ends. Do you know what I am doing wrong in the code below? Thank you!
const { launch, getStream } = require('puppeteer-stream')
const fs = require('fs')
const { exec } = require('child_process')
require('dotenv').config()
// puppeteer stream + FFmpeg example: https://github.com/Flam3rboy/puppeteer-stream/blob/main/examples/ffmpeg.js
const ffmpegConfig = (twitch) => {
return `ffmpeg -i - -v error -c:v libx264 -preset veryfast -tune zerolatency -c:a aac -strict -2 -ar 44100 -b:a 64k -y -use_wallclock_as_timestamps 1 -async 1 -bufsize 1000 -f flv ${twitch}`
}
let twitch =
'rtmp://dfw.contribute.live-video.net/app/' + process.env.TWITCH_STREAM_KEY
async function test() {
const browser = await launch({
executablePath:
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
defaultViewport: {
width: 1920,
height: 1080,
},
})
const page = await browser.newPage()
await page.goto('https://www.youtube.com/watch?v=dQw4w9WgXcQ')
const stream = await getStream(page, {
audio: true,
video: true,
frameSize: 1000,
})
console.log('recording')
// this will pipe the stream to ffmpeg and convert the webm to mp4 format
const ffmpeg = exec(ffmpegConfig(twitch))
ffmpeg.stderr.on('data', (chunk) => {
console.log(chunk.toString())
})
stream.pipe(ffmpeg.stdin)
setTimeout(async () => {
await stream.destroy()
stream.on('end', () => {
console.log('stream has ended')
})
ffmpeg.stdin.setEncoding('utf8')
ffmpeg.stdin.write('q')
ffmpeg.stdin.end()
ffmpeg.kill()
console.log('finished')
}, 1000 * 40)
}
test()
Right before the script ends loading indicator shows up

Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Stream to twitch via ffmpeg - API - Twitch Developer Forums
But then, just today… it stopped and i always got a I/O Error from ffmpeg as soon as it came to streaming to...
Read more >Streaming a stream from website to Twitch with FFMPEG
Is it possible to stream a website with a livestream (i.e. ip-camera) via FFMPEG to Twitch? If yes, does anybody know how to...
Read more >Streaming an MP4 to Twitch and YouTube with FFMPEG
In this post, I discuss how I was able to 'stream' an MP4 LIVE to YouTube and Twitch using FFMPEG.
Read more >Stream to Twitch with FFMPEG - YouTube
This is a live stream recording about how I figured out how to share my screen to Twitch with only FFMPEG. ffmpeg -f...
Read more >Streaming to twitch.tv - ArchWiki
Twitch Broadcast Requirements ... From Twitch.tv support: Video Requirements. Codec: H.264 (x264); Mode: Strict CBR; Keyframe Interval: 2 seconds.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
ok awesome, thanks so much! Both our configs seem to be working but yours seems to be producing more reliable results i think. If I can get this to work in production I’ll right another blog post about it 😃.
It works when I change the ffmpeg config to:
and remove the frameSize