avoid3d
avoid3d

Reputation: 620

FFmpeg works out mp3 duration with file input, but fails with pipe?

I am trying to get PCM data from mp3's using ffmpeg, but the files are stored on a database, gridfs, so I am trying to use pipes to give ffmpeg the data with some sucess, however there is one file which ffmpeg handles correctlt if fed the filename as an input, and incorrectly when given the file as a pipe :( any idea why?

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

gives

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

Yet

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

gives

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

How do I get the duration with the pipe? (the data is available on memory in a python app)

Upvotes: 1

Views: 3321

Answers (1)

Kevin
Kevin

Reputation: 56049

[mp3 @ 0xf33100] Estimating duration from bitrate, this may be inaccurate

When given a real file, ffmpeg can get the sizes of the file using stat. Duration is size / bitrate. But when it gets stdio, it has no way to tell how much data to expect. In fact, if it's getting a stream, there may not even be a well-defined duration. As I recall, MP3s can provide duration in the id3 tags at the start of the file, which is why some of your files do show a duration.

Upvotes: 7

Related Questions