Go to the directory where your files are.
Make sure ffmpeg is installed.
Use the following command to process the files.
for x in *.mkv; do ffmpeg -i "$x" -map 0:v -map 0:a:0 -map 0:s -c copy -c:a ac3 -b:a 640k "ac3-$x"; done
Explanation: this command finds all .mkv files and converts the first audiostream to ac3 with a bitrate 640k. The files are renamed with an “ac3-” prefix, so you can compare the result.
Remove the old files after you have checked if the audio is still correct and synced to the video. Enjoy your video files.
Cover image by Adi Goldstein