1

I have a webrtc video stream coming from the client to the server. I want to convert the stream into jpg images, but not save any image to disk (work from memory only). Currently I'm using this command line function (called from node js):

var ops = [
'-i', '-',
'-f', 'image2',
'-vcodec', 'mjpeg',
'-b:v', '1000k',
'-q:v', '2',
'-s', '640x480',
'-updatefirst', '1',
'-',
];

ffmpeg_process = cp.spawn('ffmpeg', ops);

ffmpeg_process.stdout.on('data', function(chunk) {
var size = chunk.length
data += chunk
if (((chunk[size - 2] << 8) + chunk[size - 1]) === 65497)  //EOF 
{
   if (data) 
  {
lib.addFrame(Buffer(data).toString('base64')) //full jpg data
  }
  data = ''
}
};

However, some of the output jpg images are corrupt. this is because sometimes the buffer contains only part of a jpg image data.

What are the correct params needed to be passed to ffmpeg for correctly creating the jpg images?

1
  • Your pramaters are correct. A pipe is buffered and can’t promise an object is delivered atomically. You must process the stream to determine what it contains.
    – szatmary
    Jan 2, 2018 at 15:51

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.