8

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
    Metadata:
      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 ?

SebMa
  • 1,573
  • 2
  • 19
  • 25
  • i'm curious to find if there's any way to do it with ffmpeg – cregox May 12 '21 at 07:17
  • similar issue https://superuser.com/questions/1648830/reduce-my-90gb-collection-of-mp3-to-about-10gb – cregox May 13 '21 at 11:00
  • You may use the `mutagen` Python [library](https://pypi.org/project/mutagen/). Someone has provided [an example script here](https://unix.stackexchange.com/questions/495382/how-do-i-embed-a-jpg-thumbnail-to-a-ogg-opus-audio-file-with-a-script/671204#671204). – Totor Sep 20 '22 at 12:25

3 Answers3

1

I suggest using a Matroska wrapper around the opus. It won't re-encode the opus.

This worked for me:

mkvmerge -o "Susheela Raman - Tanpa Nama.mkv"   audio.opus  --attach-file cover.jpg

Matroska also allows you to include different size cover art (square, portrait, landscape). https://www.matroska.org/technical/cover_art/index.html

hackerb9
  • 947
  • 9
  • 12
1

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.)

hackerb9
  • 947
  • 9
  • 12
  • Thanks. I also found the [opustags tool](https://github.com/fmang/opustags) which is not able to add a cover but is to be followed... – SebMa Jan 30 '21 at 21:19
  • 1
    Thanks for the link! opustags_tool can't add a picture (yet) but it may be useful to transfer the metadata from the old file to the new file since any existing tags are lost with `opusdec`. – hackerb9 Feb 01 '21 at 01:32
0

I personally prefer using ffmpeg to alter the file data, and hopefully avoid re-encoding, such as adding chapters to video files such as mkv, and even rotating them too.

I found a solution that works, but may be client specific. When I open an OPUS audio file using mpv on Fedora Linux, after I added an image file with the same file name, what ever image file extension, such as jpg, then the program combines them in the GUI. Surely this must work with any audio file in at least the same program.

I found VLC does not provide this convenient feature automatically, but is possible if you add a parameter such as :input-slave=<image_path>.

With ffmpeg, it seems to be a bit more complex, but not terrible, and requires a video container1:

ffm \
  -loop 1 -f image2 -i "$imageFile" \
  -i "$audioFile" -c:a copy -shortest \
  <outputVideoFile>

This approach did not work for me using ffplay though :(.

Pysis
  • 1,080
  • 2
  • 12
  • 25