Skip to content

Instantly share code, notes, and snippets.

@thilo
Created September 18, 2012 08:54
Show Gist options
  • Save thilo/3742120 to your computer and use it in GitHub Desktop.
Save thilo/3742120 to your computer and use it in GitHub Desktop.
Simple video conversion and streaming with node.js
var http = require('http')
ffmpeg = require('fluent-ffmpeg');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'video/x-flv'});
var pathToMovie = '/public/video.mp4';
var proc = new ffmpeg({ source: pathToMovie, logger: true, nolog: false })
.toFormat('flv')
.updateFlvMetadata()
.withSize('320x?')
.withVideoBitrate('512k')
.withVideoCodec('libx264')
.withFps(24)
.withAudioBitrate('96k')
.withAudioCodec('libfaac')
.withAudioFrequency(22050)
.withAudioChannels(2)
// The FFmpeg's "-re" flag means to "Read input at native frame rate. Mainly used to simulate a grab device."
.addOptions([ '-preset ultrafast', '-re' ])
.writeToStream(res, function(retcode, error){
console.log(error);
console.log('file has been converted succesfully');
});
}).listen(8181, '127.0.0.1');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment