[Libav-user] Separating decoding and processing frames into threads
Nikita Vaňků
vanku.nikita at gmail.com
Tue Apr 25 11:52:43 EEST 2023
I appreciate your interest!
> Hardware frames often resize in the memory of the device or its driver.
> Therefore, only a limited number of them can exist at a time. It seems
> your queue is too large for that.
I have tried to resize the queue to an absolute minimum, yet the
problem persisted in various OS and devices.
> You probably need to copy the frame at least once.
I do not understand what exactly you mean
I ran the SW decoder for several hours and noticed no memory leak.
Out of frustration, I tried to minimize the code, I now know that if I
keep reusing a single frame (allocate it once and never free it) the
problem disappears. But as soon as I try to allocate new frames for
each decoded frame while using HW acceleration I start running into
these issues.
The code for this is very simple on the decoding side I simply:
AVFrame* frame = av_frame_alloc();
ret = avcodec_receive_frame(m_codecContext, frame);
av_packet_unref(m_packet);
if (ret == AVERROR(EAGAIN)) {
av_frame_free(&frame);
continue;
} else if (ret == AVERROR_EOF) {
av_frame_free(&frame);
break;
} else if (ret != 0) {
av_frame_free(&frame);
break;
}
I skipped the processing and just call av_frame_free on the processing
side. The queue for this purpose is a size of 4. Errors in linux
differs from those experienced on Windows
[h264 @ 0x7f93f00de580] get_buffer() failed
[h264 @ 0x7f93f00de580] decode_slice_header error
[h264 @ 0x7f93f00de580] no frame!
Also I forgot to mention I'm using FFMpeg 5.1.3.
Regards,
Nikita
More information about the Libav-user
mailing list