Rhot
Rhot

Reputation: 63

ffmpeg libavcodec AVPixelFormat for png

What AvPixelFormat i should use for *.png (PNG-24 and PNG-8) image? I am trying to convert from png to PIX_FMT_YUV420P using sws_scale

Edit, code:

avpicture_fill((AVPicture*)m_encode_inpic, (uint8_t*)imagePixels, <WHAT PNG PIXELS FORMAT?>, m_imgInputWidth, m_imgInputHeight);                   //imagePixels is png bytes 
avpicture_fill((AVPicture*)m_encode_outpic, m_encode_outbuffer, PIX_FMT_YUV420P, m_encode_codec_context->width, m_encode_codec_context->height);

av_image_alloc(m_encode_outpic->data, m_encode_outpic->linesize, m_encode_codec_context->width, m_encode_codec_context->height, m_encode_codec_context->pix_fmt, 1);

struct SwsContext* fooContext = sws_getContext(m_videoOutputWidth, m_videoOutputHeight, PIX_FMT_RGB32, m_encode_codec_context->width, m_encode_codec_context->height, PIX_FMT_YUV420P, SWS_FAST_BILINEAR, NULL, NULL, NULL);
sws_scale(fooContext, m_encode_inpic->data, m_encode_inpic->linesize, 0, m_encode_codec_context->height, m_encode_outpic->data, m_encode_outpic->linesize);   

Jpeg pixel format is AV_PIX_FMT_YUVJ420P, but what format is for PNG?

Upvotes: 0

Views: 2054

Answers (1)

szatmary
szatmary

Reputation: 31120

You must decode the PNG first. SWS only works on raw pixels. Think of a compressed graphics file kind of like a zip file. You must first decompress it before you can see what is inside. Usually your browser, or other program does this for you automatically. You can use libavcodec to decompress the PNG then use pix_fmt form the codec context.

Upvotes: 3

Related Questions