0

I want to limit the bit depth of PCM audio using ffmepg, but I want to limit it to a non-standard size (specifically to 4 bits). Of course it still has to fit pcm_u8 and that's fine.

I tried this filter to AND the u8 sample with 0xf0 to keep only the 4 MSBs, but it did not do what I expected

-af aeval='bitand(val(ch),0xf0)'

How do I use ffmpeg to cut the bit depth? I do not need dither (I will keep the distortion).

1 Answer 1

0

I found out how to cut it by 4 bits. This works when the input is 8 bits:

-af aresample=dither_method=none:osf=u8,volume=1/16:fixed,volume=16:fixed

I turn off dither here on purpose. I haven't tested what dither would be best at such a low bit depth.

It's important to have fixed in the volume filters otherwise it will change the samples to floats before applying the volume changes. By keeping it fixed integer and feeding it u8 samples, setting volume to 1/16 and then amplifying it by 16 acts like 4 bit scalar quantization. If I wanted to reduce it to a bit depth of 3 then I would use 1/32 and 32. If I wanted to reduce it to 5 rather than 4 I would do 1/8 and 8. 1 bit PCM would be 1/128 and 128. You get the point.

The PCM is still 8 bit PCM but it only has 4 bit precision.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.