#9998 closed defect (fixed)

Problem with atrim and astats

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

Description

Make a 5 seconds test file:

ffmpeg -f lavfi -i sine -c:a pcm_s24le -t 5 -y test.wav

Trim this file with an invalid start point (after the end of the stream), and then measure the Min_level with astats:

ffmpeg -i test.wav -af atrim=start=6:duration=1,astats=measure_perchannel="Min_level":measure_overall=none -f null -

There is no warning or error message, but a nonsense output for the level:

C:\Users\astro\Desktop\problem>ffmpeg -i test.wav -af atrim=start=6:duration=1,astats=measure_perchannel="Min_level":measure_overall=none -f null -
ffmpeg version 2022-10-24-git-d79c240196-full_build-www.gyan.dev Copyright (c) 2000-2022 the FFmpeg developers

built with gcc 12.1.0 (Rev2, Built by MSYS2 project)
configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libaribb24 --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libaom --enable-libjxl --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-liblensfun --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libvpl --enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
libavutil 57. 39.101 / 57. 39.101
libavcodec 59. 51.100 / 59. 51.100
libavformat 59. 34.101 / 59. 34.101
libavdevice 59. 8.101 / 59. 8.101
libavfilter 8. 49.101 / 8. 49.101
libswscale 6. 8.112 / 6. 8.112
libswresample 4. 9.100 / 4. 9.100
libpostproc 56. 7.100 / 56. 7.100

Input #0, wav, from 'test.wav':

Metadata:

encoder : Lavf59.34.101

Duration: 00:00:05.00, bitrate: 1058 kb/s
Stream #0:0: Audio: pcm_s24le ([1][0][0][0] / 0x0001), 44100 Hz, mono, s32 (24 bit), 1058 kb/s

Stream mapping:

Stream #0:0 -> #0:0 (pcm_s24le (native) -> pcm_s16le (native))

Press [q] to stop, ? for help
Output #0, null, to 'pipe:':

Metadata:

encoder : Lavf59.34.101

Stream #0:0: Audio: pcm_s16le, 44100 Hz, mono, s16, 705 kb/s

Metadata:

encoder : Lavc59.51.100 pcm_s16le

size=N/A time=-577014:32:22.77 bitrate=N/A speed=N/A s/s speed=N/A
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)
[Parsed_astats_1 @ 0000014cea433a80] Channel: 1
[Parsed_astats_1 @ 0000014cea433a80] Min level: 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000

Change History (5)

comment:1 by Michael Koch, 18 months ago

Please also add this to the documentation of the astats filter:
If two or more parameters shall be measured with "measure_perchannel" or "measure_overall", then the parameters must be separated by "+" characters.

comment:2 by Michael Koch, 18 months ago

I found another problem. Use the same input file as above and trim it to a very short duration 10us which can contain only 0 or 1 sample:

ffmpeg -i test.wav -af atrim=start=1.00025:duration=0.00001,astats=measure_perchannel="Min_level+Max_level":measure_overall=none -f null -

This is the output:

[Parsed_astats_1 @ 000001762b523e00] Min level: -268369920.000000
[Parsed_astats_1 @ 000001762b523e00] Max level: 268369920.000000

The measured levels are wrong, because the Min and Max levels can't be different if the stream doesn't contain more than one sample. With duration 30us (contains 1 or 2 samples) it works as expected.

comment:3 by Elon Musk, 17 months ago

Resolution: invalid
Status: newclosed

Look at output of number of samples processed it must be >0.

comment:4 by Michael Koch, 17 months ago

Resolution: invalid
Status: closedreopened

It's still not working. Now astats gives no output at all for a 5s audio stream. Can be reproduced as follows:

ffmpeg -f lavfi -i sine -c:a pcm_s24le -t 5 -y test.wav

ffmpeg -i test.wav -af astats=measure_perchannel="Min_level+Max_level":measure_overall=none -f null -

Console output for the second command line:

C:\Users\astro\Desktop\crazy_colors>ffmpeg -i test.wav -af astats=measure_perchannel="Min_level+Max_level":measure_overall=none -f null -
ffmpeg version 2022-12-01-git-45ab5307a6-essentials_build-www.gyan.dev Copyright (c) 2000-2022 the FFmpeg developers

built with gcc 12.1.0 (Rev2, Built by MSYS2 project)
configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-sdl2 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libvpl --enable-libgme --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libtheora --enable-libvo-amrwbenc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-librubberband
libavutil 57. 43.100 / 57. 43.100
libavcodec 59. 54.100 / 59. 54.100
libavformat 59. 34.102 / 59. 34.102
libavdevice 59. 8.101 / 59. 8.101
libavfilter 8. 51.100 / 8. 51.100
libswscale 6. 8.112 / 6. 8.112
libswresample 4. 9.100 / 4. 9.100
libpostproc 56. 7.100 / 56. 7.100

Input #0, wav, from 'test.wav':

Metadata:

encoder : Lavf59.34.102

Duration: 00:00:05.00, bitrate: 1058 kb/s
Stream #0:0: Audio: pcm_s24le ([1][0][0][0] / 0x0001), 44100 Hz, mono, s32 (24 bit), 1058 kb/s

Stream mapping:

Stream #0:0 -> #0:0 (pcm_s24le (native) -> pcm_s16le (native))

Press [q] to stop, ? for help
Output #0, null, to 'pipe:':

Metadata:

encoder : Lavf59.34.102

Stream #0:0: Audio: pcm_s16le, 44100 Hz, mono, s16, 705 kb/s

Metadata:

encoder : Lavc59.54.100 pcm_s16le

size=N/A time=00:00:04.98 bitrate=N/A speed= 613x A
video:0kB audio:431kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

comment:5 by Elon Musk, 17 months ago

Resolution: fixed
Status: reopenedclosed
Note: See TracTickets for help on using tickets.