Here is the workflow I came up for someone trying to batch process files to opus:
#!/bin/bash
# Normalize audio files to pcm
ffmpeg-normalize -vn -sn -cn "$1"
# Extrac desired audios to feed opusenc
ffmpeg -nostdin -i "$1" -map 0:m:language:eng -vn -acodec copy "${1%.mkv}".en.wav
# Encode them with opusenc
opusenc "${1%.mkv}".en.wav "${1%.mkv}".en.mkv
This way you first convert input to pcm_s16le, then you extract the desired audio language from output, assuming ffmpeg will copy the highest quality (channel) audio track of that language by default to a .wav file.
Then we encode the .wav file with opusenc. To keep it simple, we will just go with the defaults, because otherwise we would have to find out if the file is 5.1 or 2.0 to set bitrate manually. It seems to use 96 kb/s for 2.0 and 320 kb/s for 5.1 input.
if you want to encode the video to vp9, which makes sense with opus audio you could use this ffmpeg command adapted from google (1080p 30 fps)
ffmpeg -y -nostdin -i "$1" -an -b:v 1800k \
-minrate 900k -maxrate 2610k -tile-columns 2 -g 240 -threads 8 -quality good -crf 31 -c:v libvpx-vp9 \
-pass 1 -speed 4 tos-1920x1080-24-30fps.webm && \
ffmpeg -y -nostdin -i "$1" -an -b:v 1800k \
-minrate 900k -maxrate 2610k -tile-columns 4 -g 240 -threads 8 -quality good -crf 31 -c:v libvpx-vp9 \
-pass 2 -speed 4 tos-1920x1080-24-30fps.webm
This should convert only the video and subtitles if SRT. For some reason after removing the audio options, it breaks the reporting of time and speed in the 1 pass.
Then just merge the files after you are done with mkvmerge.
It's not efficient, but it works. I accept criticism and help too
I have a few questions too:
1. If I wanted to just convert only all the audio tracks of a input to pcm_s16le with mkv, keeping language metadata with ffmpeg how you'd do it?
ffmpeg -nostdin -i *mkv -vn -sn -map 0:a -acodec pcm_s16le output.mkv
For some reason this give some strange error:
[matroska,webm @ 0x70483c0] Element at 0xc7288e2c ending at 0xc72a6569 exceeds containing master element ending at 0xc7288e25
2. When converting to opus after doing loudness normalization is it lost or kept?
3. Assuming lossy input, is pcm_s16le lossless? Doing lossy input > pcm_s16le > opus is the same as doing lossy input > opus?