Log in

View Full Version : DGIndex and handling demuxed audio


vampiredom
24th September 2008, 21:30
Hi all --

I'm trying to come up with a "swiss army knife" for handling demuxed audio from DGIndex using the AVS template option:

mpeg2source(__vid__)
DemuxedAudioSource(__aud__, __del__)

function DemuxedAudioSource(clip c, string "filename", float "delay", int "SampleRate", int "SampleBits", int "Channels") {
ext = RevStr(LeftStr(RevStr(LCase(filename)), 3))
delay = Default(delay, 0.0)
SampleRate = Default(SampleRate, 48000)
SampleBits = Default(SampleBits, 16)
Channels = Default(Channels, 2)


a = (ext == "wav") ? WavSource(filename) :
\ (ext == "dts") ? NicDTSSource(filename) :
\ (ext == "mpa" || ext == "mp1" || ext == "mp2") ? NicMPASource(filename) :
\ (ext == "aac") ? NicAACSource(filename) :
\ (ext == "pcm") ? NicLPCMSource(filename, SampleRate=SampleRate, SampleBits=SampleBits, Channels=Channels) :
\ DirectShowSource(filename)

AudioDub(c,a)
DelayAudio(delay)
}
Any thoughts on this? Improvements? Also: I have limited experience with LPCM and NicAudio. What's the difference between NicLPCMSource() and NicRawPCMSource()?

Thanks.

mikeytown2
25th September 2008, 00:50
Give BassAudio A try
http://forum.doom9.org/showthread.php?t=135855

Or FFMpegAudio (1.21 version)
http://forum.doom9.org/showthread.php?t=127037

try catch statements might come in handy for handling the last resort option.
http://avisynth.org/mediawiki/Control_structures


Edit:
I would use FindStr to find the "." since the file could have more/less then 3 char for it's extension.
http://avisynth.org/mediawiki/Internal_functions/String_functions

Stickboy's SelectByString might be useful?
http://avisynth.org/stickboy/

vampiredom
25th September 2008, 01:57
Thanks, mikeytown...

About FindStr / string methods in general: Well, this kind of thing always annoys me. I'm used to Perl and using Regex to find replace strings :) Ahhh... I guess my question is this: Does DGIndex ever write audio files with 4 char extensions? The only possible one I can think of here is ".lpcm", in which case the last 3 chars are still "pcm". Nifty coincidence, eh?

FFMpegAudio seems a little bit "beta" at this point, no? I'll have to give BassAudio a try. Does it work well? What would the advantages be over NicAudio, for example?

I certainly thought about try / catch... Perhaps I should try NicLPCMSource and then NicRawPCMSource if that fails. Obviously, I should also check to see if __aud__ is blank or not. I need to test what DGIndex gives for __aud__ + __del__ when there is no audio.

This is part of a larger project. I'm working on building a command line utility for batch processing DV and HDV captures. I'd like my .exe to handle all of the "sourcing" automatically, so I can use generic script templates that will work with both AVI and MPEG2 sources in a way that's transparent to the user. That's another post for a another time, though. :)

Thanks again.

tebasuna51
25th September 2008, 10:00
Any thoughts on this? Improvements? Also: I have limited experience with LPCM and NicAudio. What's the difference between NicLPCMSource() and NicRawPCMSource()?
Use the last NicAudio.dll v2.0.2 (http://www.codeplex.com/NicAudio)

- Don't exist now NicRawPCMSource, NicMPASource and never NicAACSource. You forget NicAc3Source

- pcm can be for audio data without header (then you must know SampleRate, SampleBits and Channels) in big-endian format and a specific channel order.

- raw can be also audio data without header but little-endian and channel order like wav uncompressed.

- RaWavSource can replace WavSource for uncompressed audio data, if the wav contain mp3/ac3 data (VirtualDub output for instance) you must rename to the appropriate extension. RaWavSource can be used for files >4GB wav, WAVE_EXTENSIBLE, w64, rf64, raw, ...

- Bass library can be used for aac, m4a, ogg, flac, ...

Then maybe:
a = (ext == "wav") ? RaWavSource(filename) :
\ (ext == "w64") ? RaWavSource(filename) :
\ (ext == "raw") ? RaWavSource(filename, SampleRate=SampleRate, SampleBits=SampleBits, Channels=Channels) :
\ (ext == "pcm") ? NicLPCMSource(filename, SampleRate=SampleRate, SampleBits=SampleBits, Channels=Channels) :
\ (ext == "dts") ? NicDTSSource(filename) :
\ (ext == "mpa" || ext == "mp2" || ext == "mp3") ? NicMPG123Source(filename) :
\ (ext == "ac3") ? NicAc3Source(filename) :
\ BassAudioSource(filename)

vampiredom
25th September 2008, 16:23
Excellent adivce, tebasuna! That's exactly what I was looking for. I'm not sure how I forgot "ac3" :) Actually, it appears I deleted the line accidentally. I do specifically remember typing it.

When DGIndex demuxes AAC, what extension does it give?

Guest
25th September 2008, 16:24
The extension is "aac". :)

vampiredom
25th September 2008, 18:15
Thanks "DG" of "Index" frame :) Great tool. It was actually thanks to your site that I got into AviSynth and VirtualDub in the first place. I am still hoping (not nagging) that one day DGIndex / DGDecode will be able to handle the audio natively without demuxing. That would be supremely cool, but I'm sure there are reasons why this would be impractical or impossible -- otherwise I imagine it would have been done already.

vampiredom
3rd October 2008, 19:47
neuron2 --

Can you please provide me with the "rules" for how DGIndex's demuxed audio tracks are named? I'm trying to create a regular expression to match any/all demuxed tracks from (and only from) a particular project.

The problem is that, say, we have "foo.d2v" then...
/^foo(.*?)\.(ac3|aac|lpcm|wav|mp2)$/

would also match audio files for "foo part2.d2v", which I don't want. Can you please tell me the exact "formula" for how the audio file names are derived that applies to all scenarios and possible formats (if possible)?

Much appreciated!

Guest
3rd October 2008, 20:27
Have a look at getbit.cpp in the source zip. Search for the OpenAudio(szBuffer, "wb", 0) calls and then look at how szBuffer is initialized.

vampiredom
3rd October 2008, 21:12
Thanks! Wow... there is more variation in the naming than I thought. I should be able to figure it, though. Very interesting.

vampiredom
4th October 2008, 03:33
I movewd discussion over here: http://forum.doom9.org/showthread.php?t=141647

It seems more appropriate, as I've pretty much moved past the AviSynth end of things. Thanks, all.