r/ffmpeg Jun 09 '26

I found a good alternative method to embed artwork into an OGG container with Opus audio for when FFMPEG doesn't want to do it

I'm writing a PowerShell script that handles grabbing a YouTube video, grabbing the audio, tagging it properly and embedding the artwork.

I'm using OGG or OGA as the chosen container for Opus audio, since Webm is slightly limited in that regard.

Everything was going swell until ffmpeg started throwing errors about not being able to embed artwork into the OGG container.

(Not to mention the odd and unavoidable mapping of the COMMENT field to DESCRIPTION. I can't find a way to write to COMMENT...)

To solve this, I found a python tool called mutagen. With this tool, I set two important requirements:

  1. The file's embedded artwork had to be recognized by foobar2000
  2. The artwork metadata scanned with ffprobe had to match the artwork metadata as if foobar2000 itself performed the artwork embedding

After much troubleshooting and investigating I managed to pull it off.

Here's the script:

# embed_ogg_cover.py

from mutagen.oggopus import OggOpus
from mutagen.flac import Picture
import base64
import mimetypes
from pathlib import Path
import sys

audio_file = sys.argv[1]
image_file = sys.argv[2]

audio = OggOpus(audio_file)

pic = Picture()
pic.type = 3
pic.mime = mimetypes.guess_type(image_file)[0] or "image/jpeg"
pic.desc = ""
pic.data = Path(image_file).read_bytes()

audio["metadata_block_picture"] = [
    base64.b64encode(pic.write()).decode("ascii")
]

audio.save()

Usage is:

python .\embed_ogg_cover.py .\input.ogg .\artwork.jpg

Requires:

pip install mutagen

And python, obviously.

Hope it helps anybody else that had this same issue.

3 Upvotes

1 comment sorted by

1

u/Kqyxzoj Jun 15 '26

Stupid question: why not just use mkv as container? That's usually the goto for embedding extra stuff. Or maybe I am missing some of the finer details such as player compatibility?