0

I am converting MP3 to Webm and the MP3 file includes a video stream for the cover art.

ffprobe filename.mp3
...
    Stream #0:0: Audio: mp3, 22050 Hz, stereo, fltp, 64 kb/s
    Stream #0:1: Video: mjpeg (Baseline), yuvj444p(pc, bt470bg/unknown/unknown), 300x300, 90k tbr, 90k tbn, 90k tbc (attached pic)

Using ffmpeg with libopus codec to convert the file causes a VP9 video stream that doesn't work well. I noticed:

  1. VLC Player doesn't show the duration and the progress scrubber doesn't move when playing.
  2. Android Media Player doesn't show image for the cover art of the track.
ffprobe filename.webm
...
Input #0, matroska,webm, from 'webm_bad/B01___01_Matthew_____ENGWEBN2DA.webm':
...
    Stream #0:0: Video: vp9 (Profile 1), yuv444p(tv, progressive), 300x300, SAR 1:1 DAR 1:1, 1k tbr, 1k tbn, 1k tbc (default)

If I tried to use -vcodec copy option, then I get this error:

[webm @ 0x7fdddf028e00] Only VP8 or VP9 or AV1 video and Vorbis or Opus audio and WebVTT subtitles are supported for WebM.
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
Error initializing output stream 0:1 --

Does WebM support cover art? If so, how do I transfer the MP3 cover art over using ffmpeg (or other tool)?

chrish
  • 2,352
  • 1
  • 17
  • 32

1 Answers1

3

No, WebM does not support cover art.

From the FAQ:

The WebM file structure is based on the Matroska media container.

The cover art in a Matroska container is stored in an attachment:

Attachment Elements can be used to store related cover art, [...]

A WebM container does not support attachments:

Attachment

WebM Support Element Name Description
Unsupported Attachments Contain attached files.
Unsupported AttachedFile An attached file.
Unsupported FileDescription A human-friendly name for the attached file.
Unsupported FileName Filename of the attached file.
Unsupported FileMimeType MIME type of the file.
Unsupported FileData The data of the file.
Unsupported FileUID Unique ID representing the file, as random as possible.
Unsupported FileReferral A binary value that a track/codec can refer to when the attachment is needed.
Unsupported FileUsedStartTime DivX font extension
Unsupported FileUsedEndTime DivX font extension

Maybe you can consider using a different container. Opus audio streams, like the ones in a WebM container, are supported by other containers:

Opus was originally specified for encapsulation in Ogg containers

If you still want to use WebM, an alternative would be to create a video stream with a still image along with an audio stream. The FFmpeg wiki covers that topic in the Slideshow page. Combining that with this answer, which explains how to extract the cover art of an MP3 file, you could do the following:

ffmpeg -i filename.mp3 -an -c:v copy cover.jpeg
ffmpeg -loop 1 -i cover.jpeg -i filename.mp3 -c:v libvpx-vp9 -c:a libopus -b:a 64k -shortest filename.webm

64k is the bitrate that you show in the output of ffprobe.

The encoding might be slow with the second command. The Encode/Youtube page in the FFmpeg wiki shows an example command to create a video with an still image that uses the -framerate 2 option, like this:

ffmpeg -loop 1 -framerate 2 -i cover.jpeg -i filename.mp3 -c:v libvpx-vp9 -c:a libopus -b:a 64k -shortest filename.webm

For some reason I do not know, the output video of that last command cannot be reproduced by my VLC and the player crashes. 6 was the minimum -framerate that did not crash my player, so be careful.

Hernán Alarcón
  • 3,494
  • 14
  • 16
  • 1
    The command was meant for YouTube only. Many players don't like such a low frame rate. – llogan Jan 14 '21 at 18:21
  • `-map 0:v` is preferred over `-an` in the extraction of the cover.jpeg. – chrish Jan 28 '21 at 15:52
  • This process worked. I tried using AIMP and it didn't display the cover art in the player like it does with mp3. :-( – chrish Jan 28 '21 at 16:16
  • @hernán-alarcón, If I try to use .mka (or .mkv) as an alternative container (these are supported by Android), how would I copy the cover art from mp3 to the attachment on the Matroska container? I tried the looping video and it didn't work in .mkv (and was not included in .mka). – chrish Jan 28 '21 at 16:34
  • @chrish, check [this answer](https://stackoverflow.com/a/34198604/2738151). It uses .mkv, but I guess it also works with .mka. – Hernán Alarcón Jan 30 '21 at 21:46