Log in

View Full Version : Verify quicksync, nvenc, and questions


jmac698
23rd January 2017, 07:46
Hello,
I have quicksync/nvidia hardware for the first time, and have a few questions.

Specs
I am using windows 8.1 64 bit, intel HD 3000 GPU and NVIDIA NVS 4200M
https://www.nvidia.com/object/nvs_techspecs.html

Questions
I tried using ffmpeg 3.2.2, the build from http://www.videohelp.com/software/ffmpeg, which has flags including -enable-nvenc. I'm not sure if there's supposed to be a flag for quicksync support but I don't see anything suggestive.

I tried using
ffmpeg -i sample.mpg -vcodec h264_qsv sample.mp4
but received the error:
[h264_qsv @ 0000000001e04500] Error initializing an internal MFX session

1) Is this the proper command to invoke quicksync encoding?
2) Does this binary support the codec and how can I tell, and if not where can I find the right build?
3) With quicksync enabled, does ffmpeg support both decoding of the mpg and encoding of the h264 in hardware? Is the decoding part considered quicksync or is it a normal part of dxva decoding?
4) What would be the command to use nvenc for comparison? Could I use use the hardware encoders of both GPU at the same time?
5) What are the requirements for using quicksync, how does it interact with Optimus (a type of hybrid graphics switching)?
6) My searches returned mention of making a virtual monitor to enable quicksync, is that necessary? Can I use it whether I use the laptop screen, external monitor, or both in extended or clone mode?
7) Does ffmpeg or any other encoder also support directcompute/opencl/CUDA based acceleration?
8) Which do you think would be faster, nvenc, quicksync, cuda, or cpu? Which one would use the least CPU % and why would fully hardware decode + encode use any CPU at all?
9) Can I create several encodes from the same source at the same time? That would be really awesome for some applications! Like comparing encoder settings.
10) Big one - is there a utility that can verify nvenc/quicksync availability so I can be sure everything is working. I tried DXVA checker but that didn't tell me much.
11) Once I actually get it working, what are some of the common programs which are enabled for hardware encoding for both nvidia and quicksync? ffmpeg, handbrake, anything else (looking for free as in beer or opensource here).

Sorry for all the questions, at the end of the day I'd like good quality and faster encodes, especially if it frees my CPU to do other things.

p.s. it may be relevant that I can't use Nvidia stock drivers, only OEM ones. When I tried Nvidia drivers, 3d apps were very slow (perhaps only using the Intel GPU).

Thanks for your help!

poisondeathray
23rd January 2017, 18:29
It has to be built with --enable-libmxf for qsv

Check if your intel drivers are updated

But I seem to recall that ffmpeg qsv dropped older Intel processor support (sandy bridge)


3) With quicksync enabled, does ffmpeg support both decoding of the mpg and encoding of the h264 in hardware? Is the decoding part considered quicksync or is it a normal part of dxva decoding?


gpu decoding is b0rked in general with ffmpeg . All variants. Including dxva, qsv, nv . At least on windows. Currently either it doesn't work at all, or it's much slower than CPU decoding

It works with rigaya's nvencc/qsvencc builds



4) What would be the command to use nvenc for comparison? Could I use use the hardware encoders of both GPU at the same time?

-c:v nvenc_h264

not sure if you can encode with both simultaneously; probably with 2 separate instances



8) Which do you think would be faster, nvenc, quicksync, cuda, or cpu? Which one would use the least CPU % and why would fully hardware decode + encode use any CPU at all?


nvenc is the fastest with pascal cards


9) Can I create several encodes from the same source at the same time? That would be really awesome for some applications! Like comparing encoder settings.


You can if the GPU encoder isn't full utilized. For example with SD encodes I tested an only 40-50% utilization from NVEncC , I was able to use 2 instances to get 100% . It's basically linear scaling if no bottlenecks (including decoding, I/O bottlenecks)



11) Once I actually get it working, what are some of the common programs which are enabled for hardware encoding for both nvidia and quicksync? ffmpeg, handbrake, anything else (looking for free as in beer or opensource here).



I think staxrip and hybrid are GUI's that have access to both

jmac698
24th January 2017, 08:45
Thank you, that's a very useful post. Your observations of the current state of ffmpeg and where to find working builds is something that would take me a lot of research to find.

I've done more of my own research, and will add to this discussion for any future searching engine hits who may find it useful.

Nvidia
nvdec is a separate hardware video decoding block on Fermi (GF1xx) and higher GPUs. The capabilities are listed in the NVDecode Programming Guide https://developer.nvidia.com/nvdec-programming-guide

nvenc is for encoding. It is available on Kepler and later GPUs. (GKxx).

Therefore Fermi (my GF119) only supports decoding.

FFMPEG and nvenc support
type ffmpeg and look for --enable-nvenc
then use, as an example,
ffmpeg -i sample.mpg -c:v nvenc_h264 sample.mp4
However, apparently this way is obsolete, I got the message
[nvenc_h264 @ 0000000000549be0] This encoder is deprecated, use 'h264_nvenc' instead
Since I don't have nvenc in Fermi, I got the error
[h264_nvenc @ 0000000001cc9be0] Cannot load nvEncodeAPI64.dll
This missing dll should be installed with your Nvidia display drivers.

It should be possible to make use of nvdec to quickly decode the input stream to pass to the cpu/software encoder, with the right software. The Nvidia site also says it's possible to pass the decoder directly to the encoder in hardware so it should use no cpu time (but there is the exception that some encoder features use a small amount of cuda resources).

Rigaya's software can be found here
http://rigaya34589.blog135.fc2.com/blog-category-10.html

The download link for nvenc is here
https://drive.google.com/drive/folders/0BzA4dIFteM2dS1ZUT1FjTnF3Q0E

Intel

Quicksync and ffmpeg support

requires --enable-libmxf to show when running ffmpeg. This dll is libmfxhw64.dll which should be installed with your video driver. For example for HD 3000 I had v1.4.
Also requires Intel Media SDK installed. This SDK requires gen 3 Intel CPU (Ivy Bridge) for hardware acceleration. I believe this is why I can't get ffmpeg to work on my Sandy Bridge, though I don't know why other software can work, or that decode support works in ffmpeg.
Finally needs OpenCL support. OpenCL is not supported on the 2nd gen/hd 3000/sandy bridge GPU. It won't be due to resource contraints at Intel and also it would be pointless as it has half the compute power of the CPU (from intel developer forum, lost link). OpenCL can be emulated on the CPU at version 1.2 (https://software.intel.com/en-us/articles/opencl-drivers)

Can also use Rigaya's software.
The download link for qvsenc is here
https://onedrive.live.com/?id=6BDD4375AC8933C6!482&cid=6BDD4375AC8933C6
This program will do hardware mpeg2 or h264 encoding.

FFmpeg

ffmpeg build
The version at http://www.videohelp.com/software/ffmpeg had both libmxf and nvenc support built-in (retrieved 1-24-2017), however I couldn't get the quicksync feature to work (the nvenc feature is not possible for me).

FFmpeg supports hardware decoding and hardware encoding in various combinations. It is explained here
https://trac.ffmpeg.org/wiki/HWAccelIntro

I have tested dxva2 decoding in hardware and reached 258fps on an sd mpg. I tested qsv decoding at 1320fps. No acceleration was about the same. 4 threads speeds this to about 2500fps. Also libmfx selects qs support if present, so I may not be using qs at all.

ffmpeg -hwaccel qsv -threads 1 -i sample.mpg -f null - -benchmark
ffmpeg -hwaccel dxva2 -threads 1 -i sample.mpg -f null - -benchmark

poisondeathray
24th January 2017, 16:32
Thanks for sharing your observations

The HW decoding seems at least partially fixed in ffmpeg. That is new (within last few months) . ffmpeg dxva2 decoding is unstable with h264 . It still is unless something was fixed in the last few days. It might work with mpeg2 as suggested in your test.

qsv and h264_cuvid (both qs and nv using -hwaccel_device to select , verified with GPU-z) seem to work with decoding h264. This is new. But qsv decoding (not through cuvid) pegs the CPU usage near 100% so something is still wrong . The others are between 10-20% . GPU-z suggests the proper GPU is working (indirectly by temperature with qs, but nv has a video engine load readout as well)

I only looked at preliminary speed tests. Nothing validity of frames yet. Because in the past, both qs and nv with either ffmpeg or rigaya's nvencc or qsvencc had issues with decoding (unless indexed with dgindexnv through avs or vpy). Either dropped frames or corrupted frames, not frame accurate. The only stable way was either indexed GPU, or CPU decoding. I'll revisit this when I have time

jmac698
25th January 2017, 14:19
Very interesting. I am looking forward to ffmpeg acceleration working properly, perhaps in the next few months.

I can add one insight, in something I read (I forget where), there was mention of having to copy between system/CPU memory and GPU memory, and that might use CPU time. It doesn't seem to make sense, as I thought that would be DMA, but even DMA in small chunks and often would take some CPU for setup time. Or there is some unoptimized part. Anyhow, I think they said that's why there was still CPU used for fully hardware encode/decode in some case.

There would also be CPU used for high level things like file reading, muxing, audio pass through, etc.

lansing
23rd July 2018, 04:13
I'm confused about all the different works. Is nvidia's nvenc and NVEnc developed by Rigaya referring to the same work? Since they have the same name? How about the h264_nvenc from ffmpeg?