Skip to content

Instantly share code, notes, and snippets.

@send2moran
Forked from Marak/transcodeVideo.js
Last active August 29, 2015 14:15
Show Gist options
  • Save send2moran/61bd8cbbbec20a932a60 to your computer and use it in GitHub Desktop.
Save send2moran/61bd8cbbbec20a932a60 to your computer and use it in GitHub Desktop.
Hook for transcoding video streams using FFMpeg
var Transcoder = require('stream-transcoder');
module['exports'] = function transcodeVideoStream (hook) {
var readStream = hook.open(hook.params.video);
hook.debug('Opening read stream to video');
hook.res.writeHead(200, {
"Content-Type": "video/mp4"
});
hook.debug('Set Content-Type to video/mp4')
// The transcoder API is FFMpeg, see: https://www.ffmpeg.org/
var trans = new Transcoder(orgPath)
.videoCodec('h264')
.format('mp4')
.custom('strict', 'experimental')
.on('finish', function() {
console.log('finished transcoding');
})
.on('error', function(err) {
console.log('transcoding error: %o', err);
});
trans.stream().pipe(res);
};
module['exports'].schema = {
"video": {
"type": "string",
"default": "https://api-integration-c.whipclip.com/v1/media/video/types/hls.m3u8?mediaContext=a.dXNfYWJjX3Rlc3R8MTQyMzExMTIxNjAwMHwxNDIzMTExMjc2MDAwfDE0MjM0OTE3Mjc2NTI.268657b9717895dfdc0b025f148f1f3715bd001f5f49f755da37aa787db5a3c2&startOffset=0&endOffset=60000&deviceId=SKGIfPiz0mdRK8TkHtvM",
"required": true
},
"maxHeight": {
"type": "number",
"default": 320,
"required": true
},
"maxWidth": {
"type": "number",
"default": 240,
"required": true
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment