Albert
Albert

Reputation: 68240

ffmpeg: which functions are multithreading safe?

I have read (somewhere, don't remember and find it anymore right now - maybe the question would be obsolete for me otherwise anyway) that some FFmpeg functions are not safe to call from multiple threads at the same time.

FFmpeg itself is not multithreading safe in the sense that you shouldn't call av_read_frame or avcodec_decode_audio4 on the same context from different threads at the same time - but that is mostly obvious.

But for example, it seems like avformat_find_stream_info even on separate contexts is not safe to be called from different threads at the same time. So to make that safe, you would need a global mutex.

Is there a list of the functions which are not safe?

Upvotes: 10

Views: 6614

Answers (1)

Albert
Albert

Reputation: 68240

Some discussions I found: here or here

From what I have found so far, it seems like only avcodec_open and avcodec_close are not thread safe.

However, the correct solution seems to be to use av_lockmgr_register to register a mutex handler in FFmpeg which is then called automatically by FFmpeg at the needed places. See here or here. Also Chrome does that, see here.

Upvotes: 12

Related Questions