[FFmpeg-devel] multiple stream detection in libavformat vs. thread locking

Jindrich Makovicka makovick
Sun Dec 7 20:31:14 CET 2008


I ran into a problem with detecting multiple streams from a network
using av_find_stream_info(). Because this function internally calls
avcodec_open() and avcodec_close(), it cannot be run in multiple
threads. On the other hand, putting global lock around the whole
function is inefficient, as the autodetection takes some time for a
network stream (about one second in my case), and the delay until all
streams are playing is just too long.

I currently have a working quick-and-dirty solution, but would like to
know if there is some approach acceptable for the upstream. I think
mainly of adding functions like
avcodec_enter_critical_section/avcodec_leave_critical_section to the
thread API wrappers, and calling them at avcodec_open/close

By the way, googling "insufficient thread locking around
avcodec_open/close" suggests that solving this issue could make quite
a lot people happier.

Jindrich Makovicka

More information about the ffmpeg-devel mailing list