Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone, I'm working on a Project in FFMPEG, and right now i'm stuck on a Problem.

What i am trying to do is, convert a png pic in to a mpeg Video file. I've already managed to take informatin from the Picture, but somehow i cannot convert the Picture in YUV Format. It returns "0x0->0x0 is invalid scaling dimensions".

Here'S my code:
C++
VFrame *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);
}
pre>

What I have tried:

I've tried the old functions, but it does not work either
Posted
Comments
CPallini 16-Jun-16 2:55am    
Well, the message is clear, at least. Did you debug the code to verify it?
Member 11549235 16-Jun-16 3:16am    
DEbug does not work. It's the reply when i start without debug. I have no idea why there's nothing in pFrameYUV
KarstenK 16-Jun-16 5:48am    
Check the input data and make some output of the dimensions when you run.
Michael Haephrati 21-Sep-17 14:42pm    
Just so you know, MPEG is not open source and require a license from http://www.mpegla.com/main/programs/M2/Pages/Agreement.aspx . We got one several years ago. It is free unless you sell thousands copies of your software.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900