PDA

View Full Version : Trimming A&V in AviSynth


FlezZ
25th March 2007, 17:52
Hi there.

I have been looking for something, for making frame accurate cuts on my mpeg2 streams. Since now I've had to choose between making not so accurate cuts with I- and P-frames or encode the cut parts.

I have mp2 audio on my streams. I will be encoding the mpeg2 video to xvid. So I found out, that AviSynth has a nice, frame accurate trimming option. I'm quite new to AS scripting, so I'd need a few pointers here. First of all, is it possible at all to trim the mp2 file too then? I mean, if I just add 'trim(4,28897)' to the avs script, it won't be doing anything about the audio, so the result will be out of sync, if I won't get the audio trimmed too somehow. So I'd probably have to load my mp2 file to the script somehow? I encode the mp2 file to mp3 vbr. But as far as I know, one can't encode audio with avs script file.

Well, this probably came out a bit confusing, but I hope you'll understand what I'm trying to achieve here.:rolleyes:

joseph5
25th March 2007, 18:12
To load the mp2 file in the script, use NicMPASource, then AudioDub to have the video and audio streams together. After all this, put the Trim function and everything should be synchronized.

mgh
25th March 2007, 18:24
Use dgindex for frameserving with this script for template

mpeg2source("__vid__")
aud="__aud__"
a=rightstr(aud,3)
b=rightstr(aud,10)
c=leftstr(b,4)
d=value(c)
e=d/1000
audiodub(last,mpasource(aud)).delayaudio(e)

If your d2v file is x.d2v, x.avs will be saved in same folder
Add trims as you like.
Load in virtualdub, save uncompressed wav file. Convert to xvid with no audio.Convert wav to mp3. Mux the two with virtualdubmod

FlezZ
25th March 2007, 18:47
Thanks for the responses.

I tried with the template. I checked the outcome avs file, and I saw that no audio file had been added (aud=""). You probably meant this to be done with a stream that hadn't been demux-ed yet. Well, I demux everything with ProjectX, but when I add the audio path to the brackets manually, it wouldn't hurt, right? :)

neuron2
25th March 2007, 18:53
The aud line should be this:

aud=nicac3source("__aud__")

or

aud=nicac3source("__aud__",2)

You can replace __aud__ with the actual name of the file demuxed by DGIndex.

FlezZ
25th March 2007, 19:14
If I change the audio line to 'aud=nicmpasource("asd.mp2")', vdubmod starts giving open failure errors pointing at the lines following that line.

I changed it to 'aud=("asd.mp2")' and I also changed the last line to 'audiodub(last,nicmpasource(aud)).delayaudio(e)' and vdubmod opens the script without any errors.

neuron2
25th March 2007, 20:24
You must have messed up the script that failed. If you don't post the whole script, we can't tell you where you went wrong.

FlezZ
26th March 2007, 14:03
Well, this is what my script looks like, and it does open in vdubmod without any errors.mpeg2source("__vid__")
aud=("__aud__")
a=rightstr(aud,3)
b=rightstr(aud,10)
c=leftstr(b,4)
d=value(c)
e=d/1000
audiodub(last,nicmpasource(aud)).delayaudio(e)
But when I just changed the audio line to what you suggested, it would have looked like thismpeg2source("__vid__")
aud=nicmpasource("__aud__")
a=rightstr(aud,3)
b=rightstr(aud,10)
c=leftstr(b,4)
d=value(c)
e=d/1000
audiodub(last,mpasource(aud)).delayaudio(e) and that would give me errors.

neuron2
26th March 2007, 14:20
Oh, sorry, I didn't catch on to the fact that you were parsing the delay out of the filename. Your script is correct. That's what I get for not paying full attention. :)

IanB
26th March 2007, 15:25
...
e=d/1000.0 # Force floating point division
...

FlezZ
27th March 2007, 19:07
I have done a number of encodes now, and I'm pretty satisfied with the results. :rolleyes:

I thank you all for helping me out there. :)