[FFmpeg-devel] Reopenning streams with av_open_input_file

Ratin ratin3 at gmail.com
Thu Jan 12 03:28:47 CET 2012

I have a query regarding re-openning streams but not overwrite whats
already has been populated inside AVFormatContext. Lets say we have
opened a file stream  (could be an RTMP stream) and we successfully
populated the format context and the codec context
(pFormatCtx->streams[streamIndex]->codec) within it are going to be
used elsewhere. Then at some point connection breaks and we want to
re-connect to the stream but we want to reuse the format context from
before keeping most of the data within pFormatCtx intact (specially
the same pointer pFormatCtx->streams[streamIndex]->codec needs to
remain allocated). What will be the consequence of doing the
following, i.e. could there possibly any memory leaks?

          if (bTimeout)
                if (pFFContext->pFormatCtx) av_close_input_file(

                AVFormatParameters fp;

pSourceInfo->url, NULL, 0, &fp )!=0)
                    printf("\nCould not open url %s\n",  pSourceInfo->url);


   I know that there is a NULL check and if pFFContext->pFormatCtx
that it wont reallocate if a non-NULL pointer is provided.

More information about the ffmpeg-devel mailing list