FFmpeg scaler选择 downsample/upsample

来源:互联网 发布:河南民生网络电视台 编辑:程序博客网 时间:2024/05/14 14:06

使用FFmpeg,进行HD到SD的下采样时,发现锯齿效应(aliasing)明显。顺便看了下FFmpeg中的scaler选择,
上采样要解决的是插值的问题,下采样要解决的是锯齿问题。对于不同视频内容,当然也有选择的必要,如sharp edge。
scale,分别对亮度、色度平面,按照水平垂直处理。色度的size,color range应该都是潜在需要考虑的部分。

参:MPlayer/DOCS/tech/swscaler_methods.txt

artifact types:


  • ringing

wave or noise like patterns around sharp edges
bad: sinc, lanczos (with high filter length)
acceptable: lanczos (with low filter length), cubic, spline
ok: area, (fast)blinear, gauss, point

  • blur

loss of detail / high frequency
bad: gauss with high variance
acceptable: (fast)bilinear, area
ok: others

  • aliasing (only downscale)

straight lines look like staircases
areas of high detail look worse
regular patterns turn into a funny looking mess (moire patterns)
bad: fast bilinear, point, gauss with low variance
acceptable: area
ok: others

  • blocky (only upscale)

looks like the image is made of rectangular blocks like a mosaic
bad: point
ok: others

上采样/下采样 算法推荐:

recommendations: (based upon my personal opinion many ppl might disagree …)


  • the recommended scalers for upscaling:

    • fast_bilinear, point if speed is important
    • cubic, spline, lanczos if quality is important
  • the recommended scalers for downscaling:

    • fast_bilinear, point if speed is important
    • gauss, bilinear if quality is important
    • cubic, spline, lanczos if a sharper picture is important

note: when encoding at a limited amount of bits (not constant quantizer)
then a slightly blurred input might look better after decoding than a slightly
sharpened one, especially for lower bitrates

scaler选择,对应FFmpeg sws序号:

names / artifact types


r ringing b blurry a aliasing (downscale only) m mosaic (blocky) (upscale only)

  • fast bilinear bA
  • bilinear b
  • bicubic high sharpness r low sharpness b
  • experimental ?
  • nearest neighbour AM
  • area ba
  • bicublin r
  • gauss low sharpness B high sharpness AM
  • sinc R
  • lanczos long filter R short filter b
  • bicubic spline r

Notes: area upscale is identical to bilinear

对比
Comparison of OpenCV Interpolation Algorithms

性能对比

参考: 2011-10-29 性能

  • 下采样,1920x1080 > 400x300,风景,帧率:缩放+渲染:
算法 帧率 图像主观评价 fast_bilinear 228 图像无明显失真,感觉效果很不错 bilinear 95 感觉也很不错,比上一个算法边缘平滑一些 bicubic 80 感觉差不多,比上上算法边缘要平滑,比上一算法要锐利 experimental 91 同上 neighbor 427 细节比较锐利,图像效果比上图略差一点点 area 116 与上上算法,我看不出区别 bicublin 87 同上 gauss 80 相对于上一算法,要平滑一些 sinc 30 相对于上一算法,细节要清晰一些 lanczos 70 相对于上一算法,要平滑一点点,几乎无区别 spline 47 和上一个算法,我看不出区别
  • 上采样,1024x768 > 1920x1080,风景,帧率:缩放+渲染:
算法 帧率 图像主观感受 fast_bilinear 103 图像无明显失真,感觉效果很不错 bilinear 100 和上图看不出区别 bicubic 78 相对上图,感觉细节清晰一点点 experimental 106 与上上图无区别 neighbor 112 边缘有明显锯齿 area 114 边缘有不明显锯齿 bicublin 95 与上上上图几乎无区别 gauss 86 比上图边缘略微清楚一点 sinc 20 与上上图无区别 lanczos 64 与上图无区别 spline 40 与上图无区别

在不影响质量的前提下,fast_bilinear的处理性能还是比较优异。与上面的算法推荐相应。