<div dir="ltr">Hello to all!<div><br></div><div>Recently I have faced a problem with JP2K decoding via avcodec_decode_video2. </div><div>Source picture is 6144x4096 with rgb24 pixel format and I am trying to decode it into RGB or YUV frame, but get error code -12 in avcodec_decode_video2 return and error message: </div><div>[jpeg2000 @ 009651E0] Cannot allocate memory</div><div> - in the av_log callback. </div><div><br></div><div>When I am forcing decode to YUV by setting: </div><div>context->pix_fmt = AV_PIX_FMT_YUV420P;</div><div> - the problem repeating.</div><div><br></div><div>Also tried with: </div><div><div>context->thread_count = 200;</div><div>context->thread_type = FF_THREAD_SLICE;</div></div><div> - but nothing changes.</div><div><br></div><div>ffplay.exe and ffmpeg.exe works well. Also, I have got 8Gb RAM.</div><div><br></div><div>Could you, please help me with that problem?</div><div><br></div><div>Sources samples</div><div>// Frame allocation:</div><div><div>if (!m_frame)</div><div>{</div><div>    m_frame.reset(av_frame_alloc(), [](AVFrame* f) { av_frame_free(&f); });</div><div>    if ( !m_frame )</div><div>    {</div><div><span style="white-space:pre">    </span>    return 0;</div><div><span style="white-space:pre">    </span>}</div><div>}</div></div><div><br></div><div><div>// Main decompression call.</div><div>AVPacket pkt;</div><div>av_init_packet(&pkt);</div><div>pkt.data = data;</div><div>pkt.size = static_cast<int>(size);</div><div><br></div><div>// << WORKAROUND >> START</div><div>int ret = avcodec_decode_video2(pCodecCtx, pAVFrame, &getPic, &pkt);</div><div>if (ret < 0)</div><div>{</div><div><span class="" style="white-space:pre">     </span>char buf[AV_ERROR_MAX_STRING_SIZE];</div><div><span class="" style="white-space:pre">        </span>av_strerror(ret, buf, sizeof(buf));</div><div><span class="" style="white-space:pre">        </span>av_log(pCodecCtx, AV_LOG_ERROR, "Error %s\n", av_make_error_string(buf, AV_ERROR_MAX_STRING_SIZE, ret));</div><div>}</div><div>while (!getPic && (ret > 0)</div><div><span class="" style="white-space:pre">    </span>(cID == AV_CODEC_ID_H264 ||</div><div><span class="" style="white-space:pre">        </span>cID == AV_CODEC_ID_HEVC ||</div><div><span class="" style="white-space:pre"> </span>cID == AV_CODEC_ID_MPEG4 ||</div><div><span class="" style="white-space:pre">        </span>cID == AV_CODEC_ID_JPEG2000))</div><div>{</div><div><span class="" style="white-space:pre">      </span>// attempt to get frame from queue</div><div><span class="" style="white-space:pre"> </span>int ret = avcodec_decode_video2(pCodecCtx, pAVFrame, &getPic, &pkt);</div><div><span class="" style="white-space:pre">       </span>av_log(pCodecCtx, AV_LOG_ERROR, "Another attempt to decode.");</div><div><span class="" style="white-space:pre">   </span>if (ret < 0)</div><div><span class="" style="white-space:pre">    </span>{</div><div><span class="" style="white-space:pre">          </span>char buf[AV_ERROR_MAX_STRING_SIZE];</div><div><span class="" style="white-space:pre">                </span>av_strerror(ret, buf, sizeof(buf));</div><div><span class="" style="white-space:pre">                </span>av_log(pCodecCtx, AV_LOG_ERROR, "Error %s\n", av_make_error_string(buf, AV_ERROR_MAX_STRING_SIZE, ret));</div><div><span class="" style="white-space:pre"> </span>}</div><div>}</div></div><div><br></div><div>JP2K sample frame located here</div><div><a href="https://yadi.sk/d/GyRd2t_fqZQ8f">https://yadi.sk/d/GyRd2t_fqZQ8f</a><br></div><div><br></div><div>Tell me if I could help with something else.</div><div><br></div><div>Thanks in advance!</div><div>Nikita</div><div><br></div></div>