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

Add support for other HW Accel #42

Open
mjebrahimi opened this issue May 9, 2020 · 25 comments
Open

Add support for other HW Accel #42

mjebrahimi opened this issue May 9, 2020 · 25 comments

Comments

@mjebrahimi
Copy link

Add support for other HW Accel such as:

  • cuda
  • qsv
  • d3d11va
@MattMcManis
Copy link
Owner

Hi, thanks for the suggestion. I will work on this.

@MattMcManis
Copy link
Owner

I released an update for you to test.

Press the arrow button in Axiom to update through PowerShell, or download from here
https://github.com/MattMcManis/Axiom/releases

Update


A few issues with Intel QSV:

I'm using the Software decode option -init_hw_device qsv=hw -filter_hw_device hw.
I couldn't get the regular -hwaccel qsv -c:v h264_qsv to work. It gives the error Decoding pixel format '(null)' is not supported.

and

x265 -c:v hevc_qsv gives loading plugin error, but x264 -c:v h264_qsv works.

https://trac.ffmpeg.org/wiki/Hardware/QuickSync


Examples

Works

ffmpeg -init_hw_device qsv=hw -filter_hw_device hw -i input.mpg -c:v h264_qsv output.mp4

Doesn't Work

ffmpeg -init_hw_device qsv=hw -filter_hw_device hw -i input.mpg -c:v hevc_qsv output.mp4
ffmpeg -hwaccel qsv -c:v h264_qsv -i input.mpg -c:v h264_qsv output.mp4
ffmpeg -hwaccel qsv -c:v hevc_qsv -i input.mpg -c:v hevc_qsv output.mp4

@forart
Copy link

forart commented May 15, 2020

...what about hwaccel auto ?

@MattMcManis
Copy link
Owner

@forart

I did not know it exists, I will add it in the next update soon.

@MattMcManis
Copy link
Owner

@forart

For -hwaccel auto, it works when converting mp4mp4, mp4webm, or webmwebm.
It automatically selects dxva2.

But when converting webmmp4 I get the error:

Cannot load cuvidGetDecodeStatus
Failed loading nvcuvid.
Failed setup for format cuda: hwaccel initialisation returned error.
Cannot load cuvidGetDecodeStatus

I'm not able to test it properly with my hardware. I'll add auto option, but leave off as the default so that users don't get hardware errors right out of the box.

@mjebrahimi
Copy link
Author

Hello Matt, thanks for the support.

Everything was fine, only Intel QSV was wrong for me.

This was the result of my tests on one input with 15.1 MB with different HW/A options

  • The result for other options (like cuda, d3d11va , dxva2) was 14.9 MB
  • -hwaccel qsv -c:v h264_qsv works but not same result like others. (output : 62.5 MB !)
  • -init_hw_device qsv=hw -filter_hw_device hw -c:v h264_qsv works but not same result like others. (output : 62.5 MB !)

But -hwaccel qsv -c:v libx264 works fine and result was like others (output : 14.9 MB)

I think should not change the video codec (-c:v) but, just enough to set -hwaccel qsv

@MattMcManis
Copy link
Owner

@mjebrahimi

Thanks for the info, I will change Intel QSV to use -hwaccel qsv -c:v libx264, but it's not able to auto-detect the input codec for all media, so it may have to just be -hwaccel qsv.

I'm planning to split the HW Accel options into 2 menus, decode and transcode.
Take a look at the options in this post #41 (comment), let me know if it looks correct.

@mjebrahimi
Copy link
Author

Thanks, but I don't have enough knowledge to comment on this case :)

@forart
Copy link

forart commented May 16, 2020

@MattMcManis

For -hwaccel auto, it works when converting mp4mp4, mp4webm, or webmwebm.
It automatically selects dxva2.

But when converting webmmp4 I get the error:

Seems an FFMPEG's bug.

Here's an interesting (verbose) discussion about FFMPEG hw encode:
https://emby.media/community/index.php?/topic/10723-gpu-transcoding-intel-quicksync-and-nvidia-nvenc/

@MattMcManis
Copy link
Owner

@mjebrahimi @forart

I've released an update with some new options:

  • HW Accel Decode and Transcode menus.
  • HW Accel Decode option auto.
  • HW Accel Transcode option AMD AMF for x264/x265.
  • Video Tab has new Sub Tabs, Encoding, Color, Size, to reduce the vertical scrolling height.

These changes could introduce new bugs, you will have to test it out and let me know how it works. Certain HW Accel options may need the required Intel/Nvidia/AMD hardware.
Some HW Accel Transcode codecs are only available for x264/x265.

https://github.com/MattMcManis/Axiom/releases

@mjebrahimi
Copy link
Author

All Transcode options with Decode: CUDA gives an error for me.

Impossible to convert between the formats supported by the filter 'graph 0 input from stream 0:0' and the filter 'auto_scaler_0'
Error reinitializing filters!
Failed to inject frame into filter network: Function not implemented
Error while processing the decoded data for stream #0:0
Conversion failed!

This is output script for decode CUDA and transcode off or auto that gives error.

-hwaccel cuda -hwaccel_output_format cuda 
-c:v libx264 

@MattMcManis
Copy link
Owner

@mjebrahimi

Can you find the correct options that work and post the script?


https://trac.ffmpeg.org/wiki/HWAccelIntro#NVDECCUVID

Sample decode using CUDA:

ffmpeg -hwaccel cuda -i input output

Full hardware transcode with NVDEC and NVENC:

ffmpeg -hwaccel cuda -hwaccel_output_format cuda -i input -c:v h264_nvenc -preset slow output

I'm not able to test it with my setup, I get the error:

ffmpeg -hwaccel cuda -hwaccel_output_format cuda -i input.mpg -c:v libx264 output.mp4
Cannot load cuvidGetDecodeStatus
Failed loading nvcuvid.
Failed setup for format cuda: hwaccel initialisation returned error.
Cannot load nvEncodeAPI64.dll

@mjebrahimi
Copy link
Author

I was only able to get the correct result from the below script (no full hardware transcode - by removing -hwaccel_output_format cuda)

-hwaccel cuda
-c:v libx264 

@MattMcManis
Copy link
Owner

@mjebrahimi

I will change it in an update.

Does the Intel QSV work for you?
It uses -hwaccel qsv -hwaccel_output_format qsv.


Info I could find on -hwaccel_output_format:

https://gist.github.com/Brainiarc7/95c9338a737aa36d9bb2931bed379219

-hwaccel_output_format : This option should be used every time you declare the -hwaccel method as vaapi , so that the decode stage takes place entirely in hardware. This option generates decode output directly on VAAPI hardware surfaces, speeding up decode performance significantly.

@mjebrahimi
Copy link
Author

Yes, it works well.

@MattMcManis , I don't know enough about ffmpeg hwaccel, but if you want, I can give you access to my machine (via AnyDesk or etc...) to test different scripts as you wish.

@MattMcManis
Copy link
Owner

@mjebrahimi

Thanks, I'll let you know if needed.

I've released an update for hwaccel cuda, and some other improvements, changelog.

@mjebrahimi
Copy link
Author

mjebrahimi commented May 19, 2020

Run button doesn't show any reaction anymore in v1.8.3-alpha ?!

But script for CUDA is OK now 👍.

@MattMcManis
Copy link
Owner

@mjebrahimi

Are you sure? It is working for me. I added support for CMD and PowerShell in the last update.

@MattMcManis
Copy link
Owner

@mjebrahimi

If you want to, open a separate Issue for the Run button. I am looking into it, trying to optimize the code and find bugs, but I'm unable to reproduce the error.

Let's keep this thread for HW Accel.

@mjebrahimi
Copy link
Author

Of course, I opened a new issue and explained the cause of the problem.

Thanks again for your support on HW Accel.

@MattMcManis
Copy link
Owner

@mjebrahimi

I found a problem with Intel QSV.
CRF -crf does not work, only Bit Rate -b:v 1 and 2 Pass works.
CRF ends up setting the lowest default bit rate when used with -c:v h264_qsv.


https://trac.ffmpeg.org/wiki/Hardware/QuickSync

It says "ICQ mode (which is similar to crf mode of x264)" -global_quality 25
But I cannot get it to work. I get the error Selected ratecontrol mode is unsupported.


I've fixed quite a few bugs and added some new features in v1.8.6.0.

@MattMcManis
Copy link
Owner

@mjebrahimi

It looks like none of the HW Accel codecs will work properly with CRF, they all have their own arguments.

I will have to make a system for the CRF slider that automatically converts the values into -rc:v vbr_hq -cq:v values along with bit rate.

https://superuser.com/a/1236387/740888

@forart
Copy link

forart commented Mar 19, 2021

As posted in the above FastFlix "issue", I found some interesting resouces for qsv encodes/filters:

Hope that helps/inspires !

@forart
Copy link

forart commented Apr 3, 2021

OK, seems the (greatest ?) hardware accelerated video encoders expert is @Brainiarc7 here.

I believe he could help us to understand better how to create a right commandline for FFMPEG encodings.

@Brainiarc7
Copy link

Brainiarc7 commented Apr 28, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants