How to Extract Audio Tracks from MKV Video Files to Save in MP3 MKV is a multimedia container used to encapsulate various audio and video data along with subtitles in one file, despite using different video & audio compression standard. Extract Dolby TrueHD from MKV link to this post As the title says, I am trying to extract the Dolby TrueHD audio track from an MKV file so that I can convert it to something my WD TV Live/Bravia combination will play. Well, it plays, but there is no sound, which kind of defeats the point, really.
Is there a way to convert .mkv files with DTS-HD audio to TrueHD?
Forgive me if this question is stupid, but here's the situation.
My living room surround sound system is a Sonos audio system (Playbar, sub, rear left, rear right) playing on a Samsung KS8000. (Sidenote: I understand that many people have a preference against Sonos, but I'd rather not litigate that at this time.) I've recently been looking into getting some 4K videos for my Plex server, but I immediately ran into an issue, and I'm looking for a workaround.
The problem: While I've got a reasonably solid server PC (~10k passmark score) and a more than adequate connection (300 MB/30 MB), when I tried to play the first 4K video, I immediately encountered buffering. I quickly learned that because Sonos does not play DTS audio, it tries to transcode that audio into DD 5.1. With a 4K file, that's simply not feasible. I immediately identified that two options which resolve the buffering altogether are: 1) enable DTS in Plex, resulting in the audio being pushed through by the TV to my Sonos system as a stereo signal, or 2) remux the .mkv file with a DD 5.1 audio stream instead of DTS.
The issue: Given that I'm dealing with a 4K picture, I'd like to do everything I can to use the highest quality audio I can, given my setup. Obviously the DD 5.1 audio stream will work, but the size of the stream is about 20% of the lossless DTS-HD stream in the original file. If I can, I'd like to use the Dolby equivalent of DTS-HD, which I believe is TrueHD (somebody please correct me if this is wrong). While I've found a number of freeware and payware which resolve the issue of remuxing a DTS-HD stream to a standard AC3 DD 5.1 stream, I've found nothing which converts a lossless DTS stream to a lossless DD stream. Does such a piece of software exist?
Edit: One thing to add. If my end goal of keeping lossless audio does not exist, what would be my best method to convert my DTS files to a playable surround sound format while retaining the best possible audio quality?
I tried the following command to extract audio from video:ffmpeg -i Sample.avi -vn -ar 44100 -ac 2 -ab 192k -f mp3 Sample.mp3
but i get output as
Can anyone help, please?
12 Answers
To extract the audio stream without re-encoding:
-vn
is no video.-acodec copy
says use the same audio stream that's already in there.
Read the output to see what codec it is, to set the right filename extension.
To encode a high quality MP3 from an AVI best use -q:a for variable bit rate:
If you want to extract a portion of audio from a video use the -ss option to specify the starting timestamp, and the -t option to specify the encoding duration, eg from 3 minutes and 5 seconds in for 45 seconds:
The timestamps need to be in HH:MM:SS.xxx format or in seconds.
If you don't specify the -t option it will go to the end.
ffmpeg -i sample.avi
will give you the audio/video format info for your file. Make sure you have the proper libraries configured to parse the input streams. Also, make sure that the file isn't corrupt.
The command line is correct and works on a valid video file. I would make sure that you have installed the correct library to work with mp3, install lame o probe with another audio codec.
Usually
or
would give sufficient information so that you know more.
To encode mp3 audio ffmpeg.org shows the following example:
I extracted the audio from a video just by replacing input.wav
with the video filename. The 2
means 190 kb/sec. You can see the other quality levels at my link above.
Just a guess:
should be
Seems like that could be a problem, but maybe ffmpeg is smart enough to correct it.
If the audio wrapped into the avi is not mp3-format to start with, you may need to specify -acodec mp3
as an additional parameter. Or whatever your mp3 codec is (on Linux systems its probably -acodec libmp3lame
). You may also get the same effect, platform-agnostic, by instead specifying -f mp3
to 'force' the format to mp3, although not all versions of ffmpeg still support that switch. Your Mileage May Vary.
Use -b:a
instead of -ab
as -ab
is outdated now.Make sure your input file path is correct.
To extract audio from a video I have used below command and its working fine.
Here,
-y
Overwrite output files without asking.
-i
ffmpeg reads from an arbitrary number of input “files” specified by the -i option
-vn
Disable video recording
-ar
sets the sampling rate for audio streams if encoded
-ac
Set the number of audio channels.
-b:a
Set the audio bitrate
-f
format
Check out this for my complete sample ffmpeg android project on github.
To extract without conversion I use a context menu entry - as file manager custom action in Linux - to run the following (after having checked what audio type the video contains; example for video containing ogg
audio):
which is based on the ffmpeg command ffmpeg -i INPUT -map 0:a -c:a copy OUTPUT
.
I have used -map 0:1
in that without problems, but, as said in a comment by @LordNeckbeard, 'Stream 0:1
is not guaranteed to always be audio. Using -map 0:a
instead of -map 0:1
will avoid ambiguity.'
Here's what I just used:
Options explanation:
- my.mkv is a source video file, you can use other formats as well
-map 0:3
means I want 3rd stream from video file. Put your N there - video files often has multiple audio streams; you can omit it or use-map 0:a
to take the default audio stream. Runffprobe my.mkv
to see what streams does the video file have.- my.mp3 is a target audio filename, and ffmpeg figures out I want an MP3 from its extension. In my case the source audio stream is ac3 DTS and just copying wasn't what I wanted
- 320k is a desired target bitrate
- -vn means I don't want video in target file
Here's what I just used:
ffmpeg -i input.mkv -ss 01:06:57 -to 01:21:07 -c:v copy -c:a copy output.mp4
Reference: https://www.arj.no/2018/05/18/trimvideo/
For people looking for the simpler way to extract audio from a video file while retaining the original video file's parameters, you can use:
For example, running:
extracts an mp3
audio file from a mov
video file.
protected by Jeremy ThompsonMar 31 '16 at 5:18
Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?