2016-06-16 5 views
0

저는 FFMPEG 프로젝트에서 작업하고 있습니다. 지금 당장 문제가 있습니다.FFMPEG 크기 조정 오류 - 잘못된 치수

내가하려는 것은 MPEG 비디오 파일로 PNG 그림을 변환하는 것입니다. 나는 이미 그림에서 정보를 가져올 수 있었지만 어떻게 든 YUV 형식으로 그림을 변환 할 수 없습니다. "0x0-> 0x0은 잘못된 크기 조정 치수입니다"를 반환합니다.

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); 
} 

편집 : 여기

내 코드 년대 변환 후

, 내가 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의 데이터 필드는 여전히 비어 있습니다. 어떻게 설정합니까? –