A dithered, grayscale screenshot of the scene from My Neighbor Totoro where the girls and totoros make the seeds they planted grow

Adding an audio track to an MKV file with FFmpeg

I grew up with the Streamline dub of Totoro on VHS, and I still prefer it to Disney's. However, the video quality of my Disney Bluray copy is far superior. Since I usually just stream the MKV I made of the Bluray from my home server, I decided to add the Streamline dub as an audio track.

Preparing the audio

I needed to extract the audio from the Streamline dub rip and align it with the audio from the Disney rip.

First I ripped the audio track from the Disney dub and saved it as Disney.wav:

ffmpeg -i Disney.mkv -c copy -map 0:1 Disney.wav -map 0:0 Disney.avi

Then I did the same with the Streamline rip. I had to omit the -c copy flag, though, because it produced an audio file Audacity couldn't import for some reason. Allowing FFmpeg to re-encode it seemed to fix it.

ffmpeg -i Streamline.mp4 -map 0:a Streamline.wav -map 0:v Streamline.avi

I loaded the two tracks up in Audacity and carefully aligned the music in the opening credits. This left the foley sounds after that point misaligned, so I split the Streamline track and moved it until its foley sounds aligned with the ones in the Disney track. I had to do this a couple times, as it seems Disney added a couple quick fades between scenes that didn't exist in the Streamline version, and this threw off the audio alignment each time.

Finally, with the two tracks aligned the whole way through, I muted the Disney track and exported the project audio to totoro-audio-replacement.wav.

Adding a custom audio track

Since there were already three other audio tracks on the MKV file, and since the tracks are indexed from zero, the new track was going to be assigned index #3. I used this index in the metadata flag below.

I also found that the command produced a silent track without the -max_interleave_delta 0 flag. It may be unnecessary in other situations, but I don't imagine it hurts anything to leave it in place.

ffmpeg -i Disney.mkv -i totoro-audio-replacement.wav -map 0 -map 1 -max_interleave_delta 0 -c copy -metadata:s:a:3 language=eng -metadata:s:a:3 title="English (Streamline dub)" My\ Neighbor\ Totoro.mkv 

And that's that!

Page Created: 2025-05-20

Last Updated: 2025-05-20

Last Reviewed: 2025-05-20