[Libav-user] Encoding profile for H.264 cannot be changed

Baris Demiray barisdemiray at gmail.com
Mon Oct 19 16:32:40 CEST 2015


Hi all,

I have been trying to change the encoding profile for H264 with no luck.
There are few questions here and on SO with no helpful answers that I came
across. So I looked at FFmpeg code and found that
in libavcodec/libx264.c:X264_init(AVCodecContext *avctx),
AVCodecContext->priv_data becomes X264Context with,

X264Context *x4 = avctx->priv_data

And then AVCodecContext->profile is processed only when
AVCodecContext->priv_data["profile"] (which later magically becomes
X264Context->profile) is NULL,

    /* Allow specifying the x264 profile through AVCodecContext. */
    if (!x4->profile)
        switch (avctx->profile) {
        case FF_PROFILE_H264_BASELINE:
            x4->profile = av_strdup("baseline");
            break;
        case FF_PROFILE_H264_HIGH:
            x4->profile = av_strdup("high");
            break;
        case FF_PROFILE_H264_HIGH_10:
            x4->profile = av_strdup("high10");
            break;
        case FF_PROFILE_H264_HIGH_422:
            x4->profile = av_strdup("high422");
            break;
        case FF_PROFILE_H264_HIGH_444:
            x4->profile = av_strdup("high444");
            break;
        case FF_PROFILE_H264_MAIN:
            x4->profile = av_strdup("main");
            break;
        default:
            break;
        }

I've been fiddling around these following two lines of my code for two days,

    av_opt_set(m_codecContext->priv_data, "profile", "high", 0);
  m_codecContext->profile = FF_PROFILE_H264_HIGH;

But I'm still getting following line in the logs,

[libx264 @ 0x209ae40] profile Main, level 1.2

But when I do,

    av_opt_set(m_codecContext->priv_data, "profile", "nosuch", 0);

I get,

    x264 [error]: invalid profile: nosuch
    [libx264 @ 0x25d0060] Error setting profile nosuch.
    [libx264 @ 0x25d0060] Possible profiles: baseline main high high10
high422 high444

So it's taken into account and "high" is a valid value but it's just not
working. My log level is TRACE but there is no "You wanted high but I
fallback to Main because..." kind of message.

How do I set profile? And what are the conditions that libavcodec changes
it on its own? Any clues, please?

Thanks a bunch in advance!

-- Baris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20151019/bec4f874/attachment.html>


More information about the Libav-user mailing list