是否可以在不使用 ffmpeg 重新编码的情况下更改音量?

Is it possible to change volume with no reencode with ffmpeg?

我刚刚有这个问题,因为我在 ffmpeg 中使用了以下命令:

ffmpeg -i input.wav -filter:a "volume=0.2" output.wav

按照此处的文档操作:https://trac.ffmpeg.org/wiki/AudioVolume

但是,当我创建新文件时,输出的大小是输入的一半,而且音轨的比特率也降低了。

所以我的问题是:

  1. 比特率应该像这样随着音量的减小和增大而减小吗?
  2. 是否可以在不使用 ffmpeg 重新编码的情况下更改音量?

好的,正如 Reddit 的一位好心人向我解释的那样,我应该能够在不重新编码的情况下更改音量,但是,我的输入编解码器是 pcm_f32le 并且 ffmpeg 的输出编解码器的默认设置没有任何说明符是 pcm_f16le.

第一个pcm_f32le是32位,所以它比第二个16位存储更多的信息。

所以答案是:

  1. 是的,因为在这种情况下,我在不知不觉中重新编码为信息较少的编解码器。

  2. 其实没有,还在重新编码。最好的选择是使用我上面使用的相同代码和一个额外的说明符:

ffmpeg -i input.wav -filter:a "volume=0.2" -c:a pcm_f32le output.wav

输入和输出的编解码器必须与 32 位或 16 位相同,否则我必须添加说明符,同一个人在 Reddit 上向我展示了如何做。

但是,每当您添加过滤器时,它仍然会重新编码。

我不是专家,但我增加音量的方式似乎不会引起问题.. 例如音频比特率相同...文件大小也相似。

ffmpeg -i ac.mp4 -af volume=7 -vcodec copy ac2.mp4

注意-以下是一道涉及c#的编程题,但上面有人提到了

用于文档

ffmpeg -?没有显示太多。如果你做 ffmpeg -? | grep "vol" 那么它只提到“-vol volume” 如果你做 ffmpeg -? | grep "-af" 那么它只说 -af filter_graph set audio filters" 没有提到你可以使用什么音频过滤器。

但是与一些 ffmpeg 专家交谈时,他们提到了重新文档..

"
有 ffmpeg-filters 联机帮助页以及 -h filter=NAME 向您简要介绍了可用于过滤器的选项。

在网络上你也有 ffmpeg-all 一个 https://www.ffmpeg.org/ffmpeg-all.html

https://ffmpeg.org/ffmpeg-filters.html#volume


亲眼看看来自 mediainfo 和 DIR 的文件之间的区别

请注意,源文件和目标文件的大小相似,均为 195MB。源为 195,166,205 字节,目标为 195,837,608 字节。所以大小差异很小。

注意

码率没有区别

C:\Users\User\Downloads\ac>mediainfo ac.mp4 | find /i "bit"
Overall bit rate                         : 383 kb/s
Bit rate                                 : 252 kb/s
Bit depth                                : 8 bits
Bits/(Pixel*Frame)                       : 0.010
Bit rate mode                            : Constant
Bit rate                                 : 128 kb/s

C:\Users\User\Downloads\ac>mediainfo ac2.mp4 | find /i "bit"
Overall bit rate                         : 384 kb/s
Bit rate                                 : 252 kb/s
Bit depth                                : 8 bits
Bits/(Pixel*Frame)                       : 0.010
Bit rate mode                            : Constant
Bit rate                                 : 128 kb/s

C:\Users\User\Downloads\ac>

这里是每个文件的所有媒体信息数据,因此您可以自己决定是否可以从中看到更改音量时发生的任何实质性差异。

C:\Users\User\Downloads\ac>mediainfo ac.mp4
General
Complete name                            : ac.mp4
Format                                   : MPEG-4
Format profile                           : Base Media
Codec ID                                 : isom (isom/iso2/avc1/mp41)
File size                                : 186 MiB
Duration                                 : 1 h 7 min
Overall bit rate                         : 383 kb/s
Writing application                      : Lavf58.20.100

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : High@L3.2
Format settings                          : CABAC / 1 Ref Frames
Format settings, CABAC                   : Yes
Format settings, Reference frames        : 1 frame
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 1 h 7 min
Bit rate                                 : 252 kb/s
Width                                    : 1 366 pixels
Height                                   : 768 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 24.000 FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.010
Stream size                              : 122 MiB (66%)
Writing library                          : x264 core 157 r2945 72db437
Encoding settings                        : cabac=1 / ref=1 / deblock=1:0:0 / analyse=0x3:0x3 / me=dia / subme=1 / psy=1 / psy_rd=1.00:0.00 / mixed_ref
=0 / me_range=16 / chroma_me=1 / trellis=0 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=0 / threads=4 / lookahead_threads=4 /
 sliced_threads=1 / slices=4 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=0 / weightp=1 / keyint=250 / keyint_
min=24 / scenecut=40 / intra_refresh=0 / rc=crf / mbtree=0 / crf=26.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / ip_ratio=1.40 / aq=1:1.00
Codec configuration box                  : avcC

Audio
ID                                       : 2
Format                                   : AAC LC SBR
Format/Info                              : Advanced Audio Codec Low Complexity with Spectral Band Replication
Commercial name                          : HE-AAC
Format settings                          : NBC
Codec ID                                 : mp4a-40-5
Duration                                 : 1 h 7 min
Duration_LastFrame                       : -23 ms
Bit rate mode                            : Constant
Bit rate                                 : 128 kb/s
Channel(s)                               : 2 channels
Channel layout                           : L R
Sampling rate                            : 48.0 kHz
Frame rate                               : 23.438 FPS (2048 SPF)
Compression mode                         : Lossy
Stream size                              : 62.2 MiB (33%)
Default                                  : Yes
Alternate group                          : 1



C:\Users\User\Downloads\ac>mediainfo ac2.mp4
General
Complete name                            : ac2.mp4
Format                                   : MPEG-4
Format profile                           : Base Media
Codec ID                                 : isom (isom/iso2/avc1/mp41)
File size                                : 187 MiB
Duration                                 : 1 h 7 min
Overall bit rate                         : 384 kb/s
Writing application                      : Lavf58.31.104

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : High@L3.2
Format settings                          : CABAC / 1 Ref Frames
Format settings, CABAC                   : Yes
Format settings, Reference frames        : 1 frame
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 1 h 7 min
Bit rate                                 : 252 kb/s
Width                                    : 1 366 pixels
Height                                   : 768 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 24.000 FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.010
Stream size                              : 122 MiB (66%)
Writing library                          : x264 core 157 r2945 72db437
Encoding settings                        : cabac=1 / ref=1 / deblock=1:0:0 / analyse=0x3:0x3 / me=dia / subme=1 / psy=1 / psy_rd=1.00:0.00 / mixed_ref
=0 / me_range=16 / chroma_me=1 / trellis=0 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=0 / threads=4 / lookahead_threads=4 /
 sliced_threads=1 / slices=4 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=0 / weightp=1 / keyint=250 / keyint_
min=24 / scenecut=40 / intra_refresh=0 / rc=crf / mbtree=0 / crf=26.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / ip_ratio=1.40 / aq=1:1.00
Codec configuration box                  : avcC

Audio
ID                                       : 2
Format                                   : AAC LC
Format/Info                              : Advanced Audio Codec Low Complexity
Codec ID                                 : mp4a-40-2
Duration                                 : 1 h 7 min
Duration_LastFrame                       : -19 ms
Bit rate mode                            : Constant
Bit rate                                 : 128 kb/s
Channel(s)                               : 2 channels
Channel layout                           : L R
Sampling rate                            : 48.0 kHz
Frame rate                               : 46.875 FPS (1024 SPF)
Compression mode                         : Lossy
Stream size                              : 62.4 MiB (33%)
Default                                  : Yes
Alternate group                          : 1




C:\Users\User\Downloads\ac>dir ac.mp4
 Volume in drive C has no label.
 Volume Serial Number is 4645-5DCE

 Directory of C:\Users\User\Downloads\ac

11/03/2021  15:14       195,166,205 ac.mp4
               1 File(s)    195,166,205 bytes
               0 Dir(s)   2,360,127,488 bytes free

C:\Users\User\Downloads\ac>dir ac2.mp4
 Volume in drive C has no label.
 Volume Serial Number is 4645-5DCE

 Directory of C:\Users\User\Downloads\ac

11/03/2021  15:28       195,837,608 ac2.mp4
               1 File(s)    195,837,608 bytes
               0 Dir(s)   2,360,127,488 bytes free

C:\Users\User\Downloads\ac>