Hardware videotoolbox encoding does not work in some Mac

When I doing hardware videotoolbox encoding, it always failed in some mac machines. But it works in some other mac machines. I can not find the different of the machines.

In problem machine, when I tried use ffmpeg executable do h265/h264 hardware encoding directly, it has issue. tried use ffmpeg executable h265/h264 software encoding, it has no issue.

The error is like this: ./ffmpeg -f rawvideo -s 352x288 -pix_fmt yuv420p -i akiyo_cif.yuv -c:v hevc_videotoolbox test.mp4 [rawvideo @ 0x7f80b9704780] Estimating duration from bitrate, this may be inaccurate Input #0, rawvideo, from 'akiyo_cif.yuv': Duration: 00:00:12.00, start: 0.000000, bitrate: 30412 kb/s Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 352x288, 30412 kb/s, 25 tbr, 25 tbn Stream mapping: Stream #0:0 -> #0:0 (rawvideo (native) -> hevc (hevc_videotoolbox)) Press [q] to stop, [?] for help [hevc_videotoolbox @ 0x7f80ba905640] Error encoding frame: -12905 [hevc_videotoolbox @ 0x7f80ba905640] popping: -542398533 [vost#0:0/hevc_videotoolbox @ 0x7f80ba9052c0] Error initializing output stream: Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height Conversion failed!

Did more tests in problem machine and Check the processes in mac. The first launched VTEncoderXPCService process always has something wrong. The later launched VTEncoderXPCService can work as expected

Hi Apple Expert, Do you know what's the reason is? Thanks.

from VideoToolbox/VTErrors.h kVTPixelTransferNotSupportedErr = -12905, // c.f. -8961

and in CarbonCore/MacErrors.h, -8961 is called noCodecErr.

Are you saying that if you make a second request it always works?

Thanks for your reply.

Yes. But it has a pre-condition, the first request is still in progress, which means there is the first process is continually encoding H265 frames using hardware encoder.

Let me illustrate it more clearly with two cases.

Case A:

  1. Launch a process A do H265 hardware encoding. (encoding failure)
  2. process A still do encoding, Launch another process B to do the same thing, process B works as expected.
  3. Exit process A, Process B still can work as expected.

Case B:

  1. Launch a process A do H265 hardware encoding. (encoding failure)
  2. process A exited, Launch another process B to do the same thing, process B also encoding failure.

I think your next step is to compile the binaries for ffmpeg so you can step through the code in videotoolboxenc.c and gain a better understanding of what is different between the failure and success case.

On which machine is it failing? Did you try with an higher resolution video?

Hardware videotoolbox encoding does not work in some Mac
 
 
Q