how to replace audio track in mkv file (on Ubuntu 11.10)

didi_X8 picture didi_X8 · Feb 25, 2012 · Viewed 10.9k times · Source

I have

  • a mkv file with webm video and ogg audio
  • an ogg audio file

I want to replace the audio in the mkv file with the audio from the ogg file. How can I do that on Ubuntu 11.10 with programs available from default repositories?

The resulting file may also have another format (e.g. avi), but I would prefer mkv. Btw. doesn't ffmpeg have an mkv muxer? My test with param -f mkv resulted in error Requested output format 'mkv' is not a suitable output format

Answer

Dmitry Shkuropatsky picture Dmitry Shkuropatsky · Feb 26, 2012

Matroska file format (mkv) is specified with -f matroskaoption. It should be supported by ffmpeg (version 0.7.3) in Ubuntu 11.10. Use ffmpeg -formats for a list of supported file formats.

To merge specific streams (audio or video) from several files use -i option for each input and -map input_index[:stream_index]. For example, the following command merges the first stream of the first input with the second input and keeps the codecs:

ffmpeg -i input.mkv -i input_audio.ogg -map 0:0 -map 1 \
    -vcodec copy -acodec copy output.mkv