Ticket #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
Change History
Changed 11 months ago by TheSHEEEP
-
attachment
ffmpeg_dll.cpp
added
comment:2 Changed 11 months ago by TheSHEEEP
What would av_opt_set do any different than setting the profile value directly?
comment:3 follow-up: ↓ 4 Changed 11 months ago by 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.
comment:4 in reply to: ↑ 3 Changed 11 months ago by TheSHEEEP
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.
comment:5 in reply to: ↑ 1 Changed 11 months ago by TheSHEEEP
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 follow-up: ↓ 7 Changed 11 months ago by Cigaes
"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.
comment:7 in reply to: ↑ 6 Changed 11 months ago by TheSHEEEP
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 Changed 11 months ago by TheSHEEEP
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);
}
// Doesn't seem to matter if I use AV_OPT_SEARCH_CHILDREN or something else
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.
comment:9 Changed 11 months ago by Cigaes
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 Changed 11 months ago by TheSHEEEP
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!
comment:11 Changed 11 months ago by cehoyos
- Keywords libx264 added; Profile, h264, Baseline removed
- Status changed from new to closed
- Resolution set to invalid



Our ffmpeg dll