0

I used the following to extract mono l and r wavs from a 24-bit stereo wav file but the result is two 16-bit files:

ffmpeg -i stereo24bit.wav -map_channel 0.0.0 left.wav -map_channel 0.0.1 right.wav

What do I add to this or how do I change it to preserve the 24-bit depth of the original? Searching has not turned up an answer to this, some similar results but not what I am looking for.

Run5k
  • 15,723
  • 24
  • 49
  • 63
  • Does adding in a `-c:a copy` fix it? – Mokubai Jan 27 '20 at 21:41
  • i tried it before the -map option and got a new stereo file on output rather than mono. thanks, though. – user1133964 Jan 27 '20 at 21:51
  • adding "-c:a pcm_s24le" before each instance of "-map_channels" produces 24bit mono files. is that the right way to do this? i want to be copying and to avoid any re-encoding. thanks, babag – user1133964 Jan 27 '20 at 22:16
  • [This answer](https://superuser.com/a/686050/19943) seems to suggest that your command *should* work. At the very least it also provides another couple of options and is a potential duplicate candidate for this question. The main reason not to close as a dupe as it seems that the problem here is a specific case where ffmpeg appears to add an unnecessary conversion stage to the output. – Mokubai Jan 28 '20 at 10:32
  • thanks for this, Mokubai. that documentation is a little different than what i've found in the ffmpeg wiki pages. what i found there did not preserve the bit depth. i will try this method (channelsplit) which, to me at least, would imply that it might preserve the 24 bit depth. thanks again. – user1133964 Jan 28 '20 at 20:52

1 Answers1

1

i want to be copying and to avoid any re-encoding

-map_channel is an alias for the pan filter. You can't filter a stream and also stream copy it. However, since your input and output are PCM it doesn't really matter.

How do I preserve the 24-bit depth of the original?

Some encoders, such as flac, support multiple sample formats, and ffmpeg will automatically attempt to choose the highest depth. But the default encoder for .wav output is pcm_s16le, which is only 16-bit (refer to ffmpeg -h encoder=pcm_s16le), so in this case you need to manually provide the name of an encoder that supports 24-bit, such as pcm_s24le.

-map_channel

ffmpeg -i stereo24bit.wav -map_channel 0.0.0 -c:a pcm_s24le left.wav -map_channel 0.0.1 -c:a pcm_s24le right.wav

channelsplit

Or if you want to use the channelsplit filter which might be more intuitive than the legacy -map_channel option:

ffmpeg -i stereo24bit.wav -filter_complex "channelsplit=channel_layout=stereo:channels=FL|FR[left][right]" -map "[left]" -c:a pcm_s24le left.wav -map "[right]" -c:a pcm_s24le right.wav

Or in your particular case you can just use the channelsplit default values:

ffmpeg -i stereo24bit.wav -filter_complex "channelsplit[left][right]" -map "[left]" -c:a pcm_s24le left.wav -map "[right]" -c:a pcm_s24le right.wav

Verifying

You can add the -loglevel debug global option to view more details about the process:

[graph_0_in_0_0 @ 0x55be6dfc6e00] Setting 'sample_fmt' to value 's32
[auto_resampler_0 @ 0x55be6dfcab40] picking s32p out of 6 ref:s32
[auto_resampler_0 @ 0x55be6dfcab40] [SWR @ 0x55be6dfcb000] Using s32p internally between filters
[auto_resampler_0 @ 0x55be6dfcab40] ch:2 chl:stereo fmt:s32 r:44100Hz -> ch:2 chl:stereo fmt:s32p r:44100Hz
[auto_resampler_1 @ 0x55be6dfe0940] ch:1 chl:1 channels (FR) fmt:s32p r:44100Hz -> ch:1 chl:1 channels (FR) fmt:s32 r:44100Hz
llogan
  • 57,139
  • 15
  • 118
  • 145