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

FFMPEG with hardware acceleration #854

Closed
1 task done
MaixGit opened this issue Apr 10, 2024 · 15 comments · Fixed by #899
Closed
1 task done

FFMPEG with hardware acceleration #854

MaixGit opened this issue Apr 10, 2024 · 15 comments · Fixed by #899
Labels
enhancement New feature or request low priority This is on the low priority list or still in discussion. Implementation is not guaranteed.

Comments

@MaixGit
Copy link

MaixGit commented Apr 10, 2024

Description

Most devices would be using relatively recent Qualcomm chips, which have support for hardware accelerated AVC and HEVC video encoding and decoding, via Qualcomm PDF download.

Encoding overlay merged videos with libx265 is super slow (like a whole 60 seconds slow), and libx264 is also quite slow unless you drop the quality to ultrafast and ~30 CRF, at which point the quality of the video and the file size is super unoptimised.

I'm not sure if it would be possible to achieve this, since I've only found one reference of someone else trying to do this via Reddit. But if it is possible, then it would provide a huge boost to the speed and quality, and maybe even Exynos processor hardware acceleration could be implemented, however I'm on a Qualcomm 865.

Agreement

  • There is no issue already suggesting my feature.
@MaixGit MaixGit added the enhancement New feature or request label Apr 10, 2024
@VendorAttestation
Copy link
Contributor

Definitely possible with a flag most likely the more of the issue would be determining if your CPU supports it. We could make it a option tho.

@authorisation authorisation added the low priority This is on the low priority list or still in discussion. Implementation is not guaranteed. label Apr 10, 2024
@VendorAttestation
Copy link
Contributor

Build and test this #899

@bocajthomas bocajthomas linked a pull request Apr 14, 2024 that will close this issue
@MaixGit
Copy link
Author

MaixGit commented Apr 14, 2024

I tried building it, but couldn't figure it out because I just kept encountering errors first with the Android SDK missing, and then "Task :native:configureCMakeDebug[arm64-v8a] FAILED". Is it possible that I use the artifacts from an actions run on your pull request? Sorry, I'm not the most experienced with coding.

@MaixGit
Copy link
Author

MaixGit commented Apr 14, 2024

Hi, I tested the snapenhance-armv8-debug artifact from the actions build, and unfortunately it doesn't seem to do anything on my Snapdragon 865 5G. Over multiple trials, the results were within margin of error when compared to the build without the -hwaccel flag. I also tried both libx264 and libx265 before and after, again, the results for both were within margin of error. I'm not exactly sure how FFMPEG's -hwaccel flag works, but I doubt that by default it would be able to detect Snapdragon or Exynos hardware acceleration capabilities.

@VendorAttestation
Copy link
Contributor

VendorAttestation commented Apr 14, 2024

Hi, I tested the snapenhance-armv8-debug artifact from the actions build, and unfortunately it doesn't seem to do anything on my Snapdragon 865 5G. Over multiple trials, the results were within margin of error when compared to the build without the -hwaccel flag. I also tried both libx264 and libx265 before and after, again, the results for both were within margin of error. I'm not exactly sure how FFMPEG's -hwaccel flag works, but I doubt that by default it would be able to detect Snapdragon or Exynos hardware acceleration capabilities.

I tested multiple times on a less powerful CPU and saw 10-30 FPS increase

Before:
image

After:
image

@MaixGit
Copy link
Author

MaixGit commented Apr 14, 2024

How'd you get the debug stats to show up there?

@VendorAttestation
Copy link
Contributor

How'd you get the debug stats to show up there?

I don't know if it depends on how you build but i went to a public profile and clicked download all segements

@MaixGit
Copy link
Author

MaixGit commented Apr 14, 2024

How'd you get the debug stats to show up there?

I don't know if it depends on how you build but i went to a public profile and clicked download all segements

Hmm, I can't seem to get the stats to show up, no matter where I download from. Also, I don't have the option to "Download all segments", I just have "Download media".

I've been doing the testing by downloading a snap that is saved in chat, it's about 4 seconds long, and has many overlays like text and a few gifs. And even just measuring by hand, starting a timer as soon as I click download, with and without the -hwaccel flag, it was within half a second of difference.

@MaixGit
Copy link
Author

MaixGit commented Apr 14, 2024

If you didn't change the number of threads to 4 before also adding the -hwaccel flag, then your fps increase may be due to the additional 3 threads that are used.

In my tests I always manually put the threads to 8.

@VendorAttestation
Copy link
Contributor

VendorAttestation commented Apr 14, 2024

If you didn't change the number of threads to 4 before also adding the -hwaccel flag, then your fps increase may be due to the additional 3 threads that are used.

In my tests I always manually put the threads to 8.

-hwaccel auto defaults to media codec aka androids

Also snapdragon 865 is 4 years old don't expect superior performance even with the 5G slapped on it

If your worried about speed i recommend buying a new phone sir

OnePlus 12 No HW Accel + 1 Thread

image

Your phone is old don't expect it to pump a file out instantly sir

@MaixGit

This comment was marked as off-topic.

@bocajthomas

This comment was marked as off-topic.

@VendorAttestation
Copy link
Contributor

@authorisation That last message was a bit unnecessarily rude, don't you think?

#906

I have upgraded to FFMPEG 6 (Full support for media codec) this is as new as you can get with media codec after this there's not many more improvements possible and I'm not being rude just a 4 year old chip can't pump 170+ FPS unfortunately it just how it is.

@MaixGit
Copy link
Author

MaixGit commented Apr 14, 2024

@authorisation That last message was a bit unnecessarily rude, don't you think?

#906

I have upgraded to FFMPEG 6 (Full support for media codec) this is as new as you can get with media codec after this there's not many more improvements possible and I'm not being rude just a 4 year old chip can't pump 170+ FPS unfortunately it just how it is.

Well thank you very much for the latest build. File size down from 137mb to 22mb with h264_mediacodec in the same quality

@VendorAttestation
Copy link
Contributor

@authorisation That last message was a bit unnecessarily rude, don't you think?

#906
I have upgraded to FFMPEG 6 (Full support for media codec) this is as new as you can get with media codec after this there's not many more improvements possible and I'm not being rude just a 4 year old chip can't pump 170+ FPS unfortunately it just how it is.

Well thank you very much for the latest build. File size down from 137mb to 22mb with h264_mediacodec in the same quality

Glad to help 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request low priority This is on the low priority list or still in discussion. Implementation is not guaranteed.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants