首页 > 解决方案 > 使用 ffmpeg 对 AAC 音频进行转码时,下一个 pts 与前一个 pts 加上持续时间不匹配

问题描述

在我的理解中,以下陈述必须成立:

next pts = previous pts + duration

但是,我得到了这个看起来很奇怪的PTSes列表:ffprobe

<packet codec_type="audio" ... pts="63000" duration="2089" duration_time="0.023211" ...>
<packet codec_type="audio" ... pts="65070" duration="2089" duration_time="0.023211" ...>
<packet codec_type="audio" ... pts="67140" duration="2089" duration_time="0.023211" ...>
<packet codec_type="audio" ... pts="69300" duration="2089" duration_time="0.023211" ...>
<packet codec_type="audio" ... pts="71370" duration="2089" duration_time="0.023211" ...>
<packet codec_type="audio" ... pts="73440" duration="2089" duration_time="0.023211" ...>
<packet codec_type="audio" ... pts="75510" duration="2089" duration_time="0.023211" ...>
<packet codec_type="audio" ... pts="77670" duration="2089" duration_time="0.023211" ...>

对应的PTS差距如下。您看不到以下空白匹配2089

63000 <> 65070: 2070
65070 <> 67140: 2070
67140 <> 69300: 2160
69300 <> 71370: 2070
71370 <> 73440: 2070
73440 <> 75510: 2070
75510 <> 77670: 2160

我对转码没有深入的了解AAC,所以我和一些随机的家伙交谈#ffmpeg。按照他的说法,差距应该是一个固定值:

20:01 -!- Icedream [~icedream@hzn-b.serverkomplex.de] has quit [Quit: A lol made me boom.]
20:02 < DeHackEd> I would expect them to increment at a constant rate, since AAC (which is probably what you're using) uses fixed size
                  audio chunks. But that's very inconsistent
20:03 < DeHackEd> (+/- 1 pts number would be acceptable)

说实话,这是一个有问题的视频,但不是你所期望的。如果两个或多个音频数据包被塞进一个数据包中,我会听到断断续续的音频剪辑声音PES。这个配置的特别之处在于,PTS除了第一个之外,播放器必须猜测尾随的音频包。由于PTS间隙不一致,玩家一定是用了错误PTS的 es 作为尾随的,这在我看来是原因。

但是,触发点可能是什么?以下是一些您可以参考的上下文:

$ ./foo.sh ./original.flv
diff 296448 occurs at 296448 // just a first packet (=has no previous packet)
diff 24 occurs at 296472
diff 23 occurs at 296495
$FFMPEG -hide_banner -loglevel info -nostats \
    -i $input \
    -map "[out1]" -c:v libx264 -r 30 -force_key_frames "expr:gte(t, n_forced*$keyFrameInterval)" -preset veryfast -vprofile high -minrate 4.5M -maxrate 6M -bufsize 6M \
    -map 0:a -c:a aac -b:a:1 128K -af "aformat=sample_rates=44100|48000:channel_layouts=stereo" \
    -map 0:a -c:a aac -b:a:2 32K -af "aformat=sample_rates=44100|48000:channel_layouts=stereo" \
    -f mpegts -tune zerolatency pipe:1 > \
        >($FFMPEG -hide_banner -loglevel info -nostats \
            -i - \
            -map 0:v -c:v copy -map 0:1 -c:a copy -bsf:a aac_adtstoasc -tune zerolatency -f flv -max_muxing_queue_size 1024 ${output}_1080 \
            -map 0:v -s $(width 1280 720 $orientation)x$(height 1280 720 $orientation) -c:v libx264 -r 30 -force_key_frames "expr:gte(t, n_forced*$keyFrameInterval)" -preset veryfast -vprofile high -minrate 3M -maxrate 4M -bufsize 4M -map 0:1 -c:a copy -bsf:a aac_adtstoasc -f flv -tune zerolatency -max_muxing_queue_size 1024 ${output}_720 \
            ...

标签: audiovideoffmpegstreaminghttp-live-streaming

解决方案


推荐阅读