[Libav-user] No metadata in adts container using libavformat API

Igor Serganov iserganoff at gmail.com
Sat Nov 26 20:08:42 EET 2022


Hello team! 

I would appreciate your help on the following issue.

Background of the issue:

I am doing live mp3 to aac transcoding with adts muxing. I am using C functions from libraries inside FFMPEG (libavcodec, libavformat, etc.) through CGO (a tool that allows call C code within Golang).

Scenario is as follows:
1. Open mp3 input
2. Open output format:

{{{
        adts := C.CString("adts")
	defer C.free(unsafe.Pointer(adts))
	var ctx *C.AVFormatContext
	if ret := C.avformat_alloc_output_context2(&ctx, nil,  adts, nil); ret < 0 {
		return
	}
}}}
3. Write header with several options that I need for appropriate metadata (according to: https://datatracker.ietf.org/doc/html/rfc8216#section-3.4), options taken from here - https://ffmpeg.org/ffmpeg-formats.html#adts-1:


{{{
C.av_dict_set(&f.opts.dict, "write_id3v2","1", 0)
C.av_dict_set(&f.opts.dict, "write_apetag","1", 0)
C.av_dict_set(&outAVFormatCtx.metadata, "TIPL", "Awesome production", 0)
C.avformat_write_header(&outAVFormatCtx, &f.opts.dict)
}}}

4. demuxing and decoding input stream and encoding frames and muxing to output stream. I will not provide too much details here as this part works pretty fine. 

5. Accumulating output stream of certain duration (10 seconds e.g.) and writing `.aac` segment to a storage. (Ideally this part works forever in order to produce HLS stream out of these segments later)

6. When receiving a first frame for the following segment I try to write its PTS (start time of the next segment) to the metadata tag:


{{{
C.av_dict_set(&outAVFormatCtx.metadata, "PRIV.com.apple.streaming.transportStreamTimestamp", <some random int64 value encoded to bytes>, 0)
outAVFormatCtx.event_flags |= C.avfmt_event_flag_metadata_updated
}}}

However I don't see any metadata when ffprobing my segments:

    "format": {
        "filename": "filename.aac",
        "nb_streams": 1,
        "nb_programs": 0,
        "format_name": "aac",
        "format_long_name": "raw ADTS AAC (Advanced Audio Coding)",
        "duration": "10.011431",
        "size": "26458",
        "bit_rate": "38253",
        "probe_score": 51
    }

However when I do something very similar with ffmpeg command as follows:

ffmpeg -i input.mp3 -vn -acodec copy -f adts -metadata title="Foo" -metadata PRIV.com.apple.streaming.transportStreamTimestam="1111111" -write_id3v2 1 -write_apetag 1 output.aac

I get what I want:

        "filename": "output.aac",
        "nb_streams": 1,
        "nb_programs": 0,
        "format_name": "aac",
        "format_long_name": "raw ADTS AAC (Advanced Audio Coding)",
        "duration": "5.485686",
        "size": "33278",
        "bit_rate": "48530",
        "probe_score": 51,
        "tags": {
            "TIT2": "Foo",
            "PRIV.com.apple.streaming.transportStreamTimestam": "1111111",
            "TSSE": "Lavf59.27.100"
        }


So my question is how to write ID3v2 metadata to adts container through libavformat? Since this is quite a requirement of RFC-8216 (https://datatracker.ietf.org/doc/html/rfc8216#section-3.4).









 


More information about the Libav-user mailing list