0

I want to add a protobuf message as attachment to a Matroska (mkv) video file after all video frames have been written without copying the video data. This must be possible because attaching an arbitrary file to an mkv can be achieved with the MKVToolNix suite (for a JPG):

# add attachment, no copy according to man page
mkvpropedit out.mkv --add-attachment ~/Downloads/hummingbird.jpg
.
.
# get attachment id
mkvmerge -i out.mkv
.
Attachment ID 1: type 'image/jpeg', size 821740 bytes, file name 'hummingbird.jpg'
.
# extract attachment
mkvextract attachments out.mkv 1:./test.jpg

I want to be capable to perform the same read-write-cycle by calling library methods. Preferably without the need to write the protobuf message to a file first (e.g. by passing a byte array of the serialized protobuf message).

Currently I'm using libav for reading/writing video data from/to mkv. Therefor my favorite solution would also only depend on libav. If this is not possible I would consider introducing libEBML and libMatroska as new dependencies (same as MKVToolNix).

What are the key functions in the frameworks that need to be called to achieve the goal? I'm pretty sure mbunkus knows the solution ...

Community
  • 1
  • 1
Faber
  • 1,504
  • 2
  • 13
  • 21

1 Answers1

0

I did not attach a file programmatically yet, but I was able to read an attachment. The information gathered doing so may at least help to implement the writing as well.

Attachments are handled as additional streams. The stream for the attachment does not contain frames. Instead, the data is stored as extradata to the codec for this stream. The file name and the mime type is given as meta data to the codec.

uli m.
  • 1
  • 1