I am looking to create an output file with a length exactly 30 seconds in either mp3, aac, or vorbis codecs. I have used avconv (and also tried ffmpeg) with the following command:

avconv  -i input_file_here -c:a aac -b:a 320k -t 30 out.mp4

This produces the output, stating that it has encoded exactly 30 seconds, but then:

$ avprobe out.mp4
avprobe version v13_dev0-1648-gc4642788e, Copyright (c) 2007-2018 the Libav developers
  built on Apr 24 2019 15:49:35 with gcc 7 (Ubuntu 7.3.0-27ubuntu1~18.04)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'out.mp4':
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf57.83.100
  Duration: 00:00:30.02, start: 0.023220, bitrate: 323 kb/s
    Stream #0:0(und): Audio: aac (LC) [mp4a / 0x6134706D]
      44100 Hz, stereo, fltp, 321 kb/s (default)
      handler_name    : SoundHandler
# avprobe output

When i encode in mp3 it correctly displays that it does more than 30 seconds during the encoding. When i try vorbis it does slightly less than 30 seconds.

Is it possible to achieve the length of 30 seconds to the millisecond using any tool (i prefer either avconv).

1 Answers

szatmary On

In your example, you are using aac audio 44100khz. AAC uses 1024 samples per frame. 1024/44100 is not evenly divisible by 30. so, no it not possible. It MAY be possible to adjust priming samples, But you would need to understand how priming samples work, and modify the encoder.

Mp3 uses 1152, 572 or 384 samples per frame depending on layer. There MAY be a combination that works. see more here https://hydrogenaud.io/index.php/topic,85125.0.html

I don't know anything about vorbis, so I don't know if its possible.