[Libav-user] Re-using the same AVInputContext and AVIOContext in calls to avformat_find_stream_info

Daniel Kamil Kozar dkk089 at gmail.com
Mon Dec 15 20:10:02 CET 2014

I'm using doc/examples/avio_reading.c for experimenting with the libav
API. I wanted to check if it's possible to use the same AVInputContext
and AVIOContext for two calls to avformat_find_stream_info. However,
after putting two new calls to avformat_find_stream_info and
av_dump_format after the first two ones that are already in the
source, I'm getting a segmentation fault in avformat_find_stream_info.
gdb shows the following backtrace :

#0  0x00007ffff7b3e81a in has_codec_parameters (st=0x602fc0,
errmsg_ptr=0x0) at libavformat/utils.c:2559
#1  0x00007ffff7b40734 in avformat_find_stream_info (ic=0x602040,
options=0x0) at libavformat/utils.c:3060
#2  0x0000000000400f02 in main (argc=2, argv=0x7fffffffe918) at

Line 2559 of libavformat/utils.c resolves to 'if
(st->info->found_decoder >= 0 && avctx->pix_fmt == AV_PIX_FMT_NONE)'.
I'm using a custom-compiled ffmpeg 2.5, but the very same things
happen with my distribution's (Arch Linux) libraries.

The question is : is it allowed to issue two calls to
avformat_find_stream_info with the same input structures? I'm asking
since the documentation doesn't specify anything about this not being
allowed, and it does seem kind of weird to be forced to destroy the
old structures and allocate new ones describing pretty much the same
stream. If I recreate the structures, then everything works just fine.
I just wanted to know if recreating them is the expected usage of the
API. The second call to avformat_find_stream_info fails regardless of
whether the first one was successful or not.

Thank you in advance for any help,

More information about the Libav-user mailing list