tanersener / mobile-ffmpeg

FFmpeg for Android, iOS and tvOS. Not maintained anymore. Superseded by FFmpegKit.
https://tanersener.github.io/mobile-ffmpeg
GNU General Public License v3.0
3.85k stars 787 forks source link

Optimized implementation of ffmpeg x265 for mobile chips #595

Closed aytunch closed 3 years ago

aytunch commented 3 years ago

I know that this Library is not the direct recipient of this issue but I could not find a better place to bring this subject in. So I apologize beforehand if this is not appropriate.

I am trying to encode videos on iOS and Android clients and then upload them. So Encode times are very critical for my use case. x265 had nearly %50 advantage in terms of file size. This comes with a disadvantage in encode times. Usually it is 5-10 times slower than x264 encoding. I understand that this is not totally because of the x265's algorithm but because the encoders can not use the cpu's in a fully optimized way.

I came across with this article: How Fast is H.265/HEVC Software Encoding on ARM CPUs (iPhone/Android) With FFmpeg? and the related video comparing the encode time differences of an Intel and Arm processor: video of the article

The author states that the specific Intel processor is 2.5times faster than the specific arm processor. However in the case of ffmpeg, the encode time difference is 10 times. He states that this unbalance is caused by the unoptimized implementation of ffmpeg on arm chips.

This article shows the adoption rate for mobile phones with hardware support of x265.

Lastly I found out that neon code instead of c makes a huge difference in encoding/decoding performances. Is there any plans on supporting a neon implementation of ffmpeg?

I would be glad if someone can inform us more about this subject.

tanersener commented 3 years ago

mobile-ffmpeg supports 3 Android (arm-v7a, arm-v7a-neon, arm64-v8a) and 4 iOS (armv7, armv7s, arm64, arm64e) ARM architectures. All of them except Android's arm-v7a uses neon optimisations. So, there is nothing that can be improved about neon optimisations on ffmpeg.

Regarding x265 cpu optimisations, ASM Support wiki page lists which libraries are built with cpu optimisations enabled and which are not. You can also see what kind of issues we face when we enable them. Unfortunately, cpu optimisations for x265 on ARM architectures are mostly disabled. This comes from x265 and needs to be improved by them.

aytunch commented 3 years ago

Thank you very much for the explanation and pointing me towards the right direction. I will further investigate the issue in x265 specific areas.