Log in

View Full Version : Relative path issue with sources in imports


LigH
4th July 2025, 19:57
I have similar but slightly different scripts in subdirectories processing separate sets of files. To process them in the same way, I import a script from the upper directory of this branch, like this:

D:\Videos\Project\background.png
D:\Videos\Project\import.avsi — ImageSource("background.png", ...)
D:\Videos\Project\Subdir\script.avs — Import("..\import.avsi")

---------------------------
File open error
---------------------------
Avisynth open failure:
ImageReader: error 'Could not open file' in DevIL library.
reading file "D:\Videos\Project\Subdir\background.png"
DevIL version 180.
(D:\Videos\Project\Subdir\script.avs, line XY)
---------------------------
OK
---------------------------

Editing the import script...

D:\Videos\Project\import.avsi — ImageSource("..\background.png", ...)

---------------------------
File open error
---------------------------
Avisynth open failure:
ImageReader: error 'Could not open file' in DevIL library.
reading file "D:\Videos\background.png"
DevIL version 180.
(D:\Videos\Project\Subdir\script.avs, line XY)
---------------------------
OK
---------------------------

Editing the import script...

D:\Videos\Project\import.avsi — ImageSource(".\background.png", ...)

---------------------------
File open error
---------------------------
Avisynth open failure:
ImageReader: error 'Could not open file' in DevIL library.
reading file "D:\Videos\Project\Subdir\background.png"
DevIL version 180.
(D:\Videos\Project\Subdir\script.avs, line XY)
---------------------------
OK
---------------------------

So ... the same directory (.) is the same as the script. The upper directory (..) is the upper relative to the import.

That looks a bit inconsistent to me. How to solve? Only with unwanted workarounds (move the background.png one up, or copy it in all subdirs).

Maybe important: In case of trying the upper directory (..\), AviSynth+ immediately detects the file does not exist; trying no path or the same directory (.\), it detects the missing file after trying to load all other sources.

Jamaika
4th July 2025, 21:13
You can use
Import("./import.avsi")
LWLibavVideoSource("../image.jpg")

LigH
4th July 2025, 21:19
But my common import script is located in the upper directory relative to all the specific scripts. I would not like to copy it to all subdirectories too...

StainlessS
5th July 2025, 01:53
Layout

D:\VIDEOS\PROJECT\
Background.png
Import.avs
SUBDIR\
script.avs


D:\VIDEOS\PROJECT\Import.avs

ImageSource(".\background.png") # Need '.\' relative current directory {same as Import.avs}


D:\VIDEOS\PROJECT\SUBDIR\script.avs

Import("..\Import.avs")


This works for me.

EDIT: NOT sure, but think it MAY have worked as you originally had it, but,
I think M$ did something wierd about Vista or Windows 7 where missing ".\" ie implied relative current directory doesnt work as it used to.
It's now always a good idea to explicitly add ".\" where relative to current directory.

EDIT: Actually, for me, removing ".\" from ImageSource line still works OK, with current Avs+ and Windows 10.
{I had problems with some scripts when I was on XP and users were on W7, think Pinterf my have explicitly fixed the change in W7 in AVS+ when I was complaining about M$ change}

Dont know why you are having the problem, unless you are using v2.60 or v2.58.

StainlessS
5th July 2025, 02:50
Here entire VIDEO\ folder layout as working for me (including a png file), ~20KB
EDIT: LINK Removed

I think latest version of Avs+ does away with the DevIL library, so I'm guessing that you aint using that one.
(unless you are using an OLD ImageSeq.dll file)

What version avs are you using ?

EDIT: Oh, I tried with VDub2 and also two Media Players, OK.

LigH
5th July 2025, 08:48
You are right. On its very own, and with exactly the given path and file names, your scripts (based on my simplified example) do work.

My scripts are a little more complex, though. I tried a while to cut them down from my original, failing content to a simplified content that still fails:

D:\Videos\Project\import.avsi
function LoadClip(string filename)
{
a = LSMASHAudioSource(filename)
v = LSMASHVideoSource(filename)
c = AudioDub(v, a.ConvertAudioToFloat())
return c
}

bg = ImageSource("background.png", 0, 240, 30000.0/1001.0, false, false, "RGB24")
fg = ImageSource("foreground.png", 0, 240, 30000.0/1001.0, false, false, "RGB24")
Dissolve(bg, fg, 180)
FadeIn0(60)
ConvertToYV12()
AudioDub(BlankClip(last, audio_rate=48000, channels=2, sample_type="float"))

D:\Videos\Project\test\test.avs
Import("..\import.avsi")
fn = "video.mp4"
Dissolve(LoadClip(fn), 30)
Prefetch(4)
return last.AssumeFPS(30000, 1001).FadeOut2(60)

---------------------------
File open error
---------------------------
Avisynth open failure:
ImageReader: error 'Could not open file' in DevIL library.
reading file "D:\Videos\Project\test\background.png"
DevIL version 180.
(D:\Videos\Project\test\test.avs, line 4)
---------------------------
OK
---------------------------


Installed are e.g. AviSynth+ 3.7.5 20250420 and L-SMASH-Works r1262.

StainlessS
5th July 2025, 17:33
Find VIDEOS.7z [~20MB]:- https://www.mediafire.com/file/9bxfukmr6rc6abu/VIDEOS.7z/file

As supplied, works ok, but enable Prefetch and stops working, enable FIX_NAMES=True and works again.

Layout

D:\VIDEOS\PROJECT\
Background.png
Foreground.png
Video.mp4
BgFgSrc.avsi
Func.avsi
TEST\
Test.avs


Test.avs

####
# Req RT_Stats and DebugView by M$
###

#GLOBAL FIX_NAMES = True
GLOBAL FIX_NAMES = False

Import("..\Func.avsi")
Import("..\BgFgSrc.avsi")

fn = "..\video.mp4"
fnClip = LoadClip(fn)
fnClip = FnClip.ResampleAudio(48000) # Conv my clip Audio to your format

Dissolve(BgFg_Clip, fnClip, 30)
AssumeFPS(30000, 1001).FadeOut2(60)

#Prefetch(4) # Un-Comment to produce error when also GLOBAL FIX_NAMES = False
Return Last


BgFgSrc.avsi

BgName = "background.png"
FgName = "foreground.png"

RT_DebugF("OrgBgName='%s'",BgName, name="BgFgSrc: ")
RT_DebugF("OrgFgName='%s'",FgName, name="BgFgSrc: ")

if (FIX_NAMES) {
bgName=RT_GetFullPathName(BgName)
RT_DebugF("BgName='%s'",BgName, name="BgFgSrc: ")
FgName=RT_GetFullPathName(FgName)
RT_DebugF("FgName='%s'",FgName, name="BgFgSrc: ")
}

bg = ImageSource(BgName, 0, 240, 30000.0/1001.0, false, false, "RGB24")
fg = ImageSource(FgName, 0, 240, 30000.0/1001.0, false, false, "RGB24")

Dissolve(bg, fg, 180)
FadeIn0(60)
ConvertToYV12()

AudioDub(BlankClip(last, audio_rate=48000, channels=2, sample_type="float"))

BgFg_Clip = Last # Save clip in Variable for Importer (Dont forget to pay the Tarrifs)


Func.avsi

function LoadClip(string filename)
{
RT_DebugF("OrgName='%s'",filename, name="LoadClip: ")

if (FIX_NAMES) {
filename=RT_GetFullPathName(filename)
RT_DebugF("FullName='%s'",filename, name="LoadClip: ")
}
a = LSMASHAudioSource(filename)
v = LSMASHVideoSource(filename)
c = AudioDub(v, a.ConvertAudioToFloat())
return c
}


I've split into two avsi's, as they sorta do two different things.
(Import a clip, and embed a chunk of script).

It tastes like a bug in Avs+ current, perhaps as supplied it can help narrow down cause a little bit.

EDIT: DebugView Log when Prefetch and FIX_NAMES=True

00000100 17:50:41 [12568] BgFgSrc: OrgBgName='background.png'
00000101 17:50:41 [12568] BgFgSrc: OrgFgName='foreground.png'
00000102 17:50:41 [12568] BgFgSrc: BgName='D:\VIDEOS\PROJECT\background.png'
00000103 17:50:41 [12568] BgFgSrc: FgName='D:\VIDEOS\PROJECT\foreground.png'
00000104 17:50:41 [12568] LoadClip: OrgName='..\video.mp4'
00000105 17:50:41 [12568] LoadClip: FullName='D:\VIDEOS\PROJECT\video.mp4'


EDIT: With FIX_NAMES=false, and PREFETCH=True, Error halt in BgFgSrc.avsi

00000203 17:55:30 [12176] BgFgSrc: OrgBgName='background.png'
00000204 17:55:30 [12176] BgFgSrc: OrgFgName='foreground.png'
Name accessed via eg ImageSource("D:\VIDEOS\PROJECT\Test\background.png") # Relative main script
Instead of ImageSource("D:\VIDEOS\PROJECT\background.png") # Relative Imported script
{ same for foreground.png }


EDIT: clickMe
https://i.postimg.cc/DJ19c1pk/Out.jpg (https://postimg.cc/DJ19c1pk)
The FIX_NAMES thingy only needs be applied for the BgFgSrc.avsi, FIX_NAMES NOT necessary for Func.avsi

LigH
5th July 2025, 17:44
It depends on multithreading? Well, this is indeed an interesting detail. Thanks for your investigations. And explicitly "canonicalizing" the filename is indeed a quite probable solution.

LigH
6th July 2025, 07:56
Reported as AviSynthPlus issue 448 (https://github.com/AviSynth/AviSynthPlus/issues/448), thank you for the verbose test.

LigH
9th July 2025, 14:35
Thanks @pinterf for starting investigations and @qyot27 for joining. And I can imagine the magnitude of confusion from your first reply...

LigH
11th July 2025, 14:03
Just flagged as "fixed"; looking forward to a test build getting announced soon™

pinterf
11th July 2025, 15:11
Yep, I do hope it will work on your machines as well.
And sorry, I cannot provide a test build right now, my repo contains too much other unfinished stuff, let's hope but you can obtain test builds from UVZ's site soon.

LigH
8th August 2025, 17:40
let's hope but you can obtain test builds from UVZ's site soon.

Where is that?

Xuqiwu
8th August 2025, 18:24
It should be this github: https://gitlab.com/uvz/AviSynthPlus-Builds/