Hi all
When I began to use Opus for encoding 2.0 - 7.1 channel files, I struggled with these and other problems like correct channel-mapping etc. too. So I made a short guide for me which worked so far.
The commands here where all used with a windows environment and FFmpeg and Opus together in a pipe. It shouldn't be a big deal to use it the same way with Linux. The meaning of the values like bitrate, sampling rate etc. should be self-explanatory.
Hope this can help a little bit.
FFmpeg and Opus Audio Codec (16bit, 48kHz)
- Opus is a 48kHz-only format. Other input-samplerates will be internaly converted, using an internal *Speex* resampler.
- Input bitdepth for Opus is 16bit.
- FFmpeg has an internal Opus encoder. You can use this if you want.
- If FFmpeg is a part of a pipe, you have to organise the audio channel-mapping on your own. <br>Otherwise: Output order = Input Order
- Depending on the input, sometimes you have to use the "BL" & "BR" Channels instead "SL" & "SR". <br>But it doesn't matter if you use "...c3=SL+BL|c4=SR+BR...".
- Channel Description:
- FL: Front Left, FC: Front Center, FR: Front Right
- SL: Side Left, SR: Side Right
- BL: Back Left, BR: Back Right (Also known as "Rear" instead of "Back")
- SL: Side Left, SR: Side Right
- LFE: Low Frequency Effects
- Opus channel mappings
- 1 channel: monophonic (mono).
- 2 channels: stereo (FL, FR).
- 3 channels: linear surround (FL, FC, FR).
- 4 channels: quadraphonic (FL, FR | BL, BR).
- 5 channels: 5.0 surround (FL, FC, FR | BL, BR).
- 6 channels: 5.1 surround (FL, FC, FR | BL, BR | LFE).
- 7 channels: 6.1 surround (FL, FC, FR | SL, SR | BC | LFE).
- 8 channels: 7.1 surround (FL, FC, FR | SL, SR | BL, BR | LFE).
- Source
1. Convert a 16bit 5.1 audiofile to ~512kbps Opus with "opusenc.exe":
"ffmpeg.exe" -i "input.ac3" -af "pan=0x3f|c0=FL|c1=FC|c2=FR|c3=SL+BL|c4=SR+BR|c5=LFE" -f s16le -ac 6 - | "opusenc.exe" - --raw --raw-chan 6 --raw-bits 16 --vbr --bitrate 512 --comp 10 --expect-loss 0 "output.opus"
2. Convert a 24bit 5.1 audiofile to ~512kbps Opus with "opusenc.exe":
"ffmpeg.exe" -i "input.dts" -af "aresample=resampler=soxr:dither_method=shibata,aformat=sample_fmts=s16,pan=0x3f|c0=FL|c1=FC|c2=FR|c3=SL+BL|c4=SR+BR|c5=LFE" -f s16le -ac 6 - | "opusenc.exe" - --raw --raw-chan 6 --raw-bits 16 --vbr --bitrate 512 --comp 10 --expect-loss 0 "output.opus"
3. Convert a 24bit 6.1 audiofile to ~512kbps Opus with "opusenc.exe":
"ffmpeg.exe" -i "input.dts" -af "aresample=resampler=soxr:dither_method=shibata,aformat=sample_fmts=s16,pan=6.1(back)|c0=FL|c1=FC|c2=FR|c3=SL+BL|c4=SR+BR|c5=BC|c6=LFE" -f s16le -ac 7 - | "opusenc.exe" - --raw --raw-chan 7 --raw-bits 16 --vbr --bitrate 512 --comp 10 --expect-loss 0 "output.opus"
4. Convert a 24bit 7.1 audiofile to ~512kbps Opus with "opusenc.exe":
"ffmpeg.exe" -i "input.dts" -af "aresample=resampler=soxr:dither_method=shibata,aformat=sample_fmts=s16,pan=0x63f|c0=FL|c1=FC|c2=FR|c3=SL|c4=SR|c5=BL|c6=BR|c7=LFE" -f s16le -ac 8 - | "opusenc.exe" - --raw --raw-chan 8 --raw-bits 16 --vbr --bitrate 512 --comp 10 --expect-loss 0 "output.opus"
Other FFmpeg examples
- If you lower the bitdepth from 24bit to 16bit, use dither.
- "-map" let you select the required audiostream. <br>
1. Extract a 16bit, 5.1 audiostream from a m2ts-File to 16bit WAV:
"ffmpeg.exe" -i "input.m2ts" -c:a pcm_s16le -map 0:a:4 -ac 6 -rf64 auto "output.wav"
2. Extract a 24bit, 7.1 audiostream from a m2ts-File to 24bit WAV:
"ffmpeg.exe" -i "input.m2ts" -c:a pcm_s24le -map 0:a:2 -ac 8 -rf64 auto "output.wav"
3. Extract a 24bit 192kHz, 7.1 audiostream from a m2ts-File to 16bit 48kHz WAV:
"ffmpeg.exe" -i "input.m2ts" -c:a pcm_s16le -af "aresample=resampler=soxr:osr=48000:dither_method=shibata,aformat=sample_fmts=s16" -map 0:a:1 -ac 8 -rf64 auto "output.wav"