Getting started with QSV?

Questions involving a Windows version of FFmpeg.
Post Reply
TobyEggitt
Posts: 3
Joined: Sun Jan 12, 2020 10:58 pm

Getting started with QSV?

Post by TobyEggitt »

Hi all, I'm not sure if I'm in the wrong place, so please be kind if you have to tell me to go away!

I finally managed to build ffmpeg with the Intel support libraries and have managed to get a tiny bit of hardware encoding going. However, it's clear that I don't know what I'm doing, and don't know how to control this. So far, I've found fragments of documentation for this, and 90% of the command line examples simply don't work. Usually, they give useless error messages like this:

Code: Select all

[h264_qsv @ 0x5580736f3340] Error during encoding: unknown error (-21)
. Sometimes they're more useful telling me that parameters aren't right, but not which ones, nor what they should be. That, by the way is setting the context for you to know that I don't know what I'm doing (so please speak very slowly).

My goal is simply to capture a region of my screen without using 3/4 of my CPU (I can do what I want in 100% software, but the CPU usage spoils what I'm capturing).

I have succeeded in making some captures, one using this command line:

Code: Select all

ffmpeg -y -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -f alsa  -i pulse  -acodec ac3 -f x11grab -show_region 1 -framerate 30 -video_size 1280x720 -i :0.0+100,100 -vf 'format=nv12,hwupload' -c:v h264_vaapi -qp 1 output.mp4
and another if I change the h264_vaapi to mjpeg_vaapi.

In the first case, the pixelation is just a bad joke (imagine a Star Trek episode where the comms are down, it's utterly unusable, and frequently takes several seconds to actually update a static screen to the point that any text is readable). In the second case, it's distinctly better, but for capturing text in an editor definitely not good enough to be acceptable.

I tried the other vaapi encoders that I seem to have (hevc, mpeg2, vpa, vp9) and they don't run, complaining of bad parameters mostly. I've requested the qsv encoders, and they just fail to initialize in various ways. What feels like the nearest to success I achieved was with this command line:

Code: Select all

ffmpeg -loglevel debug -y -hwaccel qsv -qsv_device /dev/dri/by-path -f alsa  -i pulse  -acodec ac3 -f x11grab -show_region 1 -framerate 30 -video_size 1280x720 -i :0.0+100,100 -vf 'format=nv12,hwupload' -c:v h264_qsv -qp 1 output.mp4
Which complained that:

Code: Select all

[hwupload @ 0x564251d6b700] A hardware device reference is required to upload frames to.
[Parsed_hwupload_1 @ 0x564251d6b600] Query format failed for 'Parsed_hwupload_1': Invalid argument
But I've not been able to work out what king of hardware device specification it wants (I have tried "card0" and "redererD128" which are the two actual device names under /dev/dri/, but they're both rejected with the same message. That said, the parameter -qsv_device was a guess anyway....

Can anyone tell me where to start looking for the info to configure these things?
Or better yet, simply tell me what to type! :)
TIA
Toby

TobyEggitt
Posts: 3
Joined: Sun Jan 12, 2020 10:58 pm

Re: Getting started with QSV?

Post by TobyEggitt »

Update:

Much more searching later, I discovered a number of things that I *believe* are true (and corrections for any of this are welcome, I really am fumbling in the dark)

1) I believe that QSV codecs are only for transcoding, not for simply encoding. That, if true, would certainly be a good explanation for my abject failure there!
2) It seems that compared to a software compression, hardware compression isn't as "clever" and needs a lot more bandwidth for a comparable result.
3) In trying to force the output of independent frames (that is, frames that describe the entire image, rather than being changes from the previous one) I found I could use "group of pictures" to actually do this.

In the end, item 3 and a generous bandwidth allowance actually got me to a point where the h264_vaapi codec created a good quality output. That was using this command (or some minor variation, I've been tinkering a lot!)

Code: Select all

ffmpeg -y -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -f alsa  -i pulse  -acodec ac3 -f x11grab -show_region 1 -framerate 30 -video_size 1280x720 -i :0.0+100,100 -vf 'format=nv12,hwupload' -c:v h264_vaapi -g 2 -b:v 40M output.mp4
Notice the -g 2 that sets group of pictures to 2 and the bandwidth at 40M. It actually ran at around 25Mbps in practice.

If I let the group size get to 4, there were far too many situations where the last frame at the end of a movement wasn't updated, and pixellation just remained static on the display. Obviously, however, that's a massive bandwidth to be spewing out. I'm currently trying to decide if it's better to hammer my disk (SSD) or my CPU!

Still hoping someone might have the magic incantation for this, since it's clear that my ignorance of the whole system is likely hiding some good stuff still.

TobyEggitt
Posts: 3
Joined: Sun Jan 12, 2020 10:58 pm

Re: Getting started with QSV?

Post by TobyEggitt »

Oh, another small update, although that last-quoted command seemed to create smooth non-pixellated output, it also only generated about half the framerate I requested.

I tried with a 24fps request, and got about 12, I tried with 12 and got about 7! I have no clue what that's about.

Post Reply