0

I was using sws_scale to convert a group of RGB32 images to YUV420 format. Each image is very similar to the previous one and they only differ on a rectangle region Q.

My question is how to utilize Q to speed up the conversion process? An additional parameter should be added to sws_scale function.

sws_scale( ctx, in_plane, in_stride, sliceY, height, out_plane, out_stride, Q){
    // parameter out_plane stores the YUV420 data of previous image
    Instead of scanning the whole image, scan through rectangle Q{
        Do conversion
    }
}
useprxf
  • 269
  • 1
  • 3
  • 13

1 Answers1

0

No such parameter exists in the current API but you can use sws_scale as is. You can create two contexts - one for whole picture and one for Q; in order to convert only Q:

  • use context you created for Q
  • Shift all data pointers so they all point at first pixel of Q in input/output pictures
  • Leave strides as they were for the full picture

Several caveats here to look for: firstly, since you use YUV420 as output format, you want to increase Q so it starts at even line/column and occupies even width/height (otherwise there can be some distorted color at Q border). Secondly, make sure pointers of all picture planes point to the same pixel - this requires different offsets for each plane depending on a pixel format. Thirdly, this works best if there's no scaling - otherwise resulting picture might not look exactly the same as it would with full-picture scale due to dithering.

Andrey Turkin
  • 1,787
  • 9
  • 18
  • Isn't creating a new context costly from the resource standpoint? For example if the region changes in each frame randomly? – Rudolfs Bundulis Dec 10 '17 at 16:45
  • It depends on your definition of costly. Its a few small memory allocations and some calculations; it is (probably) cheaper to init a new context to do single small region conversion than to do a full frame conversion using single static context. – Andrey Turkin Dec 11 '17 at 10:14
  • I guess I'll dome some bechmarking on libyuv vs swscale w/ new context every time and see how that looks. – Rudolfs Bundulis Dec 11 '17 at 11:20