Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.


Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Thread Tools Search this Thread Display Modes
Old 25th November 2021, 20:57   #1  |  Link
Broadcast Encoder
FranceBB's Avatar
Join Date: Nov 2013
Location: Metropolitan City of Milan, Italy
Posts: 2,145
GetChannels() wants a series of integers?

If I do something like:

ColorBars(848, 480, pixel_type="YV12")

it works and gets me channel 1, 2, 2.

Now, if I declare this function:

function mylist(int n, string "s")
    s = default(s, "")
    return (n > 0) ? mylist(n - 1, String(n) + "," + s)
    \              : s
and then I call it like this:

ColorBars(848, 480, pixel_type="YV12")

clip1_channels=(HasAudio) ? (AudioChannels) : 0

clip1_channels_list=mylist(clip1_channels) + String(clip1_channels)

it returns 1,2,2

however if I try to use the variable I've just got with 1,2,2 inside GetChannels() it doesn't work:

ColorBars(848, 480, pixel_type="YV12")

clip1_channels=(HasAudio) ? (AudioChannels) : 0

clip1_channels_list=mylist(clip1_channels) + String(clip1_channels)


Script error: Invalid arguments to function 'GetChannels'.

p.s the reason I brought this up is because I'm trying to write a function that takes two inputs, clip1 and clip2, uses the video from clip1 and the audio from clip1 and uses mergechannels to append the channels from clip2 to clip1. The user is gonna have two more parameters: InsertAt and DeleteCount. The first, InsertAt, allows the user to choose after which channel of the clip1 the audio from clip2 is inserted. DeleteCount instead allows the user to delete a certain channel he specifies from clip1.
I was writing the basics but the aforementioned issue came up...

function InsertExternalAudio(clip clp1, clip clp2) {

clip1_channels=(clp1.HasAudio) ? (clp1.AudioChannels) : 0
clip2_channels=(clp2.HasAudio) ? (clp2.AudioChannels) : 0

my_clip1=(clip1_channels>0) ? clp1.ResampleAudio(48000).ConvertAudioToFloat() : clp1
my_clip2=(clip2_channels>0) ? clp2.ResampleAudio(48000).ConvertAudioToFloat() : clp2

clip1_channels_list=mylist(clip1_channels) + String(clip1_channels)
clip2_channels_list=mylist(clip2_channels) + String(clip2_channels)

audio1=GetChannels(my_clip1, clip1_channels_list)
audio2=GetChannels(my_clip2, clip2_channels_list)

audio=MergeChannels(audio1, audio2)
AudioDub(video, audio)


Last edited by FranceBB; 25th November 2021 at 21:29.
FranceBB is offline   Reply With Quote
Old 26th November 2021, 06:37   #2  |  Link
HeartlessS Usurer
StainlessS's Avatar
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,151
I just popped by before I went to bed [05:32], and have done little more than glance at less than half of your post,
but methinks that [4th code block]
is calling getchannels with a string, getChannels dont work with a string, so maybe something like
Eval ( "GetChannels(" + clip1_channels_list + ")"  )
Might work [assigns result to last - maybe you can get it to work by creating array from string, but I know nought bout that new fangled stuff].
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 26th November 2021 at 06:40.
StainlessS is offline   Reply With Quote
Old 26th November 2021, 10:54   #3  |  Link
Banana User
VoodooFX's Avatar
Join Date: Sep 2008
Posts: 490
I dunno what GetChannels is, but your current mylist() could be replaced with something like this [how many channels there can be?]:

if (clip1_channels == 0) {
    audio1=GetChannels(my_clip1, 0)
} else if (clip1_channels == 1) {
    audio1=GetChannels(my_clip1, 1,1)
} else if (clip1_channels == 2) {
    audio1=GetChannels(my_clip1, 1,2,2)
} else if (clip1_channels == 3) {
    audio1=GetChannels(my_clip1, 1,2,3,3)
} else if (clip1_channels == 4) {
    audio1=GetChannels(my_clip1, 1,2,3,4,4)
} else if (clip1_channels == 5) {
    audio1=GetChannels(my_clip1, 1,2,3,4,5,5)

Last edited by VoodooFX; 26th November 2021 at 11:01.
VoodooFX is offline   Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT +1. The time now is 12:03.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2022, vBulletin Solutions Inc.