Opened 6 weeks ago

#11244 new defect

"threads" default is overridden

Reported by: psilokos Owned by:
Priority: normal Component: undetermined
Version: unspecified Keywords:
Cc: psilokos Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Hi,

When adding an encoder to 'libavcodec/' and passing a defaults dictionary in FFCodec.defaults such as:

const FFCodecDefault ff_xxx_defaults[] = {
    { "threads",           "42" },
    { NULL }
};

const FFCodec ff_xxx_encoder = {
    // ...
    .defaults         = ff_xxx_defaults
}

The "threads" default is correctly applied in init_context_defaults() in 'libavcodec/options.c':

137     if (codec && codec2->defaults) {
138         int ret;
139         const FFCodecDefault *d = codec2->defaults;
140         while (d->key) {
141             ret = av_opt_set(s, d->key, d->value, 0);
142             av_assert0(ret >= 0);
143             d++;
144         }
145     }
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
  * frame #0: 0x0000000101701970 ffmpeg_g`av_opt_set(obj=0x00007f8675005700, name="threads", val="42", search_flags=0) at opt.c:764:62
    frame #1: 0x0000000100e83def ffmpeg_g`init_context_defaults(s=0x00007f8675005700, codec=0x00000001022821a8) at options.c:141:19
    frame #2: 0x0000000100e83adf ffmpeg_g`avcodec_alloc_context3(codec=0x00000001022821a8) at options.c:156:9
    frame #3: 0x000000010002428c ffmpeg_g`ost_add(mux=0x00007f8675004680, o=0x00007ff7bfefe5d8, type=AVMEDIA_TYPE_VIDEO, ist=0x00007f8675004840, ofilter=0x0000000000000000, post=0x0000000000000000) at ffmpeg_mux_init.c:1112:24
    frame #4: 0x000000010002389b ffmpeg_g`map_auto_video(mux=0x00007f8675004680, o=0x00007ff7bfefe5d8) at ffmpeg_mux_init.c:1489:16
    frame #5: 0x0000000100021268 ffmpeg_g`create_streams(mux=0x00007f8675004680, o=0x00007ff7bfefe5d8) at ffmpeg_mux_init.c:1805:19
    frame #6: 0x00000001000208ca ffmpeg_g`of_open(o=0x00007ff7bfefe5d8, filename="y.ivf", sch=0x00007f8674705840) at ffmpeg_mux_init.c:3016:11
    frame #7: 0x00000001000340fa ffmpeg_g`open_files(l=0x00007f8674705a00, inout="output", sch=0x00007f8674705840, open_file=(ffmpeg_g`of_open at ffmpeg_mux_init.c:2942)) at ffmpeg_opt.c:1213:15
    frame #8: 0x0000000100033e07 ffmpeg_g`ffmpeg_parse_options(argc=12, argv=0x00007ff7bfeff2a8, sch=0x00007f8674705840) at ffmpeg_opt.c:1260:11
    frame #9: 0x00000001000495a8 ffmpeg_g`main(argc=12, argv=0x00007ff7bfeff2a8) at ffmpeg.c:957:11

But is then overridden by avcodec_open2(avctx, codec, options) in 'libavcodec/avcodec.c':

196     if ((ret = av_opt_set_dict(avctx, options)) < 0)

With options being fed { "threads", "auto" } a few lines above the call to avcodec_open2() by enc_open() in 'fftools/ffmpeg_enc.c':

317     if (!av_dict_get(ost->encoder_opts, "threads", NULL, 0))
318         av_dict_set(&ost->encoder_opts, "threads", "auto", 0);
* thread #19, name = 'vf#0:0', stop reason = breakpoint 1.1
  * frame #0: 0x0000000101701970 ffmpeg_g`av_opt_set(obj=0x00007fdfbef05f80, name="threads", val="auto", search_flags=0) at opt.c:764:62
    frame #1: 0x0000000101706c48 ffmpeg_g`av_opt_set_dict2(obj=0x00007fdfbef05f80, options=0x00007fdfbef05bf8, search_flags=0) at opt.c:1943:15
    frame #2: 0x0000000101706d0f ffmpeg_g`av_opt_set_dict(obj=0x00007fdfbef05f80, options=0x00007fdfbef05bf8) at opt.c:1959:12
    frame #3: 0x0000000100813f61 ffmpeg_g`avcodec_open2(avctx=0x00007fdfbef05f80, codec=0x00000001022821a8, options=0x00007fdfbef05bf8) at avcodec.c:198:16
    frame #4: 0x0000000100010e3b ffmpeg_g`enc_open(opaque=0x00007fdfbef05b00, frame=0x00007fdfbef06a40) at ffmpeg_enc.c:335:16
    frame #5: 0x000000010003d8ea ffmpeg_g`enc_open(sch=0x00007fdfbf904400, enc=0x0000600001bf9ae0, frame=0x00007fdfbef06a40) at ffmpeg_sched.c:1613:11
    frame #6: 0x000000010003befd ffmpeg_g`send_to_enc(sch=0x00007fdfbf904400, enc=0x0000600001bf9ae0, frame=0x00007fdfbef06a40) at ffmpeg_sched.c:1733:19
    frame #7: 0x000000010003be9e ffmpeg_g`sch_filter_send(sch=0x00007fdfbf904400, fg_idx=0, out_idx=0, frame=0x00007fdfbef06a40) at ffmpeg_sched.c:2389:12
    frame #8: 0x000000010001869b ffmpeg_g`fg_output_frame(ofp=0x00007fdfbef07280, fgt=0x000070000eaddde0, frame=0x00007fdfc3b04080) at ffmpeg_filter.c:2269:15
    frame #9: 0x000000010001b762 ffmpeg_g`fg_output_step(ofp=0x00007fdfbef07280, fgt=0x000070000eaddde0, frame=0x00007fdfc3b04080) at ffmpeg_filter.c:2371:11
    frame #10: 0x000000010001832d ffmpeg_g`read_frames(fg=0x00007fdfbef06740, fgt=0x000070000eaddde0, frame=0x00007fdfc3b04080) at ffmpeg_filter.c:2432:23
    frame #11: 0x0000000100015221 ffmpeg_g`filter_thread(arg=0x00007fdfbef06740) at ffmpeg_filter.c:2846:15
    frame #12: 0x000000010003c9b1 ffmpeg_g`task_wrapper(arg=0x00006000016f8030) at ffmpeg_sched.c:2447:11
    frame #13: 0x00007ff8140cc18b libsystem_pthread.dylib`_pthread_start + 99
    frame #14: 0x00007ff8140c7ae3 libsystem_pthread.dylib`thread_start + 15

This should be done before applying the defaults in FFCodec.defaults, or just not done if these defaults have one for "threads" already.

Change History (0)

Note: See TracTickets for help on using tickets.