Log in

View Full Version : Seperate audio?


Dot50Cal
8th July 2007, 01:55
Im having some trouble here, I have a video which doesnt contain audio (its tmpeg project file format) but I cant see to find the proper way to specify an outside audio source? At the moment this is what I have:

LoadVFAPIplugin("G:\Encoding\Encoding Tools\Tmpeg\TMPGEnc.vfp","TMPGsource")
source = TMPGsource("TVCMFINA.tpr")


AAA = source.trim(22211,38420)
BBB = source.trim(38923,43006)
CCC = source.trim(43507,43893)

final = (AAA+BBB+CCC).flipvertical

AS = WavSource("TVCMFINA AC3 T01 2_0ch 256Kbps DELAY -2ms.wav").trim(22211,38420)
BS = WavSource("TVCMFINA AC3 T01 2_0ch 256Kbps DELAY -2ms.wav").trim(38923,43006)
CS = WavSource("TVCMFINA AC3 T01 2_0ch 256Kbps DELAY -2ms.wav").trim(43507,43893)

audiofinal = (AS+BS+CS)


A = final.trim(0,389).crop( 0, 0, -8, -11).LanczosResize(640,480) # Intro
B = final.trim(390,670).crop( 4, 0, -10, -11).LanczosResize(640,480) # Shaded Right (Small)
C = final.trim(671,2214).crop( 6, 0, -8, -11).LanczosResize(640,480) # Stock Shots
D = final.trim(2215,3974).crop( 6, 0, -18, -11).LanczosResize(640,480) # Shaded Right (Large)
E = final.trim(3975,4186).crop( 8, 0, -10, -11).LanczosResize(640,480) # Shaded Right 2
F = final.trim(4187,4360).crop( 6, 0, -18, -11).LanczosResize(640,480) # Shaded Right (Large)
G = final.trim(4361,4405).crop( 8, 0, -10, -11).LanczosResize(640,480) # Shaded Right 2
H = final.trim(4406,4460).crop( 6, 0, -8, -11).LanczosResize(640,480) # Stock Shots
I = final.trim(4461,5311).crop( 6, 0, -18, -11).LanczosResize(640,480) # Shaded Right (Large)
J = final.trim(5312,5373).crop( 8, 0, -10, -11).LanczosResize(640,480) # Shaded Right 2
K = final.trim(5374,11170).crop( 6, 0, -18, -11).LanczosResize(640,480) # Shaded Right (Large)
L = final.trim(11171,11874).crop( 8, 0, -10, -11).LanczosResize(640,480) # Shaded Right 2
M = final.trim(11875,12109).crop( 6, 0, -18, -11).LanczosResize(640,480) # Shaded Right (Large)
N = final.trim(12110,12324).crop( 8, 0, -10, -11).LanczosResize(640,480) # Shaded Right 2
O = final.trim(12325,12493).crop( 6, 0, -18, -11).LanczosResize(640,480) # Shaded Right (Large)
P = final.trim(12494,12636).crop( 6, 0, -8, -11).LanczosResize(640,480) # Stock Shots
Q = final.trim(12637,12676).crop( 8, 0, -10, -11).LanczosResize(640,480) # Shaded Right 2
R = final.trim(12677,13916).crop( 6, 0, -18, -11).LanczosResize(640,480) # Shaded Right (Large)
S = final.trim(13917,15232).crop( 8, 0, -10, -11).LanczosResize(640,480) # Shaded Right 2
T = final.trim(15233,16204).crop( 6, 0, -8, -11).LanczosResize(640,480) # Stock Shots
U = final.trim(16205,20463).crop( 38, 8, -34, -21).LanczosResize(640,480) # Gameplay Credits
V = final.trim(20464,20681).crop( 8, 0, -10, -11).LanczosResize(640,480) # Shaded Right 2

AA = audiofinal.trim(0,389) # Intro
BB = audiofinal.trim(390,670) # Shaded Right (Small)
CC = audiofinal.trim(671,2214) # Stock Shots
DD = audiofinal.trim(2215,3974) # Shaded Right (Large)
EE = audiofinal.trim(3975,4186) # Shaded Right 2
FF = audiofinal.trim(4187,4360) # Shaded Right (Large)
GG = audiofinal.trim(4361,4405) # Shaded Right 2
HH = audiofinal.trim(4406,4460) # Stock Shots
II = audiofinal.trim(4461,5311) # Shaded Right (Large)
JJ = audiofinal.trim(5312,5373) # Shaded Right 2
KK = audiofinal.trim(5374,11170) # Shaded Right (Large)
LL = audiofinal.trim(11171,11874) # Shaded Right 2
MM = audiofinal.trim(11875,12109) # Shaded Right (Large)
NN = audiofinal.trim(12110,12324) # Shaded Right 2
OO = audiofinal.trim(12325,12493) # Shaded Right (Large)
PP = audiofinal.trim(12494,12636) # Stock Shots
QQ = audiofinal.trim(12637,12676) # Shaded Right 2
RR = audiofinal.trim(12677,13916) # Shaded Right (Large)
SS = audiofinal.trim(13917,15232) # Shaded Right 2
TT = audiofinal.trim(15233,16204) # Stock Shots
UU = audiofinal.trim(16205,20463) # Gameplay Credits
VV = audiofinal.trim(20464,20681) # Shaded Right 2

AudioDub(A+B+C+D+E+F+G+H+I+J+K+L+M+N+O+P+Q+R+S+T+U+V,AA+BB+CC+DD+EE+FF+GG+HH+II+JJ+KK+LL+MM+NN+OO+PP+QQ+RR+SS+TT+UU+VV)

As you can see theres a load of trims here, but all I would need is the audio that trims the actual video from the excess (which would be AAA+BBB+CCC). However I cant seem to find any documentation on this? Im assuming that trim isnt possible with wavsource, but it doesnt work with directshow either. Anyone?

IanB
8th July 2007, 04:35
LoadVFAPIplugin("G:\Encoding\Encoding Tools\Tmpeg\TMPGEnc.vfp","TMPGsource")
Video = TMPGsource("TVCMFINA.tpr")
Audio = WavSource("TVCMFINA AC3 T01 2_0ch 256Kbps DELAY -2ms.wav").DelayAudio(-0.002)

source = AudioDub(Video, Audio)

AAA = source.trim(22211,38420)
BBB = source.trim(38923,43006)
CCC = source.trim(43507,43893)

final = (AAA+BBB+CCC).flipvertical

Global W = 640
Global H = 480
A = final.trim( 0, 389).crop( 0,0, -8,-11).LanczosResize(W, H) # Intro
B = final.trim( 390, 670).crop( 4,0,-10,-11).LanczosResize(W, H) # Shaded Right (Small)
C = final.trim( 671, 2214).crop( 6,0, -8,-11).LanczosResize(W, H) # Stock Shots
D = final.trim( 2215, 3974).crop( 6,0,-18,-11).LanczosResize(W, H) # Shaded Right (Large)
E = final.trim( 3975, 4186).crop( 8,0,-10,-11).LanczosResize(W, H) # Shaded Right 2
F = final.trim( 4187, 4360).crop( 6,0,-18,-11).LanczosResize(W, H) # Shaded Right (Large)
G = final.trim( 4361, 4405).crop( 8,0,-10,-11).LanczosResize(W, H) # Shaded Right 2
H = final.trim( 4406, 4460).crop( 6,0, -8,-11).LanczosResize(W, H) # Stock Shots
I = final.trim( 4461, 5311).crop( 6,0,-18,-11).LanczosResize(W, H) # Shaded Right (Large)
J = final.trim( 5312, 5373).crop( 8,0,-10,-11).LanczosResize(W, H) # Shaded Right 2
K = final.trim( 5374,11170).crop( 6,0,-18,-11).LanczosResize(W, H) # Shaded Right (Large)
L = final.trim(11171,11874).crop( 8,0,-10,-11).LanczosResize(W, H) # Shaded Right 2
M = final.trim(11875,12109).crop( 6,0,-18,-11).LanczosResize(W, H) # Shaded Right (Large)
N = final.trim(12110,12324).crop( 8,0,-10,-11).LanczosResize(W, H) # Shaded Right 2
O = final.trim(12325,12493).crop( 6,0,-18,-11).LanczosResize(W, H) # Shaded Right (Large)
P = final.trim(12494,12636).crop( 6,0, -8,-11).LanczosResize(W, H) # Stock Shots
Q = final.trim(12637,12676).crop( 8,0,-10,-11).LanczosResize(W, H) # Shaded Right 2
R = final.trim(12677,13916).crop( 6,0,-18,-11).LanczosResize(W, H) # Shaded Right (Large)
S = final.trim(13917,15232).crop( 8,0,-10,-11).LanczosResize(W, H) # Shaded Right 2
T = final.trim(15233,16204).crop( 6,0, -8,-11).LanczosResize(W, H) # Stock Shots
U = final.trim(16205,20463).crop(38,8,-34,-21).LanczosResize(W, H) # Gameplay Credits
V = final.trim(20464,20681).crop( 8,0,-10,-11).LanczosResize(W, H) # Shaded Right 2

A+B+C+D+E+F+G+H+I+J+K+L+M+N+O+P+Q+R+S+T+U+VNot that it matters much with this script but in the general case the following style uses less resources, 6 resizers instances versus 22, in a 100+ cut script it could make a big difference.LoadVFAPIplugin("G:\Encoding\Encoding Tools\Tmpeg\TMPGEnc.vfp","TMPGsource")
Video = TMPGsource("TVCMFINA.tpr")
Audio = WavSource("TVCMFINA AC3 T01 2_0ch 256Kbps DELAY -2ms.wav").DelayAudio(-0.002)

source = AudioDub(Video, Audio)

AAA = source.trim(22211,38420)
BBB = source.trim(38923,43006)
CCC = source.trim(43507,43893)

Final = (AAA+BBB+CCC).flipvertical

Global W = 640
Global H = 480

F_0_0_8_11 = Final.crop( 0,0, -8,-11).LanczosResize(W, H)
F_4_0_10_11 = Final.crop( 4,0,-10,-11).LanczosResize(W, H)
F_6_0_8_11 = Final.crop( 6,0, -8,-11).LanczosResize(W, H)
F_6_0_18_11 = Final.crop( 6,0,-18,-11).LanczosResize(W, H)
F_8_0_10_11 = Final.crop( 8,0,-10,-11).LanczosResize(W, H)
F38_8_34_21 = Final.crop(38,8,-34,-21).LanczosResize(W, H)

A = F_0_0_8_11.trim( 0, 389) # Intro
B = F_4_0_10_11.trim( 390, 670) # Shaded Right (Small)
C = F_6_0_8_11.trim( 671, 2214) # Stock Shots
D = F_6_0_18_11.trim( 2215, 3974) # Shaded Right (Large)
E = F_8_0_10_11.trim( 3975, 4186) # Shaded Right 2
F = F_6_0_18_11.trim( 4187, 4360) # Shaded Right (Large)
G = F_8_0_10_11.trim( 4361, 4405) # Shaded Right 2
H = F_6_0_8_11.trim( 4406, 4460) # Stock Shots
I = F_6_0_18_11.trim( 4461, 5311) # Shaded Right (Large)
J = F_8_0_10_11.trim( 5312, 5373) # Shaded Right 2
K = F_6_0_18_11.trim( 5374,11170) # Shaded Right (Large)
L = F_8_0_10_11.trim(11171,11874) # Shaded Right 2
M = F_6_0_18_11.trim(11875,12109) # Shaded Right (Large)
N = F_8_0_10_11.trim(12110,12324) # Shaded Right 2
O = F_6_0_18_11.trim(12325,12493) # Shaded Right (Large)
P = F_6_0_8_11.trim(12494,12636) # Stock Shots
Q = F_8_0_10_11.trim(12637,12676) # Shaded Right 2
R = F_6_0_18_11.trim(12677,13916) # Shaded Right (Large)
S = F_8_0_10_11.trim(13917,15232) # Shaded Right 2
T = F_6_0_8_11.trim(15233,16204) # Stock Shots
U = F38_8_34_21.trim(16205,20463) # Gameplay Credits
V = F_8_0_10_11.trim(20464,20681) # Shaded Right 2

A+B+C+D+E+F+G+H+I+J+K+L+M+N+O+P+Q+R+S+T+U+V

Dot50Cal
8th July 2007, 05:01
Thank you! Though I seem to be getting an error on the "AudioDelay" function, is it "DelayAudio" instead?

And line 23 of LanczosResize seems to be messing up when I keep the W, H parameters instead of the usual numbers.

IanB
8th July 2007, 05:13
Oops, DelayAudio, the ol' dyslexia is acting up again.

Arrrrg! The W, H paramaters snafu is a bug. I thought that had been fixed. What version are you running.

Dot50Cal
8th July 2007, 05:28
2.5, I think its the latest. 2.56 Oct 28 2005 18:44:09

Seems a bit old but I downloaded it just a little while ago.

IanB
8th July 2007, 05:32
Please test with 2.5.8 Alpha 1 when you have a minute and report back.

tebasuna51
8th July 2007, 12:51
Not that it matters much with this script but in the general case the following style uses less resources, 6 resizers instances versus 22, in a 100+ cut script it could make a big difference.
I can't understand how

F_0_0_8_11 = Final.crop( 0,0, -8,-11).LanczosResize(W, H)
...(6 times)
F38_8_34_21 = Final.crop(38,8,-34,-21).LanczosResize(W, H)

A = F_0_0_8_11.trim( 0, 389) # Intro
...(22 times)
V = F_8_0_10_11.trim(20464,20681) # Shaded Right 2

uses less resources than

A = final.trim( 0, 389).crop( 0,0, -8,-11).LanczosResize(W, H) # Intro
... (22 times)
V = final.trim(20464,20681).crop( 8,0,-10,-11).LanczosResize(W, H) # Shaded Right 2
With first style seems all the video is cropped and resized 6 times and after only parts are accepted.

For what is better first style?

And this third style

A = final.trim( 0, 389).crop( 0,0, -8,-11) # Intro
... (22 times)
V = final.trim(20464,20681).crop( 8,0,-10,-11) # Shaded Right 2

(A+B+C+D+E+F+G+H+I+J+K+L+M+N+O+P+Q+R+S+T+U+V).LanczosResize(W, H)
with only one resize instance?

IanB
8th July 2007, 15:01
When an Avisynth script is compiled, it results in a collection of filter objects chained together. This is the filter graph. Each filter object has 2 interesting method calls, GetFrame and GetAudio, there are other methods but they are not relevant here.

The Splice filter, generated by the "+" operator, chains together the set of input clips. It selects between the input clips based on requested frame number. E.g. when it is asked for frame 390 it calculates that it should asking clip B for frame 0. Likewize with the Audio track.

For the Trim filter, it just adds an offset to the frame number and adjust the frame count property. When clip V asks for frame 0 the filter calculates to asks for frame 20464 of clip Final.

Filters like crop do not calculate new frame numbers but adjust the parameters describing a video frame, it simple does pointer arithmetic. Cropping 8 from the left advances the start of frame pointer 8 pixels. Cropping 8 from the right adjusts the width property to be 8 less.

The above 3 filters are each examples of "near zero cost" filters, they don't actually do any processing on the video data, they just calculate new frame numbers, select between several input clips, manipulate the pointers to the video data. Each of this type of filter executes typically 10's of instructions per frame or chunk of audio.

Filters like the resizers actually do work on the pixels of a video frame. In our implementation a unique MMX program is generated to resize between the input size and the output size. Instead of 10's of instructions per frame the resizer executes 10's of instructions per channel per pixel. This is about 1,000,000 times more than the near zero cost filters.

Because each resizer is individually generated and there is a fair amount of calculation involved, for Lanczos 6 sin(x) calculations plus other arithmeic per pixel, it can take a while to do this, sometimes minutes to generate 100's of resizers.

So although it seems like all the video is done 6 times in the 1st example, it is just a clever way of routing Getframe calls, only the frames of the clip actually requested get generated and resized.

The 2nd example will render frames at the same speed as the first. Except it will take longer to initially compile and use more memory to hold all the extra resizers code and data.

Because there are no filters that combine the frames of 2 or more input clips, all these graphs have 1 frame in for 1 frame out.

In the third style because the frame size of each sub-clip is different you cannot splice them. Even if the splice filter let you, each resize filter is generated to resize from a fixed input size to a fixed output size.

tebasuna51
8th July 2007, 18:32
@IanB
Thanks for your large and educative answer.