ssut / ffmpeg-on-apple-silicon

Build ffmpeg for ARM-based Apple Silicon Macs
222 stars 47 forks source link

M1 build #1

Closed stefcarlens closed 3 years ago

stefcarlens commented 3 years ago

That's more or less 'stolen' from https://www.osxexperts.net :-)

But you forgot the libsnappy and libopenh264 ;-)

stefcarlens commented 3 years ago

Forgotten to add. This does not create a static build. If you copy the compiled FFMpeg to another system, it will not find a lot of libs. It's best not to use Homebrew at all.

ssut commented 3 years ago

I've encountered just a few packages that currently failed to build, and I'll try to build them again tomorrow. Yes, I also know it's not a good idea to use the packages installed with Homebrew. It's also a plan, and I'll keep up to date.

I made this repository because I was curious if I could build FFmpeg on my m1 Mac and wanted to share the progress I've did.

ssut commented 3 years ago

Hello. I've updated the build script to link the external libs that previously have been linked dynamically to be linked statically, and also added support for missing packages (snappy, ass, aom.)

stefcarlens commented 3 years ago

That's still not creating a good static FFmpeg. Take a look at the osxexperts script which does create a good FFmpeg static build. Anyhow, there are other issues but the biggest and most important problem is that x265 is terrible slow on ARM. The Intel version is between 500% to 1500% (and yes, that's 15 times) faster compared to an ARM build. Even an Intel build running with Rosetta2 is faster! (which is odd).

Main reason is that x265 has not been optimised for ARM and sadly the x265 devs have no intention doing so in the near future (there is a note about that in the source). Basically this means it only uses ARM Neon opts which is not to be compared to SSE, SIMD, ... and waaaaaaay slower. In the Handbrake source there is a patch for x265 that introduces the Huawei ARM optimisations and that speeds it up a bit (still not up to Intel speed though). But I have failed to put that patch on x265. Very probably because that patch only works on a certain x265 release. There are other caveats - AV1 is already slow on Intel but even slower on ARM (a 120min movies takes about 20hours to encode on ARM - on Intel about 3 hours). This test was done on a Mac Mini M1 and Intel version running Rosetta2. x264 is also slower but more or less 100% - no opts are to be expected either.

Conclusion: Apple Silicon(ARM) is faster in many ways, but not for several encoders like x265, AV1, ...

ssut commented 3 years ago

Then why not you make your own FFmpeg build that is for your taste? I don't feel like this should be a perfect solution for everyone's needs, and believe that the official Homebrew release comes out in the not-so-distant future so this is just a workaround till then. As I said, this repository is created for trying out native builds on Apple Silicon.

You may know there is an HW-accelerated HEVC encoder/decoder since T2 Macs using VideoToolBox and this is way faster than the other codecs and also is officially supported. Please use this and do not take it out on me because of the performance-related issues.

stefcarlens commented 3 years ago

I am aware of VideoToolBox HW accelerated encoding and that works fast. But it does not create small files. For the same quality file size is up to 5x bigger compared to a x265 encoded file. Then it overshoots the mark a bit. That's not FFmpeg fault but more or less the implementation of Apples VideoToolbox which is not good imo.

And yes, of course I can compile my version of FFmpeg. But I only wanted to help. ;-) No offence meant.

About Homebrew: A Homebrew FFmpeg build is imo useless and I really cannot recommend using that for FFmpeg. It's dynamically build and in the past it wasn't optimised very well. For example the Intel Tessus or osxexperts static builds are faster compared to any Homebrew build I have tried.