Opened 3 years ago
Closed 8 months ago
#10770 closed defect (invalid)
avcodec_open2 overwrites flags contrary to what the doc says
| Reported by: | Jean-Michaël Celerier | Owned by: | |
|---|---|---|---|
| Priority: | normal | Component: | undetermined |
| Version: | unspecified | Keywords: | |
| Cc: | Blocked By: | ||
| Blocking: | Reproduced by developer: | no | |
| Analyzed by developer: | no |
Description
The avcodec_open2 documentation states, about the options parameter:
* @param options A dictionary filled with AVCodecContext and codec-private * options, which are set on top of the options already set in * avctx, can be NULL. On return this object will be filled with * options that were not found in the avctx codec context.
Yet given the following program, the final assert does not pass: AV_CODEC_FLAG_GLOBAL_HEADER gets overwritten in the codec context's flags.
extern "C" {
#include <libavcodec/avcodec.h>
}
#include <cassert>
int main()
{
auto codec = avcodec_find_encoder_by_name("libx264");
auto c = avcodec_alloc_context3(codec);
c->width = 1280;
c->height = 720;
c->time_base = (AVRational){100000, int(100000 * 30)};
c->framerate = AVRational{c->time_base.den, c->time_base.num};
c->gop_size = 0;
c->max_b_frames = 0;
c->pix_fmt = AV_PIX_FMT_YUV420P;
c->strict_std_compliance = FF_COMPLIANCE_NORMAL;
c->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
AVDictionary* opt{};
av_dict_set(&opt, "flags", "low_delay", 0);
avcodec_open2(c, codec, &opt);
assert(c->flags & AV_CODEC_FLAG_GLOBAL_HEADER);
}
Change History (2)
comment:1 by , 3 years ago
comment:2 by , 8 months ago
| Resolution: | → invalid |
|---|---|
| Status: | new → closed |
This is not a bug: When the AVDictionary contains an entry with key "flags" and val "low_delay", avcodec_open2() sets the AVCodecContext flags to AV_CODEC_FLAG_LOW_DELAY. Which of course resets all the other flags. As Gyan has already said, if you really only want to set one flag, you should use "+low_delay".
Note:
See TracTickets
for help on using tickets.



I think you'll find that the flag is overwritten by
av_dict_set. Use the value"+low_delay"and then check.