Opened 4 years ago

Last modified 4 years ago

#1520 new enhancement

allow mathematical expressions for -t and -ss

Reported by: dericed Owned by:
Priority: normal Component: undetermined
Version: unspecified Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no


Summary of the bug:

It seems that -t and -ss support integer and decimals up to the six places after the decimal (-t 1.033366 works but -t 1.0333666 doesn't). Sometimes greater precision is needed. Is it possible to support mathematical expression with -t and -ss as it is with some of the timing in the filters.

For instance if I try to create a wav file that contains one NTSC frame's worth of silence, it will produce an error. The closest I can seem to get is with '-t 1.033367'.

How to reproduce:

ffmpeg -t '1/(30000/1001)' -f lavfi -i aevalsrc=0 -c:a pcm_s16le out.wav
ffmpeg version 0.11.1.git Copyright (c) 2000-2012 the FFmpeg developers
  built on Jul  5 2012 11:22:03 with gcc 4.2.1 (Apple Inc. build 5666) (dot 3)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/HEAD --enable-shared --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-libfreetype --cc=/usr/bin/gcc-4.2 --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-librtmp --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libxvid --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libass --enable-libvo-aacenc
  libavutil      51. 64.100 / 51. 64.100
  libavcodec     54. 33.100 / 54. 33.100
  libavformat    54. 15.100 / 54. 15.100
  libavdevice    54.  1.100 / 54.  1.100
  libavfilter     3.  0.101 /  3.  0.101
  libswscale      2.  1.100 /  2.  1.100
  libswresample   0. 15.100 /  0. 15.100
  libpostproc    52.  0.100 / 52.  0.100
Invalid duration specification for t: 1/(30000/1001)

Change History (2)

comment:1 Changed 4 years ago by Cigaes

I see three separate issues here:

First, the possibility of putting mathematical expressions in the -t option. In the example you show, you can just let the shell do the work:
./ffmpeg -t $(printf %.6f $[1001/30000.]) -f lavfi -i aevalsrc=0 -c:a pcm_s16le out.wav
works just fine (and we could easily do away with the printf for the rounding). Of course, it does not work if you want to use in the formula values that come from the input file. That is the reason for the formulas in most filters: you can make them depend on the input video size or whatever.

Second, the accuracy of the time. It is completely unrelated to the way the time is parsed. Unless you are dealing with a recording with a sample rate beyond the megahertz, six decimal places is plenty enough.

Third, your problems getting the exact duration you request. This is in fact a completely unrelated issue. If you examine your output file, you can notice that it has exactly 2048 samples. The reason is that aevalsrc always outputs samples 1024 at a time, and ffmpeg does not change the grouping to adjust for the -t option. The immediate solution for that is to select a frame size that will fit your selected number of samples. In this particular case, n=1471 and -t 0.033356 work perfectly. There is room for enhancement here too.

comment:2 Changed 4 years ago by dericed

Thanks for the tip to use shell for the math and for breaking this down.

Note: See TracTickets for help on using tickets.