简体   繁体   English

是否可以对具有精确长度(以毫秒为单位)的音频流进行编码?

[英]Is it possible to encode an audio stream with the exact length (to millisecond)?

I am looking to create an output file with a length exactly 30 seconds in either mp3, aac, or vorbis codecs.我希望在 mp3、aac 或 vorbis 编解码器中创建长度正好为30 秒的输出文件。 I have used avconv (and also tried ffmpeg) with the following command:我已经使用 avconv (也尝试过 ffmpeg)和以下命令:

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:这会产生输出,说明它已经编码了 30 秒,但是:

$ 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':
  Metadata:
    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)
    Metadata:
      handler_name    : SoundHandler
# avprobe output

When i encode in mp3 it correctly displays that it does more than 30 seconds during the encoding.当我在 mp3 中编码时,它正确显示它在编码过程中超过 30 秒。 When i try vorbis it does slightly less than 30 seconds.当我尝试 vorbis 时,它的运行时间略少于 30 秒。

Is it possible to achieve the length of 30 seconds to the millisecond using any tool (i prefer either avconv).是否可以使用任何工具实现 30 秒到毫秒的长度(我更喜欢 avconv)。

In your example, you are using aac audio 44100khz.在您的示例中,您使用的是 aac 音频 44100khz。 AAC uses 1024 samples per frame. AAC 每帧使用 1024 个样本。 1024/44100 is not evenly divisible by 30. so, no it not possible. 1024/44100 不能被 30 整除。所以,不可能。 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. Mp3 每帧使用 1152、572 或 384 个样本,具体取决于层。 There MAY be a combination that works.可能有一个有效的组合。 see more here https://hydrogenaud.io/index.php/topic,85125.0.html在这里查看更多https://hydrogenaud.io/index.php/topic,85125.0.html

I don't know anything about vorbis, so I don't know if its possible.我对 vorbis 一无所知,所以我不知道它是否可能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM