<pre><code>function SegmentedDissolve(string base, int first_val, int last_val, string format, int dissolve_length ){
    filename = base + string(first_val, format) + &quot;.MOV&quot;
    result = FFMS2(filename)
    return (first_val &lt; last_val) \
        ? Dissolve(result, SegmentedDissolve(base, first_val+1, last_val, format, dissolve_length), dissolve_length) \
        : result
}

SegmentedDissolve(&quot;F:\_DSC&quot;, 1, 9, &quot;%03.0f&quot;, 50).Trim(3600, yyy).FadeIn(100).FadeOut(100)
</code></pre>
<p>You would need to figure out what value <code>yyy</code> needs to be for the concatenated clip. If the first clip needs to be trimmed on both sides, then the first clip should not be included in the function (start <code>first_val</code> at 2), and instead get loaded, processed, and concatenated manually.</p>
<p>As a note, the FFMS2 function also loads up any audio found in the specified clip, so you do not need to dub it unless you are doing processing on it first.</p>

CC BY-SA 4.0
2020-09-27T12:12:22.510Z
I lost access to AviSynth on Windows and could not install it on Azure. I may try this code on macOS now that AviSynth is compatible.
emonigma
CC BY-SA 4.0
2020-09-25T22:45:34.747Z
2020-09-25T22:45:34.747Z
Zach F.
<p>I am new to AviSynth+. I am concatenating 9 clips, trimming the first and last, fading in the first and fading out the last, and cross-dissolving between clips. This code works:</p>

<pre><code>audio=ffaudiosource("F:\_DSC001.MOV")
video=FFMS2("F:\_DSC001.MOV")
start=AudioDub(audio, video)
clip1=Trim(start, 3600, 30000)

audio=ffaudiosource("F:\_DSC002.MOV")
video=FFMS2("F:\_DSC002.MOV")
clip2=AudioDub(audio, video)

... same for clips 3-8 ...

audio=ffaudiosource("F:\_DSC009.MOV")
video=FFMS2("F:\_DSC009.MOV")
clip9=Trim(AudioDub(audio, video), 0, 22575)

FadeIn(clip1, 100)
Dissolve(last, clip2, 50)
Dissolve(last, clip3, 50)
Dissolve(last, clip4, 50)
Dissolve(last, clip5, 50)
Dissolve(last, clip6, 50)
Dissolve(last, clip7, 50)
Dissolve(last, clip8, 50)
Dissolve(last, clip9, 50)
FadeOut(last, 100)
</code></pre>

<p>It's quite verbose and repetitive. I wonder if some pre-processor script can take some of these parameters and arguments and produce the above AviSynth+ script.</p>

<p>Does such a pre-processor exist, or could the AviSynth+ script be optimized or improved?</p>

<avisynth>
Concatenate clips with as little code as possible in AviSynth+
emonigma
# Concatenate clips with as little code as possible in AviSynth+

(Asked by: username_0 on 2020-02-11)

I am new to AviSynth+. I am concatenating 9 clips, trimming the first and last, fading in the first and fading out the last, and cross-dissolving between clips. This code works:
audio=ffaudiosource("F:\_DSC001.MOV")
video=FFMS2("F:\_DSC001.MOV")
start=AudioDub(audio, video)
clip1=Trim(start, 3600, 30000)

audio=ffaudiosource("F:\_DSC002.MOV")
video=FFMS2("F:\_DSC002.MOV")
clip2=AudioDub(audio, video)

... same for clips 3-8 ...

audio=ffaudiosource("F:\_DSC009.MOV")
video=FFMS2("F:\_DSC009.MOV")
clip9=Trim(AudioDub(audio, video), 0, 22575)

FadeIn(clip1, 100)
Dissolve(last, clip2, 50)
Dissolve(last, clip3, 50)
Dissolve(last, clip4, 50)
Dissolve(last, clip5, 50)
Dissolve(last, clip6, 50)
Dissolve(last, clip7, 50)
Dissolve(last, clip8, 50)
Dissolve(last, clip9, 50)
FadeOut(last, 100)

It's quite verbose and repetitive. I wonder if some pre-processor script can take some of these parameters and arguments and produce the above AviSynth+ script.
Does such a pre-processor exist, or could the AviSynth+ script be optimized or improved?

**Tags:** avisynth


---

## 1 answers

### Answer by username_1 on 2020-09-25. Score: 2

function SegmentedDissolve(string base, int first_val, int last_val, string format, int dissolve_length ){
    filename = base + string(first_val, format) + ".MOV"
    result = FFMS2(filename)
    return (first_val < last_val) \
        ? Dissolve(result, SegmentedDissolve(base, first_val+1, last_val, format, dissolve_length), dissolve_length) \
        : result
}

SegmentedDissolve("F:\_DSC", 1, 9, "%03.0f", 50).Trim(3600, yyy).FadeIn(100).FadeOut(100)

You would need to figure out what value yyy needs to be for the concatenated clip. If the first clip needs to be trimmed on both sides, then the first clip should not be included in the function (start first_val at 2), and instead get loaded, processed, and concatenated manually.
As a note, the FFMS2 function also loads up any audio found in the specified clip, so you do not need to dub it unless you are doing processing on it first.

> **Comments:**
> **username_0**: I lost access to AviSynth on Windows and could not install it on Azure. I may try this code on macOS now that AviSynth is compatible.  

---

