0
我想解碼用H264編碼的視頻。我將AVPacket的數據及其大小發送給解碼器代碼。那裏我試圖解碼框架並將其顯示在GUI上。問題是當我解碼幀時,它返回的幀數與幀的大小相同意味着它不解壓縮數據。任何人都可以告訴問題是什麼。我的編碼程序工作正常。libavcodec視頻解碼不起作用
這裏是編碼
static struct SwsContext *img_convert_ctx;
pkt.data = NULL;
pkt.size = 0;
avpicture_fill((AVPicture *)srcFrame, frame,AV_PIX_FMT_BGR24, 640, 480);
if(img_convert_ctx == NULL) {
int w = 640;
int h = 480;
img_convert_ctx = sws_getContext(w, h,
AV_PIX_FMT_BGR24, c->width, c->height, PIX_FMT_YUV420P, SWS_BICUBIC, NULL, NULL, NULL);
if(img_convert_ctx == NULL) {
fprintf(stderr, "Cannot initialize the conversion context!\n");
}
}
sws_scale(img_convert_ctx, srcFrame->data, srcFrame->linesize, 0,480,picture->data, picture->linesize);
fflush(stdout);
picture->pts=counter;
ret = avcodec_encode_video2(c, &pkt, picture, &got_output);
if (ret < 0) {
fprintf(stderr, "Error encoding frame\n");
}
if (got_output) {
vdec.decode_frame(pkt.data ,pkt.size);
av_free_packet(&pkt);
}
解碼器代碼的代碼......
int len ,got_frame;
avpkt.size = data_length;
avpkt.data = frame_buffer;
if(!frame_buffer){
return "frame buffer empty\n";
}
len = avcodec_decode_video2(avctx ,frame ,&got_frame ,&avpkt);
if(len < 0){
return "error while decoding\n";
}
if(got_frame){
static struct SwsContext *img_convert_ctx;
if(img_convert_ctx == NULL) {
img_convert_ctx = sws_getContext(w, h,
PIX_FMT_YUV420P, avctx->width,
avctx->height, PIX_FMT_BGR24,
SWS_BICUBIC, NULL, NULL, NULL);
if(img_convert_ctx == NULL) {
return "Cannot initialize the conversion context!\n";
}
}
j=sws_scale(img_convert_ctx,
frame->data , frame->linesize ,
0, h ,picture->data,
picture->linesize);
if(j==0){
exit(1);
}
我初始化所有其他類似的代碼AVCodecContext和編解碼器到其他方法。
請幫我找到解決方案。
是的,它正在解碼幀,因爲got_frame總是返回1,但是當我試圖在窗口上繪製它時,它總是顯示一個扭曲的幀。 – Imrank
你在看什麼樣的失真?舉個例子,如果可能的話。 – pogorskiy
我在ffmpeg論壇中提出過同樣的問題,鏈接是http://ffmpeg.zeranoe.com/forum/viewtopic.php?f=7&t=949請參閱圖片。 – Imrank