简体   繁体   English

ffmpeg将流转换为jpg缓冲区而不保存磁盘

[英]ffmpeg convert stream to jpg buffer without saving do disk

I have a webrtc video stream coming from the client to the server. 我有一个从客户端到服务器的webrtc视频流。 I want to convert the stream into jpg images, but not save any image to disk (work from memory only). 我想将流转换为jpg图像,但不将任何图像保存到磁盘(仅从内存工作)。 Currently I'm using this command line function (called from node js): 当前,我正在使用此命令行功能(从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. 但是,某些输出的jpg图像已损坏。 this is because sometimes the buffer contains only part of a jpg image data. 这是因为有时缓冲区仅包含jpg图像数据的一部分。

What are the correct params needed to be passed to ffmpeg for correctly creating the jpg images? 为了正确创建jpg图像,需要传递给ffmpeg的正确参数是什么?

I don't remember well but shinobiCE has some code about this situation. 我不太记得,但shinobiCE对此情况有一些代码。 You can have a look. 你可以看看 It's a huge project so good luck! 这是一个巨大的项目,祝您好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM