在 OGG 音频文件中添加艺术封面

在 OGG 音频文件中添加艺术封面

我的目的是在 ogg 文件中添加仅包含音频的封面艺术,而不将其创建为视频。

输出:ffrobe audio.ogg

Input #0, ogg, from 'audio.ogg':
  Duration: 00:03:26.60, start: 0.000000, bitrate: 385 kb/s
  Stream #0:0: Audio: vorbis, 44100 Hz, stereo, fltp, 320 kb/s
    Metadata:
      encoder         : Lavc59.12.100 libvorbis
      album           : CMG Clássicos Pop Rock Nacionais
      artist          : Lobão
      date            : 1988
      genre           : Clássico Pop Rock Nacional
      TKEY            : E m
      title           : Cuidado!

我使用下面的命令,但封面艺术在输出文件中生成为视频:

ffmpeg -i "audio.ogg" -i "Cover.jpg" -map 0:a -map 1:v -c:a libvorbis -b:a 320k -metadata:s:v title="Album cover" -metadata:s:v comment="Cover (front)" -disposition:v attached_pic "audio_video.ogg" 

在生成文件时,屏幕上会出现几行消息“非单调的DTS”:

[ogg @ 000001ced2dafa00] Non-monotonous DTS in output stream 0:0; previous: 8802752, current: 8802432; changing to 8802752. This may result in incorrect timestamps in the output file.
[ogg @ 000001ced2dafa00] Non-monotonous DTS in output stream 0:0; previous: 8802752, current: 8802560; changing to 8802752. This may result in incorrect timestamps in the output file.
[ogg @ 000001ced2dafa00] Non-monotonous DTS in output stream 0:0; previous: 8802752, current: 8802688; changing to 8802752. This may result in incorrect timestamps in the output file.
[libvorbis @ 000001ced2db0a40] Queue input is backward in time
    Last message repeated 14 times
[libvorbis @ 000001ced2db0a40] Queue input is backward in timetrate=   0.3kbits/s speed=25.3x
    Last message repeated 1 times
frame=    1 fps=0.1 q=-0.0 Lsize=    9570kB time=00:03:26.59 bitrate= 379.5kbits/s speed=25.4x
video:15kB audio:9494kB subtitle:0kB other streams:0kB global headers:7kB muxing overhead: 0.638836%

最后,文件生成了,但艺术品作为视频流出现在文件中。

输出:ffrobe audio_video.ogg

Input #0, ogg, from 'audio_video.ogg':
  Duration: 00:03:26.60, start: 0.000000, bitrate: 379 kb/s
  Stream #0:0: Audio: vorbis, 44100 Hz, stereo, fltp, 320 kb/s
    Metadata:
      artist          : Lobão
      album           : CMG Clássicos Pop Rock Nacionais
      genre           : Clássico Pop Rock Nacional
      title           : Cuidado!
      TKEY            : E m
      date            : 1988
      encoder         : Lavc59.21.100 libvorbis
  Stream #0:1: Video: theora, yuv420p, 1018x1023 [SAR 1:1 DAR 1018:1023], 25 tbr, 25 tbn
    Metadata:
      title           : Album cover
      comment         : Cover (front)
      encoder         : Lavc59.21.100 libtheora

如何在不生成视频流且没有非单调的 DTS 消息行的情况下添加图像?

@mashuptwice 我使用了链接中建议的命令,但是它不起作用。见下文:

ffmpeg -i "audio.ogg" -map 0 -c:a copy -c copy -metadata:s:a METADATA_BLOCK_PICTURE="$(base64 --wrap 0 Cover.jpg)" "audio_cover.ogg"

输出:使用 METADATA_BLOCK 命令 ffmpeg

Input #0, ogg, from 'audio.ogg':
  Duration: 00:03:26.60, start: 0.000000, bitrate: 385 kb/s
  Stream #0:0: Audio: vorbis, 44100 Hz, stereo, fltp, 320 kb/s
    Metadata:
      encoder         : Lavc59.21.100 libvorbis
      album           : CMG Clássicos Pop Rock Nacionais
      genre           : Clássico Pop Rock Nacional
      title           : Cuidado!
      TKEY            : E m
      date            : 1988
      artist          : Lobão
Output #0, ogg, to 'audio_cover.ogg':
  Metadata:
    encoder         : Lavf59.17.102
  Stream #0:0: Audio: vorbis, 44100 Hz, stereo, fltp, 320 kb/s
    Metadata:
      encoder         : Lavc59.21.100 libvorbis
      album           : CMG Clássicos Pop Rock Nacionais
      genre           : Clássico Pop Rock Nacional
      title           : Cuidado!
      TKEY            : E m
      date            : 1988
      artist          : Lobão
      METADATA_BLOCK_PICTURE: $(base64 --wrap 0 Cover.jpg)
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
size=    9735kB time=00:03:26.59 bitrate= 386.0kbits/s speed=1.37e+03x
video:0kB audio:9677kB subtitle:0kB other streams:0kB global headers:4kB muxing overhead: 0.597793%

艺术作品已添加到元数据中?!,但播放歌曲时它不会在任何播放器中显示?!...我是 Windows 用户。我这么说是因为我不知道其他系统上是否有播放器可以按照添加的方式播放图像,好吗?

我也用过这个命令,用于在 MKV 文件中附加封面艺术,但 OGG 似乎不接受这个命令,如下所示:

使用 ffmpeg 和 -attach 命令:

ffmpeg -i "audio.ogg" -attach "cover.jpeg" -map 0 -c:a copy -c copy -metadata:s:t mimetype="image/jpeg" -metadata:s:t:0 filename="cover.jpeg" "audio_cover.ogg"

输出:错误

Input #0, ogg, from 'audio.ogg':
  Duration: 00:03:26.60, start: 0.000000, bitrate: 385 kb/s
  Stream #0:0: Audio: vorbis, 44100 Hz, stereo, fltp, 320 kb/s
    Metadata:
      encoder         : Lavc59.21.100 libvorbis
      album           : CMG Clássicos Pop Rock Nacionais
      genre           : Clássico Pop Rock Nacional
      title           : Cuidado!
      TKEY            : E m
      date            : 1988
      artist          : Lobão
[ogg @ 00000164388afe40] Unsupported codec id in stream 1
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
Error initializing output stream 0:1 --
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  File cover.jpeg -> Stream #0:1

ogg 文件不支持附加图像。它尝试将封面图片附加到 0:1 流,但显示编解码器错误,在 MKV 文件中不会发生这种情况?

答案1

使用的尝试-metadata:s:a METADATA_BLOCK_PICTURE=...是正确的,但是细节是错误的。

base64 编码的图像数据必须按照以下要求添加前缀:https://xiph.org/flac/format.html#metadata_block_picture

这是此类标头的示例:

$> echo -en "\0\0\0\x03\0\0\0\x0aimage/jpeg\0\0\0\x08test.jpg\0\0\0\x08\0\0\0\x0e\0\0\0\x20\0\0\0\0\0\0\x05\xad" \
  > vorbis.head
$> hexdump -C vorbis.head 
00000000  00 00 00 03 00 00 00 0a  69 6d 61 67 65 2f 6a 70  |........image/jp|
00000010  65 67 00 00 00 08 74 65  73 74 2e 6a 70 67 00 00  |eg....test.jpg..|
00000020  00 08 00 00 00 0e 00 00  00 20 00 00 00 00 00 00  |......... ......|
00000030  05 ad                                             |..|
00000032

您必须调整封面图像的标题,最值得注意的是宽度、高度、bpp 和原始尺寸,这里是 8x14@32、1453 字节(0x8、0xe、0x20、0x05ad)。

所有相关值都是 4 字节(32 位)小端字节序,即,对于宽度 320,将“\0\0\0\x08”替换为“\0\0\x01\x40”。

您可以添加封面艺术并附带如下评论:

ffmpeg -i inpug.flac.ogg  -acodec copy -map 0:a -metadata:s:a METADATA_BLOCK_PICTURE="$(cat vorbis.head cover.jpg | base64 --wrap 0)" output.flag.ogg

$(cat ....)适用于 Linux 或其他 Unixy 系统,在 Windows 上不起作用。

答案2

这对我有用:

ffmpeg -i audio.ogg -i Cover.jpg -c:a copy -c:v mjpeg `
-disposition:v attached_pic audio_video.mp4

请注意,输出的是 MP4 而不是 OGG。在我的系统上,Windows 资源管理器不支持带有 OGG 的封面图片。

相关内容