View Full Version : Any wma2wav CLI tool ???
LoRd_MuldeR
13th August 2008, 04:36
Hi!
Is there any simple tool available which is able to take a .wma file as input and produce an uncompressed .wav as output? Please note that I need a CLI tool to integrate into my own GUI application. Therefore GUI tools or Winamp plugins are useless here. Also I don't want to use MPlayer.exe/MEncoder.exe or ffmpeg.exe, because they are far to bloated for this speicifc task. Furthermore note that I do not want to support DRM'd WMA files. Last but not least the CLI tool should not depend on any external DLL's. So far I found simple CLI decoders like that for all audio formats I had been looking for. But I failed to find anything suitable for damn WMA. There seems to be a CLI tool called "wma2wav" in existence, which basically is a stripped down version ffmpeg. Unfortunately all links I found were broken/down...
I'd need a Win32 binary that works like that:
wma2wav.exe --input "c:\Foobar.wma" --output "c:\decoded.wav"
Any advice would be welcome :thanks:
[UPDATE]
I finally took the opportunity to create a simple "wma2wav" tool from the scratch:
http://img824.imageshack.us/img824/4205/cwindowssystem32cmdexe2.png (http://img824.imageshack.us/img824/4205/cwindowssystem32cmdexe2.png)
The latest version of thr 'wma2wav' tool can be found in this post:
http://forum.doom9.org/showthread.php?p=1524857#post1524857
Sharktooth
14th August 2008, 17:55
avisynth, directshowsource with avs2raw or bepipe....
LoRd_MuldeR
14th August 2008, 18:24
Dependency on Avisynth and on DirectShow filters -> Not suitable for my "self-contained" application :(
I'd need something in the tradition of OggDec or FAAD ...
LoRd_MuldeR
15th August 2008, 11:02
Think I found a solution ;)
http://forum.doom9.org/showpost.php?p=1170568&postcount=148
Snowknight26
15th August 2008, 21:42
Does this include WMA Lossless?
LoRd_MuldeR
15th July 2011, 23:08
Today I finally took the opportunity to create a simple wma2wav tool from the scratch.
It's based on the Windows Media Format SDK, so it's Windows only. Also currently only output to a "raw" PCM file and output to stdout is possible.
(I will add a Wave file writer soon).
LoRd_MuldeR
16th July 2011, 15:32
Some improvements, including proper command-line argument parser.
Midzuki
16th July 2011, 17:15
Many thanks :thanks:, a.s.a.p. I will check whether it does respect the ASF audio timestamps :devil: or not :D
LoRd_MuldeR
16th July 2011, 17:26
Many thanks :thanks:, a.s.a.p. I will check whether it does respect the ASF audio timestamps :devil: or not :D
It certainly does not. It just dumps the samples as they pop out of the WM reader :p
Since Wave Audio does not have any concept of time stamps (it's basically a simple header in front of "raw" PCM data stream), I don't know how this could be done.
Midzuki
16th July 2011, 18:05
Would it be terribly difficult to "disk-write" the .WAV as the WMA stream is being "played back" ? :confused: :confused: :confused:
Just like Vorbis, Windows Media Audio does not use a constant frame duration :(
LoRd_MuldeR
16th July 2011, 18:29
Would it be terribly difficult to "disk-write" the .WAV as the WMA stream is being "played back" ? :confused: :confused: :confused:
Just like Vorbis, Windows Media Audio does not use a constant frame duration :(
Please explain to me!
What I get from the WM reader is "raw" PCM data. I also get one WAVEFORMATEX per stream (not per sample or frame!), telling me the sampling rate of the (whole?) stream.
Consequently I have to assume that the sampling rate is constant. Anything else wouldn't fit into a Wave file anyway, as the Wave header defines a single sampling rate.
Actually, unlike variable frame rate, where you simply vary the duration that you display the frame, I can hardly imagine how a variable sampling rate would be supposed to work :confused:
What I also do get from the WM reader is the timestamp and duration (in seconds) as well as the size (in bytes) of each "chunk" of audio data that I read from the ASF file.
Actually I don't use the timestamp and the duration (except for displaying the progress) at all. I simply write one sample after another into the file. All samples I got from WM reader.
The only thing that is (or might be) "variable" is the number of samples (bytes) that I receive per GetNextSample() call. And that's no problem at all...
Midzuki
16th July 2011, 18:58
Sorry, I'm unable to explain :o, I only know that, unless I used Winamp's Disk Writer plugin, or Avisynth's BassAudio, many WMA streams generated WAV files which were shorter than their sources :( The consequence: video and audio would go out of sync, of course :(
LoRd_MuldeR
16th July 2011, 19:13
Sorry, I'm unable to explain :o, I only know that, unless I used Winamp's Disk Writer plugin, or Avisynth's BassAudio, many WMA streams generated WAV files which were shorter than their sources :( The consequence: video and audio would go out of sync, of course :(
Well, the only situation that I can think of is:
If the timestamp of chunk N+1 does not exactly match the "end" (timestamp+duration) of chunk N, then there is either a "gap" or an "overlap".
An "overlap" doesn't make much sense to me! For a "gab" we might need to compensate with null samples, if such gaps really exists in real WMA/WMV files.
I re-uploaded today's version with a consistency check for timestamps, which will throw a warning if any non-negligible "gaps" or "overlaps" are found!
(for my test files this did never happen though)
Midzuki
16th July 2011, 20:54
Hmmm, the new build of your wma2wav seems to be working as it should, at last :) :) :)
[C:\ASFBIN]
=>wma2wav -r -i zzoutput.wma -o zzzz9999.raw
wma2wav - Dump WMA/WMV files to Wave Audio [Jul 16 2011]
Copyright (c) 2011 LoRd_MuldeR <mulder2@gmx.de>. Some rights reserved.
Released under the terms of the GNU General Public License.
Input file: zzoutput.wma
Output file: zzzz9999.raw
Opening input file... OK
Analyzing input file... OK
[Audio Properties]
wFormatTag: 1
nChannels: 2
nSamplesPerSec: 48000
wBitsPerSample: 16
fDuration: 44:28.1
nMaxSampleSize: 17208
Opening output file... OK
Inconsistent timestamps: expected 41.002, but got 41.
The samples "overlap" for 0.002 seconds!
Inconsistent timestamps: expected 234.151, but got 235.
There is a "gap" of 0.849 seconds between the samples!
Inconsistent timestamps: expected 639.01, but got 639.
The samples "overlap" for 0.01 seconds!
Inconsistent timestamps: expected 713.965, but got 714.
There is a "gap" of 0.035 seconds between the samples!
Inconsistent timestamps: expected 1213.17, but got 1213.
The samples "overlap" for 0.167 seconds!
Inconsistent timestamps: expected 1817.54, but got 1818.
There is a "gap" of 0.457 seconds between the samples!
Inconsistent timestamps: expected 2191.16, but got 2192.
There is a "gap" of 0.838 seconds between the samples!
[100.0%] 44:27.8 of 44:27.8 completed, please wait...
All done.
:goodpost: and :thanks:
b66pak
16th July 2011, 21:05
@LoRd_MuldeR thanks a lot...this is a huge help...
_
L.E. i done a test and i got this:
wma2wav -i FFXIII_Demo_Cutscene_720p_part4.wmv -r -o FFXIII_Demo_Cutscene_720p_part4.raw
wma2wav - Dump WMA/WMV files to Wave Audio [Jul 16 2011]
Copyright (c) 2011 LoRd_MuldeR <mulder2@gmx.de>. Some rights reserved.
Released under the terms of the GNU General Public License.
Input file: FFXIII_Demo_Cutscene_720p_part4.wmv
Output file: FFXIII_Demo_Cutscene_720p_part4.raw
Opening input file... OK
Analyzing input file... OK
[Audio Properties]
wFormatTag: 1
nChannels: 2
nSamplesPerSec: 44100
wBitsPerSample: 16
fDuration: 4:43.4
nMaxSampleSize: 17208
Opening output file... OK
Inconsistent timestamps: expected 0, but got 0.11.
There is a "gap" of 0.11 seconds between the samples!
Inconsistent timestamps: expected 30.035, but got 31.036.
There is a "gap" of 1.001 seconds between the samples!
[100.0%] 4:43.3 of 4:43.3 completed, please wait...
All done.
i had to fix the gaps myself or the output is oos...i was under the impression that this tool will do it by itself...
_
LoRd_MuldeR
16th July 2011, 22:03
@LoRd_MuldeR thanks a lot...this is a huge help...
_
i had to fix the gaps myself or the output is oos...i was under the impression that this tool will do it by itself...
Nope, not yet. But now that I know they exist in some "real" files, I will implement the required padding.
LoRd_MuldeR
16th July 2011, 22:44
Okay, here is a new version which will compensate "timestamp gaps" by padding with zero bytes. Also it supports Wave/RIFF output now.
By default it tries to avoid padding for small gaps, because I think padding is bad for audio-only files. But I also added a more "aggressive" compensation mode.
(BTW: If somebody could provide me with a sample file that contains "gaps" in the audio stream, this would be helpful for me).
Midzuki
17th July 2011, 06:02
^ Mea culpa :o I had checked only that the resulting .WAV had the same length as the WMA source, not whether it remained "in synch" with the respective video track :uglylol: Anyway, the "aggressive padding" generates a .WAV longer than its WMA source, therefore... :(
Also, after running wma2wav (which IMHO really should be renamed to wmadec or somethig) , the CLI window does not execute .BAT files anymore :confused: :confused: :confused: :confused: :confused:
P.S.: As for the requested sample file, I've PM-ed you.
LoRd_MuldeR
17th July 2011, 13:31
^ Mea culpa :o I had checked only that the resulting .WAV had the same length as the WMA source, not whether it remained "in synch" with the respective video track :uglylol: Anyway, the "aggressive padding" generates a .WAV longer than its WMA source, therefore... :(
Well, as long as the "standard" compensation mode works okay. The "aggressive" mode is more an experimental mode.
I noticed that the timestamps/durations almost always do NOT match up exactly, which maybe is due to rounding errors or something like that.
Trying to compensate even for very small gaps (like aggressive mode does) will result in stuttering audio. Actually it gives an interesting kill-switch (http://en.wikipedia.org/wiki/Kill_switch#Musical_instruments) effect ^^
That is why the "standard" mode will ignore tiny gaps. And it's probably the best we can do...
Also, after running wma2wav (which IMHO really should be renamed to wmadec or somethig) , the CLI window does not execute .BAT files anymore :confused: :confused: :confused: :confused: :confused:
Strange. I cannot reproduce.
Maybe it is because I set the console output CP to UTF-8, which is required to correctly print Unicode (UTF-8) characters.
Will add code to restore the "original" CP on program exit...
P.S.: As for the requested sample file, I've PM-ed you.
Thanks :)
That file has some "overlaps", i.e. the timestamp of the "sample" (chunk of audio samples returned by the WM reader) is actually before the end (timestamp + duration) of the previous "sample". I don't think this should ever by the case (timestamps should be strictly none-decreasing!), so maybe the file is fishy...
Anyway, with the standard compensation mode, wma2wav will produce a Wave file of duration 44:27.959, the original WMA had a duration of 44:28.098 (according to Foobar 2000).
I think less than 0.2 seconds difference for a 45 minutes samples is pretty much okay ;)
LoRd_MuldeR
17th July 2011, 14:12
Yet another update. Will now restore the previous codepage on exit. Also fixed a bug where padding zero bytes would also zero out the next samples!
Midzuki
17th July 2011, 16:03
Codepage bug fixed :thanks:
LoRd_MuldeR
17th July 2011, 18:04
Fixed the "alternative" timestamp calculation mode. Still this mode is experimental and the default mode seems to work better for me.
LoRd_MuldeR
17th July 2011, 21:14
Can somebody send me a sample WMA file that is DRM protected or at least run some tests for me with such file?
I added a check for DRM protected files, because such files cannot be processed (for obvious reasons). However I cannot test it without an example file.
LoRd_MuldeR
18th July 2011, 13:58
Improved "alternative" timestamp calculation mode (option "-x"). Should be a viable alternative now.
More info at:
http://mulder.googlecode.com/svn/trunk/Utils/wma2wav/Readme.txt
Brazil2
18th July 2011, 14:08
Can somebody send me a sample WMA file that is DRM protected or at least run some tests for me with such file?
I added a check for DRM protected files, because such files cannot be processed (for obvious reasons). However I cannot test it without an example file.
http://samples.mplayerhq.hu/A-codecs/WMA/crypt/Sixpence_None_the_Richer-Breathe_Your_Name.wma
http://samples.mplayerhq.hu/A-codecs/WMA/crypt/track0.wma
http://samples.mplayerhq.hu/A-codecs/WMA9/drm/WMA_protected_napster.wma
LoRd_MuldeR
18th July 2011, 14:12
http://samples.mplayerhq.hu/A-codecs/WMA/crypt/Sixpence_None_the_Richer-Breathe_Your_Name.wma
http://samples.mplayerhq.hu/A-codecs/WMA/crypt/track0.wma
:thanks:
b66pak
18th July 2011, 19:30
@LoRd_MuldeR thanks a lot...now its OK...
_
b66pak
18th July 2011, 21:54
can you add multichannel support? also if the source is 24bit then a 24bit pcm wav is better...
from a file like this i get stereo audio (downmixed)...
General
Complete name : sample.wmv
Format : Windows Media
File size : 40.0 MiB
Duration : 1mn 0s
Overall bit rate mode : Variable
Overall bit rate : 5 519 Kbps
Maximum Overall bit rate : 17.7 Mbps
Encoded date : UTC 2009-11-25 16:58:08.171
Video
ID : 2
Format : VC-1
Format profile : AP@L3
Codec ID : WVC1
Codec ID/Hint : Microsoft
Description of the codec : Windows Media Video 9 Advanced Profile
Duration : 1mn 0s
Bit rate mode : Variable
Bit rate : 4 671 Kbps
Width : 1 280 pixels
Height : 720 pixels
Display aspect ratio : 16:9
Frame rate : 23.976 fps
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Compression mode : Lossy
Bits/(Pixel*Frame) : 0.211
Stream size : 33.8 MiB (85%)
Language : English (US)
Audio
ID : 1
Format : WMA
Format profile : Pro
Codec ID : 162
Codec ID/Info : Windows Media Audio
Description of the codec : Windows Media Audio 10 Professional - 768 kbps, 48 kHz, 5.1 channel 24 bit 1-pass CBR
Duration : 1mn 0s
Bit rate mode : Constant
Bit rate : 768 Kbps
Channel(s) : 6 channels
Sampling rate : 48.0 KHz
Bit depth : 24 bits
Stream size : 5.56 MiB (14%)
Language : English (US)
--------------------------------------------------------------------
Input file: sample.wmv
Output file: sample.wav
Opening input file... OK
Analyzing input file... OK
[Audio Properties]
wFormatTag: 1
nChannels: 2
nSamplesPerSec: 48000
wBitsPerSample: 16
fDuration: 1:00.8
nMaxSampleSize: 77420
Opening output file... OK
Inconsistent timestamps: Expected 0.00000000 next, but got 0.15600000.
There is a "gap" of 0.15600000 seconds, padding 29952 zero bytes!
[100.0%] 1:00.3 of 1:00.3 completed, please wait...
Warning: Sync correction inserted 29952 zero bytes, skipped 0 bytes.
All done.
LoRd_MuldeR
18th July 2011, 22:18
Hmm, actually my tool should be prepared for multi-channel audio and higher bit-depths. It dumps the audio data as received.
What you see below "[Audio Properties]" is exactly what the WMReader object reports for the audio stream. So it obviously does the down-mix automatically.
I don't know if there is a way to convince the WMReader object to output the "native" audio without downmixing. But I will look into this. Tomorrow...
For the moment, here is a small update that will detect and print out some Codec information.
tebasuna51
18th July 2011, 23:18
About multichannel output:
There are other tool (dshow2wav.exe) here : http://forum.doom9.org/showthread.php?p=1209087#post1209087
And the WMA 5.1ch. in WMV only decodes to stereo? (http://forum.doom9.org/showthread.php?t=110449) thread
LoRd_MuldeR
19th July 2011, 02:40
Okay, here is a new test version ;)
It gave me some headache, but I think I found a way to read out the "native" sampling rate and channel count of the WMA stream.
Also I will now try to set the output format accordingly. As a result, we can now get multi-channel output as well as 24-Bit.
Midzuki
19th July 2011, 03:10
Again, thanks for the good job :thanks:
BTW, where the :devil: is zambelli? ;) :)
LoRd_MuldeR
19th July 2011, 13:25
This version contains a massive clean-up of the recent changes to allow 24-bit and multi-channel output.
Also I added an option to force the "default" output format. Use this, if more than 16-Bit/Stereo output is not desired.
Added MSVC 9.0 build that should work on Win2k + added Win2k channel workaround
Brazil2
19th July 2011, 17:39
Great work, channels are ok, 24 bits resolution is ok, one thing isn't working though: it always downsample to a maximum of 48 kHz from a 96 kHz or 192 kHz file.
Sample: http://samples.mplayerhq.hu/A-codecs/WMA9/WMAPro_5dot1/ambient1_192_mulitchannel.wma
BTW the attached file is a VS2008 build which should run on Windows 2000 (not tested on Windows 2000 though but it's working fine on XP).
LoRd_MuldeR
19th July 2011, 18:00
Great work, channels are ok, 24 bits resolution is ok, one thing isn't working though: it always downsample to a maximum of 48 kHz from a 96 kHz or 192 kHz file.
Sample: http://samples.mplayerhq.hu/A-codecs/WMA9/WMAPro_5dot1/ambient1_192_mulitchannel.wma
Hmm, that one is reported as 48 KHz by the IWMReader/IWMProfile interface, so the output format is set "correctly", I think.
Also MediaInfo reports:
Audio
ID : 1
Format : WMA
Format profile : Pro
Codec ID : 162
Codec ID/Info : Windows Media Audio
Description of the codec : Windows Media Audio 9 Professional - 192 kbps, 48 kHz, 5.1 channel 24 bit 2-pass VBR
Duration : 1mn 13s
Bit rate mode : Variable
Bit rate : 192 Kbps
Channel(s) : 6 channels
Sampling rate : 48.0 KHz
And Foobar2000 as well as Winamp agree ;)
Also I think more than 48 KHz output is rarely supported by consumer-grade hardware audio interfaces, let alone all the "on board" audio chips...
Brazil2
19th July 2011, 18:17
My mistake, it seems I got confused by the filename from all of these samples I've grabbed, sorry. :o
And everything is working fine with a 96 kHz file, at least it does with this sample:
http://samples.mplayerhq.hu/A-codecs/WMA9/wmapro/Classical_96_24_6_256000_1_20.wma
And please, don't forget to approve my VS2008 build from my previous post ;)
b66pak
19th July 2011, 20:23
@LoRd_MuldeR thanks a lot...all is OK now...
_
tebasuna51
20th July 2011, 20:08
Thanks, work fine for me also.
LoRd_MuldeR
22nd July 2011, 00:52
Fixed a bug that could cause the tool to crash, when the ASF file had a very long Title or Codec Info.
You live and learn: wcscpy_s() doesn't gracefully truncate the string when the buffer is too small, but invokes Watson crash reporting instead.
"...which causes the application to crash and asks the user if they want to load the crash dump to Microsoft for analysis." :)
Midzuki
22nd July 2011, 01:08
As I said before, Nic had already created a WMA2WAV.EXE ( for adding a .WAV header to WMA files :devil: :D ). Do you still resist renaming your most useful WMA-decompressor ? :)
LoRd_MuldeR
22nd July 2011, 01:13
As I said before, Nic had already created a WMA2WAV.EXE ( for adding a .WAV header to WMA files :devil: :D ). Do you still resist renaming your most useful WMA-decompressor ? :)
Google for "wma2wav" and you will find at least a dozen of different tools. Probably the same applies to "wmadec".
So I think I'll just keep the name as-is. You may rename it to whatever you prefer :)
Midzuki
22nd July 2011, 01:18
Google for "wma2wav" and you will find at least a dozen of different tools. Probably the same applies to "wmadec".
:eek:
So I think I'll just keep the name as-is. You may rename it to whatever you prefer :)
Yes, sir! :) However things would be easier if I didn't have to un-UPX before hex-editing the binary. :p
wma-dec - Dump WMA/WMV files to Wave Audio [Jul 18 2011]
Copyright (c) 2011 LoRd_MuldeR <mulder2@gmx.de>. Some rights reserved.
Released under the terms of the GNU General Public License.
Error: Input and/or output file not specified!
Usage:
wma-dec.exe [options] -i <input> -o <output>
Options:
-i <input> Select input ASF (WMA/WMV) file to read from
-o <output> Select output Wave file to write to, specify "-" for STDOUT
-f Force overwrite of output file (if already exists)
-r Output "raw" PCM data to file instead of Wave/RIFF file
-s Silent mode, do not display progress indicator
-x Use the "alternative" timestamp calculation mode
-a Enable "aggressive" sync correction mode (not recommended)
-n No sync correction (can not use with '-a' or '-x')
Example:
wma-dec.exe "c:\my music\input.wma" "c:\temp\output.wav"
:thanks:
b66pak
22nd July 2011, 18:49
@LoRd_MuldeR thanks a lot...
_
LoRd_MuldeR
24th July 2011, 00:37
Yet another bugfix release :rolleyes: :)
This version adds a workaround for a bug in LoadLibraryEx() that could prevent WMVCORE.DLL from loading or even cause the application to crash.
I was unable to reproduce this on Win7, WinXP or Win2k. But crashes have been reported for Vista (64-Bit) without KB2533623 (http://support.microsoft.com/kb/2533623) installed.
LoRd_MuldeR
8th September 2011, 15:35
Added an option to write a RIFF/Wave file to STDOUT. Now a command-line like this can work:
wma2wav.exe -i input.wma -w -s -o - | neroaacenc.exe -ignorelength -if - -of output.m4a
Note: It is expected that closing the Wave file will fail when piping the STDOUT to another application, because the chunk sizes cannot be updated for obvious reasons.
It is not possible to seek back to the beginning of the file when a pipe is being used to write to!
Also there is no "MSVC 9.0" build included anymore, because the normal MSVC 10.0 (Visual Studio 2010) build should now work on the Windows 2000 platform too.
tebasuna51
8th September 2011, 16:17
Thanks, great improvement!
b66pak
8th September 2011, 18:04
thanks a lot...
_
b66pak
1st October 2011, 19:12
new version (wma2wav.2011-10-01) here (http://code.google.com/p/mulder/downloads/list?can=2&q=&sort=-uploaded&colspec=Filename%20Summary%20Type%20Uploaded%20Size%20DownloadCount)...thanks a lot...
_
LoRd_MuldeR
1st October 2011, 19:23
For users there should be no difference to the previous version. I only use a "better" (less hackish) method to fix the stdout/stderr problem now...
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.