从带有专辑封面的ffmpeg进行管道传输时,mp3中的元数据无法正常工作 [英] Metadata in mp3 not working when piping from ffmpeg with album art

查看:118
本文介绍了从带有专辑封面的ffmpeg进行管道传输时,mp3中的元数据无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的程序中,我将Webm从流传递到ffmpeg,然后将输出传递到http请求.该过程的一部分是为mp3添加元数据.到目前为止,这一直很好.但是,在将图片添加为专辑封面后,它开始表现出意想不到的效果.

In my program I am piping a webm from a stream to ffmpeg and then pipe the output to a http request. Part of the process is adding metadata for the mp3. This has so far worked great. However after adding an image as album art it has started to act unexpected.

首先,这是我在程序内部使用的命令行:

First this is the command line I am using inside the program:

    val parameters = listOf("ffmpeg",
            "-i", "-",
            "-i", albumImage.absolutePath,
            "-map", "0",
            "-map", "1",
            "-c:v", "copy",
            "-f", "mp3",
            "-id3v2_version", "4",
            "-metadata", "title=${info.title}",
            "-metadata", "album=YouTube",
            "-metadata", "artist=${info.author}",
            "-metadata:s:v", "title=Album Cover",
            "-metadata:s:v", "comment=Cover (front)",
            "-"
    )

它创建了一个有效的mp3文件,我可以在mp3文件中找到元数据和图像,但是在播放时,它们都不会显示在VLC或其他任何位置.为了测试各种配置,我已将其转换为命令行.

It creates a valid mp3 file and I can find both the metadata and the image in the mp3 file, however when playing it none of them are displayed in VLC or anywhere else. To test various configurations I have converted it to the command line.

在第一次尝试中,我保存了视频和图像,并完全停止使用管道,结果是:

In a first try I have saved the video and the image and stopped using pipes altogether, which results in this:

ffmpeg -i video.webm -i image.jpeg -map 0 -map 1 -c:v copy -f mp3 -id3v2_version 4 -metadata title="Tiësto & KSHMR feat. Vassy - Secrets (Official Music Video)" -metadata album="YouTube" -metadata artist="Spinnin' Records" -metadata:s:v title="Album Cover" -metadata:s:v comment="Cover (front)" output3.mp3

在这种情况下,包括专辑封面在内的所有元数据都将显示在VLC中.

In this case all metadata including the album art is displayed in VLC.

然后我重新创建了与程序中相同的内容,将视频输入和音频输出进行管道传输,如下所示:

I then recreated the same thing as in my program, piping both video input and audio output, looking like this:

ffmpeg -i - -i image.jpeg -map 0 -map 1 -c:v copy -f mp3 -id3v2_version 4 -metadata title="Tiësto & KSHMR feat. Vassy - Secrets (Official Music Video)" -metadata album="YouTube" -metadata artist="Spinnin' Records" -metadata:s:v title="Album Cover" -metadata:s:v comment="Cover (front)" - < video.webm > output3.mp3

此文件与我的程序输出相同.既不显示标题,也不显示相册,也不显示相册图像(但是可以播放文件)

This file is the same as my programs output. Neither title nor album nor album image are displayed (however it can play the file)

要测试更多选项,我已对输出文件进行了硬编码,但通过管道将输入文件如下:

To test a few more options I have hardcoded the output file but pipe the input file like this:

ffmpeg -i--i image.jpeg -map 0 -map 1 -c:v复制-f mp3 -id3v2_version 4 -metadata title =Tiësto&KSHMR专长Vassy-秘密(官方音乐视频)"-元数据专辑="YouTube" -metadata artist ="Spinnin'Records" -metadata:s:v title =专辑封面" -metadata:s:v comment =封面(封面)" output3.mp3< video.webm

ffmpeg -i - -i image.jpeg -map 0 -map 1 -c:v copy -f mp3 -id3v2_version 4 -metadata title="Tiësto & KSHMR feat. Vassy - Secrets (Official Music Video)" -metadata album="YouTube" -metadata artist="Spinnin' Records" -metadata:s:v title="Album Cover" -metadata:s:v comment="Cover (front)" output3.mp3 < video.webm

现在,元数据可以再次使用.当对输入视频进行硬编码并将输出通过管道传输时,其再次消失.

Now the metadata is working again. When hardcoding the input video and piping the output, its again gone.

因此可以总结一下:当通过管道传输ffmpeg的输出时,文件中的元数据无法正常工作.有趣的是,ffmpeg的stderr输出看起来非常相似

So to sum up: When piping the output of ffmpeg the metadata in the file is not properly working. Interestingly the stderr output of ffmpeg looks quite similar

硬编码的output3.mp3:

Hardcoded output3.mp3:

ffmpeg version 3.4.4-0ubuntu0.18.04.1 Copyright (c) 2000-2018 the FFmpeg developers
Input #0, matroska,webm, from 'pipe:':
  Metadata:
    encoder         : google/video-file
  Duration: 00:03:39.58, start: -0.007000, bitrate: N/A
    Stream #0:0(eng): Audio: opus, 48000 Hz, stereo, fltp (default)
Input #1, image2, from 'image.jpeg':
  Duration: 00:00:00.04, start: 0.000000, bitrate: 1466 kb/s
    Stream #1:0: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 320x180, 25 tbr, 25 tbn, 25 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (opus (native) -> mp3 (libmp3lame))
  Stream #1:0 -> #0:1 (copy)
Output #0, mp3, to 'output3.mp3':
  Metadata:
    TPE1            : Spinnin' Records
    TIT2            : Tiësto & KSHMR feat. Vassy - Secrets (Official Music Video)
    TALB            : YouTube
    TSSE            : Lavf57.83.100
    Stream #0:0(eng): Audio: mp3 (libmp3lame), 48000 Hz, stereo, fltp (default)
    Metadata:
      encoder         : Lavc57.107.100 libmp3lame
    Stream #0:1: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 320x180, q=2-31, 25 tbr, 25 tbn, 25 tbc
    Metadata:
      title           : Album Cover
      comment         : Cover (front)

带管道输出:

ffmpeg version 3.4.4-0ubuntu0.18.04.1 Copyright (c) 2000-2018 the FFmpeg developers
Input #0, matroska,webm, from 'pipe:':
  Metadata:
    encoder         : google/video-file
  Duration: 00:03:39.58, start: -0.007000, bitrate: N/A
    Stream #0:0(eng): Audio: opus, 48000 Hz, stereo, fltp (default)
Input #1, image2, from 'image.jpeg':
  Duration: 00:00:00.04, start: 0.000000, bitrate: 1466 kb/s
    Stream #1:0: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 320x180, 25 tbr, 25 tbn, 25 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (opus (native) -> mp3 (libmp3lame))
  Stream #1:0 -> #0:1 (copy)
Output #0, mp3, to 'pipe:':
  Metadata:
    TPE1            : Spinnin' Records
    TIT2            : Tiësto & KSHMR feat. Vassy - Secrets (Official Music Video)
    TALB            : YouTube
    TSSE            : Lavf57.83.100
    Stream #0:0(eng): Audio: mp3 (libmp3lame), 48000 Hz, stereo, fltp (default)
    Metadata:
      encoder         : Lavc57.107.100 libmp3lame
    Stream #0:1: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 320x180, q=2-31, 25 tbr, 25 tbn, 25 tbc
    Metadata:
      title           : Album Cover
      comment         : Cover (front)

推荐答案

是的,当必须分两步写入ID3v2元数据时(例如,当必须插入图像包时),不能填写ID3标头大小&输出是不可寻求的.

Yes, the ID3 header size cannot be filled in when the ID3v2 metadata has to be written in two steps (such as when an image packet has to be inserted) & the output is not seekable.

您仍然可以通过告诉ffmpeg不要快速刷新数据来在某种程度上解决此问题.但是,如果ffmpeg的缓冲区超过256 kB,它将刷新.为ID3标头的其他部分留一些余地,这为您提供了最大图像上限.

You can still work around this to a degree by telling ffmpeg to not flush the data quickly. However, ffmpeg will flush if its buffer exceeds 256 kB. Make a small allowance for the other parts of the ID3 header, and that gives you a ceiling for the maximum size of the image.

ffmpeg -i - -i image.jpeg -map 0 -map 1 -c:v copy -f mp3 -id3v2_version 4 -metadata title="Tiësto & KSHMR feat. Vassy - Secrets (Official Music Video)" -metadata album="YouTube" -metadata artist="Spinnin' Records" -metadata:s:v title="Album Cover" -metadata:s:v comment="Cover (front)" -flush_packets 0 - > output3.mp3 < video.webm

这篇关于从带有专辑封面的ffmpeg进行管道传输时,mp3中的元数据无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆