Skip to content

Instantly share code, notes, and snippets.

@niusounds
Created April 19, 2019 04:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niusounds/2fac61c62a0966cdda2211eb2d9fe6f1 to your computer and use it in GitHub Desktop.
Save niusounds/2fac61c62a0966cdda2211eb2d9fe6f1 to your computer and use it in GitHub Desktop.
ffmpeg live transcode test
const express = require('express')
const app = express()
const { spawn } = require('child_process');
const URL = 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_4x3/bipbop_4x3_variant.m3u8'
app
.get('/video.webm', (req, res) => {
res.type('video/webm')
const ls = spawn('ffmpeg', ['-i', URL, '-f', 'webm', '-']);
ls.stdout.pipe(res)
ls.stderr.on('data', (data) => {
console.log(`${data}`);
});
})
.get('/', (req, res) => {
res
.type('html')
.sendFile(__dirname + '/index.html')
})
.listen(3000);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<video src="video.webm" controls></video>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment