[Libav-user] Id3v2 tag writing in ADTS encoder

KIM daniel.morandini at keepinmind.info
Thu Mar 28 10:55:25 EET 2024


> For the encoding part instead I do not understand how I am supposed to set the id2v3tag field of the encoder’s ADTSContext [1], which apparently if set is going to be written in the header. Any help/hint would be greatly appreciated.
Got it. Posting here the answer for future readers.

There are two things that have to be done:
- set the id3v2 metadata of the target AVFormatContext
```c
  const AVDictionaryEntry *e = NULL;
  while ((e = av_dict_iterate(metadata, e))) {
    av_dict_set(&fmtctx->metadata, e->key, e->value, 0);
  }
```

- When writing the header, set the appropriate option (in this case write_id3v2 for the ADTS encoder)
```c
  AVDictionary *opts = NULL;
  av_dict_set_int(&opts, "write_id3v2", 1, 0);
  ret = avformat_write_header(encoder->fmt, &opts);
```

Done!

Cheers,
Daniel



More information about the Libav-user mailing list