[FFmpeg-devel] memory leak in h264 decoder?
tuitfun
tuitfun
Tue Sep 11 16:24:36 CEST 2007
Hello,
I've written a small test program that decodes video and seeks a lot. Its
memory usage keeps going up, as high as 150 MB, until the end of the program
when decoding h264 files . With xvid files, memory usage seems to be constant
from start to finish at less than 50 MB. So, I am suspecting that there might
be
memory leaks in the h264 decoder. With some h264 files, the program couldn't
even run to the end and gave many errors:
[h264 @ 688A7640]get_buffer() failed (-1 559755355 825042976 5F65646F)
[h264 @ 688A7640]decode_slice_header error
[h264 @ 688A7640]no frame!
[h264 @ 688A7640]pic->data[0]!=NULL in avcodec_default_get_buffer
[h264 @ 688A7640]get_buffer() failed (-1 559755355 825042976 5F65646F)
[h264 @ 688A7640]decode_slice_header error
[h264 @ 688A7640]no frame!
[h264 @ 688A7640]pic->data[0]!=NULL in avcodec_default_get_buffer
[h264 @ 688A7640]get_buffer() failed (-1 559755355 825042976 5F65646F)
[h264 @ 688A7640]decode_slice_header error
[h264 @ 688A7640]no frame!
I was testing this program in windows xp with ffmpeg revision 10408 which has
been configured with: ./configure --prefix=/usr/local --enable-memalign-hack
--enable-static --enable-shared --enable-gpl --enable-swscaler
--enable-libamr-nb --enable-libamr-wb --enable-libfaad --enable-libgsm
--disable-encoders --disable-muxers --disable-bsfs --disable-network
--disable-vhook --disable-ffmpeg --disable-ffserver --disable-ffplay
--extra-ldflags=-L/usr/local/lib --extra-cflags=-I/usr/local/include
--disable-protocol=http --disable-protocol=rtp --disable-protocol=tcp
--disable-protocol=udp
If it's something wrong with my test program, please let me know. :)
Thanks a lot,
tuit
// modified from http://www.dranger.com/ffmpeg/tutorial01.c
#include <ffmpeg/avcodec.h>
#include <ffmpeg/avformat.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
AVFormatContext *pFormatCtx;
int i, videoStream;
AVCodecContext *pCodecCtx;
AVCodec *pCodec;
AVFrame *pFrame;
AVPacket packet;
int got_picture;
if(argc < 2) {
printf("Please provide a movie file\n");
return -1;
}
// Register all formats and codecs
av_register_all();
// Open video file
if(av_open_input_file(&pFormatCtx, argv[1], NULL, 0, NULL)!=0)
return -1; // Couldn't open file
// Retrieve stream information
if(av_find_stream_info(pFormatCtx)<0)
return -1; // Couldn't find stream information
// Dump information about file onto standard error
dump_format(pFormatCtx, 0, argv[1], 0);
// Find the first video stream
videoStream=-1;
for(i=0; i<pFormatCtx->nb_streams; i++)
if(pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO) {
videoStream=i;
break;
}
if(videoStream==-1)
return -1; // Didn't find a video stream
AVStream *pStream = pFormatCtx->streams[videoStream];
// Get a pointer to the codec context for the video stream
pCodecCtx=pFormatCtx->streams[videoStream]->codec;
// Find the decoder for the video stream
pCodec=avcodec_find_decoder(pCodecCtx->codec_id);
if(pCodec==NULL) {
fprintf(stderr, "Unsupported codec!\n");
return -1; // Codec not found
}
// Open codec
if(avcodec_open(pCodecCtx, pCodec)<0)
return -1; // Could not open codec
// Allocate video frame
pFrame=avcodec_alloc_frame();
// Read frames
int64_t timestamp = 0;
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, &got_picture,
packet.data, packet.size);
// Did we get a key video frame?
if(got_picture && 1 == pFrame->key_frame) {
fprintf(stderr, "k");
// seek 60 seconds
timestamp += 60.0 / av_q2d(pStream->time_base);
if (av_seek_frame(pFormatCtx, videoStream, timestamp, 0) < 0) { //
failed
break;
}
avcodec_flush_buffers(pCodecCtx);
}
}
// Free the packet that was allocated by av_read_frame
av_free_packet(&packet);
}
// last packet might not get freed
fprintf(stderr, "\n");
// Free the YUV frame
av_free(pFrame);
// Close the codec
avcodec_close(pCodecCtx);
// Close the video file
av_close_input_file(pFormatCtx);
return 0;
}
____________________________________________________________________________________
Shape Yahoo! in your own image. Join our Network Research Panel today! http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7
More information about the ffmpeg-devel
mailing list