Thomas Worth wrote:
Ideally, I'd like to have several threads do this in parallel. If I
can get the disk reads to go fast enough, I could have, for example, 8
threads reading from disk and decoding simultaneously. This means that
avcodec_decode_video2() could be called by one thread while another
thread is still decoding another frame.
If you mean using 8 threads to decode 8 different compressed streams, then that works correctly now. Decodes overlapping-in-time are fine, as long as different AVCodecContexts are being used. In my experience, avcodec_decode_video2() is thread-safe, at least for any FFmpeg version from the last 6 months.
[...]

If there's a way to first read from disk first into a unique buffer
and then pass just that buffer to avcodec_decode_video2(), that would
solve the problem because there would be no possibility that multiple
reads would pull from this same shared object. I would be OK with
having something like 8 frames worth of memory (for 8 threads) tied up
for decoding. So basically, I just need to direct
avcodec_decode_video2() to one of the 8 unique buffers I've allocated
(or more, depending on how many threads I've specified).
No, what you propose will not work. It sounds like you're thinking that your app passes a pixel buffer into avcodec_decode_video2() to be filled in, but this is not how this function call works.

Your app passes in an AVFrame, and the decoder fills in the fields of the AVFrame. AVFrame.data[0] is a pointer to pixel data. That pixel data lives in one of many buffers hidden in the AVCodecContext. So, through AVFrame.data[0], your app gets back a pointer to pixel data that it is allowed to copy, but the AVCodecContext keeps ownership of the underlying buffer. The decoder will free the hidden buffer when it makes sense to free it, outside your app's control.

The rule is that the AVFrame.data[0] pointer is only good until the next time you call avcodec_decode_video2() with the matching AVCodecContext.

--
Mike Scheutzow

_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to