[Libav-user] Calling avcodec_decode_video2 fails to get picture in multithreaded application

עופר בר ofer.fly at gmail.com
Thu Dec 26 14:49:02 CET 2013


Hi all,

I have a multithreaded C# application on windows 7 that displays multiple
video streams from a server.
The way it works is that each stream is connected to the server to get the
frames, and a dedicated thread (one per stream) is decoding the frame using
ffmpeg and then rendering.

There is a wrapper class that calls ffmpeg that was written in managed
C++/CLI (vs 2010).
The frame memory is allocated in unmanaged code using
Marshal.AllocHGlobal().

The problem is that when having multiple threads (above 8)
calling avcodec_decode_video2  returns zero in gotPicture return parameter.
As a result, there's no frame to display.

I enabled debug logging and noticed that this happens only in the last 4
threads that were added.
The error log says: "no picture ooo" (Out Of Order debug log in h264.c.

I verified that the frames are coming from the server at the right order by
checking the timestamp on each one.

I tried to add a lock around the call to avcodec_decode_video2   but that
didn't change anything.

Is this a threading issue with avcodec_decode_video2 or h264?
any idea what am I doing wrong or how can this be fixed?

Running on Windows 7 64 bit.
Using zeranoe ffmpeg build from last week.
Mainly using H264 decoding but I also saw this error when using MPEG4.

Many thank!

Ofer Bar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20131226/0b68d7b8/attachment.html>


More information about the Libav-user mailing list