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

[Feature Request] Support for hwaccel decoding #326

Closed
MobyGamer opened this issue Apr 10, 2022 · 10 comments
Closed

[Feature Request] Support for hwaccel decoding #326

MobyGamer opened this issue Apr 10, 2022 · 10 comments
Labels
feature request New idea for project

Comments

@MobyGamer
Copy link

Currently fastflix has no options for adding -hwaccel auto to the processing pipeline. I can add this myself by copying the generated commands and adding it, but it would be nice to have this option added to the GUI so that no such step is necessary. Without it, my CPU usage becomes 100% dedicated to decoding, which throttles the speed of the process, thereby negating much of the benefits of using hardware acceleration in the first place.

My use case: Due to various technical constraints(*), I am only able to successfully stream UHD 4K rips that have average bitrates of 60 Mbps or less; anything higher (for example Cloverfield, which has an abr of 89 Mbps) will pause and buffer occasionally. My goal in using FastFlix was to use my RTX 3080 to transcode some of these larger rips to a slightly smaller rate, such as 50 Mbps, while still retaining full HDR information. It works very well for that, however I must always copy the commands to a batch file and add -hwaccel auto to enable NVENC-assisted decoding

(*)The constraint is not one of network bandwidth, but of processing power on my LG C8, which can only decode up to 60 Mbps of network traffic at the same time HEVC video decoding is being processed.

@cdgriffith cdgriffith added the feature request New idea for project label Apr 14, 2022
@cdgriffith
Copy link
Owner

Does -hwaccel auto have to be added before the input / at a certain place, or can it just be added as Custom FFmpeg Options at the bottom of the encoder panel? (If unsure I can look up more documentation on it as well, just might be a quick workaround for you).

@MobyGamer
Copy link
Author

MobyGamer commented Apr 15, 2022

Good question. I tried adding it as a command-line param, but it doesn't show up in the first pass bitrate command, and in the second pass bitrate command it is placed after the input file (specifically, after the encoding profile) which generates this error:

"C:\Users\mobyg\AppData\Roaming\FFmpeg\bin\ffmpeg.exe" -y      -i (input) -metadata title="(title) -max_muxing_queue_size 1024 -map 0:0   -c:v hevc_nvenc -pix_fmt p010le     -tune:v hq -color_primaries bt2020 -color_trc smpte2084 -colorspace bt2020nc -spatial_aq:v 0 -tier:v main -rc-lookahead:v 0 -gpu -1 -b_ref_mode disabled -profile:v main  -pass 2 -passlogfile "E:\temp\temp_4e67a83b907dab4a7dd6c088\pass_log_file_805748394bfa59308eb4" -2pass 1 -b:v 35000k -preset:v slow -hwaccel auto  -map_metadata -1 (etc. etc.)"

Option hwaccel (use HW accelerated decoding) cannot be applied to output url e:\temp\outputfile.mkv -- you are trying to apply an input option to an output file or vice versa. Move this option before the file it belongs to.

When I manually relocate it to the beginning, before the input file, it works:

"C:\Users\mobyg\AppData\Roaming\FFmpeg\bin\ffmpeg.exe" -y -hwaccel auto -i (input) -metadata title="(title) -max_muxing_queue_size 1024 -map 0:0   -c:v hevc_nvenc -pix_fmt p010le     -tune:v hq -color_primaries bt2020 -color_trc smpte2084 -colorspace bt2020nc -spatial_aq:v 0 -tier:v main -rc-lookahead:v 0 -gpu -1 -b_ref_mode disabled -profile:v main  -pass 2 -passlogfile "E:\temp\temp_4e67a83b907dab4a7dd6c088\pass_log_file_805748394bfa59308eb4" -2pass 1 -b:v 35000k -preset:v slow -map_metadata -1 (etc. etc.)"

It should be added to the first pass command-line too. Without it, on a test hdr 4k file on my setup, 1st pass runs at 32fps and burns up 60% total CPU, but when -hwaccel auto is added to the 1st pass, it runs at the same speed but with only 20% CPU.

Ideally I'd like to see this in the GUI as a checkbox called something like "hardware-accelerated decoding", although I'm not sure where the best place in the GUI would be for it, so I leave that up to you. Also, using the "auto" param for -hwaccel is probably the best option; you can specify something specific (like -hwaccel cuvid for nvidia specifically) but "auto" has always done the correct thing on my hardware (I have both intel quicksync as well as NVENC present, and ffmpeg correctly uses the NVENC block for decoding and encoding with -hwaccel auto).

@MarcoRavich
Copy link

MarcoRavich commented Apr 21, 2022

It should be added to the first pass command-line too. Without it, on a test hdr 4k file on my setup, 1st pass runs at 32fps and burns up 60% total CPU, but when -hwaccel auto is added to the 1st pass, it runs at the same speed but with only 20% CPU.

Ideally I'd like to see this in the GUI as a checkbox called something like "hardware-accelerated decoding", although I'm not sure where the best place in the GUI would be for it, so I leave that up to you. Also, using the "auto" param for -hwaccel is probably the best option; you can specify something specific (like -hwaccel cuvid for nvidia specifically) but "auto" has always done the correct thing on my hardware (I have both intel quicksync as well as NVENC present, and ffmpeg correctly uses the NVENC block for decoding and encoding with -hwaccel auto).

Yes "-hwaccel auto" enables hw DECODING only (unfortunally).
Already discussed here:
[Feature Request] Hardware encoders (hevc_qsv, nvenc_hevc, hevc_amf, vaapi)

@MobyGamer
Copy link
Author

It should still be added, as decoding the source file is necessary to complete both a 1st pass and the 2nd pass, and my use case is recompressing h.265 HDR files to fit within a target bitrate. "-hwaccel auto" drastically reduces CPU usage for supported source codecs in this case.

@MarcoRavich
Copy link

It should still be added, as decoding the source file is necessary to complete both a 1st pass and the 2nd pass, and my use case is recompressing h.265 HDR files to fit within a target bitrate. "-hwaccel auto" drastically reduces CPU usage for supported source codecs in this case.

Same needs here (we have to perform 4K HDR encodings with best possible quality @ 6000kbps), but hw DEcoding doesn't help mutch to be honest.

It would be really great to perform a full - not only decoding - HW-based 1stpass (= "analysis") to feed x265-2ndpass.
We don't know if is technically possible, but theoretically - if the encoders don't "break" the HEVC standard - it should be possible.

@MobyGamer
Copy link
Author

You don't want a hardware ENcoding first pass for a software encoding second pass, because they have incompatible bit allocation strategies. All passes of an N-pass encoding must be with the same encoder.

Even using x265, "-hwaccel auto" still helps, as it makes decoding of supported sources "free", giving more CPU time to the software encode.

@MarcoRavich
Copy link

MarcoRavich commented Apr 24, 2022

You don't want a hardware ENcoding first pass for a software encoding second pass

Right, we would like to have 2-pass hw encoding (which would reduce the whole process needed time - and electricity consumption - of 50% at least).

Even using x265, "-hwaccel auto" still helps, as it makes decoding of supported sources "free", giving more CPU time to the software encode.

Of course, we do always use that FFMPEG parameter in our x265 encodings, but - in our best machine, an i7-7700 - it perform very slow (compared to an "equal parameters" QSV encode on the same source material) anyway.

Last but not least, keep in consideration that we don't care (mutch) about "superfine quality" of the encoding - like x265 seems oriented - 'cause we believe that you have to backup your original "lossless" sources.

Speed and target filesize (then quality) are our goals.

@MobyGamer
Copy link
Author

MobyGamer commented Apr 25, 2022

As a data point, some more details on my usage and the background behind this request: My use case as stated earlier is transcoding 4k HDR rips of my collection to stream to my TV via Plex. My TV, an LG C8, has a processing power upper bound of about 60mbit/s when h.265 decoding occurs at the same time data is being transferred over the network. (Local h.265 files on a usb stick inserted into the TV don't exhibit this problem, nor do h.264 files of the same high bandwidth streamed over the network.) Since most UltraHD 4k files are h.265 @ 60-80mbps, most of them pause and skip when streaming directly to the TV.

My need for transcoding is not to obtain a high-quality replacement for the original files, but rather just a "best effort" that gets stored alongside the original to be switched to in case the original file has sections that exceed the processing bandwidth of my TV. I own an RTX 3080 and leverage it for this in windows using the following arguments (line breaks inserted for formatting, not present in the batch file):

mkdir "Plex Versions\LG C8"

for %%a in ("*.*") do ffmpeg -find_stream_info -hwaccel auto -i "%%a" -map 0 -c copy \
-c:v hevc_nvenc -pix_fmt p010le \
-tune:v hq -preset:v p7 \
-color_primaries bt2020 -color_trc smpte2084 -colorspace bt2020nc \
-spatial_aq:v 1 -temporal_aq:v 1 -b_ref_mode middle \
-profile:v main10 -tier:v high \
-b:v 40M -maxrate:v 60M -bufsize:v 120M \
"Plex Versions\LG C8\%%~na.mkv"

(I suppose another feature request could be "can we have single-pass nvenc encoding, unless I missed that somewhere in fastflix?)

@MobyGamer
Copy link
Author

Now that there have been several releases past the one where this issue was opened, I'm hoping that my feature requests can now more easily be implemented?

cdgriffith added a commit that referenced this issue Apr 20, 2023
cdgriffith added a commit that referenced this issue Apr 21, 2023
* Adding option to disable messages on encoding completion or error
* Adding #266 multiple disposition types for subtitles (thanks to lobofoots)
* Adding #326 support for hwaccel decoding with ffmpeg nvenc (thanks to Jim Leonard)
* Fixing end of run command ran after message box was closed instead of before (thanks to sn6op)
cdgriffith added a commit that referenced this issue Apr 23, 2023
* Adding decoder option for NVEncC and QSVEncC
* Adding option to disable messages on encoding completion or error
* Adding output depth to VCEEncC
* Adding #266 multiple disposition types for subtitles (thanks to lobofoots)
* Adding #326 support for hwaccel decoding with ffmpeg nvenc (thanks to Jim Leonard)
* Adding #329 Hardware VAAPI encoding support for HEVC, H264, VP9 and MPEG2
* Adding #351 option to disable automatic tab switching (thanks to Wontell)
* Adding #357 QSVencC adapt-ref, adapt-ltr, and adapt-qm parameters (thanks to F.O.R.A.R.T.)
* Adding #368 VCEEncC Pre-Analysis options of sc, ss, activity type, caq, sc qp,lookahead, ltr, paq, taq and motion quality (thanks to Wontell)
* Adding #379 #410 dispositions for audio tracks (thanks to markmarz and Don Gafford)
* Fixing videotoolbox setting panels not having custom_q
* Fixing end of run command ran after message box was closed instead of before (thanks to sn6op)
* Fixing changing video or track title did not update the command
@cdgriffith
Copy link
Owner

Can now add that flag for ffmpeg nvenc in 5.5.0! https://github.com/cdgriffith/FastFlix/releases/tag/5.5.0

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

3 participants