PDA

View Full Version : MPASource: direct MP1 MP2 MP3 reading


WarpEnterprises
27th December 2002, 22:10
Hi!

I made an AviSynth 2.0 plugin which can read mp2 and mp3.
(the decoding is based on mpg123 in a version from the lame project)

You simply put

MPASource("filename.mp3", normalize=false)

and get the audio.

Trimming and seeking is supported, although it may be a little slow.

When opening a script the whole file is scanned (fast without normalize, 5x slower with normalize) which can take 20-120 sec for one hour video, but this is the only way to always get the exact sample count (don't use it while preparing the video filters).

MPASource (http://www.avisynth.org/warpenterprises)

Koepi
27th December 2002, 22:18
Hu, I can't imagine what it's all good for, but I think the purpose is to feed it with i.e. an avi+it's dewmuxed soundtrack to create a SVCD or something similar.

In that matter, since I only use ogg in ogm (and sometimes find avi+ac3), would it be possible to extend that plugin with that?

Like a general "CompressedAudioSource()"?

Cheers,
Koepi

WarpEnterprises
27th December 2002, 22:29
My main purpose is for MP2 source (DVB or SVCD reencoding).
It completely depends on mpg123 and can read only what this líbrary can read.
So I fear it can't.

bb
28th December 2002, 18:49
As far as I know, DSPguru is planning on making a BeSweet version for AviSynth (BeSynth). That one would do the trick, but I don't know when this will be finished.

bb

BaronVlad
29th December 2002, 15:59
Hi WarpEnterprises,

thanks alot. This is the most useful Plugin that I have seen for a while as a Newbie in avisynth.

Now I am able to cut out the commercials of my DVB caps without pvacut and at the frame I like to, very easy to use, 100 % in sync. Great.

:)

WarpEnterprises
30th December 2002, 21:35
Compiled a version for AviSynth 2.5
mpasource for AviSynth2.5 (http://www.avisynth.org/warpenterprises)

jcsston
31st December 2002, 00:54
Great plugin! Now I don't have to decode and normalize the audio of my TV captures :)

BaronVlad
31st December 2002, 17:22
@Warpenterprises:

As you are from Austria, you may be able to read something in German language :D I have implemented your great plugin in my little DVB guide here:

http://doom9.de/extern_guides/digiCaptureGuide/Inhalt.html

Happy new year.
:)

WarpEnterprises
1st January 2003, 20:44
Are there sometimes corrupt audio tracks in DVB?
It would be interesting (if this is a common thing) how this could be handled.

soulfx
2nd January 2003, 04:38
Great plugin WarpEnterprises, this saves me from having to convert my TV caps MP2 audio tracks into WAVS.

It's worked great as far as I can tell. No bugs or crashes to report on my end.

I do have a question though. How can I handle delayed audio? When I demux an audio track with DVD2AVI and I get something that has a delay of 10ms, does this filter compensate for that? Do I need to delay the audio by some other method?

jcsston
2nd January 2003, 06:09
You use a script like this

video = mpeg2source("masterpiece_part3_vd.d2v")
audio = MPASource("MASTERPIECE_PART3_VD MPA T01 DELAY -123ms.mpa", normalize=false)
DelayAudio(audio,-0.123)
AudioDub(video, audio)

This is actually exactly what my small program I made MPEG-2 to VirtualDub does.
Select an MPEG-2 file
Create a d2v project with DVD2AVI commandline
Decode the mpa to wav with MADPlay, use DirectShow Decoder, or Use the MPASource AviSynth plugin
Write a AviSynth script
Open the script in VirtualDub
Download (http://webjory.tripod.com/vb/)
Put the mpasource.dll in your AviSynth Plugin dir.

@WarpEnterprises: Is it ok for me to distribute the .dll with my program?

Si
2nd January 2003, 10:56
@jcsston
Brilliant:D :D :D

The simplest way yet to get a normal MPEG-2 into an avi that doesn't need a degree in video processing.

Is there an existing thread/forum to discuss your program - you've made a killer app.

And should be easier/quicker if you use WarpEnterprises plugin :D

regards

Simon

jcsston
2nd January 2003, 19:03
@siwalters
I made a new thread here (http://forum.doom9.org/showthread.php?s=&threadid=41896)
I also have an older thread at the 'Unofficial VirtualDub Support Forums' here (http://virtualdub.everwicked.com/index.php?act=ST&f=16&t=1018)

onesoul
2nd January 2003, 19:43
Originally posted by BaronVlad
Now I am able to cut out the commercials of my DVB caps without pvacut and at the frame I like to, very easy to use, 100 % in sync. Great.

Could you post an example script of a cutting you made using mpasource?

Thanks :)

cweb
3rd January 2003, 17:27
Sometimes there are clicks. To eliminate them I'm currently
using Winamp to convert the mp2 file into a wav using the MAD plugin.
The MAD plugin has a feature to remove this kind of clicks and pops.
Any utility to remove clicks should replace them possibly with silence,
so that audio sync is not lost.

It would be useful if mpasource would handle this automatically.

Thank you anyway. I will be experimenting with mpasource.

Originally posted by WarpEnterprises
Are there sometimes corrupt audio tracks in DVB?
It would be interesting (if this is a common thing) how this could be handled.

BaronVlad
3rd January 2003, 17:47
Originally posted by onesoul
Could you post an example script of a cutting you made using mpasource?

Thanks :)

I think this is a misunderstanding.

I have my avs created from GKnot or written on my own and add the audio with mpasource. After this I load the new avs with VDub Mod and cut there. After this compress to divx:

http://doom9.de/extern_guides/digiCaptureGuide/Avisynth.html

(example for avisynth script, explanation in German)

DVB and audio: I have a problm with my source (antenna = DVB-T). The most interesting channels have not much power yet and because of this I have damaged mpeg streams from time to time (like a broken SVCD). And then there are also the probs with the audio. But they will fix it in March I think, no other audio problems apart from that occured

onesoul
3rd January 2003, 18:25
Oops :o

I don't want to put down the work being done but wouldn't make more sense to use an universal language, which is english, so that useful information wouldn't spread out for just some guides?

Cheers

BaronVlad
3rd January 2003, 18:41
Originally posted by onesoul
Oops :o

I don't want to put down the work being done but wouldn't make more sense to use an universal language, which is english, so that useful information wouldn't spread out for just some guides?

Cheers

You may be right, but I had not so much time and my "natural born" language is German and i am more active in the german board. There also is an analogue Capture Guide that is waiting for its translation, so everybody who is able to do so, feel free to contact me ! There were some thoughts about that in the past, but that was the last I heard from it somehow. :eek: I think the analogue stuff should be done when the VCR function of Joe Redfish is integrated into VDub Mod but however. I would be happy if someone would translate all this. :)

WarpEnterprises
3rd January 2003, 21:14
Originally posted by cweb
Sometimes there are clicks. ....
It would be useful if mpasource would handle this automatically.

Thank you anyway. I will be experimenting with mpasource.

Could you mail me a short (<2MB) example?

peche at aon dot at.

BaronVlad
30th January 2003, 22:59
hi WarpEnterprises,

let me allow one short question... would it be possible for you to update your great plugin to avisynth2.5 beta ... that would be very nice and highly appreciated...


thanks for your efforts

regards BaronVlad:)

WarpEnterprises
31st January 2003, 08:46
It's there since many weeks :)

But if you wait till weekend I will make a version which creates a little index file so that it needs to scan the mp2 only once.

Now I have a DVB myself and it is too annoying to wait evertime 60sec to open the AVS.

BaronVlad
31st January 2003, 10:58
:stupid: Yes it is. I had an "old" Version for avisynth 2.5, it didnt work so far, I read nothing here, so I didnt look at your page, think next time I should do this before posting...and I used 2.07 or the old 2.5 all the time :scared:

Thanks, and I will get the newest version with the scan also when it is ready...:)

WarpEnterprises
31st January 2003, 23:46
The new version is THERE (http://members.aon.at/archi/warpenterprises)

sh0dan
1st February 2003, 00:04
@WE: Would you consider doing an AC3Source - Marc's virtually useless, and we are left without a source (again). I guess Azid would be a good place to start, but I really don't know.

If you need _any_ assistance in the AviSynth interfacing - I'd be more than willing to help!

WarpEnterprises
1st February 2003, 00:19
Is azid at sourcefourge/opensource?
Could you point me to some sources?
(somewhere a AC3 lib was mentioned - I don't find it.)

If I can use it similarily easy as mpg123, it should be possible.

sh0dan
1st February 2003, 00:32
Azid is a library (dll) that can be downloaded from d9's software page. The dev-kit is in the sources section also here. I assume this is also the one DSP-Guru is using.

You could also have a look at http://liba52.sourceforge.net/ or maybe ffmpeg.

kitsaros2000
1st February 2003, 02:04
WarpEnterprises if you can add ac3 - source in your plug in i wll be glad !!!!!! (AC3 Dowbnstreaming to stereo)

SiXXGuNNZ
1st February 2003, 03:02
Originally posted by Koepi
since I only use ogg in ogm

what is ogg in ogm?

I use the search function of this forum so many times it can hurt the brain, lol

maybe I do not know how to word my searches, but I rarely can find what I want just by searching.

is there a guide to this ogg in ogm? I have seen it mentioned alot lately, and I have no clue what it is.

ffroms
1st February 2003, 14:12
OGG is audio format and OGM is container for video and audio. Try to look in New A/V Formats or read doom9's guide about OGM.

FFS

sillKotscha
1st February 2003, 18:02
vorbis is the audio-format and OGG the container for Vorbis... and is the container for video as well!! but due to windows video and audio content need different extensions, otherwise windows wouldn't know how to render the specific content propperly. That's why (I guess it was Koepi ;) ) introduced OGM to us. Now windows knows that a file with ogm as extension contains audio + video.

That's why he is talking about ogg in ogm... ogm as a 'nutshell' for Ogg/Vorbis audio and [e.g. DivX, Xvid, MSMPEG4v2 or whatever] avi video...

SiXXGuNNZ
1st February 2003, 20:57
lol, yeah, after the post, I was tooling around in vdubmod and noticed the OGM menu :eek:

thanks guys :D

sh0dan
1st February 2003, 20:59
One more to consider:

http://ac3filter.sourceforge.net/

mrwho
29th March 2003, 01:00
Is it possible that there's a timelenght-limit for the files mpasource can read ?

A mpa-file from dvd2avi with 5 hours ! returns in VirtualDubMod
0 Frames, but no Error-Message ?

avisynth 2.51
dvd2avi 1.76
mpasource v2
virtualdubmod 1.4.13

Smaller Files with the same avisynth-script work without any problem.

symonjfox
30th March 2003, 18:40
I had a problem using CCE. Here's my script:

LoadPlugin("D:\PROGRA~1\avisynth 2.5\plugins\mpeg2dec3.DLL")
LoadPlugin("D:\Programmi\avisynth 2.5\plugins\mpasource.dll")
V=mpeg2source("E:\prova.d2v",ipp=False,CPU=4)
V=Bilinearresize(V,352,576)
V=Letterbox(V,8,8,8,8)
A=mpasource("e:\biancaneve.mpg.mpa", Normalize=True)
AudioDub(V,A)
Converttoyuy2
Trim(12989,131445)

When I try to use the multipass option in CCE, I noticed that it performs just 1 pass and then crashes (CCE don't close and reload the source file). I think there's a problem on seeking, I think it works just from the beginning to the end (and no turning back).

Yes, I know that I can encode video and audio separately (so, doing a script without any audio), I just tell you a bug.
However is a good plugin, I'm gonna use it a lot with my DVB captures :)

WarpEnterprises
31st March 2003, 10:06
could you both please tell me the content of the little .d2a file which was created and the cce version you use?
At first tests the error are not reproduceable (there should not be a limit for the length).

It should contain 3 numbers:

bytes of the source file
bytes of resulting PCM data
max volume found


precise bug reports are always welcome !

[EDIT: found the limit! AviSynth 2.0x cannot handle audio with more than 2^31 PCM bytes ~ 3hours stereo. This was expanded in 2.5 but I forgot to adapt in the plugin - will do it asap]

sh0dan
31st March 2003, 11:52
It should be approx 11 hours with 48khz stereo IIRC.

Be sure to check to check bounds on every sample request - meaning - it is possible for any filter to request more samples than actually exists.

Actually it could also be put into the cache to eliminate these requests, and once and for all make these problems go away (even though I don't know if this is the case).

WarpEnterprises
31st March 2003, 14:49
Ah, I see.

I already check on each GetAudio, but used internally a 32bit int to count the BYTES of the samples.

So your 11 hours are

2.147.483.647 / 48000 / 3600

but this needs 4 bytes each sample so only 11/4 hours in my plugin...

btw is __int64 the correct declaration for such a 64bit counter?

scmccarthy
31st March 2003, 17:23
@WarpEnterprisesbtw is __int64 the correct declaration for such a 64bit counter? What an excuse to show you code from my monochrome plugin! Love the name and avatar by the way.

I am not 100% sure how you want to use __int64, so there's less confusion if I just show you how I use it with a little explanation(been listening to Brittish shows).

from monochrome:

// Note that my variable names are borrowed from the Levels filter.
// Originally, I assumed that Y could not go higher than 240.
// By experiment, I discovered Y can be treated like the unsigned char it is.
// Like unsigned char, its limits are 0..255 inclusive.

double contrast = level/32 + 1.0;
int input_high = int(255/contrast + 1);

__int64 Cb64 = ((__int64)Cb<<56) | ((__int64)Cb<<48) | ((__int64)Cb<<40) | ((__int64)Cb<<32) | ((__int64)Cb<<24) | ((__int64)Cb<<16) | ((__int64)Cb<<8) | (__int64)Cb;
__int64 Cr64 = ((__int64)Cr<<56) | ((__int64)Cr<<48) | ((__int64)Cr<<40) | ((__int64)Cr<<32) | ((__int64)Cr<<24) | ((__int64)Cr<<16) | ((__int64)Cr<<8) | (__int64)Cr;

if(vi.IsYV12()){
if(_fast){ // fast mode disables level, It is a straight copy.
env->BitBlt(dstpY,dst_pitchY,srcpY,src_pitchY,row_sizeY,heightY);
}
else{
for (int y = 0; y < heightY; y++) {
for (int x = 0; x < row_sizeY; x++)
if (srcpY[x] < input_high) // default input_high is 205
dstpY[x] = srcpY[x] * contrast; // default contrast is 1.25
else
dstpY[x] = 255;
srcpY += src_pitchY;
dstpY += dst_pitchY;
}}

for (int y = 0; y < heightUV; y++) {
for (int x = 0; x < row_sizeUV; x++) {
dstpU[x] = Cb64;
dstpV[x] = Cr64;
}
dstpU += dst_pitchUV;
dstpV += dst_pitchUV;
}}

This is how to pack it in C, but it is also how you declare it in C for use in assembler, which I never mess with.

Stephen

mrwho
31st March 2003, 18:29
Glad that you found the bug already WarpEnterprises.

Had already a bad feeling the i saw


403209774
2540219904
0

in my .d2a-file (4hours)

*Freude* :)

WarpEnterprises
3rd April 2003, 14:07
AviSynth 2.5 version with fixed "3 hour bug" uploaded.
Look at the "www" button under the message.

symonjfox
6th April 2003, 19:02
The problem I posted above is gone ... I just have to wait some time, when I did my first tests there was another application running so it seems it crashed, while its not real. I'm sorry about that.

I have a question: is it possible to read MPA streams in MPEG 2 PS files?

so

MPEG2SOURCE("c:\video.d2v")
MPASOURCE("c:\video.mpg")

I tell you this because I have lot of synch problems using my DVB captures. I use PVASTRUMENTO, but sometimes appends that the MPA is out of synch with M2V, and I have to manually delay audio.

I precise that my board only captures in MPEG 2 PS streams, not TS or PVA, so my capture is a valid PS file (I use PVASTRUMENTO just to cut bad parts and resynch audio).

Maybe it should be nice if an MPEG2 PS filter will come up, but it's still far to be developed (if I am a developer, I would work on it).

MPEG2PSSOURCE("C:\video.mpg") :rolleyes:

WarpEnterprises
6th April 2003, 23:27
I'm sorry but after thinking a little about it demuxing seems to be not that easy and beyond what is possible to me.

Is the only thing you have to do add a DelayAudio of the muxing delay (which PVStr tells you) or are there more troubles?

symonjfox
7th April 2003, 12:09
I'm sorry, but I was wrong. Your DLL works fine, and PVASTRUMENTO, too. I have a DVB card from few time, and after spending 1 day on it, I discovered that it's just my fault :eek:

The idea of a MPEG2PSDEC is still a nice idea, maybe someone will work on it ...

WarpEnterprises
14th April 2003, 22:35
Found a bug when using the "normalize" parameter (I used only the positive max volume which can be quite different from the negative max volume)

New versions uploaded.

DDogg
14th April 2003, 22:42
WE, I just wanted to send up a simple "Thank you" for this dll and the continuing upkeep. It solves a lot of problems for me and makes several chores much easier.

WarpEnterprises
15th April 2003, 00:28
I uploaded 2 wrong ZIPs for a short time - sorry.

PLEASE MAKE SURE YOU DO _NOT_ USE ...20030414.zip

That's the best I can imagine to hear if it's not only nice but even useful. :)

DDogg
15th April 2003, 16:42
W.E., your website is a great resource for the group:http://www.avisynth.org/~warpenterprises/

Why don't you breakdown and put it in your sig so folks can see all the goodies you have collected for us there :)
/edit
:o Ahhhh, heck, yep, I see the www button now. Many don't use it so I didn't even think about looking for it. I am too used to looking at the sig. The gods conspire to make me look like an idiot, but I don't need the extra help :rolleyes:

celtic_druid
15th April 2003, 17:10
Just click the www button.

WarpEnterprises
15th April 2003, 22:00
The collection was not finished until now, so I wanted to keep it a little "secret".

WarpEnterprises
10th January 2004, 00:09
Thanks to sh0dan I am glad to announce:

MPASource with FLOAT-SAMPLE output

As you may know AviSynth can handle float-samples - this is the way to feed it into.
The main advantage: there is no clipping anymore!

Previously if a sample value was bigger than 32767 it was clipped which sounds bad, even if you normalized it (with the parameter or with Normalize).

I made some code cleanup which will give a little speed boost and the function
BufferAudio (renamed from CacheAudio as this already exists)
is added in the DLL to assist when nonlinear access is needed.
It does not hurt if you always use:

MPASource(...).BufferAudio()

In upcoming versions of AviSynth this buffering is built-in and automatic.

(as always on the AviSynth filter collection - click my www button)

cweb
3rd July 2004, 10:34
Hi

mpaSource("all MPA T01 DELAY 0ms.mpa", normalize = true).BufferAudio()

gives me blank audio. The source file is dvb-s, 48khz 192kbs.
I had to change it to normalize=false to get sound with the actual audio.

Thanks for a great plugin by the way!

WarpEnterprises
3rd July 2004, 22:56
Please use
- latest AviSynth
- float mpasource
- NO bufferaudio (it's already built-in in AviSynth)

Does it then work with normalize and can you post the content of the .d2a file (please delete it first!) ?

WarpEnterprises
20th February 2008, 22:47
New version:
- without mpeg1 Layer1 support (ID3 tags were misidentified as Layer1)
- global variables removed which prohibited to use it more than once in a script reliably
- EXIT on some rare stream errors removed which could close the application
- some bugfixes from the mpg123-lib of the LAME project which were made after mpasource.

tebasuna51
9th April 2008, 04:21
New version:
- without mpeg1 Layer1 support (ID3 tags were misidentified as Layer1)
- global variables removed which prohibited to use it more than once in a script reliably
- EXIT on some rare stream errors removed which could close the application
- some bugfixes from the mpg123-lib of the LAME project which were made after mpasource.

A bug is introduced in this version, when use 'pipe' commands like:

Bepipe --script "MPASource(^sample.mp2^)" | neroaacenc -if - -of sample.mp4 -q 0.5

the audio data is corrupted by text messages like:

MPEG 1.0 layer II, 384 kbit/s, 48000 Hz stereo

The problem is in the mpg123/common.c:
--- D:/NicAudio/mpg123/common.c Mon Feb 18 23:30:44 2008
+++ D:/Releases/common.c Wed Apr 09 03:12:44 2008
@@ -208,7 +208,7 @@
static const char *modes[4] = { "stereo", "joint-stereo", "dual-channel", "mono" };
static const char *layers[4] = { "Unknown" , "I", "II", "III" };

- fprintf(stdout,"MPEG %s layer %s, %d kbit/s, %ld Hz %s\n",
+ fprintf(stderr,"MPEG %s layer %s, %d kbit/s, %ld Hz %s\n",
fr->mpeg25 ? "2.5" : (fr->lsf ? "2.0" : "1.0"),
layers[fr->lay],
tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index],

In old version is correct with 'stderr'.