2016-06-16 6 views
0

私はFFMPEGのプロジェクトで作業しています。今は問題が残っています。FFMPEGスケーリングエラーの無効な次元

私がしようとしているのは、pngピクチャをmpegビデオファイルに変換することです。私はすでに画像からインフォーマントを取ることができましたが、何とか私はYUV形式の画像を変換できません。 "0x0-> 0x0は無効なスケーリングディメンション"を返します。ここで

は私のコード'S:

AVFrame *pFrame; 
AVFrame *pFrameYUV; 
pFrame = av_frame_alloc(); 
pFrameYUV = av_frame_alloc(); 
int numBytes;//Groesse des Bildes 
uint8_t *buffer= NULL; 
numBytes=avpicture_get_size(AV_PIX_FMT_RGB24, pCodecCtx->width,pCodecCtx->height); 
buffer=(uint8_t *)av_malloc(numBytes*sizeof(uint8_t)); 

/*avpicture_fill((AVPicture *)pFrameYUV, buffer, AV_PIX_FMT_YUV420P, 
       pCodecCtx->width, pCodecCtx->height);*/ 
av_image_fill_arrays(pFrameYUV->data,pFrameYUV->linesize,buffer,AV_PIX_FMT_YUV420P,pCodecCtx->width,pCodecCtx->height,32); 


struct SwsContext *sws_ctx = NULL; 

AVPacket packet; 
// initialize SWS context for software scaling 
sws_ctx=sws_getCachedContext(NULL,pFrame->width,pFrame->height,AV_PIX_FMT_RGB24,pFrameYUV->width,pFrameYUV->height,AV_PIX_FMT_YUV420P,0,0,0,0); 
pFrameYUV->height= pFrame->height; 
pFrameYUV->width= pFrame->width; 

while (av_read_frame(pFormatCtx,&packet)>=0) 
{ 
    if(packet.stream_index == videoStream) 
    { 
     avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet); 

     if(frameFinished) 
     { 

     sws_scale(sws_ctx, (uint8_t const * const *)pFrame->data, 
      pFrame->linesize, 0, pCodecCtx->height, 
      pFrameYUV->data, pFrameYUV->linesize); 
     printf("%d",pFrameYUV->height); 

    } 
    } 
    av_free_packet(&packet); 
} 

EDIT:

変換した後、私は、OAパケット内のフレームを符号化しようとしたが、パケットの彼のサイズは0 コード

AVPacket pkt; 
av_init_packet(&pkt); 
pkt.stream_index= st->index; 
pkt.data= buffer; 
pkt.size=numBytes; 
int got_pkt; 
test=avcodec_encode_video2(st->codec,&pkt,pFrameYUV,&got_pkt); 

printf("%d",got_pkt); 
です

答えて

0

sws_getCachedContextを呼び出すと、これらの値pFrameYUV->height, pFrame->height, pFrameYUV->width, pFrame->widthは設定されませんでした。

次元が変更されないことを意味しますか?その場合は、sws_getCachedContextの前に設定してください。

pFrameYUV->height = pFrame->height = pCodecCtx->height; 
pFrameYUV->width = pFrame->width = pCodecCtx->width; 
sws_ctx=sws_getCachedContext(NULL,pFrame->width,pFrame->height,AV_PIX_FMT_RGB24,pFrameYUV->width,pFrameYUV->height,AV_PIX_FMT_YUV420P,0,0,0,0); 
+0

私はそれらがav_image_fill_Arraysで設定されていると思いましたか?私はフレームのpix fmtも設定する必要がありますか? –

+0

はい、安全のために 'pix_fmt'も設定するべきです。 – alijandro

+0

ねえ、それは動作します。しかし、スケーリングの後、pFrameYUVのデータフィールドはまだ空です。どうすれば設定できますか? –

関連する問題