将AVPicture转换为数组<unsigned char =“”>

时间:2016-10-25 07:00:11

标签: arrays ffmpeg c++-cli

我使用ffmpeg在c ++中提取视频帧。我希望在c ++中获得array<unsigned char>帧,但我从此行代码中获得AVFrame

avcodec_decode_video2(codecContext, DecodedFrame, &gotPicture, Packet);

所以我使用sws_scaleAVFrame转换为AVPicture,但我也无法从框架中获得array<unsigned char>

sws_scale(convertContext, DecodedFrame->data, DecodedFrame->linesize, 0, (codecContext)->height, convertedFrame->data, convertedFrame->linesize);

那么有人可以帮助我将AVFrameAVPicture转换为array<unsigned char>吗?

1 个答案:

答案 0 :(得分:1)

AVPicture已弃用。转换为它是没有意义的,因为AVFrame是它的替代品。

如果我正确理解了这个问题,那么您正尝试将原始图片像素值设为std::array。如果是这样,只需将AVFrame avcodec_decode_video2(codecContext, DecodedFrame, &gotPicture, Packet); // If you need rgb, create a swscontext to convert from video pixel format sws_ctx = sws_getContext(DecodedFrame->width, DecodedFrame->height, codecContext->pix_fmt, DecodedFrame->width, DecodedFrame->height, AV_PIX_FMT_RGB24, 0, 0, 0, 0); uint8_t* rgb_data[4]; int rgb_linesize[4]; av_image_alloc(rgb_data, rgb_linesize, DecodedFrame->width, DecodedFrame->height, AV_PIX_FMT_RGB24, 32); sws_scale(sws_ctx, DecodedFrame->data, DecodedFrame->linesize, 0, DecodedFrame->height, rgb_data, rgb_linesize); // RGB24 is a packed format. It means there is only one plane and all data in it. size_t rgb_size = DecodedFrame->width * DecodedFrame->height * 3; std::array<uint8_t, rgb_size> rgb_arr; std::copy_n(rgb_data[0], rgb_size, rgb_arr); 字段转储到其中。

var express = require('express');
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
console.log(__dirname);
app.use(express.static(__dirname+'/public'));
app.get('/', function(req, res){
  res.sendfile(__dirname+'/public/registration.html');
});

io.on('connection', function(socket){

    socket.on('registration',function(msg){
    console.log('user data'+ msg);
  });
});

http.listen(3000, function(){
  console.log('listening on *:3000');
});