I am struggling with this problem for already a week.
My program captures the MPEG 2 Transpotr Stream from a DVB-S card and saves its 
parts to files in the MPEG Program Stream.

I use libav* functions to demux and mux again data. Video and audio are 
recorded just fine.

The problem is that after about 1 hour of work the program consumes all 
available RAM and the system kills it. This is undesirable, as my program is 
going to work forever in a daemon mode.

The main cycle is general:

AVPacket pkt;

while(!is_exiting()) {
  av_read_frame(input,&pkt);
    [ do something with the packet, 
      possibly write it with av_write_frame() ]
  av_free_packet(&pkt);
}

If I take out calls to av_read_frame and av_free_packet and replace them with a 
simple reading to the static array (the code is following), the program works 
fine and doesn't go over 10Mb of RAM. 

This cycle doesn't drive the program beyond 10Mb of memory consumption.

int thread_proc(void)
{uint8_t buf[10240];
 int mqsize=0;

  linsys_read(this,buf,1024); //is a function reading the data from a device.
  while(!is_exiting()){
    linsys_read(this,buf,10240);
    if(is_exiting())
      break;
  }
  return 0;
}

And another cycle, this eats all available memory.
I have read about issue #361 (https://roundup.mplayerhq.hu/roundup/ffmpeg/
issue361) and have set up before it:

input->pb->is_streamed=1;
input->pb->max_packet_size=188;
input->flags|=AVFMT_NOFILE|AVFMT_FLAG_IGNIDX;
input->max_index_size=1024*50;
input->max_picture_buffer=1024*100;

int thread_proc(void)
{AVPacket pkt;
 AVFormatParameters ap;

   memset(&ap, 0, sizeof(ap));
   ap.prealloced_context=1;
        
   int r=av_open_input_stream(&input,input->pb,"linsys",input->iformat,&ap);
   r=av_find_stream_info(input);
        
   while(!is_exiting()){
    av_read_frame(input,&pkt);
    if( pkt.stream_index < input->nb_streams ){
        int pid=input->streams[pkt.stream_index]->id;
                        
      if ( [if the packet is to be saved] ){  //program eats the memory even if 
this condition is never true
        int r=av_write_frame(m_tasks[i]->output,&pkt); //and this call is never 
executed.
      }
    }
    av_free_packet(&pkt);
  }
}

If I comment out the internal if( ) and leave simply av_read_frame() and 
av_free_packet(), the memory consumption still grows.

My program works on windows and uses the specific API for the DVB-S device, 
provided by the manufacturer. Since that I cannot use ffmpeg command line 
utility and see how it behaves.

To make ffmpeg read data from the device I have defined ByteIOContext, with 
reading function linsys_read, mentioned above.
If I use this function directly (first cycle) it doesn't make memory 
consumption.

I use the following ffmpeg version:

FFmpeg version SVN-r12758, Copyright (c) 2000-2008 Fabrice Bellard, et al.
  configuration: --enable-memalign-hack --enable-static --disable-shared --
disable-stripping --enable-w32threads --extra-cflags=-ggdb3 -D 
EPROTONOSUPPORT=43 --cpu=pentium --cross-prefix=i586-mingw32msvc- --enable-
cross-compile --target-os=mingw32 --prefix=/home/wl/mingw32
  libavutil version: 49.6.0
  libavcodec version: 51.54.0
  libavformat version: 52.13.0
  libavdevice version: 52.0.0
  built on Apr  7 2008 12:34:01, gcc: 4.2.1-sjlj (mingw32-2)

Will now refresh it.

Thanks anyone for attention and help.


_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to