FFmpeg – how to pipe 24-bit PCM to 24-bit flac?

I’m trying to pipe 24-bit signed integer samples (either as 3-bytes or 4-bytes samples) to FFmpeg to create 24-bit FLAC file, which preserves the sample values, but so far no success. Here is my command:

ffmpeg -f s24le -c:a pcm_s24le -sample_fmt s24 -ac 1 -ar 4000 -i - output.flac

This fails with

Guessed Channel Layout for Input Stream #0.0 : mono
Input #0, s24le, from 'pipe:':
  Duration: N/A, bitrate: 96 kb/s
  Stream #0:0: Audio: pcm_s24le, 4000 Hz, mono, s32 (24 bit), 96 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (pcm_s24le (native) -> flac (native))
[pcm_s24le @ 0000027104f33600] Multiple frames in a packet.
[pcm_s24le @ 0000027104f33600] Invalid PCM packet, data has size 2 but at least a size of 3 was expected
Error while decoding stream #0:0: Invalid data found when processing input

I am calling FFmpeg from Python and dumping the 2000 samples (6000 bytes) at once to input argument of subprocess.run. So, is there a way to set the input packet size?

Read more here: Source link