Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Apple Silicon M1 encoders #196

Closed
singhkays opened this issue Feb 4, 2021 · 19 comments
Closed

Support for Apple Silicon M1 encoders #196

singhkays opened this issue Feb 4, 2021 · 19 comments
Labels
feature request New idea for project

Comments

@singhkays
Copy link

Hi, do you have plans to support the Apple M1 hardware encoders that are supported in ffmpeg? h264_videotoolbox for H.264, hevc_videotoolbox for H.265

These are available in FFmpeg builds
https://trac.ffmpeg.org/wiki/HWAccelIntro#VideoToolbox

@cdgriffith cdgriffith added the feature request New idea for project label Feb 4, 2021
@cdgriffith
Copy link
Owner

I do not have a Mac even for testing, so nothing I could well vet, but I am not opposed to adding hardware acceleration options. I am actually working on NVENC HEVC capabilities at the moment.

If you (or anyone) has access to one, please provide the output of:

ffmpeg -h encoder=hevc_videotoolbox

and the configuration of:

ffmpeg -version

Can also provide h264_videotoolbox, but honestly I am not really working towards adding more H.264 at this time

@singhkays
Copy link
Author

I'm happy to help test this as well as if you can build a native Apple Silicon build. Here are the outputs you requested

➜  ~ ffmpeg -h encoder=hevc_videotoolbox
ffmpeg version git-2021-01-09-42ee389 Copyright (c) 2000-2021 the FFmpeg developers
  built with Apple clang version 12.0.0 (clang-1200.0.32.28)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/HEAD-42ee389_6 --enable-shared --cc=clang --host-cflags= --host-ldflags= --enable-gpl --enable-libaom --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-demuxer=dash --disable-libjack --disable-indev=jack --enable-opencl --enable-videotoolbox --disable-htmlpages --enable-libfdk-aac --enable-nonfree
  libavutil      56. 63.100 / 56. 63.100
  libavcodec     58.115.102 / 58.115.102
  libavformat    58. 65.101 / 58. 65.101
  libavdevice    58. 11.103 / 58. 11.103
  libavfilter     7. 95.100 /  7. 95.100
  libswscale      5.  8.100 /  5.  8.100
  libswresample   3.  8.100 /  3.  8.100
  libpostproc    55.  8.100 / 55.  8.100
Encoder hevc_videotoolbox [VideoToolbox H.265 Encoder]:
    General capabilities: delay hardware
    Threading capabilities: none
    Supported pixel formats: videotoolbox_vld nv12 yuv420p p010le
hevc_videotoolbox AVOptions:
  -profile           <int>        E..V....... Profile (from 0 to 3) (default 0)
     main            1            E..V....... Main Profile
     main10          2            E..V....... Main10 Profile
  -allow_sw          <boolean>    E..V....... Allow software encoding (default false)
  -require_sw        <boolean>    E..V....... Require software encoding (default false)
  -realtime          <boolean>    E..V....... Hint that encoding should happen in real-time if not faster (e.g. capturing from camera). (default false)
  -frames_before     <boolean>    E..V....... Other frames will come before the frames in this session. This helps smooth concatenation issues. (default false)
  -frames_after      <boolean>    E..V....... Other frames will come after the frames in this session. This helps smooth concatenation issues. (default false)
➜  ~ ffmpeg -version
ffmpeg version git-2021-01-09-42ee389 Copyright (c) 2000-2021 the FFmpeg developers
built with Apple clang version 12.0.0 (clang-1200.0.32.28)
configuration: --prefix=/usr/local/Cellar/ffmpeg/HEAD-42ee389_6 --enable-shared --cc=clang --host-cflags= --host-ldflags= --enable-gpl --enable-libaom --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-demuxer=dash --disable-libjack --disable-indev=jack --enable-opencl --enable-videotoolbox --disable-htmlpages --enable-libfdk-aac --enable-nonfree
libavutil      56. 63.100 / 56. 63.100
libavcodec     58.115.102 / 58.115.102
libavformat    58. 65.101 / 58. 65.101
libavdevice    58. 11.103 / 58. 11.103
libavfilter     7. 95.100 /  7. 95.100
libswscale      5.  8.100 /  5.  8.100
libswresample   3.  8.100 /  3.  8.100
libpostproc    55.  8.100 / 55.  8.100
➜  ~ ffmpeg -h encoder=h264_videotoolbox
ffmpeg version git-2021-01-09-42ee389 Copyright (c) 2000-2021 the FFmpeg developers
  built with Apple clang version 12.0.0 (clang-1200.0.32.28)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/HEAD-42ee389_6 --enable-shared --cc=clang --host-cflags= --host-ldflags= --enable-gpl --enable-libaom --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-demuxer=dash --disable-libjack --disable-indev=jack --enable-opencl --enable-videotoolbox --disable-htmlpages --enable-libfdk-aac --enable-nonfree
  libavutil      56. 63.100 / 56. 63.100
  libavcodec     58.115.102 / 58.115.102
  libavformat    58. 65.101 / 58. 65.101
  libavdevice    58. 11.103 / 58. 11.103
  libavfilter     7. 95.100 /  7. 95.100
  libswscale      5.  8.100 /  5.  8.100
  libswresample   3.  8.100 /  3.  8.100
  libpostproc    55.  8.100 / 55.  8.100
Encoder h264_videotoolbox [VideoToolbox H.264 Encoder]:
    General capabilities: delay
    Threading capabilities: none
    Supported pixel formats: videotoolbox_vld nv12 yuv420p
h264_videotoolbox AVOptions:
  -profile           <int>        E..V....... Profile (from 0 to 5) (default 0)
     baseline        1            E..V....... Baseline Profile
     main            2            E..V....... Main Profile
     high            3            E..V....... High Profile
     extended        4            E..V....... Extend Profile
  -level             <int>        E..V....... Level (from 0 to 52) (default 0)
     1.3             13           E..V....... Level 1.3, only available with Baseline Profile
     3.0             30           E..V....... Level 3.0
     3.1             31           E..V....... Level 3.1
     3.2             32           E..V....... Level 3.2
     4.0             40           E..V....... Level 4.0
     4.1             41           E..V....... Level 4.1
     4.2             42           E..V....... Level 4.2
     5.0             50           E..V....... Level 5.0
     5.1             51           E..V....... Level 5.1
     5.2             52           E..V....... Level 5.2
  -coder             <int>        E..V....... Entropy coding (from 0 to 2) (default 0)
     cavlc           1            E..V....... CAVLC entropy coding
     vlc             1            E..V....... CAVLC entropy coding
     cabac           2            E..V....... CABAC entropy coding
     ac              2            E..V....... CABAC entropy coding
  -a53cc             <boolean>    E..V....... Use A53 Closed Captions (if available) (default true)
  -allow_sw          <boolean>    E..V....... Allow software encoding (default false)
  -require_sw        <boolean>    E..V....... Require software encoding (default false)
  -realtime          <boolean>    E..V....... Hint that encoding should happen in real-time if not faster (e.g. capturing from camera). (default false)
  -frames_before     <boolean>    E..V....... Other frames will come before the frames in this session. This helps smooth concatenation issues. (default false)
  -frames_after      <boolean>    E..V....... Other frames will come after the frames in this session. This helps smooth concatenation issues. (default false)

@cdgriffith
Copy link
Owner

wow not a lot of options, makes it easier for moi!

For a build have to wait on github actions support for it: actions/runner-images#2187

@singhkays
Copy link
Author

For a build have to wait on github actions support for it: actions/runner-images#2187

Ooh..that's going to take a while :| Is it possible for me to compile a native build myself?

@cdgriffith
Copy link
Owner

If you goal is to just run it, should be able to do that: https://github.com/cdgriffith/FastFlix#running-from-source-code Good first step to make sure of either way, I do not know if all the packages are supported on the new macs yet.

If you want to actually do the work to make a redistributable executable, you could go through the steps in the build script and see how it works out: https://github.com/cdgriffith/FastFlix/blob/master/.github/workflows/build_mac.yaml

@singhkays
Copy link
Author

If you goal is to just run it, should be able to do that: https://github.com/cdgriffith/FastFlix#running-from-source-code Good first step to make sure of either way, I do not know if all the packages are supported on the new macs yet.

Yep, I tried this already with Python 3.9.1 (Apple Silicon installer). Looks like the Python itself is still "Intel" architecture and hasn't transitioned to Apple Silicon. I'm assuming building the redistributable will also be an Intel version.

@MarcoRavich
Copy link

MarcoRavich commented Feb 20, 2021

Interesting readings about Apple Silicon software porting:

Hope that helps !

@moonwhaler
Copy link

moonwhaler commented May 20, 2021

Personally, I don't mind using Fastflix with Rosetta 2. What is important to me, as mentioned in the first post, is the use of "Apple Silicon" encoders. What I did was to download the pre compiled version of ffmpeg from here: https://www.osxexperts.net/

And then pointing FastFlix to that location. If you look into top/ps/activity monitor and expand the process of FastFlix / Python you should recognize a "Apple Silicon" process while encoding. Works for me.

Plus, the binary from the URL above also includes support ARM Neon, which speeds up the encoding significantly!

Another way would be using Homebrew to install ffmpeg binaries. BUT, those don't include the ARM Neon patch. Resulting in lower fps - at least for me.

@chadbrewbaker
Copy link

Bump this to M1 MAX encoders :) What needs to be done, just getting the ARM patches into the Homebrew build?

@jannisberry
Copy link

jannisberry commented Nov 3, 2021

ffmpeg version 4.4.1 Copyright (c) 2000-2021 the FFmpeg developers
  built with Apple clang version 13.0.0 (clang-1300.0.29.3)
  configuration: --prefix=/opt/homebrew/Cellar/ffmpeg/4.4.1_2 --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-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --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-avresample --enable-videotoolbox
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
Encoder hevc_videotoolbox [VideoToolbox H.265 Encoder]:
    General capabilities: delay hardware 
    Threading capabilities: none
    Supported pixel formats: videotoolbox_vld nv12 yuv420p bgra p010le
hevc_videotoolbox AVOptions:
  -profile           <int>        E..V....... Profile (from 0 to 3) (default 0)
     main            1            E..V....... Main Profile
     main10          2            E..V....... Main10 Profile
  -alpha_quality     <double>     E..V....... Compression quality for the alpha channel (from 0 to 1) (default 0)
  -allow_sw          <boolean>    E..V....... Allow software encoding (default false)
  -require_sw        <boolean>    E..V....... Require software encoding (default false)
  -realtime          <boolean>    E..V....... Hint that encoding should happen in real-time if not faster (e.g. capturing from camera). (default false)
  -frames_before     <boolean>    E..V....... Other frames will come before the frames in this session. This helps smooth concatenation issues. (default false)
  -frames_after      <boolean>    E..V....... Other frames will come after the frames in this session. This helps smooth concatenation issues. (default false)

These are M1 Max and presumably M1 Pro encoders if that would be helpful anywhere

ffmpeg version 4.4.1 Copyright (c) 2000-2021 the FFmpeg developers
built with Apple clang version 13.0.0 (clang-1300.0.29.3)
configuration: --prefix=/opt/homebrew/Cellar/ffmpeg/4.4.1_2 --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-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --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-avresample --enable-videotoolbox
libavutil      56. 70.100 / 56. 70.100
libavcodec     58.134.100 / 58.134.100
libavformat    58. 76.100 / 58. 76.100
libavdevice    58. 13.100 / 58. 13.100
libavfilter     7.110.100 /  7.110.100
libavresample   4.  0.  0 /  4.  0.  0
libswscale      5.  9.100 /  5.  9.100
libswresample   3.  9.100 /  3.  9.100
libpostproc    55.  9.100 / 55.  9.100

and dis ffmpeg version

@cdgriffith
Copy link
Owner

I have created a new branch with hevc_videotoolbox support. Any brave users willing to test would be greatly appreciated as I don't have a box to try it on.

git clone https://github.com/cdgriffith/FastFlix.git
cd FastFlix
git checkout videotoolbox
python3 -m venv venv
. venv/bin/activate
pip install -r requirements.txt
python -m fastflix

There should be a new dropdown option for HEVC videotoolbox. Please test to make sure it works / try to break it!

@E-t-z
Copy link

E-t-z commented Apr 2, 2022

Nice, will try it out in upcoming days. :)
By any chance, could you add avc (h264_videotoolbox) support as well?

@cdgriffith
Copy link
Owner

By any chance, could you add avc (h264_videotoolbox) support as well?

Yup, will add that if this one works well. Just easier to do one at a time.

@cdgriffith
Copy link
Owner

cdgriffith commented Apr 13, 2022

@E-t-z I've added support for h264 in that branch as well if you can test it out!

@E-t-z
Copy link

E-t-z commented Apr 15, 2022

@cdgriffith will take a look on Sunday, sorry for the delay.

h265_videotoolbox seemed to work quite well.

cdgriffith added a commit that referenced this issue Apr 24, 2022
* Adding #109 Support for AVC and HEVC QSV encoding with rigaya's QSVEncC (thanks to msaintauret)
* Adding #196 Support for AVC and HEVC Apple Videotoolbox encoder (thanks to Kay Singh)
* Adding #323 ignore errors options options for queue (thanks to Don Gafford)
* Adding #331 NVEncC API v10 Quality presets: P1 to P7 (thanks to Wontell)
* Fixing #321 dhdr10_opt not added for x265 commands (thanks to GizmoDudex)
* Fixing #327 FastFlix Duplicates encoding task and encodes same movie to infinity (thanks to Wontell)
* Fixing #324 NVEncC wrong Interlace Value set by FastFlix (thanks to Wontell)
* Fixing #278 FastFlix occasionally getting stuck on a single video in a queue (thanks to kamild1996)
* Fixing #330 "Remove Metadata" only removes video metadata for Rigaya's hardware encoders (thanks to wynterca)
* Fixing level was not being passed to hardware encoders
@cdgriffith
Copy link
Owner

@sublimal
Copy link

How do I select videotoolbox encoder?
image

Looking at the code I suspect the issue is requires which should be videotoolbox as per ffmpeg version/configuration provided above, eg --enable-videotoolbox in:

% ffmpeg -version
ffmpeg version 5.0.1 Copyright (c) 2000-2022 the FFmpeg developers
built with Apple clang version 13.1.6 (clang-1316.0.21.2.5)
configuration: --prefix=/opt/homebrew/Cellar/ffmpeg/5.0.1-with-options_2 --enable-shared --cc=clang --host-cflags= --host-ldflags= --enable-gpl --enable-libaom --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-demuxer=dash --enable-opencl --enable-audiotoolbox --enable-videotoolbox --enable-neon --disable-htmlpages

@cdgriffith
Copy link
Owner

You are totally right @sublimal, good catch, thank you!

@cdgriffith cdgriffith reopened this Jun 17, 2022
@cdgriffith
Copy link
Owner

Ok hopefully that did it, please let me know if not working with https://github.com/cdgriffith/FastFlix/releases/tag/4.9.4 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New idea for project
Projects
None yet
Development

No branches or pull requests

8 participants