Search code examples
macosffmpegvideo-toolbox

How encode video using hevc/h265 codec via ffmpeg OSX


I try to encode video using hevc codec

./ffmpeg -i 1234.mp4   -vcodec hevc_videotoolbox -vb 1000k  -acodec aac -ab 192k   -sn  2.mp4

error:

[hevc_videotoolbox @ 0x7fc681813a00] Error: cannot create compression session: -12908
[hevc_videotoolbox @ 0x7fc681813a00] Try -allow_sw 1. The hardware encoder may be busy, or not supported.
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height

i try change bitrate, width, height, error still exist is it possible encode video on my macbook air 2015? is videotoolbox can't use my old GPU and its possible on newest macbooks?


Solution

  • I have the same question recently, I found this when I was looking for answers:

    enter image description here Screenshot from this pdf: enter link description here

    It's possible that old mac doesn't support HEVC hardware acceleration natively, I don't have a new mac to test if ffmpeg has anything related to it, maybe someone whose mac has 6th Gen CPU can help you address the problem.

    Edit: I tested following code on the latest 2018 mbp and it worked.

    ffmpeg -i VIDEO_PATH -vcodec hevc_videotoolbox -tag:v hcv1 OUT_PATH
    

    The size of the hevc_videotoolbox-encoded video#1 is smaller than the original test file(h264) but larger than libx265-encoded video#2 (using default parameters).

    Unexpectedly, the quality of video#1 is much worse than that of the original, whereas video#2 seems untouched. Besides, hevc_videotoolbox doesn't support -crf option, so I'm still stick to libx265, even though it is really slow.