[Libav-user] Why does setting a custom io AVIOContext on AVFormatContext try to read ID3 information from my data source?

Rasmus Diederichsen rasmus at psiori.com
Fri Apr 4 17:21:15 EEST 2025


Hi, 
I am attempting to do custom IO to demux rtp packets from an external source.
The documentation for AVIOContext* AVFormatContext::pb states

> demuxing: either set by the user before avformat_open_input() <https://ffmpeg.org/doxygen/4.3/group__lavf__decoding.html#gaff468dcc45289542f4c30d311bc2a201> (then the user must close it manually) or set by avformat_open_input() <https://ffmpeg.org/doxygen/4.3/group__lavf__decoding.html#gaff468dcc45289542f4c30d311bc2a201>.

So, I am setting the pb field before opening the input

```
  constexpr int bufsize = 4096;
  readbuf_ = (uint8_t *)av_malloc(bufsize);
  avio_ctx_ =
      avio_alloc_context(readbuf_, bufsize, 1, this, &read_packet, NULL, NULL);
  fmt_ctx_->pb = avio_ctx_;

  const std::string sdp_url =
      "data:text/plain;charset=UTF-8," + make_video_sdp(CodecID::H264);
  const int success = avformat_open_input(&fmt_ctx_, sdp_url.c_str(),
                                          file_iformat, &format_opts);
```

Which then calls my read_callback() while trying to read some kind of id3 information. At that point, i cannot produce any packets yet, and nothing that would have id3 data, so I am confused why this happens. The function code in demux.c does this:

```
    if (s->pb)
        ff_id3v2_read_dict(s->pb, &si->id3v2_meta, ID3v2_DEFAULT_MAGIC, &id3v2_extra_meta);
```

so the presence of an AVIOContext leads to the assumption that id3 information can be read?

Can i disable this somehow? The only way i have found is to go against the documentation: first call avformat_open_input, then delete the pb field and replace it with my context.

Thanks,
Rasmus


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20250404/846beaf2/attachment.htm>


More information about the Libav-user mailing list