-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ffmpeg: remove superfluous custom cuvid hwaccel
It's a duplicate of the properly implemented nvdec libavcodec hwaccel Reviewed-by: Timo Rothenpieler <timo@rothenpieler.org> Signed-off-by: James Almer <jamrial@gmail.com>
- Loading branch information
Showing
4 changed files
with
1 addition
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60b1f85
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What have you done? Why you removed
cuvid
?cuvid
is the only correct value for NVIDIA hardware accelerated video decoding. https://trac.ffmpeg.org/ticket/6989#comment:7 explains it very well. It is essential that NVDEC engine software interface is integrated with the CUDA driver, because the video surfaces are allocated by the CUDA driver and can be accessed from CUDA kernels for things like color space conversion. Also some other features are implemented in CUDA.There is no other way you can use NVIDIA hardware accelerated video decoding besides cuvid.
60b1f85
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea what you are talking about, neither here nor in that ticket.
The generic hwaccel code for CUDA hwaccels is in proper shape and correctly sets up the required contexts. The old coda in ffmpeg.c pre-dates it and was removed because it is no longer needed and was causing issues. No functionality was lost or changed in the process.
I just tried all possible combinations of -hwaccel values and legacy cuvid and native nvdec decoding. They all worked perfectly fine.
60b1f85
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes there is native nvdec decoding. The cuvid family is only a legacy standalone decoder that predates the native nvdec hwaccels.
Just doing
ffmpeg -hwaccel cuda -i some_h264_file.mp4 -f null -
will utilize it.The only reason I haven't deprecated the cuvid decoders yet is because they expose some of the scaling/cropping/deinterlacing capabilities of the nvidia hardware, which are otherwise not available.
60b1f85
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still have no idea what you are talking about.
The cuvid decoder and nvdec hwaccels in ffmpeg both utilize the exact same nvidia API. The cuvid decoder is just from before nvidia renamed it to nvdec.
Also no idea what you mean by "outside of CUDA driver". FFmpeg is clearly not a driver, and using the APIs quite successfully.
60b1f85
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue you refer to is not related to the commandline argument, but the decoder being unable to predict how many frames the downstream chain needs.
So the only actual issue I see there is that the maximum number of allocated frames being capped at 32 is too low of a maximum, and should be 128 or something like that.
60b1f85
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see why it would be dead code. It's not in any condition and not in an unused function.
"cuda" is just what ffmpeg calls its generic CUDA hwaccel infrastructure. It created a cuda context and frames context for decoders/filters to use.
FFmpeg is not the nvidia driver.
60b1f85
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both the legacy cuvid decoders and the nvdec hwaccel work fine for me. I'm really confused what kind of issue you are hunting here.
First of all, cuvid_init was removed by this patch. There is no function left in the codebase with that name.
If you do not specify any -hwaccel cuda/nvdec/cuvid parameter to ffmpeg.c, the legacy cuvid standalone decoder will just create its own, copy back the frames to normal frames at the end, and calls it a day.
The nvdec hwaccel relies on being externally supplied with a hwframes context. When passing -hwaccel cuda to ffmpeg.c, the generic codebase will make sure an appropiate one is being created.
decode.c then moves on to call frame_params on the codec specific hwaccel, which sets a few codec specific parameters and then passes on the the generic nvdec.c function ff_nvdec_frame_params. This happens unconditionally. There is no way the fields you are complaining about will ever end up unset. Specially as decode.c itself adds on to the initial pool size based on some more factors.
60b1f85
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of rambling about code out of context and a change you blame for everything not working, why don't you actually demonstrate a command line which does not actually work like its supposed to (and worked with the cuvid option)? And don't just link to some old and long rambling trac issue that supposedly explains it, show actual tangible repeatable examples.
60b1f85
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition https://github.com/FFmpeg/FFmpeg/blob/master/libavcodec/nvdec.c#L303 you are referring to solely exists for a potential API user to supply their own hw_frames_ctx.
The generic hwaccel path, which is now the only path available for CUDA hwaccel, will only create a hw_device_ctx. nvdec.c will thus call ff_decode_get_hw_frames_ctx, which will call avcodec_get_hw_frames_parameters which will call (via the nvdec codec specific frame_params wrapper) ff_nvdec_frame_params, where the desired initial pool size is set.
If an external hw_frames_ctx is supplied, it is expected to be properly setup. The old cuvid hwaccel code in ffmpeg.c did NOT set it up properly, but was only ever meant to run the standalone cuvid family of decoders. Hence why combining -hwaccel cuvid + nvdec decoding used to break.
Instead of patching up the old code to somehow work with it, just removing it entirely and relying on the generic codepath to do its thing works just as fine, and gets rid of needless code duplication.
60b1f85
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only one with attitude in this thread are you. And I haven't seen a single constructive error report, only a lot of opionated criticism.
I asked for an actual error report, something that worked before this change, and something that doesn't work now - basically, a reason why this change is so bad, instead of only theoretical "cuvid is superior" talk. If noone can even point to anything of that sort, then it must not be so bad (nevermind that "cuvid", "nvdec" and "cuda" hwaccels all point to the same code in ffmpeg anyway).
60b1f85
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have actually been discussing adding a deprecation warning to the -hwaccel cuvid compat code, so its likely that it'll make it in there.
In the meantime, the mentioned patch above will restore previous behavior without having to manually specify the output format when using -hwaccel cuvid, but do note that this is considered deprecated and will go away eventually (and using it will then inform you of this, once those patches land).
60b1f85
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cuvid stands for CUda + VIDeo. It's a part of CUDA driver API and is the only way to access NVIDIA video decoding hardware acceleration capabilities. There are no cousins or siblings. It's the only offspring.
60b1f85
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The official name of the decode API, as per Nvidia, is nvdec. When it first launched, it was called cuvid, and because of that all the functions of the API still carry the cuvid prefix.
It was officially renamed, and all documentation and information material you find from Nvidia refers to it as nvdec. For example https://developer.nvidia.com/video-encode-decode-gpu-support-matrix
nvenc was always called nvenc though, and never related to cuvid/nvdec from an API point of view.
60b1f85
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no special "native" acceleration method. There is only one method to access video acceleration: via CUDA driver.
60b1f85
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really do not understand what you are trying to argue against. Nobody has ever doubted that you access the hardware de/encoders via the Nvidia driver.
On top of that, video hwaccel is also not strictly related to CUDA. nvenc is only loosely tied to CUDA and can operate nearly without it other than context bringup.
And for decoding there is at least one other CUDA-free API per OS to utilize it.
Everything else is just about the name of the old cuvid, now nvdec, API. Of course it's the exact same API. It was just renamed, without changing the API in any way.
60b1f85
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're talking about FFmpeg terminology here, not NVIDIA ones. All access to the hardware is obviously done using the same API calls, since there is only one (unless you call platform APIs like DXVA).
In FFmpeg:
None of those names really relate to what is done under-the-hood, since thats obviously all quite similar using the same "NVDEC" (formerly CUVID) API.
60b1f85
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The table at this link in the capabilities of the actual hardware on the chip, i.e. NVDEC and NVENC refer in this table to specific GPU hardware blocks. You can easily see it in the name of the columns. This table has nothing to do with API. For example, the API supports decoding of JPEG, but you won't find it in this table, because it is emulated in CUDA.
60b1f85
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly my point. The access to the hardware is via CUDA driver. Therefore the right name is cuvid.
60b1f85
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nvidia disagrees with that, having renamed it to nvdec in every piece of documentation.
For API and ABI compat reasons, only the technical part of the API itself(i.e. function names, constants, structs, ...) retain the old name.
The only reason I linked that table is to show it's called nvdec, not cuvid or nvcuvid anymore. See also for example https://developer.nvidia.com/nvidia-video-codec-sdk
"NVDECODE API for video decode acceleration (formerly called NVCUVID API)"
60b1f85
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Nvidia driver" usually refers to a display driver. CUDA driver has nothing to do with it. You can access NVDEC hardware via NVIDIA driver, but it's a proprietary API, which NVIDIA never is going to publish.
Only CUDA driver can give you access to the hardware acceleration.
60b1f85
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this table "NVDEC" is the name of the GPU hardware block, which of course has nothing to do with CUDA.
60b1f85
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nvidia only has one big driver. Which provides a ton of different APIs.
So far I have never heard anyone referring to different parts of it as different drivers.
There is no separately installed CUDA-Driver. Only the one, big, Nvidia driver. Internals of the driver, which probably is split into separate parts, are of no concern for the normal direct API user and enduser.
I don't get what kind of weird terminology problems you are fighting about here, but I franky don't care anymore. If you find any actual issues, please open a ticket on trac about them, with commandlines to reproduce.
60b1f85
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a nightmare to program, it won't make life easier. Besides, it can be different for different chips.