7

What is lib Swscale used for by ffmpeg programers?

  • What benefits it gives for AV encoding/decoding?
  • What is its position relevantly to av* libs?
Rella
  • 65,003
  • 109
  • 363
  • 636

2 Answers2

23

Swscale is mainly used for players, not encoding/decoding. It's necessary if you want to display the video at a different pixel size/aspect ratio than it was encoded at and you don't have hardware video scaling support. Swscale also performs colorspace conversion between various RGB and YUV color formats, and conversion between packed (all channels in a single buffer) and planar (each channel has its own buffer) formats. All of these routines are highly optimized; as far as I know, no faster software implementation presently exists for any of them, at least on x86 and x86_64.

Swscale also may be needed for encoding video, if the source video is not already in the format needed by the encoder. For instance, if your source video is RGB, you'll probably need to convert it to the appropriate YUV planar format, since most codecs work on YUV. This entails both colorspace conversion (an affine transformation of the R,G,B vectors) and actual scaling (resampling), since most YUV formats use half-resolution U and V planes (color planes) compared to the Y plane (luma, i.e. intensity data).

R.. GitHub STOP HELPING ICE
  • 208,859
  • 35
  • 376
  • 711
  • Hi, Does Swscale operate on frames only , or can operate on encoded frame too ? For example, if I have encoded buffer in YVU420 format, can I use Swscale to convert it to YUV420 (swap u,v) ? – ransh Mar 31 '15 at 05:40
  • What you're calling "encoded" is not encoded. It's just a normal image format, and yes it should work. – R.. GitHub STOP HELPING ICE Mar 31 '15 at 05:43
  • Hi, isn't there any difference between format of frame before encoding to the buffer format after encoding ? the buffer size after encoding is also not the same size as frame image size (which is HxW). – ransh Mar 31 '15 at 06:01
3

swscale can also do high quality resampling, ex: using the lanczos algorithm. So basically it converts between colorspaces, between "number of bits", and also does resizing. It also has options to use MMX etc. so can be fast.

rogerdpack
  • 62,887
  • 36
  • 269
  • 388