3

Question

I have 2 files:

  • audio.opus (extension also possible: .opus.ogg),
  • cover.jpg.

How can I use ffmpeg to put cover.jpg as an embedded "cover" image into audio.opus?

Constraints

  • I don't want to re-encode the audio (so unfortunately, opusenc --picture seems out of scope),
  • I don't want to re-encode the image (jpeg), although that's not much of a problem,
  • I don't want to transform the image into a video (!),
  • I'd really prefer doing it with ffmpeg and not another tool,
  • I don't want to hear about mp3.

Expected result

Here is how it should look like when it's properly done:

$ opusinfo audio_with_cover.opus
Processing file "audio_with_cover.opus"...

New logical stream (#1, serial: 39a74bbb): type opus
Encoded with libopus 1.3.1
User comments section follows...
    ENCODER=opusenc from opus-tools 0.1.10
    METADATA_BLOCK_PICTURE=3|image/jpeg||1280x720x24|<45952 bytes of image data>
    ENCODER_OPTIONS=--bitrate 56
Opus stream 1:
    Pre-skip: 312
    [...]

Or seen from ffprobe:

$ ffprobe audio_with_cover.opus 
[ogg @ 0x55675650ca80] 761 bytes of comment header remain
Input #0, ogg, from 'audio_with_cover.opus':
  Duration: 00:02:25.64, start: 0.000000, bitrate: 71 kb/s
  Stream #0:0: Audio: opus, 48000 Hz, stereo, fltp
    Metadata:
      ENCODER         : opusenc from opus-tools 0.1.10
      ENCODER_OPTIONS : --bitrate 56
  Stream #0:1: Video: mjpeg (Baseline), yuvj420p(pc, bt470bg/unknown/unknown), 1280x720, 90k tbr, 90k tbn (attached pic)
    Metadata:
      comment         : Cover (front)

Not possible?

If you know it is not possible, please let me know, I will open a feature request at ffmpeg.

2

1 Answer 1

0

You can use the -metadata:s:a METADATA_BLOCK_PICTURE=... to add the image data manually, but the provided data has to follow the Xiph Vorbis Comment structure.

First, you have to create a matching header block (which fortunately can be reused when the image size etc. stays the same), and then concatenate it with the base64 encoded image data.

For more details, see https://superuser.com/a/1816195/1860118

1
  • Nice hint! Would you give an example of the commands needed to do this (if the starting file is, for example, cover.jpg)?
    – Totor
    Dec 18, 2023 at 13:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .