在 Mac M1 CPU 上编译ffmpeg,并支持 opencl和videotoolbox

目的:希望能使用上 mac 版纯 gpu 加速转码.

通过 brew 安装的 ffmpeg 默认支持了 videotoolbox,但都不支持 opencl.

参数是这样的:

configuration: --prefix=/usr/local/Cellar/ffmpeg/5.0 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox


通过 https://trac.ffmpeg.org/wiki/CompilationGuide/macOS 的这文章是可以很顺利编译成功的.

configuration: --prefix=/usr/local/ffmpeg-videotoolbox --enable-gpl --enable-nonfree --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libopus --enable-libxvid --samples=fate-suite --enable-opencl --enable-videotoolbox

我在这里其实卡在:

ERROR: videotoolbox requested, but not all dependencies are satisfied: corefoundation coremedia corevideo

而在网上找了一些,并没有答案.

后来发现其实是在 xcode 里没有点上这里,如图:


后来这一步是成功了,也成功编译了包含 videotoolbox,opencl 的版本的 ffmepg.
但是还是无法运行之前通过gpu 把 hdr 内容转成 sdr的命令.
原来的命令是这样的:

/usr/local/ffmpeg/ffmpeg  -hwaccel cuda  -init_hw_device opencl=ocl -filter_hw_device ocl -extra_hw_frames 3 -c:v hevc_cuvid -resize 3840x2080 -accurate_seek  -ss 585 -i "imputfile"  -t 15 -max_muxing_queue_size 9999 -force_key_frames "expr:gte(t,n_forced*15)" -vf "hwupload,tonemap_opencl=tonemap=mobius:param=0.01:desat=0:r=tv:p=bt709:t=bt709:m=bt709:format=nv12,hwdownload,format=nv12"  -map 0:0 -c:v h264_nvenc -output_ts_offset 585 "1.ts" -y
改成下面红色

/usr/local/ffmpeg-videotoolbox/bin/ffmpeg -hwaccel videotoolbox -init_hw_device opencl=gpu:0.0 -filter_hw_device gpu -extra_hw_frames 3 -c:v h264_videotoolbox -accurate_seek -ss 585 -i "input.file" -t 15 -max_muxing_queue_size 9999 -force_key_frames "expr:gte(t,n_forced*15)" -vf "hwupload,tonemap_opencl=tonemap=mobius:param=0.01:desat=0:r=tv:p=bt709:t=bt709:m=bt709:format=nv12,hwdownload,format=nv12" -map 0:0 -c:v h264_videotoolbox -output_ts_offset 585 "1.ts" -y



报:
[AVHWDeviceContext @ 0x7fd14c705180] OpenCL error: [CL_IMAGE_FORMAT_NOT_SUPPORTED] : OpenCL Error : clCreateImage failed: The specified format is not supported for the specified image type.
[AVHWFramesContext @ 0x7fd14d0888c0] Failed to create image for plane 0: -10.
Error while filtering: Cannot allocate memory
Failed to inject frame into filter network: Cannot allocate memory
Error while processing the decoded data for stream #0:0


 

暂时没有方向了.

结果:

通过:

/usr/local/ffmpeg-videotoolbox/bin/ffmpeg -decoders |grep videotoolbox

发现 mac 下并不支持纯 gpu 解码

./congure --list-decoders

也没有发现有支持

目前看来无解了,mac 下相关编码并不成熟.

一些有用的命令记录:

/usr/local/ffmpeg-videotoolbox/bin/ffmpeg -v debug -init_hw_device opencl

/usr/local/ffmpeg-videotoolbox/bin/ffmpeg  -hwaccel videotoolbox  -init_hw_device opencl=gpu:0.1 -filter_hw_device gpu



查看程序是否是 x86还是 arm 架构

lipo -archs ffmpeg


评论

此博客中的热门博文

在南京见到的农民工午饭情景

购买了iacces for iPad