2

I'm using FFmpeg with Directshow input. The output is a series of single JPEG images. FFmpeg itself maps the stream to mjpeg and uses image2 for the output.

Is it possible to increase performance by using the Intel QuickSync Video (QSV) hardware acceleration for this process? The FFmpeg QuickSync Wiki actually lists JPEG encoding since Braswell.

This is what I tried so far:

ffmpeg -init_hw_device qsv=hw -filter_hw_device hw -f dshow -video_size 3840x2160 -framerate 25 -i "video=My Webcam" -vf hwupload=extra_hw_frames=64,format=qsv -vcodec mjpeg_qsv "C:\out\%d.jpg"

The command works, images are generated - but the GPU load seems to be the same as without any qsv options..?

Thanks!

clic
  • 365
  • 1
  • 13
  • How do you check the GPU load? Like you said already QSV is made by Intel. This runs on the integrated graphics chip of your CPU. So just in case you have another GPU from Nvidia/AMD the load there will not change. If you really did look for the right hardware, you can try to remove your QSV options and compare the CPU load. Depending on resolution, the load might be very low, since your input is dshow and therefore the fps are limited to that source. To see the performance differences with and without QSV, use a video as an input. You can compare the execution time for extracting all frames. – user2267367 Mar 18 '22 at 05:19
  • @user2267367 yes thanks, actually my mistake was that I used GPUz to check the GPU load. It supports the integrated Intel GPUs, but obviously does not show correct values for some reason. Some months ago I checked again with the Windows built in tools and ... it works. GPU load can be observed. – clic Mar 18 '22 at 14:21

1 Answers1

1

I compared it for a h264 encoded video. First with the QSV jpeg encoder:

ffmpeg -c:v h264_qsv -i myvideo.mkv -vcodec mjpeg_qsv images/%06d.jpg

and afterwards without mjpeg_qsv:

ffmpeg -c:v h264_qsv -i myvideo.mkv images/%06d.jpg

The example is minimalistic and can be improved in many ways. In the picture you can see the load of the GPU. In the red box with mjpeg_qsv and the blue box without mjpeg_qsv. The execution time was also better with mjpeg_qsv, speed=3.34x vs speed=1.84x. Since you are using your webcam as an source, your pipeline is limited by the frame rate of the live video. So, your hardware will only process 25 frames per second (-framerate 25). Depending on the resolution and your hardware, this might be an easy job for your GPU, in both cases. Also, make sure you look for the Intel GPU and not your Nvidia/AMD GPU. If you still have the impression that you can't see a performance gain, please let us know both of your commands for comparison.

enter image description here

user2267367
  • 704
  • 7
  • 19
  • for my h264 RTSP IP-cam the input parameters "-c:v h264_qsv" were not enough to activate QSV on the input stream. I had to add "-hwaccel qsv" directly after the ffmpeg command: ffmpeg -hwaccel qsv -c:v h264_qsv – clic Mar 18 '22 at 14:41
  • Yes, there are several improvements to make, this was only a minimal example. The -c:v before the -i is the decoder. Probably your camera stream is not even h264 encoded. Speaking of, many cameras offer a hw mjpeg encoding. If the only purpose is to save the steam as jpgs, this could be a good way for you to try – user2267367 Mar 18 '22 at 21:35
  • any idea on how to control JPG image quality when using mjpeg_qsv? Usually I can use qscale:v but it seems to have no effect when using mjpeg_qsv.. – clic Apr 07 '22 at 15:05