Log in

View Full Version : Scaling issue with ffmpeg


koliva
15th October 2013, 10:12
I have a live encoder + decoder application where the frame width and height may vary over time. I use the following code (simplified) to decode the frames and convert them to RGB32 format:


fDec = avcodec_decode_video2(c1, av_pic, &gPic, &pkt);
if (gPic)
{
swsCtx= sws_getContext(w, h, PIX_FMT_YUV420P, w, h, PIX_FMT_RGB32, SWS_FAST_BILINEAR, NULL, NULL, NULL);
sws_scale(swsCtx, av_pic->data, av_pic->linesize, 0, h, fRGB->data, fRGB->linesize);
}


This code works good and I have the RGB image in the fRGB. The problem happens when I play with the width and height.

Here is the illustration of the problem. I cropped the top-right part of the frame to show you. This is the part before encoding:
http://i1002.photobucket.com/albums/af143/roseframbozen/0_zpsd9e5bded.png

This is the part from the RGB image which is after decoding and color space conversion (above code). As you see, there exists a black bar. This bar actually is not extra like padding but on top of the actual information. So I lose information over there and look annoying. Could anybody point me where I am doing wrong? I got a comment that I need to use visible width instead of linesize when using sws_scale but I didn't get it working. I dumped the encoded frames to check if the problem happens at the encoder side, but has no such black bar over there.
http://i1002.photobucket.com/albums/af143/roseframbozen/1_zps7340d691.png

koliva
15th October 2013, 11:05
Here is a small update which is very weird but works.

swsCtx= sws_getContext(w + 1, h, PIX_FMT_YUV420P, w, h, PIX_FMT_RGB32, SWS_FAST_BILINEAR, NULL, NULL, NULL);


As you see in the above code, if I use w+1 instead of w, it works perfect in every resolutions. However, I need an explanation and verification for this since I don't want my application to crash in the middle of a process.