1

If I have a .opus file, how can I use FFmpeg to set the album art?

I've had success with:

ffmpeg -i Pogo.mp3 -i StellarDrone.png -map 0:0 -map 1:0 -codec copy -id3v2_version 3 -metadata:s:v title="Album cover" -metadata:s:v comment="Cover (front)" out.mp3

Using Pogo.mp3 and Stellardrone.png as test files. This doesn't work for .opus apparently though.

ffmpeg -i Hotlines.opus -i StellarDrone.png -map 0:0 -map 1:0 -codec copy -id3v2_version 3 -metadata:s:v title="Album cover" -metadata:s:v comment="Cover (front)" out.opus
ffmpeg version 4.0 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.3.0-16ubuntu3)
  configuration: 
  libavutil      56. 14.100 / 56. 14.100
  libavcodec     58. 18.100 / 58. 18.100
  libavformat    58. 12.100 / 58. 12.100
  libavdevice    58.  3.100 / 58.  3.100
  libavfilter     7. 16.100 /  7. 16.100
  libswscale      5.  1.100 /  5.  1.100
  libswresample   3.  1.100 /  3.  1.100
Input #0, ogg, from 'Hotlines.opus':
  Duration: 00:04:01.00, start: -0.960000, bitrate: 359 kb/s
    Stream #0:0: Audio: opus, 48000 Hz, stereo, fltp
    Metadata:
      ARTIST          : ChrisKeya
      FMPS_PLAYCOUNT  : 0
      FMPS_RATING_AMAROK_SCORE: 0.04
      TITLE           : Hotlines
    Stream #0:1: Video: png, rgb24(pc), 1280x720 [SAR 1:1 DAR 16:9], 90k tbr, 90k tbn, 90k tbc
    Metadata:
      comment         : Cover (front)
      title           : ChrisKeya - LateNight [Full EP].png
Input #1, png_pipe, from 'StellarDrone.png':
  Duration: N/A, bitrate: N/A
    Stream #1:0: Video: png, rgb24(pc), 1280x720 [SAR 1:1 DAR 16:9], 25 tbr, 25 tbn, 25 tbc
[opus @ 0x55a1a7d72100] 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

Of particular interest is the section is red:

[opus @ 0x55af9c499100] Unsupported codec id in stream 1
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
Giacomo1968
  • 58,727

1 Answers1

1

This ffmpeg command can be used:

ffmpeg -i in.opus -i metadata.dat -map_metadata 1 -codec copy out.opus

where metadata.dat is a text file composed as:

;FFMETADATA1
METADATA_BLOCK_PICTURE=<img_blob64>

where <img_blob64> is a base64 encoding of some info about the image and the image itself. Unfortunately, forming this encoded blob is a bit complicated. For more info on doing so, including some helper scripts, see Embed album art in OGG through command line in linux