Bounding Unicorns

ffmpeg Ignored Options

-sample_fmt

The -sample_fmt option is ignored in all positions other than for an output file. For example:

% ffmpeg -hide_banner -sample_fmt bogus1 -f alsa -sample_fmt bogus2 -i hw:0 -sample_fmt bogus3 -y /tmp/out.wav
[aist#0:0/pcm_s16le @ 0x5568290ed400] Guessed Channel Layout: stereo
Input #0, alsa, from 'hw:0':
  Duration: N/A, start: 1700952355.301252, bitrate: 1536 kb/s
  Stream #0:0: Audio: pcm_s16le, 48000 Hz, 2 channels, s16, 1536 kb/s
[aost#0:0/pcm_s16le @ 0x5568290ee440] Invalid sample format 'bogus3'
Error opening output file /tmp/out.wav.
Error opening output files: Invalid argument

The last -sample_fmt option is read and validated. If I remove it, ffmpeg happily records in pcm_s16le ignoring both of the remaining -sample_fmt specifications:

% ffmpeg -hide_banner -sample_fmt bogus1 -f alsa -sample_fmt bogus2 -i hw:0 /tmp/out.wav 
[aist#0:0/pcm_s16le @ 0x55eeb7c543c0] Guessed Channel Layout: stereo
Input #0, alsa, from 'hw:0':
  Duration: N/A, start: 1700952364.990361, bitrate: 1536 kb/s
  Stream #0:0: Audio: pcm_s16le, 48000 Hz, 2 channels, s16, 1536 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (pcm_s16le (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
Output #0, wav, to '/tmp/out.wav':
  Metadata:
    ISFT            : Lavf60.16.100
  Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 48000 Hz, stereo, s16, 1536 kb/s
    Metadata:
      encoder         : Lavc60.31.102 pcm_s16le
...

So, how do you set input sample format? Using the audio codec option on the input:

% ffmpeg -hide_banner -c:a pcm_s24le -f alsa -i hw:2 -y /tmp/out.wav
[aist#0:0/pcm_s24le @ 0x5605efa53440] Guessed Channel Layout: stereo
Input #0, alsa, from 'hw:2':
  Duration: N/A, start: 1700954323.714164, bitrate: 2304 kb/s
  Stream #0:0: Audio: pcm_s24le, 48000 Hz, 2 channels, s32 (24 bit), 2304 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (pcm_s24le (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
Output #0, wav, to '/tmp/out.wav':
  Metadata:
    ISFT            : Lavf60.16.100
  Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 48000 Hz, stereo, s16, 1536 kb/s
    Metadata:
      encoder         : Lavc60.31.102 pcm_s16le

I figured this out by reading ffmpeg source, the documentation (and user questions/answers on Stack Overflow, etc.) was of no help.