Opened 2 months ago

Last modified 6 weeks ago

#8131 new defect

s302m in combination with loudnorm filter

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

Description

Summary of the bug:
The audio codec s302m produce in combination with loudnorm filter an error:

[s302m @ 00000275a32cba00] number of samples in frame too big
Audio encoding failed

How to reproduce:

%  ffmpeg -f lavfi -i testsrc=size=1280x720:rate=25:duration=5 -f lavfi -i sine=frequency=1000:duration=5 -af "loudnorm=I=-23.0:TP=-1.5:LRA=11.0:dual_mono=true" -ac 2 -c:a s302m -strict -2 -f null -

Uncut output:

ffmpeg -f lavfi -i testsrc=size=1280x720:rate=25:duration=5 -f lavfi -i sine=frequency=1000:duration=5 -af "loudnorm=I=-23.0:TP=-1.5:LRA=11.0:dual_mono=true" -ac 2 -c:a s302m -strict -2 -f null -
ffmpeg version N-94713-g9c369b3222 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 9.2.0 (Rev1, Built by MSYS2 project)
  configuration:  --enable-sdl2 --enable-gmp --enable-libmp3lame --enable-libvpx --enable-libx264 --enable-libx265 --enable-fontconfig --enable-libfreetype --enable-libmysof
a --enable-libopenjpeg --enable-libsoxr --enable-libtwolame --enable-libwavpack --enable-libwebp --enable-libxml2 --enable-libzimg --enable-gpl --enable-avisynth --enable-ch
romaprint --enable-libfdk-aac --enable-libfribidi --enable-librubberband --enable-libzmq --enable-opengl --enable-libsrt --enable-libaom --enable-schannel --extra-cflags=-DL
IBTWOLAME_STATIC --extra-cflags=-DCHROMAPRINT_NODLL --extra-libs=-lstdc++ --extra-cflags=-DZMQ_STATIC --extra-cflags=-DLIBXML_STATIC --enable-version3 --enable-nonfree --dis
able-stripping
  libavutil      56. 33.100 / 56. 33.100
  libavcodec     58. 56.100 / 58. 56.100
  libavformat    58. 31.104 / 58. 31.104
  libavdevice    58.  9.100 / 58.  9.100
  libavfilter     7. 58.101 /  7. 58.101
  libswscale      5.  6.100 /  5.  6.100
  libswresample   3.  6.100 /  3.  6.100
  libpostproc    55.  6.100 / 55.  6.100
Input #0, lavfi, from 'testsrc=size=1280x720:rate=25:duration=5':
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: rawvideo (RGB[24] / 0x18424752), rgb24, 1280x720 [SAR 1:1 DAR 16:9], 25 tbr, 25 tbn, 25 tbc
Input #1, lavfi, from 'sine=frequency=1000:duration=5':
  Duration: N/A, start: 0.000000, bitrate: 705 kb/s
    Stream #1:0: Audio: pcm_s16le, 44100 Hz, mono, s16, 705 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> wrapped_avframe (native))
  Stream #1:0 -> #0:1 (pcm_s16le (native) -> s302m (native))
Press [q] to stop, [?] for help
Output #0, null, to 'pipe:':
  Metadata:
    encoder         : Lavf58.31.104
    Stream #0:0: Video: wrapped_avframe, rgb24(progressive), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc
    Metadata:
      encoder         : Lavc58.56.100 wrapped_avframe
    Stream #0:1: Audio: s302m, 48000 Hz, stereo, s32 (24 bit), 2688 kb/s
    Metadata:
      encoder         : Lavc58.56.100 s302m
[Parsed_sine_0 @ 00000275a32aef00] EOF timestamp not reliable
[s302m @ 00000275a32cba00] number of samples in frame too big
Audio encoding failed
Conversion failed!

,asetnsamples=n=1024 could fix it, but produce randomly, depending from input, other errors and warnings.

Attachments (1)

audio-test.zip (1.4 MB) - added by jb_alvarado 2 months ago.

Download all attachments as: .zip

Change History (9)

comment:1 Changed 2 months ago by richardpl

The limit in s302 is by design, max size of packet is 16bit number.
Can't you use -frame_size to set number of samples?

comment:2 Changed 2 months ago by jb_alvarado

I tried -frame_size 1024, but it had no effect. When I use the filter asetnsamples=n=1024, it works with the command on top (sine source), but if I use a real audio source I get:

[out_0_0 @ 000002660d73d200] 100 buffers queued in out_0_0, something may be wrong.

In debug mode it looks also that not all packets are encoded:

cur_dts is invalid st:0 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
    Last message repeated 139 times
[out_0_0 @ 0000021e3727e140] 100 buffers queued in out_0_0, something may be wrong.
[out_0_0 @ 0000021e3727e140] EOF on sink link out_0_0:default.
No more output streams to write to, finishing.
size=N/A time=00:00:25.12 bitrate=N/A speed=21.2x
video:0kB audio:8263kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Input file #0 (D:/stream/loudness/Sprache Leise.wav):
  Input stream #0:0 (audio): 1178 packets read (4823244 bytes); 1178 frames decoded (1205811 samples);
  Total: 1178 packets (4823244 bytes) demuxed
Output file #0 (pipe:):
  Output stream #0:0 (audio): 4712 frames encoded (1206016 samples); 4712 packets muxed (8460960 bytes);
  Total: 4712 packets (8460960 bytes) muxed
1178 frames successfully decoded, 0 decoding errors
[AVIOContext @ 0000021e3725e200] Statistics: 4888878 bytes read, 1 seeks
Last edited 2 months ago by jb_alvarado (previous) (diff)

comment:3 Changed 2 months ago by richardpl

I can not reproduce in any way issue with asetnsamples, please provide input file.

Changed 2 months ago by jb_alvarado

comment:4 Changed 2 months ago by jb_alvarado

Ok, here the file. I use this command:

ffmpeg.exe -i "Sprache Leise.wav" -af "loudnorm=I=-23.0:TP=-1.5:LRA=11.0,asetnsamples=n=1024" -c:a s302m -strict -2 -f null -

Another issue is, when I save the file, as a mpegts and I read it again, i get:

[s302m @ 000001e5830f9980] frame has invalid header
Error while decoding stream #0:0: Invalid data found when processing input
Last edited 2 months ago by jb_alvarado (previous) (diff)

comment:5 Changed 2 months ago by richardpl

s302 encoder is marked as experimental for the reason that proper muxing need correct set for frame size in each packet.

100 queued buffers message is caused by bug/misfeature in loudnorm filter.

comment:6 Changed 2 months ago by jb_alvarado

Yes I know is experimental, but s302 is the only supported lossless codec for mpegts. And in general works very nice in my project, better then mp2 and aac.

Is there a workaround to prevent this bug?

comment:7 Changed 2 months ago by jb_alvarado

  • Keywords loudnorm added

comment:8 Changed 6 weeks ago by jb_alvarado

I think I have now the "workaround". The correct numbers of samples per frame needs to be calculated. For example for a 25 FPS Video: 192000 / 25 = 7680, this can be used in asetnsamples=7680, or in combination with aresample=48000: 48000 / 25 = 1920 -> asetnsamples=1920.

Is a bit confusing, because there is not always a video line and it also looks like that higher numbers like 8192 or also working...

Note: See TracTickets for help on using tickets.