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

22.9k views Asked by At

I just had this question because I used the following command with ffmpeg:

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

Following the documentation here: https://trac.ffmpeg.org/wiki/AudioVolume

However, when I created the new file, the output was half the size of the input and the bitrate of the audio track was reduced as well.

So my questions are:

  1. Is the bitrate supposed to decrease with decreasing and increasing volume like so?
  2. Is it possible to change volume without reencoding with ffmpeg?
2

There are 2 answers

3
John Smith On BEST ANSWER

Okay as someone from Reddit kindly explained to me, I should be able to change the volume without reencoding, however, my input codec was pcm_f32le and the default setting for the output codec for ffmpeg without any specifiers is pcm_f16le.

The first one pcm_f32le is 32 bits, so it stores more information than the second which is 16 bits.

So the answer is:

  1. Yes it is because in this case I was reencoding unknowingly to a codec with less information.

  2. Actually no, it still reencoding. The best option is to use the same code I used above with an extra specifier:

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

The codec for input and output must be the same as in both 32 bit or 16 bit or else I have to add a specifier which I was shown how to do by the same person on Reddit.

However, this is still reencoding whenever you add a filter.

1
barlop On

I'm no expert but the way I increase volume doesn't seem to me to cause an issue.. e.g. bitrate of audio is the same... File size is similar too.

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

Note- the following is a programming question involving c# but somebody mentions the above Increase/Decrease audio volume using FFmpeg

For documentation

ffmpeg -? doesn't show much. If you do ffmpeg -? | grep "vol" then all it mentions is "-vol volume" And if you do ffmpeg -? | grep "-af" then all it says is -af filter_graph set audio filters" No mention of what audio filters you can use.

But speaking to some ffmpeg experts, they mentioned re documentation..

"
There's the ffmpeg-filters manpage as well as -h filter=NAME which shows you a brief of the options usable for the filter.

On the web you have the ffmpeg-all one too https://www.ffmpeg.org/ffmpeg-all.html

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


See for yourself the difference between the files, from mediainfo and DIR

Notice that both files, source and destination, are similar size, 195MB. The source is 195,166,205 bytes, the dest is 195,837,608 bytes. so a very small difference in size.

Notice that

there is no difference in bitrate

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>

Here is all the mediainfo data for each file so you can decide for yourself if you can see from that, any substantial difference that took place when the volume was changed.

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                           : [email protected]
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                           : [email protected]
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>