2

I'm using a NVIDIA Quadro P4000 and my config is Intel i7 2.4 GHz with 8 Go of RAM. I'm working on Ubuntu 16.04, I've installed NVIDIA drivers using apt repo aswell as CUDA. I'm using FFmpeg in version 3.3.

I've managed to display a mosaic of 4 x 4K videos (same videos for test purpose) with FFmpeg, using hardware acceleration (previous post), using this command line :

ffmpeg \
-hwaccel cuvid -c:v h264_cuvid -i bbb_sunflower_2160p_30fps_normal.mp4 \
-hwaccel cuvid -c:v h264_cuvid -i bbb_sunflower_2160p_30fps_normal.mp4 \
-hwaccel cuvid -c:v h264_cuvid -i bbb_sunflower_2160p_30fps_normal.mp4 \
-hwaccel cuvid -c:v h264_cuvid -i bbb_sunflower_2160p_30fps_normal.mp4 \
-filter_complex "nullsrc=size=2560x1440 [base]; \
[0:v] scale_npp=1280:720, hwdownload, format=nv12 [upperleft]; \
[1:v] scale_npp=1280:720, hwdownload, format=nv12 [upperright]; \
[2:v] scale_npp=1280:720, hwdownload, format=nv12 [lowerleft]; \
[3:v] scale_npp=1280:720, hwdownload, format=nv12 [lowerright]; \
[base][upperleft] overlay=shortest=1:eval=init [tmp1]; \
[tmp1][upperright] overlay=shortest=1:eval=init:x=1280 [tmp2]; \
[tmp2][lowerleft] overlay=shortest=1:eval=init:y=720 [tmp3]; \
[tmp3][lowerright] overlay=shortest=1:eval=init:x=1280:y=720, hwupload_cuda" \
-c:v h264_nvenc -preset llhp -profile:v baseline -f matroska pipe:1 | ffplay -i -

Now my issue is about performance, videos are played at 80% of their original speed, so close to my goal...

As I understand from now, this manipulation has several steps :

  1. The four videos are decoded by the GPU.
  2. Scaling to 720p is also performed by the GPU.
  3. The four flux are downloaded in the CPU and formated in NV12.
  4. Mosaic is made by the CPU using overlay filter.
  5. Mosaic video flux is uploaded in the GPU.
  6. The GPU encodes it in H.264.

After this I'm not sure if the encoded video is retrieved by the CPU and then piped to ffplay or if it's stays in the GPU and directly displayed on the monitor.

Moreover, I'd like ffplay to use hardware acceleration but I didn't manage to force it to use h264_cuvid.

9
  • ffplay s/w h264 decoder gives me 300 fps for a 1440p stream on a Ivy Bridge i5 so that's not the bottleneck. Check the presets for nvenc.
    – Gyan
    Oct 24, 2018 at 10:56
  • I've tried all presets and all profiles but I still got speed around 0.8, sometime worse
    – c.censier
    Oct 24, 2018 at 12:07
  • What's the fps speed if you replace -c:v h264_nvenc -preset llhp -profile:v baseline -f matroska pipe:1 with -an -f null -?
    – Gyan
    Oct 24, 2018 at 12:11
  • I get a speed around 0.9
    – c.censier
    Oct 24, 2018 at 12:18
  • ok, what about ffmpeg -hwaccel cuvid -c:v h264_cuvid -i bbb_sunflower_2160p_30fps_normal.mp4 -hwaccel cuvid -c:v h264_cuvid -i bbb_sunflower_2160p_30fps_normal.mp4 -hwaccel cuvid -c:v h264_cuvid -i bbb_sunflower_2160p_30fps_normal.mp4 -hwaccel cuvid -c:v h264_cuvid -i bbb_sunflower_2160p_30fps_normal.mp4 -map 0:v -map 1:v -map 2:v -map 3:v -f null - ?
    – Gyan
    Oct 24, 2018 at 12:31

1 Answer 1

2

The problem was about the overlay filter which is too slow. I've changed for a combination of hstack and vstack as you can see here :

ffmpeg \
-hwaccel cuvid -c:v h264_cuvid -i bbb_sunflower_2160p_30fps_normal.mp4 \
-hwaccel cuvid -c:v h264_cuvid -i bbb_sunflower_2160p_30fps_normal.mp4 \
-hwaccel cuvid -c:v h264_cuvid -i bbb_sunflower_2160p_30fps_normal.mp4 \
-hwaccel cuvid -c:v h264_cuvid -i bbb_sunflower_2160p_30fps_normal.mp4 \
-filter_complex " \
[0:v] scale_npp=1280:720, hwdownload, format=nv12 [upperleft]; \
[1:v] scale_npp=1280:720, hwdownload, format=nv12 [upperright]; \
[2:v] scale_npp=1280:720, hwdownload, format=nv12 [lowerleft]; \
[3:v] scale_npp=1280:720, hwdownload, format=nv12 [lowerright]; \
[upperleft][upperright] hstack [upperline]; \
[lowerleft][lowerright] hstack [lowerline]; \
[upperline][lowerline] vstack [mosaic]; \
[mosaic] hwupload_cuda" \
-c:v h264_nvenc -preset llhp -profile:v baseline -f matroska pipe:1 | ffplay -i -

It works very well and I even can build a 1080p mosaic using lossless preset and high444p profile.

1
  • 1
    You should switch to xstack filter, it would give even more speed boost as it would be called only once as it is single filter.
    – user12174
    Aug 13, 2019 at 12:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.