PDA

View Full Version : Importing Multiple Audio Sources Into Script


EpheMeroN
25th October 2006, 09:51
I am hoping that BeHappy can do what I need. I have 2 videos and both have different audio formats (one AC3 & one MP3). As you'll see from my script below, if I simply transcoded them alone and joined together I would end up with out of sync audio due to the editing I did. What I am looking for is to load my script somehow and output 1 single WAVE file. Can this be done?

LoadPlugin("C:\Program Files\AviSynth 2.5\Plugins\DGDecode.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\Plugins\TDeint.dll")

Video1 = MPEG2Source("D:\Scream Awards
2006\Scream.Awards.2006.Part1.d2v").TDeint(1,1).BicubicResize(704,480,0,0.5).SeparateFields().SelectEvery(4,1,2).Weave().FadeIn0(5).FadeOut0(5)

Video2 = Trim(AVISource("D:\Scream Awards 2006\Scream.Awards.2006.Part2.avi", audio=false),97209,155730).BicubicResize(704,480,0,0.5).FadeIn0(5).FadeOut0(5)

Blank1 = BlankClip(Video1).Trim(0,59).Amplify(0.0)

Blank2 = BlankClip(Video1).Trim(0,25).Amplify(0.0)

AlignedSplice(Blank1,Video1,Blank2,Video2,Blank1)

AddBorders(8,0,8,0)

EpheMeroN
25th October 2006, 19:46
Or can BeHappy only handle 1 audio file at a time? I'm quite uncertain.

tebasuna51
25th October 2006, 21:38
BeHappy is only a AviSynth interface to send the uncompressed audio output (only one stream) from AviSynth to a encoder.

But AviSynth can manage more than one audio input.
The problem is: in your script there aren't audio streams because
MPEG2Source("D:\...Part1.d2v") is only video and
AVISource("D:\...Part2.avi", audio=false) is only video also.

Then the Trim(), Fade's, ... have no sense for the audio

You need open the Part1.ac3 with NicAc3Source() (or DirectShowSource) and downmix to stereo if is 5.1

Open Part2.mp3 with NicMPG123Source() (or DSS) Trim and Fade and so on.

Rockaria
25th October 2006, 21:47
First of all, BeHappy does not replace AviSynth. It's just an Avisynth client designed for audio transcoding.
It can process the AVS script but does not handle the video frames accordingly even from a single source.
So the Avisynth section is the correct place to get fully considered(video+audio) helps.

AFAIK, Avsynth can handle(frame serve) only one(last clip) audio stream.
So, in order to join/mix or merge the audio clips to fully stream serve, you must create a new audio clip from existing clips, and DUB it to the last video clip.

related functions from the AviSynth manual :
. MixAudio (clip1, clip2, float "clip1_factor", float "clip2_factor") : Mixes audio from two clips. A volume for the two clips can be given, but is optional.
. MergeChannels (clip1 , clip2 [, clip3, ...]) : can create a new Audio clip with new set of channels.
. GetChannels (clip, int ch1 [, int ch2, ...]) : get a audio clip(with different set of channels) from existing clip, the resulting clip can also be used for the above functions
. + operator (clip1 + clip2) : can join the clips, also the resulting clip can be used in the above functions
. AudioDubEx (video_clip, audio_clip) : use it for the last clip for the 'mixed' audio.

MPC will be useful to preview the resulting clip(*.avs). vDub(megui and many other a/v clients) will be useful to process the movie clips.
The resulting audio frames can also be encoded(using cli encoders) thru many known Avisynth audio clients : avs2wav(cli), bepipe(cli), SNG, DAudioK, behappy.................

[edit] I am not sure if it is the last or first clip to be (the only clip) audio frame served.

EpheMeroN
25th October 2006, 22:03
The problem is: in your script there aren't audio streams because
MPEG2Source("D:\...Part1.d2v") is only video and
AVISource("D:\...Part2.avi", audio=false) is only video also.

Then the Trim(), Fade's, ... have no sense for the audio

You need open the Part1.ac3 with NicAc3Source() (or DirectShowSource) and downmix to stereo if is 5.1

Open Part2.mp3 with NicMPG123Source() (or DSS) Trim and Fade and so on.
Yes you are right. This was because a) I did not know how to load AC3 audio into an AviSynth script, and b) since Part1 had no audio if I did not put audio=false for Part2 the script would return an error how one video has audio and the other does not.

The trims to the video will not affect the audio? Will they affect the audio if I join the audio to the video with an AudioDub(v,a) call? Also when using this NicMPG123Source() do I also need to use the EnsureVBRMP3Sync() function since the audio is vbr?

So the Avisynth section is the correct place to get fully considered(video+audio) helps.
If this thread needs to be moved I totally understand. I just wasn't sure which sub-forum it should be in.

EpheMeroN
25th October 2006, 22:39
The revised script below actually loads into VDubMod but shows no audio being present. If I gray out the Video2/Audio2 lines the AC3 audio from Part1 loads perfectly. Does 2 AudioDub calls cancel itself out?

LoadPlugin("C:\Program Files\AviSynth 2.5\Plugins\DGDecode.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\Plugins\TDeint.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\Plugins\NicAudio.dll")
Import("C:\Program Files\AviSynth 2.5\Plugins\LimitedSharpenFaster.avs")
Import("C:\Program Files\AviSynth 2.5\Plugins\jdl-util.avsi")
Import("C:\Program Files\AviSynth 2.5\Plugins\jdl-range.avsi")


Video1 = MPEG2Source("D:\Scream Awards
2006\Scream.Awards.2006.Part1.d2v").TDeint(1,1).BicubicResize(704,480,0,0.5).SeparateFields().SelectEvery(4,1,2).Weave().FadeIn0(5).FadeOut0(5)

Audio1 = NicAC3Source("D:\Scream Awards 2006\Scream.Awards.2006.Part1.ac3")

AudioDub(Video1,Audio1)

Video2 = Trim(AVISource("D:\Scream Awards 2006\Part2.avi",audio=false),97209,155730).BicubicResize(704,480,0,0.5).LimitedSharpenFaster(Smode=3,strength=75).FadeIn0(5).FadeOut0(5)

Audio2 = NicMPG123Source("D:\Scream Awards 2006\Part2.mp3")

AudioDub(Video2,Audio2)

Blank1 = BlankClip(Video1).Trim(0,59).Amplify(0.0)

Blank2 = BlankClip(Video1).Trim(0,25).Amplify(0.0)

AlignedSplice(Blank1,Video1,Blank2,Video2,Blank1)

AddBorders(8,0,8,0)

Rockaria
25th October 2006, 22:53
Video1 = AudioDub(Video1,Audio1) will DUB the Audio1 to the Video1.
if the 'AlignedSplice' is stacking the clips, only one clip from them(last or first) will be audio frame served.(check above)

EpheMeroN
25th October 2006, 23:00
Would you mind modifying my script to show me how this would work? I'm not really that advanced w/ scripting and am a bit confused right now. Thanks!

Rockaria
25th October 2006, 23:57
The first thing to clarify seems to be ' what do you want to do with two audio?', to join or mix. And what is the number of the channels of the ac3? 2.0 or 5.1?
In order to join/mix with mp3 to make(DUB) a working(the only audio frame serving) clip, they need to have(or use) same number of channels for join(+) or mix(mixaudio()) process.

<DPL II invert-only script example : getchannel, mixaudio, mergechannels>

audio=dpl2Norm(ConvertAudioToFloat(last).Amplify(0.2), 0.7).normalize()

function dpl2Norm(clip a, LF2){return dpl2Enc(a, 0.7071, LF2, -0.866, -0.5, 0.5, 0.866)}
function dpl2Enc(clip a, CC2, LF2, Ls3, Rs1, Ls1, Rs3){
cc = MixAudio(GetChannel(a, 3),GetChannel(a, 4),CC2,LF2)
Lt = MixAudio(GetChannel(a, 1),cc,1,1)
Rt = MixAudio(GetChannel(a, 2),cc,1,1)

Ls = GetChannel(a, 5)
Rs = GetChannel(a, 6)
Lss = MixAudio(Ls, RS, LS3, Rs1)
Rss = MixAudio(Ls, RS, LS1, Rs3)
return MergeChannels(MixAudio(Lt,Lss,1,1), MixAudio(Rt,Rss,1,1))
}

This will give a DPL II(invert-only) mixed 2ch PCM if you have a 5.1 ac3 to be joined/mixed with 2ch mp3.

If this thread needs to be moved I totally understand. I just wasn't sure which sub-forum it should be in.
If the mods do not move to the correct section, I suggest you to use http://forum.doom9.org/showthread.php?t=117483 if nobody gives you the correct ready-to-run answer here. I don't have the full answer atm.

PS. sorry, the linked thread is cancelled(maybe by the owner)

EpheMeroN
26th October 2006, 00:07
I just want to join the 2 audio files together and have a WAVE file be outputted so I can later use it for my dvd authoring. The AC3 is 192 2.0, and the MP3 is 128 vbr.

Rockaria
26th October 2006, 00:18
Audio1 = NicAC3Source("D:\Scream Awards 2006\Scream.Awards.2006.Part1.ac3")
Audio2 = NicMPG123Source("D:\Scream Awards 2006\Part2.mp3")
Audio1+Audio2

If the sampling rates are different(other than 48k), you may want to include ResampleAudio(Audiox, 48000) in the joining.

EpheMeroN
26th October 2006, 01:16
Both audio files have the same 48k sampling rate.

When I added that code to my script it told me that only 1 video had audio and the other did not. What am I doing wrong?

Rockaria
26th October 2006, 01:22
LoadPlugin("C:\Program Files\AviSynth 2.5\Plugins\NicAudio.dll")

Audio1 = NicAC3Source("D:\Scream Awards 2006\Scream.Awards.2006.Part1.ac3")
Audio2 = NicMPG123Source("D:\Scream Awards 2006\Part2.mp3")
Audio1+Audio2
This will be enough. You can also place the NicAudio.dll in the avisynth's plugin folder to load it automatically.;)
PS. It seems you don't need to load the dll explicitly.

EpheMeroN
26th October 2006, 01:48
So the script you are proposing is to handle the audio by itself and then to do the video within another script yes?

I was really hoping to be able to output the WAVE file with all of the edits and blank clip additions, etc etc, so that the resulting WAVE file would be in perfect sync with the video.

Rockaria
26th October 2006, 02:31
I just want to join the 2 audio files together and have a WAVE file be outputted so I can later use it for my dvd authoring. The AC3 is 192 2.0, and the MP3 is 128 vbr.
I just read your PM. But if you leave it as it is in the public forum, I might be a bit crazy. lol.
To process the audio only, you don't need the video clips or frames. (now hopefully as you know).

If you wanna preview the video to sync the audio(with trim()) with the older script, have only one video.

If you reread my posts, you will find stating only one clip of the stacked clips can stream the audio. (of course you can verify which one is streaming):)

EpheMeroN
26th October 2006, 03:34
Yes I know I don't need to also load the video to process the audio, but I want to process both together to ensure proper sync. I make a cut in the second video, and I add 2 seconds of blank video to the beginning and end and as well as a few frames in-between Video1 and Video2. If I simply processed the audio by itself it would be out of sync by default.

Also, if I only use AlignedSplice with 1 of the videos, how will the other video and audio be joined?

One of us has to be mis-interpreting the other ;-)

Rockaria
26th October 2006, 04:00
Also, if I only use AlignedSplice with 1 of the videos, how will the other video and audio be joined?

One of us has to be mis-interpreting the other ;-)
To prevent no-enough-information(not mis-interpreting), we may need some information about the AlignedSplice here : what is it and what exactly you want to do with it.:cool:

Rockaria
26th October 2006, 04:20
http://avisynth.org.ru/docs/english/corefilters/splice.htm

So the ++ operator seems to be doing the allignedsplice joining of the two a/v clips.(not stacking as I stated with if)
My idea is preparing the two DUBed & SYNCed a/v clips and join them using the ++;

av1=audiodub(v1,a1)
av2=audiosub(v2,a2)
av1++av2

when a1 & a2 are properly synced & trimmed to each video.

http://forum.doom9.org/showthread.php?p=348150

EpheMeroN
26th October 2006, 07:50
New script worked but the outputted audio looped the first audio track instead of the second audio playing after the first audio ended.

LoadPlugin("C:\Program Files\AviSynth 2.5\Plugins\DGDecode.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\Plugins\TDeint.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\Plugins\NicAudio.dll")
Import("C:\Program Files\AviSynth 2.5\Plugins\LimitedSharpenFaster.avs")
Import("C:\Program Files\AviSynth 2.5\Plugins\jdl-util.avsi")
Import("C:\Program Files\AviSynth 2.5\Plugins\jdl-range.avsi")

Video1 = MPEG2Source("D:\Scream Awards 2006\Scream.Awards.2006.Part1.d2v").TDeint(1,1).BicubicResize(704,480,0,0.5).SeparateFields().SelectEvery(4,1,2).Weave().FadeIn0(5).FadeOut0(5)
Video2 = Trim(AVISource("D:\Scream Awards 2006\Part2.avi", audio=false),97209,155730).BicubicResize(704,480,0,0.5).LimitedSharpenFaster(Smode=3,strength=75).FadeIn0(5).FadeOut0(5)

Audio1 = NicAC3Source("D:\Scream Awards 2006\Scream.Awards.2006.Part1.ac3").AmplifydB(2)
Audio2 = NicMPG123Source("D:\Scream Awards 2006\Part2.mp3").EnsureVBRMP3Sync()

AV1 = AudioDub(Video1,Audio1)
AV2 = AudioDub(Video2,Audio2)
AV1++AV2

Blank1 = BlankClip(AV1).Trim(0,59).Amplify(0.0)
Blank2 = BlankClip(AV1).Trim(0,25).Amplify(0.0)

AlignedSplice(Blank1,AV1,Blank2,AV2,Blank1)

JDL_ApplyRange(66, 3302, "Crop(0,60,0,-60).AddBorders(0,60,0,60)")


AddBorders(8,0,8,0)

Rockaria
26th October 2006, 12:31
As I said, you don't need to explicitly load/import the stuffs in the avisynth folders.


Video1 = MPEG2Source("D:\Scream Awards 2006\Scream.Awards.2006.Part1.d2v")
Video2 = AVISource("D:\Scream Awards 2006\Part2.avi", audio=false),

Audio1 = NicAC3Source("D:\Scream Awards 2006\Scream.Awards.2006.Part1.ac3").AmplifydB(2)
Audio2 = NicMPG123Source("D:\Scream Awards 2006\Part2.mp3").EnsureVBRMP3Sync()

AV1 = AudioDub(Video1,Audio1)
AV2 = AudioDub(Video2,Audio2)
AV1++AV2
Just preview with this content and see what happens. I guess the (duration Audiox must<= duration Videox) requiring correct trimmings of audio.
If it does not play accordingly, check the DUBs one by one. I wonder why not read the original clips with A/V signal together, anyway.

If successful in joining the two A/V, you can add the other effects/silence one by one also, to verify which is malfunctioning, if any.

Good luck.(you may want to correct the thread title in case)

EpheMeroN
26th October 2006, 20:55
Can a forum moderator please move this to the AviSynth Usage forum? Thank you!

EpheMeroN
28th October 2006, 08:43
Well, after almost a week of testing I got it to work. Below is what I threw together somehow and it works. If there's a more efficient or better way of doing this guys let me know. I don't even know how I got this to work haha.

LoadPlugin("C:\Program Files\AviSynth 2.5\Plugins\DGDecode.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\Plugins\TDeint.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\Plugins\NicAudio.dll")
Import("C:\Program Files\AviSynth 2.5\Plugins\LimitedSharpenFaster.avs")
Import("C:\Program Files\AviSynth 2.5\Plugins\jdl-util.avsi")
Import("C:\Program Files\AviSynth 2.5\Plugins\jdl-range.avsi")

Video1 = MPEG2Source("D:\Scream Awards 2006\Scream.Awards.2006.Part1.d2v").TDeint(1,1).BicubicResize(704,480,0,0.5).SeparateFields().SelectEvery(4,1,2).Weave().FadeIn0(5).FadeOut0(5)

Video2 = AVISource("D:\Scream Awards 2006\Part2.avi", audio=false).BicubicResize(704,480,0,0.5)

Audio1 = NicAC3Source("D:\Scream Awards 2006\Scream.Awards.2006.Part1.ac3")

Audio2 = NicMPG123Source("D:\Scream Awards 2006\Part2.mp3")

AV1 = AudioDub(Video1,Audio1)

AV2 = AudioDub(Video2,Audio2).Trim(97209,155730).LimitedSharpenFaster(Smode=3,strength=75).FadeIn0(5).FadeOut0(10)

Blank1 = BlankClip(AV1).Trim(0,59).Amplify(0.0)

Blank2 = BlankClip(AV1).Trim(0,25).Amplify(0.0)

AlignedSplice(Blank1,AV1,Blank2,AV2,Blank1)

JDL_ApplyRange(66, 3302, "Crop(0,60,0,-60).AddBorders(0,60,0,60)")

AddBorders(8,0,8,0)

Rockaria
28th October 2006, 20:39
Great to be informed you did it all by yourself!!! :)