Opened 7 months ago

Last modified 7 months ago

#7056 new enhancement

Make ffmpeg to automatically convert audio sample format to floating point before apllying filters

Reported by: Rollinnn Owned by:
Priority: normal Component: undetermined
Version: git-master Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:
It seems that currently, if source file has sample format 16 or 24 bit fixed point, then ffmpeg process it also in fixed point format. With some processing this can result in audible clipping, even if "alimiter" filter is used in the end of filter chain. So it is needed to manually change sample format with "aformat=sample_fmts=flt" in the beginning if filters chain to be able to prevent clipping.

Suggestion is to convert sample format to floating point automatically before applying filters.

Example. If attached flac file is processed with command

ffmpeg -i input.flac -af "pan=stereo|FL=0.707*FC+FL+0.707*BL+0.707*SL+0.5*BC|FR=0.707*FC+FR+0.707*BR+0.707*SR+0.5*BC, alimiter=attack=0.1" output.flac

then resulted file contains obvious and audible clipping regardless alimiter was used

But if "aformat=sample_fmts=flt" is added to beginning of filter chain, so command is

ffmpeg -i input.flac -af "aformat=sample_fmts=flt, pan=stereo|FL=0.707*FC+FL+0.707*BL+0.707*SL+0.5*BC|FR=0.707*FC+FR+0.707*BR+0.707*SR+0.5*BC, alimiter=attack=0.1" output.flac

there is no clipping in resulted file, because alimiter succesfully supress it.
Yes, i know that i can simlpy use -ac 2 for downmixing.
ffmpeg is static build from Zeranoe.

How to reproduce:
Once again
This command results in file with no clipping

ffmpeg -i C:\000\sample_8channels_16bit.flac -af "aformat=sample_fmts=flt, pan=stereo|FL=0.707*FC+FL+0.707*BL+0.707*SL+0.5*BC|FR=0.707*FC+FR+0.707*BR+0.707*SR+0.5*BC, alimiter=attack=0.1" C:\000\downmixed.flac
ffmpeg version N-90173-gfa0c9d69d3 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 7.3.0 (GCC)
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libmfx --enable-amf --enable-cuda --enable-cuvid --enable-d3d11va --enable-nvenc --enable-dxva2 --enable-avisynth
  libavutil      56.  7.101 / 56.  7.101
  libavcodec     58. 13.100 / 58. 13.100
  libavformat    58. 10.100 / 58. 10.100
  libavdevice    58.  2.100 / 58.  2.100
  libavfilter     7. 12.100 /  7. 12.100
  libswscale      5.  0.101 /  5.  0.101
  libswresample   3.  0.101 /  3.  0.101
  libpostproc    55.  0.100 / 55.  0.100
Input #0, flac, from 'C:\000\sample_8channels_16bit.flac':
  Duration: 00:00:11.04, start: 0.000000, bitrate: 2828 kb/s
    Stream #0:0: Audio: flac, 48000 Hz, 7.1, s16
Stream mapping:
  Stream #0:0 -> #0:0 (flac (native) -> flac (native))
Press [q] to stop, [?] for help
[flac @ 006dacc0] encoding as 24 bits-per-sample
Output #0, flac, to 'C:\000\downmixed.flac':
  Metadata:
    encoder         : Lavf58.10.100
    Stream #0:0: Audio: flac, 48000 Hz, stereo, s32 (24 bit), 128 kb/s
    Metadata:
      encoder         : Lavc58.13.100 flac
size=    2315kB time=00:00:11.04 bitrate=1717.9kbits/s speed=100x
video:0kB audio:2307kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.350835%

And this command results in file with audible clipping:

C:\Users\Андрей>ffmpeg -i C:\000\sample_8channels_16bit.flac -af "pan=stereo|FL=0.707*FC+FL+0.707*BL+0.707*SL+0.5*BC|FR=0.707*FC+FR+0.707*BR+0.707*SR+0.5*BC, alimiter=attack=0.1" C:\000\downmixed.flac
ffmpeg version N-90173-gfa0c9d69d3 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 7.3.0 (GCC)
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libmfx --enable-amf --enable-cuda --enable-cuvid --enable-d3d11va --enable-nvenc --enable-dxva2 --enable-avisynth
  libavutil      56.  7.101 / 56.  7.101
  libavcodec     58. 13.100 / 58. 13.100
  libavformat    58. 10.100 / 58. 10.100
  libavdevice    58.  2.100 / 58.  2.100
  libavfilter     7. 12.100 /  7. 12.100
  libswscale      5.  0.101 /  5.  0.101
  libswresample   3.  0.101 /  3.  0.101
  libpostproc    55.  0.100 / 55.  0.100
Input #0, flac, from 'C:\000\sample_8channels_16bit.flac':
  Duration: 00:00:11.04, start: 0.000000, bitrate: 2828 kb/s
    Stream #0:0: Audio: flac, 48000 Hz, 7.1, s16
Stream mapping:
  Stream #0:0 -> #0:0 (flac (native) -> flac (native))
Press [q] to stop, [?] for help
[flac @ 0487acc0] encoding as 24 bits-per-sample
Output #0, flac, to 'C:\000\downmixed.flac':
  Metadata:
    encoder         : Lavf58.10.100
    Stream #0:0: Audio: flac, 48000 Hz, stereo, s32 (24 bit), 128 kb/s
    Metadata:
      encoder         : Lavc58.13.100 flac
size=    1286kB time=00:00:11.04 bitrate= 954.5kbits/s speed=  69x
video:0kB audio:1278kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.633161%

Change History (1)

Note: See TracTickets for help on using tickets.