View Full Version : Volume normalization?


BGane
22nd November 2002, 19:02
:confused: Hi folks. I was wondering if there might be a way that I can exploit the powers of dvd2svcd to normalize the volume levels in a number of existing mpg files that have been produced from various authoring sources.

Here is the issue: One of the nice things about the processing within dvd2svcd is that it applies the processing of BeSweet to set a maximum audio gain. Then, it muxes the normalized audio together with the video that has been produced by, in my case, TMPGENC. This is what I need to do. However, what I do NOT need to do is to re-encode the video.

It is easy enough to use TMPGENC to split the existing MPGs into an MPV and MP2 file. But then I need dvd2svcd to pick up from there with its BeSweet processing, and re-muxing (with bbMPEG).

Is there a way that I can "turn off" the first parts of dvd2svcd that would attempt to produce a video file and start the processing on my existing MPV and MP2 files?

markrb
22nd November 2002, 19:24
Why don't you just use BeSweet by itself? There is even a Gui for it. Look for any post by DSPGuru and in his signiture will be the BeSweet homepage.

Mark

BGane
22nd November 2002, 19:32
Yeah. Can do. But then I must also re-mux. I'm trying to find a way to build an automated batch with as few steps as possible. I have a library of 1,000 files. Even ONE extra step means a lot of extra work. I'm willing to do the TMPG processing to split the files that I need into parts, but then was hoping to use dvd2svcd to automatically process the audio gain maximization and recombine.

markrb
23rd November 2002, 18:21
There is no way to Skip portions of DVD2SVCD without major manual intervention that makes it just like doing it manually anyway.

Mark

Math
3rd December 2002, 00:41
HI BGane,

I guess using DVD2SVCD for the purpose you just described is really overkill.

I would advise to simply make a batch file on your own, reusing the tool that is provided with DVD2SVCD. Indeed, DVD2SVCD uses most of them through command-lines. If you're a not really acquainted with DOS batch files, you could start from the command lines contained in the log files generated by DVD2SVCD and play with the settings.

BGane
3rd December 2002, 12:35
Thanks Math.

Yes I am familiar with batch files. Yes - I will likely just copy the lines from the dvd2svcd log files. However, the tricky part that would prevent me from completely automating my process is how to set up a command line for TMPGENC. I suppose that all I need to do is start up TMPGENC or some other appropriate tool that can be launched in a batch and split the MPG file into its component video and audio streams.

If we reduce my problem then to simply one of how to trigger TMPGENC, can someone point me to instructions for how to set up a batch trigger for TMPGENC? From what I have found, the batch switches are not that well documented.

BGane
16th December 2002, 19:49
Ok, well - after a little work - I have an answer to my own question. I have constructed a batch file that uses the components of DVD2SVCD to allow you to batch normalize the volume level in however many MPG files you may have.

The only component that is not a standard part of DVD2SVCD is BBDMUX. You must find a copy of bbTools and extract at least the BBDMUX executable. The batch file will look for BBDMUX in the DVD2SVCD bbMPEG directory.

You must also create a default.ini file in your working directory, which is a copy of the bbMPEG template - bbMPEG Movie Settings1.ini -usually found in your DVD2SVCD Movie directory after running DVD2SVCD. You must change the AudioFilename parameter to "audio_file.mp2" and VideoFilename parameter to "video_file". The macro expects these as default intermediate filenames.

The output file created will have the same name as the input file, except that "00" is appended by RunbbMPEG. So, if input is "abc.mpg", then the output file, with max volume, will be "abc00.mpg".

Question for the experts: Can you tell me the name of the parameter in the default.ini file that could be used to override this default name so that "00" is NOT appended?

I would also welcome any comments on the options included below. I'm new to this, so don't assume that it is 100%. Use at your own risk.

Here it is:


REM AudioNormalizer
REM
REM Usage: AudioNormalizer <input_file>
REM

REM De-mux components of the input file into separate audio and video files

del video_file
del audio_file
del audio_file.mp2

"C:\Program Files\DVD2SVCD\bbMPEG\BBDMUX" "%1" 0xE0 video_file
"C:\Program Files\DVD2SVCD\bbMPEG\BBDMUX" "%1" 0xC0 audio_file

REM Apply BeSweet processing to input audio_file - output audio file has max gain applied

"C:\Program Files\DVD2SVCD\BeSweet\BeSweet.exe" -core( -input "audio_file" -output "audio_file.mp2" -azid( -L -3db -c normal -s surround -g max ) -ota( -d -129 ) -shibatch( --rate 44100 ) -2lame( -e -b 224 -m d )


REM Use bbMPEG to re-mux components
REM
REM Note: RunbbMPEG relies upon hard-coded parameters in default.ini
REM for input and output file names

copy default.ini "C:\Program Files\DVD2SVCD\bbMPEG"

"C:\Program Files\DVD2SVCD\bbMPEG\RunbbMPEG.exe" "%1"

del "C:\Program Files\DVD2SVCD\bbMPEG\default.ini"

BGane
16th December 2002, 21:16
markrb or dvd2svcd:

Ok - I've taken it this far, but I could use a little help, if you would, please?

There are a couple of files that I have processed through this batch where the end product will not play properly. Example: Start with file called, say, abc.mpg. Process it through the batch file. Resulting file abc00.mpg (1) is a different size than the original (ie. larger), and (2) video plays haltingly - stopping and starting - as if in slow motion. Not good!

This is where I need to borrow a little of your expertise with bbMPEG. Are there parameters that are used in the bbMPEG INI file that are more suited to the DVD2SVCD process but which could be tweaked to be more appropriate for my task?

markrb
16th December 2002, 23:16
It sounds like your mux rate was wrong. Try muxing it again and watch for overflow errors. If you get any you will need to adjust the force mux rate higher until the errors go away.

Mark

BGane
16th December 2002, 23:54
Hmmm. Right you are, Mark. In fact, in the messages from bbMPEG, there is a NOTE: Mux rate may be too low for data rate, watch for PTS/DTS underflows. And in fact, that is what I am getting - PTS and DTS underflows.

Can you help me a little bit to understand what the mux rate is? Will I have to somehow determine a mux rate for each file, or is there a general purpose number that can be used? I suppose that with DVD2SVCD it is easier, as you have control of how the source is generated. I note that the standard bbMPEG ini file includes a userMuxRate of 3528.

markrb
17th December 2002, 01:40
I don't know what it is exactly, but that doesn't stop me from making it work.

The only way to get it to work is to keep adding to that mux rate number until the errors go away. You are looking for the lowest possible number without getting an error. I would start at about 500 points higher and raise or lower the mux rate until you get it right.

If you are doing a Mpeg-2 SVCD you can set the Mux rate to 0 and set the computed bitrate of BBmpeg to use maximum. This is the automatic setting, but for VCD Mpeg-1 this doesn't work.

Just click on the BBmpeg Output Settings on the BBmpeg tab for the place to alter the mux rate.

An example from my own experience is a CBR Mpeg-1 bitrate of 1500 plus 224 audio and I use about 4420 as the mux rate.


Mark

BGane
17th December 2002, 03:55
I found the following detailed response that describes how to set the mux rate from the man himself - Brent Beyeler - author of bbMPEG. He was responding to a question from someone who was having overflows playing a 14Mb/s data stream.

The DTS (Decoding Time Stamp) and PTS (Presentation Time Stamp) timestamps are when the decoder is supposed to decode and display the frame relative to the SCR (System Clock Reference) timestamp. The SCR can be thought of as the time the decoder is supposed to read
the data from the disk.

Every packet of data in the mpeg file has an SCR timestamp and this timestamp is the value the system clock should be at when the packet is read. Usually, a decoder will start the system clock when it starts reading an mpeg stream (the initial value of the system clock is the SCR from the first packet of data, usually zero but it does not have to start at zero). The DTS timestamp tells the decoder to decode the frame when the SCR time reaches the DTS time, likewise for the PTS timestamp. Usually, the DTS/PTS timestamps indicate a time later than the SCR of the packet the video/audio appear in. For example, if the SCR of a packet of video data is 100ms (meaning it is read from the disk 100ms after the start of playback), the DTS/PTS values would be something like 200/280ms, meaning when the SCR reaches 200ms this video data is supposed to be decoded and then 80ms later it is to be displayed (the video data is held in a buffer until decoding time).

Underflows usually occur when the video data rate is too high with respect to the muxing rate. If the muxing rate is 1000000 bits/sec (meaning the decoder will read 1000000 bits/sec from the file), but the video bitrate is 2000000 bits/sec (meaning 2000000 bits/sec are needed to display a seconds worth of video data), the video data is not being read off the disk fast enough to read all the video bits needed for one second. In this case the DTS/PTS timestamps will indicate the video was to be decoded/displayed before it is read from the disk (the DTS/PTS timestamps are earlier in time than the SCR timestamps of the packet they are contained in). Now depending on the decoder, this can be a problem or not (although the MPEG file is not MPEG compliant as there should be no underflows!). Some decoders (most notably PC based players) read the file as fast as needed to display the video, ignoring the SCR as needed.

Note that in the listing you provided, the average video bitrate is ~3Mbps (3000000 bits/sec) but that it peaks as high as 14Mbps (rather large, DVD is limited to 9.8Mbps). This means the mux rate needs to be large enough to handle the 14Mbps part and bbMPEG’s calculated mux rate is sometimes too low leading to underflows. Are you intending the video bitrate to be so high? This is beyond DVD specifications and probably not playable on most standalone players. If not, I would either increase the mquant value from 1 or enter a maximum bitrate of 9Mbps on the Video Settings page to keep the bitrate down a bit. If you do want the video bitrate to be that high, you will need to increase the mux rate. From the listing provided, bbMPEG determined the mux rate to be 14706800 bits/sec or 1838350 bytes/sec (the Total data rate : 1838350 bytes/sec (14706800 bits/sec) line). The value you would enter in the Force Mux Rate field would be the bytes/sec value divided by 50. So I would start with 36767 (1838350 / 50) and increase the value from there until you get rid of the underflow messages.

Now, in my case, I am finding that most of the MPEG1 files that I have are encoded with average data rates of around 170,000 bits/second. For these, the mux rate of 3528 (DVD2SVCD default) is sufficient because 3528 x 50 = 176,400. However, the problematic files have average bit rates as high as 263,000 bits/second. Hence the mux rate is too low.

So - now I know what a mux rate is. But I'm still not sure that I understand what, if any, would be the negative consequences of setting a mux rate to an arbitrarily high number. Any comments?