Why can't avprobe determine the duration of an MP3 file when supplied via STDIN?

621 views Asked by At

I am attempting to lookup the duration of an MP3 file with avprobe. This works (albeit with some strange warnings):

$ avprobe somefile.mp3
...
[mp3 @ 0x657b20] max_analyze_duration reached
[mp3 @ 0x657b20] Estimating duration from bitrate, this may be inaccurate
Input #0, mp3, from 'somefile.mp3':
  Duration: 00:03:38.10, start: 0.000000, bitrate: 128 kb/s
    Stream #0.0: Audio: mp3, 44100 Hz, stereo, s16, 128 kb/s

However, if I turn around and pipe the file via STDIN, I run into problems:

cat somefile.mp3 | avprobe -
...
[mp3 @ 0x255db20] max_analyze_duration reached
[mp3 @ 0x255db20] Estimating duration from bitrate, this may be inaccurate
Input #0, mp3, from 'pipe:':
  Duration: N/A, start: 0.000000, bitrate: 128 kb/s
    Stream #0.0: Audio: mp3, 44100 Hz, stereo, s16, 128 kb/s

Duration is reported as "N/A". Why can't it figure out the duration when reading from STDIN?

1

There are 1 answers

0
Biapy On

As far as i know, avprobe use two information to compute a mp3 file duration:

  • MP3 file bitrate.
  • MP3 file size.

When used directly with a file, avprobe is able to get filesize from the file stats (see stat "file.mp3" command).

When used with a pipe input, avprobe is unable to detect filesize, since the pipe can be of any size/length. If the mp3 file does not have duration metadata, avprobe has no mean to compute a duration estimate.