[FFmpeg-user] How can I correctly set duration on MP3 output when input is streamed to ffmpeg?

Tom Barnsbury ruralmyth at gmail.com
Sun Jan 19 22:43:25 EET 2020


 Hi,

 I am streaming an mp3 file from a remote server, piping it through ffmpeg
to add custom id3 tags and then offering it as a file download from my own
server. It seems that ffmpeg cannot add duration metadata to the file as
the input data is streamed. I was led to this conclusion by the this post
on Stack Overflow: https://stackoverflow.com/a/11987600. My output files
are always missing bytes compared to the source file from the remote server.

 Is it possible that the missing metadata can be added by passing the
duration in to ffmpeg as an argument? I tried using -t as a parameter (as
an input, output and both) but this didn't have the desired effect.

 My ffmpeg commands are below. The input and output files are FIFO files
(using FIFO files does not seem to cause any problems in itself).

 ffmpeg -f mp3 -i /tmp/dc7f36e4-353b-4e1b-a148-8d8e5ab8b606-input -y
-metadata artist="My artist" -metadata title="My title" -codec copy -f mp3
/tmp/dc7f36e4-353b-4e1b-a148-8d8e5ab8b606-output

 Note: When I say missing metadata, I'm not talking about id3 tags. ffprobe
reports the 'deficient' file as follows (note: "Estimating duration from
bitrate, this may be inaccurate"):

 ffprobe version 4.2.2 Copyright (c) 2007-2019 the FFmpeg developers
   built with Apple LLVM version 10.0.0 (clang-1000.11.45.5)
   configuration: --prefix=/usr/local/Cellar/ffmpeg/4.2.2 --enable-shared
--enable-pthreads --enable-version3 --enable-avresample --cc=clang
--host-cflags='-I/Library/Java/JavaVirtualMachines/adoptopenjdk-13.0.1.jdk/Contents/Home/include
-I/Library/Java/JavaVirtualMachines/adoptopenjdk-13.0.1.jdk/Contents/Home/include/darwin'
--host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl
--enable-libaom --enable-libbluray --enable-libmp3lame --enable-libopus
--enable-librubberband --enable-libsnappy --enable-libtesseract
--enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx
--enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma
--enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass
--enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg
--enable-librtmp --enable-libspeex --enable-libsoxr --enable-videotoolbox
--disable-libjack --disable-indev=jack
   libavutil      56. 31.100 / 56. 31.100
   libavcodec     58. 54.100 / 58. 54.100
   libavformat    58. 29.100 / 58. 29.100
   libavdevice    58.  8.100 / 58.  8.100
   libavfilter     7. 57.100 /  7. 57.100
   libavresample   4.  0.  0 /  4.  0.  0
   libswscale      5.  5.100 /  5.  5.100
   libswresample   3.  5.100 /  3.  5.100
   libpostproc    55.  5.100 / 55.  5.100
 [mp3 @ 0x7f91fb002a00] Estimating duration from bitrate, this may be
inaccurate
 Input #0, mp3, from 'streamed-with-additional-id3-tags.mp3':
   Metadata:
     title           : My title
     artist          : My artist
     encoder         : Lavf58.29.100
   Duration: 02:59:56.09, start: 0.000000, bitrate: 128 kb/s
     Stream #0:0: Audio: mp3, 48000 Hz, stereo, fltp, 128 kb/s


 Whereas I am looking to produce a file that reports the following output
(note the "Duration" "start" value, and additional "Metadata" section with
an "encoder" field. I'm not sure if the additional "Metadata" section is
related to the duration issue):


 ffprobe version 4.2.2 Copyright (c) 2007-2019 the FFmpeg developers
   built with Apple LLVM version 10.0.0 (clang-1000.11.45.5)
   configuration: --prefix=/usr/local/Cellar/ffmpeg/4.2.2 --enable-shared
--enable-pthreads --enable-version3 --enable-avresample --cc=clang
--host-cflags='-I/Library/Java/JavaVirtualMachines/adoptopenjdk-13.0.1.jdk/Contents/Home/include
-I/Library/Java/JavaVirtualMachines/adoptopenjdk-13.0.1.jdk/Contents/Home/include/darwin'
--host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl
--enable-libaom --enable-libbluray --enable-libmp3lame --enable-libopus
--enable-librubberband --enable-libsnappy --enable-libtesseract
--enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx
--enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma
--enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass
--enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg
--enable-librtmp --enable-libspeex --enable-libsoxr --enable-videotoolbox
--disable-libjack --disable-indev=jack
   libavutil      56. 31.100 / 56. 31.100
   libavcodec     58. 54.100 / 58. 54.100
   libavformat    58. 29.100 / 58. 29.100
   libavdevice    58.  8.100 / 58.  8.100
   libavfilter     7. 57.100 /  7. 57.100
   libavresample   4.  0.  0 /  4.  0.  0
   libswscale      5.  5.100 /  5.  5.100
   libswresample   3.  5.100 /  3.  5.100
   libpostproc    55.  5.100 / 55.  5.100
 Input #0, mp3, from 'directly-from-file-with-additional-id3-tags.mp3.mp3':
   Metadata:
     title           : My title
     artist          : My artist
     encoder         : Lavf58.29.100
   Duration: 02:59:56.09, start: 0.023021, bitrate: 128 kb/s
     Stream #0:0: Audio: mp3, 48000 Hz, stereo, fltp, 128 kb/s
     Metadata:
       encoder         : Lavc57.89


Ultimately, I just want an identical file but for the id3 tags replaced by
the tags provided in my ffmpeg command.

 Thanks


More information about the ffmpeg-user mailing list