[Ffmpeg-devel] saving frames - which function to use

sanjay kumar gupta sanjay417
Fri Feb 23 06:49:28 CET 2007


  Hi mark,
use like this to save image in ppm format:
-------------------------
	// Read frames and save frames to disk
	i=0;
	while(av_read_frame(pFormatCtx, &packet)>= 0)
	{
		// Is this a packet from the video stream?
		if(packet.stream_index==videoStream)
		{
			// Decode video frame
			avcodec_decode_video(pCodecCtx, pFrame, &frameFinished, 
					packet.data, packet.size);

			// Did we get a video frame?
			if(frameFinished)
			{
				// Convert the image from its native format to RGB
				img_convert((AVPicture *)pFrameRGB, PIX_FMT_RGB24, 
						(AVPicture*)pFrame, pCodecCtx->pix_fmt, pCodecCtx->width, 
						pCodecCtx->height);
				// Save the frame to disk as well as display it to SDL surface.
				SaveFrame(pFrameRGB, pCodecCtx->width, pCodecCtx->height,i++);
				SDL_Delay(50);	
			}

		}

		// Free the packet that was allocated by av_read_frame
		av_free_packet(&packet);
	}

void SaveFrame(AVFrame *pFrame, int width, int height, int iFrame)
{
	FILE *pFile;
	char szFilename[32];
	unsigned char *buffer;	
	int  y;
	uint8_t *pixel=NULL;

	// Open file
	sprintf(szFilename, "frame%d.ppm", iFrame);
	pFile=fopen(szFilename, "wb");
	// Write header to each file (it is format of header for ppm)
	fprintf(pFile, "P6\n%d %d\n255\n", width, height);
	// Write pixel data
	for(y=0; y<height; y++)
		fwrite(pFrame->data[0]+y*pFrame->linesize[0], 1, width*3, pFile);
	// Close file
	fclose(pFile);
}
-----------------------------------


On Fri, 23 Feb 2007 mark wrote :
>Hi
>I decode video using this function:
>
>   avcodec_decode_video( m_vDec, m_decodedPicture,
>                                              &got_picture, (uint8_t*)
>samplePtr,
>                                              sampleLength );
>
>I want to save each m_decodedPicture to an image file. Can you tell
>which function I should use for this?
>Thanks a lot!
>mark
>_______________________________________________
>ffmpeg-devel mailing list
>ffmpeg-devel at mplayerhq.hu
>http://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel




More information about the ffmpeg-devel mailing list