trenskow/stream-transcoder.js

How to transcode-stream local file via http

Opened this issue · 3 comments

Hi, I'm trying to figure out how could I make the opposite action, I got a bunch of h264 files which I want to watch over http (so, able to play them with a browser, mobiles (mp4), etc...)

var express = require('express'),
    Transcoder = require('stream-transcoder'),
    fs = require('fs');

var app = express();


app.get('/video/', function(req, res, next) {

    var stream = fs.createReadStream('file.mkv');
    res.writeHead(206, { 'Content-Type': 'video/mp4' });

    new Transcoder(stream)
        .videoCodec('h264')
        .videoBitrate(800 * 1000)
        .fps(25)
        .audioCodec('libfaac')
        .sampleRate(44100)
        .channels(2)
        .audioBitrate(128 * 1000)
        .format('mp4')
        .on('finish', function() {
            next();
        })
        .stream().pipe(res);
});

app.listen(5000);

but for some reason the browser only displays the first 2 seconds of the file.

any ideas?, thanks in advance

Hi i have the same problem, have you solved ?

Thanks

nope, at the end, I created a temporary folder where the converted mp4s would be stored, and then allow the folder to be served.

So, the client asks for a file, if it doesn't exist, the stream-transcoder creates a "temporary" mp4 version of the .mkv in that path, so, when the requests comes in again it'll find the file.

see, https://github.com/Alvaroctal/FocaMediaServer/blob/master/web/assets/js/controllers.js#L293, kind a shitty solution, I know.

Ok thanks a lot !