What options do I have to set to make a cover.jpg attachment compatible with ffmpeg?

When I add a cover.jpg attachment to a video file in ffmpeg, it has the following structure (with ffprobe):

Stream #0:1: Attachment: none
      Metadata:
        filename        : cover.jpg
        mimetype        : image/jpg

ffmpeg -y -i input.mkv -attach cover.jpg -map 0 -c copy -metadata:s:t mimetype="image/jpg" -metadata:s:t:0 filename=cover.jpg input_cover.mkv was used to add the cover.

This plays well with further encoding steps, because the cover image gets transferred with -map 0:t and doesn’t interfere with the rest.

When I add a cover with mkvtoolnix-gui as attachment and default options, it is recognized differently:

Stream #0:7: Video: mjpeg (Baseline), yuvj420p(pc, bt470bg/unknown/unknown), 640x360 [SAR 96:96 DAR 16:9], 90k tbr, 90k tbn (attached pic)
      Metadata:
        filename        : cover.jpg
        mimetype        : image/jpeg

This doesn’t work will with ffmpeg, since it is treated as a second video stream with all kinds of ugly side effects after a reencode and can’t be transferred via -map 0:t.

What’s the best way to make mkvtoolnix-gui attach a cover image the way ffmpeg does?

That’s a bug in ffmpeg. It seems to think that the MIME type image/jpeg (with the e) of an attached file is a video of type Motion JPEG, which it simply isn’t. No attachment in Matroska is a vide track, it… just isn’t.

With image/jpg (without the e) ffmpeg’s Motion JPEG auto-detection seems to fail, therefore it falls back to treating it like an actual attachment.

The official MIME type of JPEG images is image/jpeg, which is what MKVToolNix produces. What you’ve used, image/jpg, is not an official MIME type. MKVToolNix’s usage is correct, your usage is incorrect, and ffmpeg’s handling of the official type is buggy.

1 Like

Thanks, I’ll strip my files from attachments with mkvmerge and attach them to the reencoded file afterwards, this seems to be the cleanest solution.