ffmpeng获取音频文件中的专辑封面图片

一,用ffmpeg命令来操作

下载后,不用做过多的配置和修改, 直接使用

从音频文件中提取出专辑封面图片:

$ ./ffmpeg.exe -i 黑色毛衣\ -\ 周杰伦.mp3 bb.jpg
ffmpeg version N-92237-g305e523105 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 8.2.1 (GCC) 20181017
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth
  libavutil      56. 19.101 / 56. 19.101
  libavcodec     58. 33.102 / 58. 33.102
  libavformat    58. 19.101 / 58. 19.101
  libavdevice    58.  4.105 / 58.  4.105
  libavfilter     7. 36.100 /  7. 36.100
  libswscale      5.  2.100 /  5.  2.100
  libswresample   3.  2.100 /  3.  2.100
  libpostproc    55.  2.100 / 55.  2.100
Input #0, mp3, from '黑色毛衣 - 周杰伦.mp3':
  Metadata:
    title           : 黑色毛衣
    artist          : 周杰伦
    album           : 十一月的萧邦
  Duration: 00:04:11.64, start: 0.025056, bitrate: 128 kb/s
    Stream #0:0: Audio: mp3, 44100 Hz, stereo, fltp, 128 kb/s
    Metadata:
      encoder         : LAME3.98r
    Side data:
      replaygain: track gain - -7.700000, track peak - unknown, album gain - unknown, album peak - unknown,
    Stream #0:1: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 500x500 [SAR 1:1 DAR 1:1], 90k tbr, 90k tbn, 90k tbc
    Metadata:
      comment         : Cover (front)
Stream mapping:
  Stream #0:1 -> #0:0 (mjpeg (native) -> mjpeg (native))
Press [q] to stop, [?] for help
[image2 @ 000002284216ae40] Frame rate very high for a muxer not efficiently supporting it.
Please consider specifying a lower framerate, a different muxer or -vsync 2
Output #0, image2, to 'bb.jpg':
  Metadata:
    title           : 黑色毛衣
    artist          : 周杰伦
    album           : 十一月的萧邦
    encoder         : Lavf58.19.101
    Stream #0:0: Video: mjpeg, yuvj420p(pc), 500x500 [SAR 1:1 DAR 1:1], q=2-31, 200 kb/s, 90k fps, 90k tbn, 90k tbc
    Metadata:
      comment         : Cover (front)
      encoder         : Lavc58.33.102 mjpeg
    Side data:
      cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
frame=    1 fps=0.0 q=6.2 Lsize=N/A time=00:00:00.00 bitrate=N/A speed=0.00217x
video:22kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

执行完这条命令后,专辑封面图片会保存在bb.jpg文件中;

往音频文件中添加专辑封面:
ffmpeg -y -i audio1.mp3 -i cover.jpg -map 0:0 -map 1:0 -c copy -id3v2_version 3 audio2.mp3
执行完这条命令后,audio2.mp3中便会包含cover.jpg作为它的专辑封面了。

posted @ 2024-07-24 17:05  枫奇丶宛南  阅读(223)  评论(0编辑  收藏  举报