<div dir="ltr"><div>Hi all,</div><div><br></div><div>I'm trying to get hardware-accelerated decoding with VideoToolbox working on iOS. I'm using FFmpeg 3.2, and I'm trying to decode a live TV stream (streamed from an HD Homerun) with mpegts & h264.</div><div><br></div><div>I've got a very simple toy program that works on macOS - see attached sources. Poc.cpp/h creates and runs the decoder class, and exposes a function that's callable from C (and Objective-C.) Decoder.cpp/hpp is a simple C++ class which sets up the appropriate FFmpeg contexts and runs a simple packet/frame pump. To enable HWA decoding, I set a custom get_format function on the codec context before opening it; my get_format implementation then watches to see if AV_PIX_FMT_VIDEOTOOLBOX is an available option. If so, it callsĀ av_videotoolbox_default_init on the codec context and returns indicating selection of that format. Again, on macOS this appears to work as expected, that is, my dummy frame handler function gets a steady stream of frames, and CPU usage is much lower than it is without my custom get_format implementation.</div><div><br></div><div>However, the same code fails on iOS, and then crashes. Specifically, the setup code succeeds (or at least, it neither reports nor logs any errors), then I enter my packet pump, and start pumping a few packets from the demux to the codec. The first few times, this gets logged:</div><div><br></div><div><div>[h264 @ 0x101982400] Failed to decode frame (-12911)</div><div>[h264 @ 0x101982400] hardware accelerator failed to decode picture</div></div><div><br></div><div>...and avcodec_receive_frame returns AVERROR(EAGAIN) (not surprising, as the codec buffer starts to fill.) Then after a few rounds of that (and before avcodec_receive_frame actually returns any frames), avcodec_send_packet crashes, EXC_BAD_ACCESS (code=1, address=0x0) with this call stack:</div><div><br></div><div><div>#0<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>0x0000000100274f04 in ff_h264_decode_ref_pic_list_reordering ()</div><div>#1<span class="gmail-Apple-tab-span" style="white-space:pre">      </span>0x000000010027bc58 in ff_h264_decode_slice_header ()</div><div>#2<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>0x000000010023a9c8 in h264_decode_frame ()</div><div>#3<span class="gmail-Apple-tab-span" style="white-space:pre">   </span>0x0000000100596248 in avcodec_decode_video2 ()</div><div>#4<span class="gmail-Apple-tab-span" style="white-space:pre">       </span>0x0000000100597824 in do_decode ()</div><div>#5<span class="gmail-Apple-tab-span" style="white-space:pre">   </span>0x000000010158883c in decoder::run() at /Users/josh/Git/ffmpeg-sandbox/ffmpeg-poc/ffmpeg-poc/decoder.cpp:85</div><div>#6<span class="gmail-Apple-tab-span" style="white-space:pre">  </span>0x0000000101584e0c in ::run_poc() at /Users/josh/Git/ffmpeg-sandbox/ffmpeg-poc/ffmpeg-poc/poc.cpp:42</div></div><div><br></div><div>So, is there something that I need to do differently on iOS vs macOS, or is this a bug, or...?</div><div><br></div><div>Or, if nothing else, can anyone point me to an example of working source code which successfully uses HWA decode on iOS?</div><br clear="all"><div><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div style="color:rgb(0,83,153);font-family:"helvetica neue";font-size:12px;margin:0px"><b><font size="2">Josh Gustafson</font></b></div><div style="font-size:12.8px;font-family:"helvetica neue";margin:0px;color:rgb(82,82,82)"><b><i>Senior Software Engineer</i></b></div><div style="font-family:"helvetica neue";font-size:12px;margin:0px;color:rgb(82,82,82)"><font size="2"><a href="tel:650.209.0952" value="+16503837332" style="color:rgb(17,85,204)" target="_blank">650.209.0952</a></font></div><div style="font-family:"helvetica neue";font-size:12px;margin:0px;color:rgb(82,82,82)"><font size="2"><a href="http://www.simplecontrol.com/" style="color:rgb(17,85,204)" target="_blank">www.simplecontrol.com</a></font></div><br style="color:rgb(0,83,153);font-family:"helvetica neue";font-size:12px"><span style="color:rgb(0,83,153);font-family:"helvetica neue";font-size:12px"><img height="30" width="200" src="cid:9D448536-0E2A-4BFE-91FD-B7B3BDFA2679"></span><br></div></div></div></div></div>
</div>