Add album art cover to an OGG/opus file from the command line


I managed to add an album art cover to an OGG/opus file with Kid3 – Audio Tagger but I'd like to do it via the command line on all the files of an album.

I tried with ffmpeg but it did not work :

$ ffmpeg -i myMP3File.opus -i Back_Cover-SMALLER.jpg -map 0:0 -map 1:0 -c copy -metadata:s:v title="Back_Cover-SMALLER.jpg" -metadata:s:v comment="Cover (back)" out.opus
Input #0, ogg, from 'myMP3File.opus':
  Duration: 00:03:04.25, start: 0.000000, bitrate: 98 kb/s
    Stream #0:0: Audio: opus, 48000 Hz, stereo, fltp
      ALBUM           : Toto
      track           : 1/14
Input #1, image2, from 'Back_Cover-SMALLER.jpg':
  Duration: 00:00:00.04, start: 0.000000, bitrate: 27608 kb/s
    Stream #1:0: Video: mjpeg, yuvj444p(pc, bt470bg/unknown/unknown), 768x768 [SAR 100:100 DAR 1:1], 25 tbr, 25 tbn, 25 tbc
File 'out.opus' already exists. Overwrite ? [y/N] y
[opus @ 0x565557805300] Unsupported codec id in stream 1
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #1:0 -> #0:1 (copy)
    Last message repeated 1 times

Does anyone know another way ?

Best Answer

  • Here's a method which decodes “audio.opus” and then re-encodes it to the file “merged.opus”, attaching the image “coverart.jpg” along the way:

    opusdec --force-wav audio.opus - | opusenc --picture coverart.jpg - merged.opus

    I don't actually use this method as I dislike transcoding audio, but it does work and keeps the file in ogg/opus format. Hopefully someday the opus-tools will be able to handle editing metadata without reencoding. (As of early 2021, they appear to be lacking.)