3

I have an mkv file, only with audio, and I attached a cover art to it, but when I convert it to mp3 the art is not added to the mp3.

The command I used to attach the cover art was the only one that didn't generate the art as a video stream in mkv, but it seems that this way limits the cover art to mkv only and I can't convert it to mp3, see the process below:

Output of: ffprobe mkv_without_cover.mkv

Input #0, matroska,webm, from 'mkv_without_cover.mkv':
  Metadata:
    title           : Cuidado!
    ARTIST          : Lobão
    ALBUM           : CMG Clássicos Pop Rock Nacionais
    GENRE           : Clássico Pop Rock Nacional
    TKEY            : E m
    DATE            : 1988
    ENCODER         : Lavf59.17.102
  Duration: 00:03:26.63, start: 0.000000, bitrate: 322 kb/s
  Stream #0:0: Audio: mp3, 44100 Hz, stereo, fltp, 320 kb/s
    Metadata:
      ENCODER         : Lavc59.12
      DURATION        : 00:03:26.628000000

Command to Attach cover art in mkv:

ffmpeg -i "mkv_without_cover.mkv" -attach "art_cover.jpeg" -map 0 -c copy -metadata:s:t mimetype="image/jpg" -metadata:s:t:0 filename="cover.jpg" "mkv_with_cover.mkv"

Output of: attach command

Input #0, matroska,webm, from 'mkv_without_cover.mkv':
  Metadata:
    title           : Cuidado!
    ARTIST          : Lobão
    ALBUM           : CMG Clássicos Pop Rock Nacionais
    GENRE           : Clássico Pop Rock Nacional
    TKEY            : E m
    DATE            : 1988
    ENCODER         : Lavf59.17.102
  Duration: 00:03:26.63, start: 0.000000, bitrate: 322 kb/s
  Stream #0:0: Audio: mp3, 44100 Hz, stereo, fltp, 320 kb/s
    Metadata:
      ENCODER         : Lavc59.12
      DURATION        : 00:03:26.628000000
Output #0, matroska, to 'mkv_with_cover.mkv':
  Metadata:
    title           : Cuidado!
    ARTIST          : Lobão
    ALBUM           : CMG Clássicos Pop Rock Nacionais
    GENRE           : Clássico Pop Rock Nacional
    TKEY            : E m
    DATE            : 1988
    encoder         : Lavf59.17.102
  Stream #0:0: Audio: mp3 (U[0][0][0] / 0x0055), 44100 Hz, stereo, fltp, 320 kb/s
    Metadata:
      ENCODER         : Lavc59.12
      DURATION        : 00:03:26.628000000
  Stream #0:1: Attachment: none
    Metadata:
      mimetype        : image/jpg
      filename        : cover.jpg
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  **art_cover.jpeg -> Stream #0:1**
Press [q] to stop, [?] for help
size=    8398kB time=00:03:26.62 bitrate= 332.9kbits/s speed=3.78e+03x
video:0kB audio:8071kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 4.046549%

It seems that the problem is in the way the cover art is attached to the mkv, the attaching does not define a specific codec for the cover art.

The cover art was successfully added to stream #0:1 of the mkv_with_cover file, but ffprobre shows some warning related to the codec of the attachent, see below:

Output of: ffprobe mkv_with_cover.mkv

[matroska,webm @ 0000026d25388d00] Could **not find codec** parameters for **stream 1** (Attachment: none): unknown codec
Consider increasing the value for the 'analyzeduration' (0) and 'probesize' (5000000) options
Input #0, matroska,webm, from 'output_mkv_with_cover.mkv':
  Metadata:
    title           : Cuidado!
    DATE            : 1988
    ARTIST          : Lobão
    ALBUM           : CMG Clássicos Pop Rock Nacionais
    GENRE           : Clássico Pop Rock Nacional
    TKEY            : E m
    ENCODER         : Lavf59.17.102
  Duration: 00:03:26.63, start: 0.000000, bitrate: 332 kb/s
  Stream #0:0: Audio: mp3, 44100 Hz, stereo, fltp, 320 kb/s
    Metadata:
      ENCODER         : Lavc59.12
      DURATION        : 00:03:26.628000000
  Stream #0:1: Attachment: **none**
    Metadata:
      filename        : cover.jpg
      mimetype        : image/jpg
**Unsupported** codec with id 0 for input stream 1

Convert command mkv to mp3:

ffmpeg -i "mkv_with_cover.mkv" -c:a copy "song.mp3"

Output of: converte command

[matroska,webm @ 0000020a74908dc0] Could **not find codec** parameters for **stream 1** (Attachment: none): **unknown codec**
Consider increasing the value for the 'analyzeduration' (0) and 'probesize' (5000000) options
Input #0, matroska,webm, from 'mkv_with_cover.mkv':
  Metadata:
    title           : Cuidado!
    DATE            : 1988
    ARTIST          : Lobão
    ALBUM           : CMG Clássicos Pop Rock Nacionais
    GENRE           : Clássico Pop Rock Nacional
    TKEY            : E m
    ENCODER         : Lavf59.17.102
  Duration: 00:03:26.63, start: 0.000000, bitrate: 332 kb/s
  Stream #0:0: Audio: mp3, 44100 Hz, stereo, fltp, 320 kb/s
    Metadata:
      ENCODER         : Lavc59.12
      DURATION        : 00:03:26.628000000
  Stream #0:1: Attachment: none
    Metadata:
      filename        : cover.jpg
      mimetype        : image/jpg
Output #0, mp3, to 'song.mp3':
  Metadata:
    TIT2            : Cuidado!
    TDRC            : 1988
    TPE1            : Lobão
    TALB            : CMG Clássicos Pop Rock Nacionais
    TCON            : Clássico Pop Rock Nacional
    TKEY            : E m
    TSSE            : Lavf59.17.102
  Stream #0:0: Audio: mp3, 44100 Hz, stereo, fltp, 320 kb/s
    Metadata:
      ENCODER         : Lavc59.12
      DURATION        : 00:03:26.628000000
Stream mapping:
  **Stream #0:0 -> #0:0 (copy)**
Press [q] to stop, [?] for help
size=    8073kB time=00:03:26.62 bitrate= 320.0kbits/s speed=4.22e+03x
video:0kB audio:8071kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.015027%

Conversion ignores stream #0:1 and cover art is not added to mp3 file output.

I also used the following commands in the conversion, and they all only generated the audio in the output of the mp3 file, see below:

ffmpeg -i "mkv_with_cover.mkv" -map 0:0 -c:v copy -c:a copy "song.mp3"

error message: Could not find codec parameters for stream 1

ffmpeg -i "mkv_with_cover.mkv" -map 0:0 -vcodec copy -c:a copy "song.mp3"

error message: Could not find codec parameters for stream 1

ffmpeg -i "mkv_with_cover.mkv" -vcodec copy -c:a copy "song.mp3"

error message: Could not find codec parameters for stream 1

ffmpeg -i "mkv_with_cover.mkv" -map 0:1 -vcodec copy -c:a copy "song.mp3"

error message: Only audio streams and pictures are allowed in MP3. Could not write header for output file #0

How to make the cover art in this mkv file to be included in the conversion to mp3 file?

thank's

1 Answer 1

2

I managed to find the problem!

In mimetype="image/jpg" field, the jpg, has to be jpeg so that the mjpeg codec can encode the image.

What happens is that the mjpeg codec, looks for information in the command so that it can encode the image correctly, this information is in the mimetype="image/jpg" field. Note that where is jpg, it has to be jpeg. As in the command I posted this, the field was with jpg, the codec, despite not giving an error, simply attached the image without any encoding, causing many problems at the time of conversion.

For this reason, the image was being tacked without encoding and had the errors related to the codec I posted above.

the correct command is:

ffmpeg -i "mkv_without_cover.mkv" -attach "art_cover.jpeg" -map 0 -c copy -metadata:s:t mimetype="image/jpeg" -metadata:s:t:0 filename="cover.jpeg" "mkv_with_cover.mkv"

thanks

You must log in to answer this question.

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