Question

I am muxing pictures in the PIX_FMT_ARGB format into an mp4 video.

All of it works well, except that the last pixel row of the outgoing image is screwed up, in most cases the last row is completely black, sometimes there are other colors, it seems somehow dependant on the machine it runs on.

I am absolutely sure that the error must be in sws_scale, as I am saving the images before and after the scaling. The input images do not have the error, but after the sws_scale() I save the yuv image and the error is apparent.

Here is an example:

Original

enter image description here

Yuvfile (after sws_scale)

enter image description here

At the bottom of the Yuvfile, you will see the black row.

This is how I do the scaling (it is after the official ffmpeg examples, more or less):

static int sws_flags = SWS_FAST_BILINEAR | SWS_ACCURATE_RND;

if (img_convert_ctx == NULL)
{
   img_convert_ctx = sws_getContext( srcWidth, srcHeight,
           PIX_FMT_ARGB,
           codecContext->width, codecContext->height,
           codecContext->pix_fmt,
           sws_flags, NULL, NULL, NULL );
   if (img_convert_ctx == NULL)
   {
      av_log(c, AV_LOG_ERROR, "%s","Cannot initialize the conversion context\n");
      exit(1);
   }
}
fill_image(tmp_picture, pic, pic_size, frame_count, ptr->srcWidth, ptr->srcHeight );

sws_scale(img_convert_ctx, tmp_picture->data, tmp_picture->linesize,
        0, srcHeight, picture->data, picture->linesize);

I also tried a number of different SWS_ flags, but all yield the same result.

Could this be a bug in sws_scale or am I doing something wrong? I am using the latest version of the ffmpeg libraries.

Was it helpful?

Solution

The problem was this function:

fill_image(tmp_picture, pic, pic_size, frame_count, ptr->srcWidth, ptr->srcHeight );

It did not copy the input image to the tmp_picture correctly. Indeed skipped the last line.

Morale: Do not trust years-old functions :D

OTHER TIPS

180 is not a multiple of 8, this could be the reason for the black row. Can you try scaling it to the nearest multiple of 8,say 184 or 192(multiple of 16)? Non h264 codecs need multiple of 8 as height.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top