【问题标题】:FFmpeg works out mp3 duration with file input, but fails with pipe?FFmpeg 通过文件输入计算出 mp3 持续时间,但使用管道失败?
【发布时间】:2012-08-12 18:11:59
【问题描述】:

我正在尝试使用 ffmpeg 从 mp3 中获取 PCM 数据,但这些文件存储在一个数据库 gridfs 中,因此我尝试使用管道为 ffmpeg 提供一些成功的数据,但是有一个文件由 ffmpeg 处理如果将文件名作为输入提供,则正确,而将文件作为管道提供时则错误:(知道为什么吗?

ffmpeg -i - -f s16le -acodec pcm_s16le output.raw < testMp3s/test-corrupt.mp3 

给予

ffmpeg version 0.11.1 Copyright (c) 2000-2012 the FFmpeg developers
built on Jun  9 2012 13:50:13 with gcc 4.7.0 20120505 (prerelease)
configuration: --prefix=/usr --enable-libmp3lame --enable-libvorbis --enable-libxvid --        enable-libx264 --enable-libvpx --enable-libtheora --enable-libgsm --enable-libspeex -- enable-postproc --enable-shared --enable-x11grab --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libschroedinger --enable-libopenjpeg --enable-librtmp --enable-libpulse --enable-libv4l2 --enable-gpl --enable-version3 --enable-runtime-cpudetect --  disable-debug --disable-static
libavutil      51. 54.100 / 51. 54.100
libavcodec     54. 23.100 / 54. 23.100
libavformat    54.  6.100 / 54.  6.100
libavdevice    54.  0.100 / 54.  0.100
libavfilter     2. 77.100 /  2. 77.100
libswscale      2.  1.100 /  2.  1.100
libswresample   0. 15.100 /  0. 15.100
libpostproc    52.  0.100 / 52.  0.100
[mp3 @ 0x16d7100] Unknown attached picture mimetype: JPG, skipping.
[mp3 @ 0x16d7100] max_analyze_duration 5000000 reached at 5015510
[mp3 @ 0x16d7100] Estimating duration from bitrate, this may be inaccurate
Input #0, mp3, from 'pipe:':
Metadata:
album           : FreshNewMusik.Com
encoded_by      : iTunes 10.6.3
title           : No Lie (Freestyle)
artist          : Lil Wayne
album_artist    : Lil Wayne
genre           : Hip-Hop/Rap
TT3             : twitter.com/jakejarvis
date            : 2012
Duration: N/A, start: 0.000000, bitrate: 320 kb/s
Stream #0:0: Audio: mp3, 44100 Hz, stereo, s16, 320 kb/s

还是

ffmpeg -i testMp3s/test-corrupt.mp3 -f s16le -acodec pcm_s16le output.raw 

给予

ffmpeg version 0.11.1 Copyright (c) 2000-2012 the FFmpeg developers
built on Jun  9 2012 13:50:13 with gcc 4.7.0 20120505 (prerelease)
configuration: --prefix=/usr --enable-libmp3lame --enable-libvorbis --enable-libxvid --    enable-libx264 --enable-libvpx --enable-libtheora --enable-libgsm --enable-libspeex --enable-postproc --enable-shared --enable-x11grab --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libschroedinger --enable-libopenjpeg --enable-librtmp --enable-libpulse --enable-libv4l2 --enable-gpl --enable-version3 --enable-runtime-cpudetect --disable-debug --disable-static
libavutil      51. 54.100 / 51. 54.100
libavcodec     54. 23.100 / 54. 23.100
libavformat    54.  6.100 / 54.  6.100
libavdevice    54.  0.100 / 54.  0.100
libavfilter     2. 77.100 /  2. 77.100
libswscale      2.  1.100 /  2.  1.100
libswresample   0. 15.100 /  0. 15.100
libpostproc    52.  0.100 / 52.  0.100
[mp3 @ 0xf33100] Unknown attached picture mimetype: JPG, skipping.
[mp3 @ 0xf33100] max_analyze_duration 5000000 reached at 5015510
[mp3 @ 0xf33100] Estimating duration from bitrate, this may be inaccurate
Input #0, mp3, from 'testMp3s/test-corrupt.mp3':
Metadata:
album           : FreshNewMusik.Com
encoded_by      : iTunes 10.6.3
title           : No Lie (Freestyle)
artist          : Lil Wayne
album_artist    : Lil Wayne
genre           : Hip-Hop/Rap
TT3             : twitter.com/jakejarvis
date            : 2012
Duration: 00:02:33.86, start: 0.000000, bitrate: 320 kb/s
Stream #0:0: Audio: mp3, 44100 Hz, stereo, s16, 320 kb/s

如何获得管道的持续时间? (数据在 python 应用程序的内存中可用)

【问题讨论】:

  • 只是猜测:估计是根据文件的长度进行的。当数据通过管道到达时,此信息不可用,因为您需要在知道长度之前读取到EOF。如果你知道有多少数据,你不能自己计算吗?

标签: bash shell ffmpeg pipe


【解决方案1】:
[mp3 @ 0xf33100] Estimating duration from bitrate, this may be inaccurate

当给定一个真实文件时,ffmpeg 可以使用 stat 获取文件的大小。持续时间是大小/比特率。但是当它得到 stdio 时,它无法判断需要多少数据。事实上,如果它正在获取流,甚至可能没有明确定义的持续时间。我记得,MP3 可以在文件开头的 id3 标签中提供持续时间,这就是为什么您的某些文件确实显示持续时间。

【讨论】:

  • 你推荐什么方法来获取mp3流的PCM数据和时长?顺便说一句,整个流都在内存中。
  • 我不确定,但最简单的方法可能是先将其写入磁盘(如果您的操作系统支持,可能是 ramdisk)并让 ffmpeg 从文件中获取大小。
猜你喜欢
  • 2017-05-31
  • 1970-01-01
  • 1970-01-01
  • 2020-05-07
  • 2013-05-12
  • 1970-01-01
  • 2014-07-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多