'How to use Intel QSV record screen based on ffmpeg

I want to record my screen with ffmpeg.
I succeeded in the normal way.
ffmpeg -f gdigrab -framerate 30 -draw_mouse 1 -i desktop -c:v h264 -r 30 -preset ultrafast -tune zerolatency -pix_fmt yuv420p "record.mp4"

But I want use GPU record my screen now.
I'm trying to use Intel QSV on ffmpeg.
ffmpeg -f gdigrab -framerate 30 -draw_mouse 1 -i desktop -c:v h264_qsv -r 30 -tune zerolatency -pix_fmt yuv420p "record.mp4"

It does not work and show:
[h264_qsv @ 0000000000479080] Error initializing the encoder: invalid video parameters (-15) Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height I don't know what happened.

And I'm trying simple way.
ffmpeg -i test_input.mp4 -c:v h264_qsv -preset:v faster test_output.mp4
It does not work too.

My computer information:
acer notebook: TravelMate P243-MG
OS: windows 7 64bits
CPU: Intel i5-3210M
Graphics card: Nvidia GT-630M

Thanks in advance!



Solution 1:[1]

As your output says, you must set width and height. Also, QSV doesn't have options such as -tune zerolatency, and -pix_fmt yuv420p may be invalid to QSV.
Just try here.


$ ffmpeg -f gdigrab -framerate 30 -i desktop -an -c:v h264_qsv -video_size 640x480 output.mp4

Solution 2:[2]

Very late to this party. But it looks like you're using Intel QSV on an NVidia card. Hardware encoding moves the processing from cpu to gpu - so it has to match your hardware.

Take a look at https://trac.ffmpeg.org/wiki/Capture/Desktop which suggests using "-c:v h264_nvenc -qp 0" instead of "-c:v h264_qsv"

Solution 3:[3]

You need to tell ffmpeg to upload the video frames to the Intel GPU. Try this:

ffmpeg -init_hw_device qsv=hw -filter_hw_device hw -f gdigrab -i desktop -vf hwupload=extra_hw_frames=64 -c:v h264_qsv record.mp4

You can find more information on how to use Intel Quick Sync Video (QSV) at https://trac.ffmpeg.org/wiki/Hardware/QuickSync

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 n-kai-cj
Solution 2 bigAl
Solution 3 Francisco Vera