20

I need FFmpeg to grab an audio feed and reencode it to 16-Bit FLAC.

How do I force a 16-Bit FLAC output?

./ffmpeg -i http://7359.live.streamtheworld.com:80/CONTINENTALAAC_SC -vn -ac 1 -ar 16000 -acodec flac -map 0 -f segment -segment_list /flac/out.list -segment_time 00:00:12.00 /flac/out%03d.flac
ffmpeg version N-49622-g127ff88 Copyright (c) 2000-2013 the FFmpeg developers
  built on Feb  6 2013 05:11:38 with gcc 4.6 (Debian 4.6.3-1)
  configuration: --prefix=/root/ffmpeg-static/32bit --arch=x86_32 --extra-cflags='-m32 -I/root/ffmpeg-static/32bit/include -static' --extra-ldflags='-m32 -L/root/ffmpeg-static/32bit/lib -static' --extra-libs='-lxml2 -lexpat -lfreetype' --enable-static --disable-shared --disable-ffserver --disable-doc --enable-bzlib --enable-zlib --enable-postproc --enable-runtime-cpudetect --enable-libx264 --enable-gpl --enable-libtheora --enable-libvorbis --enable-libmp3lame --enable-gray --enable-libass --enable-libfreetype --enable-libopenjpeg --enable-libspeex --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-version3 --enable-libvpx
  libavutil      52. 17.101 / 52. 17.101
  libavcodec     54. 91.100 / 54. 91.100
  libavformat    54. 61.104 / 54. 61.104
  libavdevice    54.  3.103 / 54.  3.103
  libavfilter     3. 35.101 /  3. 35.101
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
[aac @ 0xa163680] max_analyze_duration 5000000 reached at 5015510 microseconds
[aac @ 0xa163680] Estimating duration from bitrate, this may be inaccurate
Input #0, aac, from 'http://7359.live.streamtheworld.com:80/CONTINENTALAAC_SC':
  Duration: 150:52:44.61, bitrate: 29 kb/s
    Stream #0:0: Audio: aac, 44100 Hz, stereo, fltp, 29 kb/s
[flac @ 0xa16ee40] encoding as 24 bits-per-sample
Output #0, segment, to '/flac/out%03d.flac':
  Metadata:
    encoder         : Lavf54.61.104
    Stream #0:0: Audio: flac, 16000 Hz, mono, s32, 128 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (aac -> flac)
Press [q] to stop, [?] for help
size=N/A time=00:00:19.22 bitrate=N/A    
video:0kB audio:647kB subtitle:0 global headers:0kB muxing overhead -100.003322%
1

2 Answers 2

32

By default, the FFmpeg FLAC encoder takes the bit depth of the original. The bit depth can be changed with the sample_fmt option, e.g.

ffmpeg -i … -c:a flac -sample_fmt s16 output.flac

Note that not all formats are supported by every encoder.

For a list of all supported sample formats, run:

ffmpeg -sample_fmts

See the chapter Audio Options in the FFmpeg command line documentation.

6
  • This generates output with a bit depth of 4 for me, even when I specify s16 (bit depth 16). Full command: ffmpeg -i newwave.wav -c:a adpcm_ima_qt -sample_fmt s16 -ar 22500 newwave.aiff
    – xjcl
    Commented Sep 19, 2018 at 1:00
  • @xjcl The codec you are using only supports 4 bit.
    – slhck
    Commented Sep 19, 2018 at 5:11
  • What's the difference between e.g. s16 and s16p
    – minseong
    Commented Nov 2, 2019 at 12:36
  • 1
    This does not work for me. I get " Specified sample format s16 is invalid or not supported"
    – Arete
    Commented Dec 29, 2019 at 20:15
  • 2
    @theonlygusti "p" means "planar"; the other formats use "packed" storage. See: en.wikipedia.org/wiki/Packed_pixel (Sorry for the late reply, I missed the comment.)
    – slhck
    Commented Dec 30, 2019 at 15:47
4

To reduce bit depth to 16 with dithering:

ffmpeg -i input.flac -acodec flac -af aresample=osf=s16:dither_method=triangular_hp output.flac

See e.g. https://www.waves.com/audio-dithering-what-you-need-to-know

4
  • 2
    Thank you this worked for me, unlike the accepted answer which gave [aac] Specified sample format s16 is invalid or not supported.
    – hraban
    Commented Aug 12, 2023 at 5:03
  • 1
    """what is dither? It’s a form of low-level noise that is intentionally added to a digital audio file as it’s rendered to a lower bit depth. The concept of dithering might seem counterintuitive, but it’s an effective process. Dither noise actually masks what’s called “quantization distortion” which causes noise and artifacts in digital audio.""" (source)
    – milahu
    Commented May 18 at 8:08
  • 1
    "It’s crazy how good samplerate conversion is now compared to say 20 years ago. I still try to avoid unnecessary conversions as much as possible but now I don’t sweat it when it has to be done." ... "SRC is a solved problem. src.infinitewave.ca" (source) → use ffmpeg with soxr
    – milahu
    Commented May 18 at 8:23
  • I've asked this a couple of times on #ffmpeg and this is the answer. It's a good general purpose filter for dithering: gets the job done so I can move on, etc., Realistically, I could probably convert everything to 64 kb/s .opus and never notice a difference and I'm never going to do an AB test so this satisfices for me.
    – bvargo
    Commented May 24 at 11:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .