Question

I'm trying to capture video using FFmpeg with Node.js, and send it to a browser via websockets for playing using the MediaSource API. What I have so far works in Firefox but doesn't decode properly in Chrome. Apparently, from reading this question I need to use the sample_muxer program to ensure each 'cluster' starts with a keyframe.

Here's the code I'm using:

var ffmpeg = child_process.spawn("ffmpeg",[
    "-y",
    "-r", "30",

    "-f","dshow",           
    "-i","video=FFsource:audio=Stereo Mix (Realtek High Definition Audio)",

    "-vcodec", "libvpx",
    "-acodec", "libvorbis",

    "-threads", "0",

    "-b:v", "3300k",
    "-keyint_min", "150",
    "-g", "150",

    "-f", "webm",

    "-" // Output to STDOUT
]);

ffmpeg.stdout.on('data', function(data) {
    //socket.send(data); // Just sending the FFmpeg clusters works with Firefox's 
                         // implementation of the MediaSource API. No joy with Chrome.

    // - - - This is the part that doesn't work - - -
    var muxer = child_process.spawn("sample_muxer",[
        "-i", data, // This isn't correct...

        "-o", "-" // Output to STDOUT
    ]);

    muxer.stdout.on('data', function(muxdata) {
        socket.send(muxdata); // Send the cluster
    });
});

ffmpeg.stderr.on('data', function (data) {
    console.log("" + data); // Output to console
});

Obviously I'm not piping it correctly and I'm unsure how I would while also including the arguments. Appreciate any help getting this working. Thanks!

Was it helpful?

Solution

The sample_muxer program takes -i argument as the name of file. It cannot read video data as standard input. To view error, you should send error stream from sample_muxer to an error log file.

var muxer = child_process.spawn("sample_muxer",[
    "-i", data, // This isn't correct...
    "-o", "-" // Output to STDOUT
]);

This code will result in error at https://code.google.com/p/webm/source/browse/sample_muxer.cpp?repo=libwebm#240

You can try writing to a file from ffmpeg and then reading that file from sample_muxer. Once that works, try with a FIFO file to pipe data from ffmpeg to sample_muxer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top