avcodec_decode_video2方法崩潰,當我嘗試分配avpkt.size。當我將它設置爲0時,它可以工作,但它不會解碼任何內容(返回值爲0)。我缺少什麼東西,或者有什麼值必須分配給avpklt.size?我想解碼在istream參數中編碼的一個Frame。avcodec_decode_video2崩潰時,當avpkt.size分配
謝謝
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;
}
好的我發現了這個錯誤..我需要明顯地使用avcodec_find_decoder(CODEC_ID_WMV1);)+嚴重的其他noob錯誤,比如outstream分配等。 – vacetahanna