Log in

View Full Version : Extracting audio from MKV


Katie Boundary
20th December 2020, 01:40
I tried to extract audio from an MP4 earlier using ffaudiosource but the result was noisy garbage, like it had been recompressed at a really low bitrate. I'm now trying to extract audio from a certain MKV file using ffaudiosource, but the result is even noisier garbage. I need advice on alternatives.

poisondeathray
20th December 2020, 01:42
You can try LSmash ,

eg.

LWLibavAudioSource("file.mkv")

or even DirectShowSource("file.mkv" , vidoe=false)

Katie Boundary
20th December 2020, 01:53
DirectShowSource creates an unreadable file.

I'll try Lsmash next but since it goes through ffmpeg anyway, my expectations are low.

StainlessS
20th December 2020, 02:02
Try this, you need edit those in BLUE

KatieFavouriteBat.bat

setlocal

REM Where to Find ffmpeg
set FFMPEG="C:\BIN\ffmpeg.exe"

REM Where to get input file, No terminating Backslash, "." = current directory
set INDIR="."

REM Where to place output file, No terminating Backslash.
set OUTDIR=".\OUTPUT"

FOR %%A IN (*.mpg *.avi *.flv *.mov *.mp4 *.mkv) DO (
%FFMPEG% -i "%INDIR%\%%A" -vn -acodec pcm_s16le "%OUTDIR%\%%~nxA.WAV"

)

Pause

Those in red are containers where WAV extracted, can add to them SPACE separated as in *.XVID
Can [[I think] also add eg "*.mp3" ie audio container to extract WAV.

EDIT: Above set OUTDIR=".\OUTPUT" is directory within current dir, must exist, or use eg "." for current dir.
Will batch process all found container files to wavs.

poisondeathray
20th December 2020, 02:10
DirectShowSource creates an unreadable file.


Do you have a directshow splitter and decoder installed appropriate for your file ?

What kind of audio ?


I'll try Lsmash next but since it goes through ffmpeg anyway, my expectations are low.

Certain lsmash and ffms2 builds have known issues with certain types of audio. Some release are better than others

You can also try BestAudioSource
http://avisynth.nl/index.php/BestAudioSource

Katie Boundary
20th December 2020, 02:10
AVIsynth insists it can't find LWLibavAudioSource or LSMASHAudioSource even though the 32-bit version of LSMASHSource.dll is in the plugins folder.

I have no idea what black magic Stainless is trying to use. Is that supposed to go in the avisynth script somewhere?

StainlessS
20th December 2020, 02:12
Its a batch (.bat) file, using ffmpeg to extract wav, batch process, so many files processed at once.
[ffmpeg.exe usually works fine no matter what the prob is with ffms or LSmash]

That LSmash file looks like it may require some CPP runtime, use AvsMeter to find out what the problem is.

AvsMeter avsinfo

Katie Boundary
20th December 2020, 02:14
Do you have a directshow splitter and decoder installed appropriate for your file ?

I have no bloody idea.

What kind of audio ?

The MKV is 5.1-channel, 48000 hz, which I adjusted for in the script, but it doesn't matter because the audio is unreadable even if I leave the channels and sample rate alone and just try to open the script with MPC or VLC instead of Premiere.

You can also try BestAudioSource
http://avisynth.nl/index.php/BestAudioSource

Thanks, I'll give that a spin next.

EDIT:

only available in 64-bit.

Well, so much for that plan.

poisondeathray
20th December 2020, 02:22
The MKV is 5.1-channel, 48000 hz, which I adjusted for in the script, but it doesn't matter because the audio is unreadable even if I leave the channels and sample rate alone and just try to open the script with MPC or VLC instead of Premiere.



Uncompressed PCM WAV ? What kind of audio ?

Does that mean MPC or VLC cannot read it , only Premiere can read it correctly ?

Or VLC can read it, and audio "sounds" correct ?

poisondeathray
20th December 2020, 02:25
AVIsynth insists it can't find LWLibavAudioSource or LSMASHAudioSource even though the 32-bit version of LSMASHSource.dll is in the plugins folder.


It might be that you're using an older version

Try this one, x86 and x64 versions are included
https://github.com/HolyWu/L-SMASH-Works/releases/tag/20200728

hello_hello
20th December 2020, 11:13
Reading the word "extract" I initially assumed that means using a tool such as gMKVExtractGUI or MKVCleaver.
Whatever the case though, maybe use MKVToolNix to split off a small sample and post a link?

richardpl
20th December 2020, 11:18
I'll try Lsmash next but since it goes through ffmpeg anyway, my expectations are low.

You clearly lacks insight into using ffmpeg.

tebasuna51
20th December 2020, 19:40
- 12 posts and still we don't know the audio codec. Use MediaInfo please.

- LWLibavAudioSource, LSMASHAudioSource, BestAudioSource or DirectShowSource can't extract audio. Can decode audio but not extract the audio in the original format.

- To extract audio, without decode, use MKVExtract, eac3to or ffmpeg.

StainlessS
21st December 2020, 11:22
One has to make the assumption that Katie wants use in Avisynth as decompressed audio, as she has tried to use
ffaudiosource, LWLibavAudioSource, LSMASHAudioSource.

The Bat file I gave uses ffmpeg.Exe [not ffms], and extracts audio as 16 bit PCM WAV for use via WavSource("...").
ffmpeg.exe almost always works perfectly even if Lsmash or ffms have problems.

tebasuna51
21st December 2020, 13:55
Without decode we can use:

FOR %%A IN (*.mpg *.avi *.flv *.mov *.mp4 *.mkv) DO (%FFMPEG% -i "%INDIR%\%%A" -vn -acodec copy "%OUTDIR%\%%~nxA.mka"

The .mka container can support many codecs.
Of course if we know the codec (with MediaInfo, eac3to, ffmpeg -report, ...) we can use the appropriate extension.

BTW if mpc and vlc can't play it maybe it is corrupted.