Start with an MKV master and a square JPEG named cover.jpg. Keep the original master. This example assumes it contains no existing attachments or embedded cover. Run the commands in the folder containing both files and choose a new output filename.
Check the input streams first
ffprobe -v error -show_streams input.mkv
Look for attachment streams, filename tags and attached_pic=1. If any are present, review their purpose before proceeding. For example, a subtitle font is an attachment worth preserving, and adding a second cover can leave a player with two images to choose from.
Attach the image
ffmpeg -i input.mkv -map 0 -c copy -attach cover.jpg -metadata:s:t:0 mimetype=image/jpeg archive.mkv
Here -map 0 selects the input streams and -c copy copies their compressed data. The new JPEG is the first attachment in this example, so t:0 targets it. Matroska recommends cover.jpg for a square JPEG cover and 600 pixels on its shortest side for the normal size.
Inspect the result
ffprobe -v error -show_entries stream=index,codec_name:stream_tags=filename,mimetype:stream_disposition=attached_pic -of compact archive.mkv
On a one-second FFV1 test clip with a 600 × 600 JPEG, the output retained the FFV1 stream and gained an MJPEG entry with attached_pic=1, filename=cover.jpg and mimetype=image/jpeg. Your main video codec may differ. Check both entries before replacing any archive copy. A file browser can still show a frame from the video because support for displaying Matroska cover art varies by reader. This procedure changes the local archive. Set the public video thumbnail separately in your publishing workflow.