Opened 5 months ago

Closed 5 months ago

Last modified 5 months ago

#10739 closed defect (invalid)

Weird behavior of aresample filter in the presence of -map argument

Reported by: bubbleguuum Owned by:
Priority: normal Component: undetermined
Version: unspecified Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

There is a weird difference of behavior between FFmpeg 5 and 6 when the aresample filter is used in conjunction with -map argument.
Here converting a mp3 to WAV with resampling. It is not super useful, but for illustration purpose and the input and output codecs are not relevant.

FFmpeg 6 fails:

% ffmpeg -hide_banner -y -i ~/Music/audio\ formats/MP3_192K.mp3  -map 0:0 -filter_complex aresample=resampler=soxr ~/tmp/file.wav
Input #0, mp3, from '/home/bobbie/Music/audio formats/MP3_192K.mp3':
  Duration: 00:03:54.08, start: 0.025057, bitrate: 192 kb/s
  Stream #0:0: Audio: mp3, 44100 Hz, stereo, fltp, 192 kb/s
    Metadata:
      encoder         : LAME3.93 
Stream mapping:
  Stream #0:0 (mp3float) -> aresample:default (graph 0)
  aresample:default (graph 0) -> Stream #0:0 (pcm_s16le)
  Stream #0:0 -> #0:1 (mp3 (mp3float) -> pcm_s16le (native))
Press [q] to stop, [?] for help
[wav @ 0x55c1836f7a80] WAVE files have exactly one stream
[out#0/wav @ 0x55c1836f7980] Could not write header (incorrect codec parameters ?): Invalid argument
[aost#0:1/pcm_s16le @ 0x55c183704800] Error initializing output stream: 
Conversion failed!

FFmpeg 5 works

% ffmpeg -hide_banner -y -i ~/Music/audio\ formats/MP3_192K.mp3  -map 0:0 -filter_complex aresample=resampler=soxr ~/tmp/file.wav
Input #0, mp3, from '/home/bobbie/Music/audio formats/MP3_192K.mp3':
  Duration: 00:03:54.08, start: 0.025057, bitrate: 192 kb/s
  Stream #0:0: Audio: mp3, 44100 Hz, stereo, fltp, 192 kb/s
    Metadata:
      encoder         : LAME3.93 
Stream mapping:
  Stream #0:0 (mp3float) -> aresample:default
  aresample:default -> Stream #0:0 (pcm_s16le)
Press [q] to stop, [?] for help
Output #0, wav, to '/home/bobbie/tmp/file.wav':
  Metadata:
    ISFT            : Lavf59.16.100
  Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, stereo, s16, 1411 kb/s
    Metadata:
      encoder         : Lavc59.18.100 pcm_s16le
size=   40317kB time=00:03:54.04 bitrate=1411.2kbits/s speed= 389x    
video:0kB audio:40317kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000189%

For some reason, FFmpeg 6 creates 2 output streams when -map and aresample are used at the same time, while FFmpeg 5 creates 1 output which I what I would expect. The former makes writing the output file fail because the format (WAV but could also be FLAC) expects exactly 1 output audio stream.

What is the reason for this and is it a regression ?
Not specifying -map 0:0 fixes it, but I'd like to understand this change in behavior between FFmpeg 5 and 6.

Change History (3)

comment:1 by Gyan, 5 months ago

This has nothing to do with aresample or any particular filter.

Check with -filter_complex anull in place of -filter_complex aresample=resampler=soxr

Till ver 5.1, there was a bug in the mapping code. Any unlabelled outputs of complex filtergraphs were supposed to be implicitly mapped in addition to manually mapped streams but they apparently weren't. This was corrected after 5.1.

Read the chapter on Stream Selection, especially section 4.1.3 and the examples at the end.

For your use case, you should use

ffmpeg -hide_banner -y -i ~/Music/audio\ formats/MP3_192K.mp3 -map 0:0 -af aresample=resampler=soxr ~/tmp/file.wav

comment:2 by Gyan, 5 months ago

Resolution: invalid
Status: newclosed

comment:3 by bubbleguuum, 5 months ago

Thank you for the detailed explanation.
I wondered because I have a program that rely on the buggy behavior and it will require an update to work with the fixed behavior.

Note: See TracTickets for help on using tickets.