Laurent’s Blog

Thursday, 13 November, 2008

Converting WMA 5.1 to AC3 – Part 4 (final)

Filed under: Audio Encoding — Tags: , , , , , , , — hemie143 @ 23:42

In the previous part, we had found a way to convert a WMA 5.1 stream into AC3. And this method should work for pretty much any audio source. However, some people may suggest other solutions, like foobar2000 or dbPowerAmp. Both tools are incredibly useful and can help you in most cases, however, in my case they were of no help.

First, dbPowerAmp is, at least to my knowlegde, not able yet to encode into AC3. This means that you should first create an intermediate file using another format, like Vorbis, FLAC, AAC or even WAV. This way, you will simply create another (big) file with a very short life. Furthermore, I have seen that many people have issues with the order of the 6 channels.

Secondly, foobar2000 has more or less the same problem. There is currently no plugin to encode directly in AC3. However, you may define a new converter, or encoder based on Aften. In this case, you would define the arguments of the encoder with identical values to what we defined in the previous part. Unfortunately, in this case, I’m not understanding the added value of foobar2000 compared to bepipe.

Furthermore, for both tools, we still should have to solve the issue of downsampling from 96 KHz to 48 KHz, and I have not found yet whether any of those tools offers this feature. If anyone has got any suggestions, she/he’s welcome.

Converting WMA 5.1 to AC3 – Part 3

Filed under: Audio Encoding — Tags: , , , , , , , — hemie143 @ 22:31

In the previous part, we had defined a way to read the WMA 5.1 stream, and resample it to 48 KHz. The goal in this part is to re-encode this stream in the AC3 format.

As previously said, we will use Aften as the AC3 encoder. So, place the aften.exe binary in the same place as the other files (wma, avs and bepipe). And type in the following command :

BePipe.exe --script "import(^wma2ac3.avs^)" - | aften.exe -v 0 -b 448 -m 0 -readtoeof 1 -cmix 0 -smix 0 -dsur 0 -dnorm 31 -dynrng 5 - "output.ac3"

The aften arguments are :

  • -v 0 : quiet mode, no output to stderr
  • -b 448 : CBR bitrate = 448 bps, which is a minimal value for AC3 5.1
  • -m 0 : no stereo rematrixing, so we don’t touch to the stereo mixing
  • -readtoeof 1 : read to the end of file, in order to prevent the 4 GB limit, which can easily be reached with a 5.1 WAV stream.
  • -cmix 0 : center mix level of -3dB compared to the left and right front channels, this is a default value.
  • -smix 0 : surround mix level of -3dB, which is also a default value
  • -dsur 0 : the Dolby Surround mode is not marked, anyway this is not a Dolby Surround track
  • -dnorm 31 : dialog normalization of -31dB, which is the default value. This implies that the output volume will not be changed
  • -dynrng 5 : no dynamic range compression profile is defined, so we do not alter the initial encoding
  • – : a single hyphen to specify to take the input from the stdin
  • “output.ac3” : output file

Tadaa ! And after a while, you finally get a nice AC3 file. Of course, you can remux this AC3 with the VC-1 stream, or re-encode this one in the H.264 format. But that’s another story.

Next time, I’ll write about the other tools we could have tried to use for this conversion, in part 4.

Wednesday, 12 November, 2008

Converting WMA 5.1 to AC3 – Part 2

Filed under: Audio Encoding — Tags: , , , , , , , , — hemie143 @ 21:12

In part 1, I wanted to convert the audio stream of a WMV file into an AC3 file. That should not be a problem, unless the audio stream has a strange sampling frequency and you want to keep the 5.1 channels. The solution is to use Aften for encoding and bepipe.exe to stream the audio into Aften.

What’s BePipe ? This is a tool that found its roots in avs2wav and it allows you to pipe an audio stream from any audio/video file, if that file can be read by AviSynth.

In order to work with smaller files, a good option is to demux the audio stream from the movie. This can easily be done with the help of the Windows Media Stream Editor, a tool from the Windows Media Encore 9 Series. So, instead of working with a 8Gb WMV movie file, we can now work with a WMA audio file of about 300-400 Kb. Let’s call this file “soundtrack.wma”.

First, we should ensure that AviSynth is able to read the file. First install AviSynth, but that should already be done, if you are using MeGUI. Next, download the BassAudio plugin for AviSynth. You should be able to find it from the Doom9’s forums, from RapidShare or from aviSynth.org.  The file should be BassAudio23.7z. Decompress it and copy the DLLs from the BassAudio23/Release folder to the plugins folder of AviSynth, wherever you have installed it.

Secondly, copy the BePipe.exe from the same BassAudio23.7z to the folder where soundtrack is located.

Create an AVI script “wma2ac3.avs” containing the following :

BassAudioSource("soundtrack.wma")
ConvertAudiotoFloat()
SSRC(48000)

The first line will make sure that the BassAudio libraries are used to decode the audio, instead of the default DirectShow decoder. The second line will force to use a float resolution in order to use any resolution that is used (from 8 to 24 bit). The third line will force a resampling frequency of 48 KHz.

You may test the process with the following command at the prompt :

BePipe.exe --script "import(^wma2ac3.avs^)" -

There are two arguments. The first argument (–script) allows you to define an AviSynth script. In this case, this is simply a script importing the previously created AviSynth script. The caret characters are there to replace the double quotes. The second argument (-, a single hyphen) instructs bepipe to redirect the output to stdout (standard output, or on screen).

If all is working well, you should see some garbage scrolling in your DOS box. What remains now is to encode this stuff into an AC3 stream. But that will be for next time.

Converting WMA 5.1 to AC3 – Part 1

Filed under: Audio Encoding — Tags: , , , , , , , — hemie143 @ 9:49

Lately, I wanted to convert a WMV file to a more standard format. So, I thought about my preferred encoding tool (actually just an interface to encoders), which is MeGUI. But that conversion failed…

The WMV contained a VC-1 video stream which can easily be read by MeGUI with the help of AviSynth. The WMV file also contained a WMA3 audio stream. The total size of the file was about the size of a DVD-9 and the movie was a bit longer than 2 hours.

As usual, I first convert the audio, just to be able to calculate the bitrate for the video encoding. However, in this case, it failed and the error log of MeGUI reported an exception “The pipe has been ended”. Mmhh, strange. So, I thought I had to follow another path. Back to basics.

Actually, I discovered that the WMA3 stream was not very standard. The specs were :

  • Codec : Windows Media Audio 10 Pro
  • Bitrate : variable at 383 kbps
  • Channels : 6 (5.1)
  • Sampling rate : 96 KHz (very very strange and rather useless)
  • Resolution : 24 bit

I had to stick with Aften because this is the best AC3 encoder. However, it is only able to encode WAV to AC3. Maybe there was the option to convert the WMA stream into a giganormous WAV file or into 6 different WAVs, one for each channel, but that was certainly not the most elegant solution.

Here were my requirements :

  1. Keep the best quality available.
  2. Keep the 5.1 channels.
  3. Convert from 96 KHz to a standard 48 KHz.
  4. Convert to a standard constant bitrate of 448 kbps.

The solution I found was to pipe the audio stream into Aften. And how do you do that ? With bepipe.exe and AviSynth, of course.  bepipe.exe is a small tool provided with the BassAudio libraries, which are the best audio decoding libraries.

To be continued in part 2

Blog at WordPress.com.