[Libav-user] sws_scale - "Warning: data is not aligned!" when using opencv::Mat

Carl Eugen Hoyos ceffmpeg at gmail.com
Sat Dec 22 20:26:20 EET 2018


2018-12-22 18:41 GMT+01:00, Wodzu <brucedickinson at wp.pl>:

>> 2018-12-22 15:33 GMT+01:00, Wodzu <brucedickinson at wp.pl>:
>>
>> > I am using this code (simplified to show the issue) to convert
>> > from AV_PIX_FMT_GRAY8 to AV_PIX_FMT_YUV420P:
>>
>> Are you sure that you need to convert?
>> This depends on the range of your gray8 input, assuming you
>> want mpeg range for encoding.
>>
>> Newest x264 also supports gray8 as input.
>
> I've tried to remove
> sws_scale from my code and replaced it with:
>
> av_image_fill_arrays(frame->data, frame->linesize, image_data,
> AV_PIX_FMT_GRAY8, context->width, context->height, 0)
>
> But now I am getting "Input picture width (1280) is greater than stride (0)"
> when call to avcodec_send_frame is being made.
> frame->linesize data is {1280, 0, 0, 0, 0, 0, 0, 0}  Should I change this
> manually? I am shooting in the dark here...

First, I meant you can only remove the conversion if you verified
that the range of your input is the same (mpeg range) as the range
expected by your h264 encoder.
Second, if you are using libx264, it nowadays accepts gray8 as input
(instead of yuv420p), if you use it, there should be no additional steps
necessary, you pass the gray8 frames to libx264.

If you need AV_PIX_FMT_YUV420P, you could fake it by using
the (only) one plane of your gray8 frame and use it as y plane
for yuv420p. Iirc, you have to set the other two planes to 0x80...

Please do not top-post here, Carl Eugen


More information about the Libav-user mailing list