Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: How do I extract audio from an MKV file without losing quality (Read 101518 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

How do I extract audio from an MKV file without losing quality

I got the Inception Soundtrack in 5.1 surround sound, but its all in separate MKV files (it's sourced from the Blu-Ray special features disc, if it matters). I can't find a way I convert them to nice Lossless audio formats, or even into another video codec without converting it to something like MP3. It is currently in FLAC, 5.1, 24 bit depth, 48,000 kHz. I'd prefer to keep the 5.1 channels, but Stereo is ok too, I'm really just looking for a way to extract the audio without losing quality.

How do I extract audio from an MKV file without losing quality

Reply #1
I'm going to assume that you sourced those files from the Blu-Ray special features disc yourself. Let's not suggest otherwise, unless you'd like this topic to disappear again.

Anyway, you could use ffmpeg with -c:a copy to copy the FLAC stream directly to a .flac file. If they're already split into one file per track, it's already easy.

If it's one or more files with chapters, you will need to re-encode those FLAC streams to individual files. Foobar2000 and its converter can do this losslessly, assuming the input is indeed lossless, and you convert to another lossless format. It can even transfer the tags for you.


How do I extract audio from an MKV file without losing quality

Reply #3
MKVToolNix (surprise!).  specifically, mkvextract from the mkvtoolnix package.  works on most platforms (possibly all modern ones).

if you're not comfy with the command line (the default), there is also mkvextractgui2, which requires the main mkvtoolnix package.

How do I extract audio from an MKV file without losing quality

Reply #4
I use mkvextract - but I've only done this with mkv that have dolby ac3 in them. This is from my script.

Code: [Select]
n=`mkvinfo ${base}.mkv |grep "Track type" |grep -n "audio" |cut -d":" -f1`
audTrack=`echo "${n} - 1" |bc`
mkvextract tracks ${base}.mkv ${audTrack}:${base}.ac3


Then

Code: [Select]
a52dec -o wavdolby ${base}.ac3 > tmp.wav
sox --norm tmp.wav -b 16 ${base}.wav rate 48000 dither -s
rm -f tmp.wav


Now it is a stereo wav file I can encode into anything I want.
If you want to preserve the 5.1 then obviously you don't want to do that last part.

How do I extract audio from an MKV file without losing quality

Reply #5
Any decent converter should do it.
I use Xmedia Recode.

How do I extract audio from an MKV file without losing quality

Reply #6
eac3to

or

ffmpeg -i input.mkv -acodec copy -vn output.flac

How do I extract audio from an MKV file without losing quality

Reply #7
Any decent converter should do it.
I use Xmedia Recode.


But the OP wants "without losing quality", I assume that will re-encode.

I had issues with mkvextract, it just wouldn't work, the gui for it is 32-bit so doesn't work if you're using the 64-bit version.

How do I extract audio from an MKV file without losing quality

Reply #8
Is there anything that will extract the audio from an .mkv (or other container formats for that matter) and save it to a "preferred for this codec" format, without nesting a helluvalot of IF commands?

Say, automatically choose .mp3 if it is MP3, or MPEG-4 .m4a if it is AAC audio, or FLAC if it is lossless max 24 bits, WavPack if it is more than 24 (I just had to plug this example for generality).

How do I extract audio from an MKV file without losing quality

Reply #9
Any decent converter should do it.
I use Xmedia Recode.


But the OP wants "without losing quality", I assume that will re-encode.

No, you can select 'copy' for audio and it will simply copy it to the desired container (without video, if that's what you want).
That's what I meant by decent converter, unlike some "one click EZ convert, with Ask toolbar" that you can find out there.

A lot of these tools (including Xmedia Recode) are pretty much just GUIs for ffmpeg.

Another one I used occasionally is Avidemux.


Is there anything that will extract the audio from an .mkv (or other container formats for that matter) and save it to a "preferred for this codec" format, without nesting a helluvalot of IF commands?

Say, automatically choose .mp3 if it is MP3, or MPEG-4 .m4a if it is AAC audio, or FLAC if it is lossless max 24 bits, WavPack if it is more than 24 (I just had to plug this example for generality).

I don't know just how automatically you want this to work, but for example Xmedia Recode will show the audio/video codec info when you open a file and then you can select the proper container with a couple of clicks.
In Avidemux you can look at the file properties and then select Audio->Save... with the desired extension.

How do I extract audio from an MKV file without losing quality

Reply #10
No, you can select 'copy' for audio and it will simply copy it to the desired container (without video, if that's what you want).
That's what I meant by decent converter, unlike some "one click EZ convert, with Ask toolbar" that you can find out there.


OK, thanks for correcting me