谢谢
int DecodeVideoFFMPEG::dec_main( void *istream, void *outstream, int width, int height )
{
avcodec_register_all();
int got_picture;
int BYTEPIC = width * height * 3;
AVCodecContext *d;
AVCodec *decodec = avcodec_find_encoder(CODEC_ID_WMV1);
d = avcodec_alloc_context3(decodec);
d->codec_id = CODEC_ID_WMV1;
d->pix_fmt = PIX_FMT_YUV420P;
d->width = width;
d->height = height;
d->time_base.num = 1;
d->time_base.den = 25;
int status = avcodec_open2(d, decodec, NULL);
AVFrame *picture2 = alloc_picture420P(width, height);
AVFrame *pictureBGR = alloc_pictureBGR24(width, height);
AVPacket avpkt;
av_init_packet(&avpkt);
unsigned char *image = new unsigned char[BYTEPIC];
memcpy(image, istream, BYTEPIC);
avpkt.data = image;
avpkt.size = BYTEPIC; // ????
//prepare for changing color space
struct SwsContext *img_convert_ctx2 =
sws_getContext(width, height, PIX_FMT_YUV420P,
width, height, PIX_FMT_BGR24,
SWS_BICUBIC, NULL, NULL, NULL);
int len = avcodec_decode_video2(d, picture2, &got_picture, &avpkt);
sws_scale(img_convert_ctx2, picture2->data, picture2->linesize, 0, height, pictureBGR->data, pictureBGR->linesize);
outstream = pictureBGR->data;
return len;
}
答案 0 :(得分:0)
您正在将缓冲区传递给不包含编码视频的avcodec_decode_video2()。这是一个完全无效的操作。