3

I'm converting some code from FFMPEG 0.8 to FFMPEG 1.2. I have an error during the call to the method avcodec_open2():

Specified pixel format %s is invalid or not supported

The format I use is : AV_PIX_FMT_RGB24. It should be enabled by default, right?

Below is my code:

av_register_all();

codec = avcodec_find_encoder(AV_CODEC_ID_MPEG2VIDEO);

if(!codec)
{
    throw SystemException("codec not found");
}

codecContext = avcodec_alloc_context3(codec);

codecContext->bit_rate = 200000;
codecContext->time_base.den = 1;
codecContext->time_base.num = 90000;
codecContext->gop_size = 8;
codecContext->pix_fmt = AV_PIX_FMT_RGB24;

_codecContext->width = 320
_codecContext->height = 240

if(avcodec_open2(_codecContext, _codec, NULL) < 0)
{
    throw SystemException("Unable to open codec");
}

2 Answers 2

5

In latest version of ffmpeg MPEG2/MPEG1 AV_PIX_FMT_RGB24 is not supported.

You will need to use AV_PIX_FMT_YUV420P or AV_PIX_FMT_YUV422P.

So I if your input PIX format is not AV_PIX_FMT_YUV420P/AV_PIX_FMT_YUV422P, you will need a conversion. You can make use of Sws_Context and sws_scale for the same.

Sign up to request clarification or add additional context in comments.

1 Comment

Where is this documented?
1

Instead of converting to YUV420P you could also use libx264rgb codec, rather than libx264. It supports the current AV_PIX_FMT_RGB24 type.

1 Comment

Can you elaborate how to do that?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.