Opened 12 years ago

Closed 12 years ago

#1548 closed defect (invalid)

avcodec ignores profile when using ffmpeg C API

Reported by: TheSHEEEP Owned by:
Priority: important Component: avcodec
Version: 0.10.4 Keywords: libx264
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

I first posted this on stackoverflow as I thought this was my mistake (maybe it is), but was encouraged that this might be a bug in ffmpeg.

I am encoding an h264 mp4 in code using the latest ffmpeg libraries on Windows. I definitely set the profile property of the AVCodecContext to FF_PROFILE_H264_CONSTRAINED_BASELINE.

However, no matter what I set the profile property to, the video always ends up using the "High" profile instead of "Constrained Baseline".

As the command line "-profile:v baseline" works, this is either a bug in the libraries. Or something else must be set from the user, in addition to the profile. In the latter case, this must definitely be communicated to people using this. Like me ;)

See the link for more info:
http://stackoverflow.com/questions/11537830/ffmpeg-api-h264-encoded-video-does-not-play-on-all-platforms

I have also attached the *.cpp that includes the functions used to encode the video.

Attachments (2)

ffmpeg_dll.cpp (30.0 KB ) - added by TheSHEEEP 12 years ago.
Our ffmpeg dll
ffmpeg_dll.h (3.2 KB ) - added by TheSHEEEP 12 years ago.

Download all attachments as: .zip

Change History (13)

by TheSHEEEP, 12 years ago

Attachment: ffmpeg_dll.cpp added

Our ffmpeg dll

by TheSHEEEP, 12 years ago

Attachment: ffmpeg_dll.h added

comment:1 by Cigaes, 12 years ago

Try av_opt_set(avc, "profile", "base", 0.

comment:2 by TheSHEEEP, 12 years ago

What would av_opt_set do any different than setting the profile value directly?

comment:3 by Cigaes, 12 years ago

They do not do the same thing at all. One affects the codec private options, the other the codec context. libx264 uses a private option.

in reply to:  3 comment:4 by TheSHEEEP, 12 years ago

Replying to Cigaes:

They do not do the same thing at all. One affects the codec private options, the other the codec context. libx264 uses a private option.

Okay, I will try that, but I have problems compiling when using av_opt_set although I do link against avutil.lib (unresolved external symbol, really strange). I'll have to figure that one out, first.

in reply to:  1 comment:5 by TheSHEEEP, 12 years ago

Got that one sorted out.

But when I do av_opt_set(avc, "profile", "base", 0), I get the error messages:

"Undefined constant or missing '(' in 'base'"
and
"Unable to parse option value "base""

comment:6 by Cigaes, 12 years ago

"base" is not a x264 profile. You can probably find the list of supported profiles in the documentation of x264. I do not know where is the best place to look for x264 documentation, but "x264 documentation profile" in a search engine would probably be a good start.

in reply to:  6 comment:7 by TheSHEEEP, 12 years ago

Well, according to this ( http://mewiki.project357.com/wiki/X264_Settings ), "baseline" should do the trick. But I get the same error message, just with "baseline" instead of "base". I also tried with Baseline, Constrained Baseline, etc. All the same error message.

I also tried this:
av_opt_set_int(codecContext, "profile", (int64_t)FF_PROFILE_H264_CONSTRAINED_BASELINE, AV_OPT_SEARCH_CHILDREN);

The result was: No error, but still "High" profile.

comment:8 by TheSHEEEP, 12 years ago

The problem with error was, as it seems, that I have to use av_set_opt AFTER avcodec_open2(c, codec, NULL).

When I do it like this:

if (avcodec_open2(c, codec, NULL) < 0) 
{
	av_log(c, AV_LOG_ERROR, "%s","could not open video codec\n");
	exit(1);
}
av_opt_set(c, "profile", "baseline", AV_OPT_SEARCH_CHILDREN);

The error is gone, but the video remains of "High" profile. I really start to think that this is a bug.

Version 0, edited 12 years ago by TheSHEEEP (next)

comment:9 by Cigaes, 12 years ago

You are right, this is not the correct code: the option must not be set after the codec is opened, but when the codec is opened, using the thirs argument of avcodec_open2.

comment:10 by TheSHEEEP, 12 years ago

I got it working!

You need to use the priv_data instead of the context itself. I got the hint when searching for "av_opt_set profile".

So this works:

av_opt_set(c->priv_data, "profile", "baseline", AV_OPT_SEARCH_CHILDREN);

And I actually do it before calling avcodec_open2().

Consider this resolved. And thanks for the support!

Uhm... can I close this or will a dev/mod do that?

Last edited 12 years ago by TheSHEEEP (previous) (diff)

comment:11 by Carl Eugen Hoyos, 12 years ago

Keywords: libx264 added; Profile h264 Baseline removed
Resolution: invalid
Status: newclosed
Note: See TracTickets for help on using tickets.