【问题标题】:ffmpeg convert and add silent audio track to an mpegffmpeg 转换并将静音音轨添加到 mpeg
【发布时间】:2016-04-18 18:22:35
【问题描述】:

我需要删除 B 帧并向 mpeg 添加静音音轨。这是我的源文件(mediainfo input.mpg):

General
Complete name                            : input.mpg
Format                                   : MPEG-PS
File size                                : 3.88 MiB
Duration                                 : 4s 0ms
Overall bit rate                         : 8 131 Kbps
Writing library                          : encoded by TMPGEnc (ver. 2.525.64.184)

Video
ID                                       : 224 (0xE0)
Format                                   : MPEG Video
Format version                           : Version 1
Format settings, BVOP                    : Yes
Format settings, Matrix                  : Default
Format settings, GOP                     : M=3, N=9
Duration                                 : 4s 0ms
Bit rate                                 : 8 000 Kbps
Width                                    : 800 pixels
Height                                   : 600 pixels
Display aspect ratio                     : 4:3
Frame rate                               : 30.000 fps
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Compression mode                         : Lossy
Bits/(Pixel*Frame)                       : 0.556
Time code of first frame                 : 00:00:00:00
Time code source                         : Group of pictures header
GOP, Open/Closed                         : Open
GOP, Open/Closed of first frame          : Closed
Stream size                              : 3.80 MiB (98%)
Writing library                          : TMPGEnc 2.525.64.184

我正在尝试:

ffmpeg -f lavfi -i anullsrc -i input.mpg -c:v mpeg1video -b:v 8000k \
-minrate 8000k -maxrate 8000k -pix_fmt yuv420p -g 9 -acodec mp2 \
-ac 2 -ab 128k -ar 44100 -async 1 -shortest -y out.mpg

mediainfo out.mpg

General
Complete name                            : out.mpg
Format                                   : MPEG-PS
File size                                : 3.96 MiB
Duration                                 : 4s 23ms
Overall bit rate                         : 8 251 Kbps

Video
ID                                       : 224 (0xE0)
Format                                   : MPEG Video
Format version                           : Version 1
Format settings, BVOP                    : No
Format settings, Matrix                  : Default
Format settings, GOP                     : N=9
Duration                                 : 4s 0ms
Bit rate                                 : 8 000 Kbps
Width                                    : 800 pixels
Height                                   : 600 pixels
Display aspect ratio                     : 4:3
Frame rate                               : 30.000 fps
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Compression mode                         : Lossy
Bits/(Pixel*Frame)                       : 0.556
Time code of first frame                 : 00:00:00:00
Time code source                         : Group of pictures header
GOP, Open/Closed                         : Open
GOP, Open/Closed of first frame          : Closed
Stream size                              : 3.80 MiB (96%)

Audio
ID                                       : 192 (0xC0)
Format                                   : MPEG Audio
Format version                           : Version 1
Format profile                           : Layer 2
Duration                                 : 4s 23ms
Bit rate mode                            : Constant
Bit rate                                 : 128 Kbps
Channel(s)                               : 2 channels
Sampling rate                            : 44.1 KHz
Compression mode                         : Lossy
Delay relative to video                  : -11ms
Stream size                              : 62.9 KiB (2%)

不幸的是,音频持续时间与视频持续时间不同,并且有一些“相对于视频的延迟”为 -11 毫秒 我在另一篇文章中发现了这个选项:

-af asetpts=PTS+0.011/TB

这给了我这个输出:

Audio
ID                                       : 192 (0xC0)
Format                                   : MPEG Audio
Format version                           : Version 1
Format profile                           : Layer 2
Duration                                 : 3s 997ms
Bit rate mode                            : Constant
Bit rate                                 : 128 Kbps
Channel(s)                               : 2 channels
Sampling rate                            : 44.1 KHz
Compression mode                         : Lossy
Stream size                              : 62.5 KiB (2%)

这个很接近,但仍然不是我预期的“4s 0ms”。我怎样才能 添加具有“绝对准确”持续时间的无声音轨?我对视频进行编码吗?

【问题讨论】:

    标签: audio video ffmpeg


    【解决方案1】:

    试试

    ffmpeg -f lavfi -i aevalsrc=0|0:d=4.00 -i input.mpg -c:v mpeg1video -b:v 8000k \
    -minrate 8000k -maxrate 8000k -pix_fmt yuv420p -g 9 -acodec mp2 \
    -ac 2 -ab 128k -ar 44100 -async 1 -shortest -y out.mpg
    

    【讨论】:

    • MPEG 音频存储在帧中。 MP2 中每个通道有 1152 帧。 153 帧为您提供 3.9967 秒的音频(您得到的),并且由于编解码器只会输出全帧,下一个可能性是 4.022 秒。要获得精确的 4.00 秒,您的采样率应该是 144 的倍数。在标准采样率中,没有一个符合条件。您可以通过选择具有最低小数部分的那个来最小化上/下。
    • 更正:MP2中每帧有1152个样本
    猜你喜欢
    • 1970-01-01
    • 2012-09-04
    • 2017-03-21
    • 2022-01-19
    • 1970-01-01
    • 2015-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多