Olive: [CODEC] Hardware accelerated video decoding/encoding

Created on 8 Feb 2018  路  28Comments  路  Source: olive-editor/olive

do it

Codec Export Low Priority

Most helpful comment

I've actually seen an example of being able to transfer OpenGL textures to CUDA memory to be encoded by FFmpeg. At least as far as NVENC goes, this may be a lot easier than initially expected. Maybe this is the same for VAAPI/VDPAU.

All 28 comments

Presently, I don't think I would use the existing FFmpeg library for this because there doesn't seem to be a (documented) way to decode an H.264 frame and draw an OpenGL texture with it. The official NVIDIA NVDEC documentation states very clearly how to do this, so it seems like using that directly would be a better solution.

Currently is there any Hardware decoding / encoding (mainly decoding) for ProRes or other high quality editing formats? (not in Olive, but available as a library etc.)

I am aware that Apple has an private API for accelerating ProRes, which obviously isn't available, but I don't know of any for DNxHD or similar. Hardware decoding for intermediate media would be very useful when Olive gets the ability to render material in the timeline, speeding up the process and also quickly zooming over media.

As far as I know there isn't, NVENC/NVDEC seem to be solely for H.264 and HEVC. Perhaps it would be possible for someone to write a decoder for OpenCL, but I don't think it exists at the moment.

For an optimised internal media codec, possibly Cineform could solve this issue. It is highly optimised, (much more than ProRes) and it鈥檚 also MIT licensed.

Like other NLE鈥檚 there could be an option to optimise media in bins, which would initiate a conversion of selected media into Cineform for editing.

Although I am not aware if Cineform is GPU accelerated, internal usage could provide a substantial speed up, especially with modern CPU鈥檚.

FFmpeg's ProRes decoder is multi-threaded and afaik, the format is not that complex.

It would be nice if possible to include AMD hardware support (theoretically even dual-GPU things down the line, as my laptop's APU paradoxically supports many more codecs in hardware than the dedicated GPU, so that's just lovely).

Presently, I don't think I would use the existing FFmpeg library for this because there doesn't seem to be a (documented) way to decode an H.264 frame and draw an OpenGL texture with it.

h264-vaapi provides hardware acceleration for thr first half of the process, though I'm not sure about the "OpenGL texture" thing.

I'm aware FFmpeg has hardware accelerated encoders, but the important part is directly interfacing with OpenGL. Otherwise the (most likely) workflow would be transferring a packet to the GPU for decoding, transferring the decoded frame back to the CPU, and the CPU transferring the frame back to the GPU as an OpenGL texture. The overhead of transferring data back and forth negates any performance improvement.

At one point Intel QuickSync was implemented, but showed little to no improvement because of a workflow similar to this. A lot of hardware accel libs _can_ interface with OpenGL (notably NVENC/NVDEC), but it doesn't seem FFmpeg exposes this functionality meaning the libs will likely have to be implemented manually.

A lot of hardware accel libs _can_ interface with OpenGL (notably NVENC/NVDEC)

Umm, would that also include VAAPI/VDPAU? I only really know of their use in VLC, and it doesn't seem to be bottlenecked anywhere, so I would assume as much.
If that _IS_ the case, how realistic would it be to implement within one to two years (if that works like that and is implemented, it would open it up to those not using Nvidia's silicon, so here's hoping)?

@elsandosgrande From what I can tell, yes VAAPI has a system of encoding/decoding H.264 frames to OpenGL textures. The only equivalent I could find with QuickSync was interfacing with DirectX textures which won't work for Olive (but perhaps there's another way to do those). All I'm saying is it seems all of these will have to be implemented outside of FFmpeg which is unfortunate (unless somewhere more familiar with FFmpeg knows more about this).

From what I can tell, yes VAAPI has a system of encoding/decoding H.264 frames to OpenGL textures. All I'm saying is it seems all of these will have to be implemented outside of FFmpeg which is unfortunate (unless somewhere more familiar with FFmpeg knows more about this).

Well then...
One, yes, there is hope!
Two, guess I better get acquainted with FFmpeg's codebase then.

I believe that Nvidia can now decode/encode h264 & h265 directly on the GPU.
In Davinci Resolve, Blackmagic enabled this for Nvidia cards (obviously):
https://forum.blackmagicdesign.com/viewtopic.php?f=21&t=82235

nvidia_gpu

I believe that Nvidia can now decode/encode h264 & h265 directly on the GPU.

Any word on AMD cards?

NVENC/NVDEC has been a thing for quite some time, but it looks like Resolve has just implemented it. It'd be very cool to have this, but as I said before I'm not sure I can get it (and libs like it) working with the current FFmpeg workflow.

Any word on AMD cards?

I think VAAPI/VDPAU is still our best bet. The only OpenCL-based H.264 is proprietary and expensive to license.

@itsmattkc Wait, is the only one referring to Nvidia or AMD?

@elsandosgrande I was mostly talking about AMD, but it does seem VDPAU can provide some acceleration for NVIDIA cards too.

I'm not sure I can get it (and libs like it) working with the current FFmpeg workflow.

Moving towards an internal design that disconnects FFmpeg from input/output is probably a good idea then. (I'm not saying to get rid of FFmpeg) Being able to use FFmpeg to get footage into Olive, then have Olive do what it needs to the footage, (editing/effects) then exporting using independent libraries / backends. I think that implementing a caching system would go a long way to detaching FFmpeg, per the discussion in #237

I've actually seen an example of being able to transfer OpenGL textures to CUDA memory to be encoded by FFmpeg. At least as far as NVENC goes, this may be a lot easier than initially expected. Maybe this is the same for VAAPI/VDPAU.

It would be a good idea, Nvidia is pushing NVENC technology. However this would also leave Intel & AMD users out in the dark?

That's hopefully what VAAPI/VDPAU will help address if the same thing can be done for that API, but yes NVENC is naturally NVIDIA exclusive.

+1 for supporting Cineform

I've cooled down on the idea of supporting Cineform, however what other decoders apart from FFmpeg (libav) are there on the Linux front? (or more specifically OSS front)

There are no other decoders for ProRes, DNxHD etc. For H264 / 5 yes, probably NVENC but that is basically all.

@alcomposer coughVAAPIcough

I wonder if OBS supports QuickSync only on Windows, where it uses a DirectX renderer (for encoding though). There is support for AMD cards through https://github.com/obsproject/obs-amd-encoder - probably limited to h.264?

h264_nvenc even if only for export it would be nice, I use it with ffmpeg and it makes the difference.

Many GPUs screw up the encoding if done using their API paths. It wasn鈥檛 uncommon for example, for video sites to have the wrong decoding when flipping to full screen GPU. Clueless monkeys at the GPU driver level shouldn鈥檛 surprise anyone.

I tried a raw patch over the 0.1.x branch, I added a dummy codec in export, video only, which uses popen () to launch ffmpeg with rawvideo input and h264_nvenc output.

The encoding of a half-hour video has gone from half an hour to less than 15 minutes (but without audio, and probably I should check other quality factors), but the most interesting difference for me is that the CPU load remains almost free and does not heat up at 90掳 for half an hour (the GPU reaches at most only 50掳/60掳).

I believe that for export, launching a process could be interesting, it's simple to make and there is no need to link libraries

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Reaper10 picture Reaper10  路  31Comments

winfr34k picture winfr34k  路  20Comments

sobotka picture sobotka  路  35Comments

Symbian9 picture Symbian9  路  18Comments

itsmattkc picture itsmattkc  路  18Comments