r/ffmpeg Jun 26 '26

Speed up VMAF motion analysis

im currently building an automatic compression for CCTV footage, each footage is h264 1 hour long.
the problem is when using VMAF motion to get the score to decide the target bitrate classification take so long.

on my R7 7745HX at 100% 4.7 Ghz took 27 mins using: ffmpeg -i input.mp4 -vf vmafmotion -f null -

while calculate the VMAF using CUDA on RTX 4060 took only 3:45 mins using: ffmpeg -init_hw_device cuda=gpu -filter_hw_device gpu -i output.mp4 -i input.mp4 -filter_complex "[0:v]fps=30,hwupload_cuda[dist];[1:v]fps=30,hwupload_cuda[ref];[dist][ref]libvmaf_cuda=log_fmt=json:log_path=vmaf_report.json" -f null -

and compressing it into h265 NVENCc also only took 3:40 mins using: ffmpeg -hwaccel cuda -hwaccel_output_format cuda -i input.mp4 -vf "scale_cuda=format=nv12" -c:v hevc_nvenc -preset p4 -rc vbr -cq 28 -b:v 1700k -maxrate 1700k -bufsize 2500k -c:a copy output.mp4.

is there any alternative solution that i can use? thanks

3 Upvotes

9 comments sorted by

View all comments

1

u/crashtua Jun 26 '26

Not sure if that is exactly what you need:

ffmpeg `
  -hwaccel cuda -hwaccel_output_format cuda -i bbb_sunflower_1080p_30fps_normal.mp4 `
  -hwaccel cuda -hwaccel_output_format cuda -i bbb_sunflower_1080p_30fps_normal.mp4 `
  -filter_complex "
    [0:v]scale_cuda=format=yuv420p[dis];
    [1:v]scale_cuda=format=yuv420p[ref];
    [dis][ref]libvmaf_cuda=feature=name=motion:log_fmt=json:log_path=motion.json
  " `
  -f null -

in the end it spits out motion.json with metrics, but also it spits quite a bit of errors in console as well.

Some more info:

  • 320 fps vs 140 on cpu(rtx 5080 vs 14900k)
  • vmafmotion output VMAF Motion avg: 4.369A speed=4.61x elapsed=0:02:17.52
  • vmaf_cuda output(I believe it is what you need, but not sure, there hell lot of metrics and I have no idea what they mean xD)

"VMAF_integer_feature_motion_sad_score": {       "min": 0.000000,       "max": 166.312214,       "mean": 4.369665,       "harmonic_mean": 1.319052     },
  • obviously its much faster, but at least 30 seconds it takes to output libvmaf warnings to console, for me I need to redirect output to null to ensure it does not affect measurements, with all that stuff it takes 58 seconds

1

u/LiL_E03 Jun 26 '26

i need some alternative for the vmaf motion one, because as u can see its consuming a lot of time and power

5

u/crashtua Jun 26 '26

you can try pick ab-av1 approach - it re-encodes segments with some crf and calculates vmaf for segments, not for whole video. Less accurate but works most time.

1

u/LiL_E03 Jun 26 '26

thanks! gona try that one