View Full Version : Universal Source functions
MrC
21st November 2008, 14:17
For my project AVStoDVD, I am trying to write a couple of fuctions (video and audio sources) that combine well known general purpose Source methods:
# Following AviSynth plugins are required:
# FFMpegSource.dll @ http://forum.doom9.org/showthread.php?t=127037
# GetSystemEnv.dll @ http://avisynth.org/stickboy
LoadPlugin("FFMpegSource.dll")
LoadPlugin("GetSystemEnv.dll")
Function A2DVideoSource(string VideoSource, bool "debug")
{
debug = default(debug, false)
Try {
SourceStr = "A2DVideoSource: AVISource"
Video = AVISource(VideoSource, audio = false)
}
Catch(Err_Msg) {
Try {
SourceStr = "A2DVideoSource: DirectShowSource"
Video = DirectShowSource(VideoSource, convertfps = true, audio = false)
}
Catch(Err_Msg) {
SourceStr = "A2DVideoSource: FFmpegSource"
Video = FFmpegSource(VideoSource, vcachefile = GetSystemEnv("temp") + "\A2DVideoSource.cache", seekmode = 0)
}
}
Video = (debug == true) ? Subtitle(Video.Info(), SourceStr, font = "courier new", size = 16, align = 1) : Video
return(Video)
}
Function A2DAudioSource(string AudioSource)
{
Try {
Audio = DirectShowSource(AudioSource, video = false)
}
Catch(Err_Msg) {
Audio = FFAudioSource(AudioSource, atrack = -1, acachefile = GetSystemEnv("temp") + "\A2DAudioSource.cache", acachefile2 = GetSystemEnv("temp") + "\A2DAudioSource2.cache")
}
return(Audio)
}
I am not a great AviSynth scripter, any suggestion how to improve it will be appreciated.
:)
Bye
Myrsloik
22nd November 2008, 01:28
That is very, very wrong. FFmpegSource always assumes that if an index exists it will also be the correct index. Call your function twice to see very interesting results. Use vcache=false if you're that concerned about writing files everywhere. Why you set seekmode=0 is also a mystery.
My recommendation to you is to read the manuals first and script later.
MrC
23rd November 2008, 14:56
Myrsloik, first of all I would like to thank you for FFmpegSource, really a great AviSynth plugin. Then I would like to thank you for reviewing my first attempt to write an AviSynth function. Now, let's go thru the discussion and, please, be patient if I am making mistakes.
FFmpegSource always assumes that if an index exists it will also be the correct index. Call your function twice to see very interesting results.
If I have correctly understood, you are saying that using vcache = vcachefile = GetSystemEnv("temp") + "\A2DVideoSource.cache" on multiple FFmpegSource calls would create conflicts because cache filename is the same? OK, got it. For video I can disable vcache (what is the impact?), but what about audio? acachefile is mandatory, isn't it? Is there any way to disable audio cache? Alternatively, is there any way to redirect audio cache to temp folder?
Why you set seekmode=0 is also a mystery.
Really? From your documentation:
0: linear access, the definition of slow but should make some formats "usable"
Shouldn't it mean that seekmode=0 can have higher success at decoding formats? If so, IMO it makes sense using it for a "universal" source function.
My recommendation to you is to read the manuals first and script later.
Do you refer to FFmpegSource manuals? I have found only a html file called "FFmpegSource Documentation" written by you, I guess. I read it.
I have read some portions of FFmpegSource Doom9 forum thread too.
If you can point me other resources, please do it, I will appreciate.
:)
Bye
Myrsloik
24th November 2008, 10:16
Seekmode=0 is most of the time useless unless you can guarantee linear access. So much for being universal...
Also if you for some reason really have to create the cache(s) somewhere else (why exactly?) generate a random temporary filename for it and then delete it when the script closes using on of the utility filters I can't remember the name of (or at least I think it exists). Of course you'll still clog up the temp directory if something crashes...
I guess what I'm trying to say is: why are you trying to change the default behavior in the first place? which problem are you trying to solve?
MrC
24th November 2008, 10:59
Ok about seekmode=0. I will remove it.
The reason to create cache files in a different (safe) folder is: what does it happen if you try to open a file located in a read-only position (i.e. CD or DVD)? FFmpegSource will prompt:
Failed to write video cache info
It would be great if you may add an input option to save elsewhere cache files. Otherwise I will manage it by myself.
Thanks in advance
:)
Bye
Comatose
24th November 2008, 15:03
Seekmode=0 is most of the time useless unless you can guarantee linear access. So much for being universal...
Well, reading what he quoted from the documentation, it gives off the impression that seekmode=0 is the same a seekzero=true for DirectShowSource() or EnsureVBRMP3Sync() for audio... which guarantees frame accuracy, but is "the definition of slow" :P
MrC
30th November 2008, 15:52
Finally I have come out with this script:
# A2DSource library: Universal AviSynth Source Functions
# Written by MrC (November 2008)
# Following AviSynth plugins are required in the same A2DSource folder:
# FFMpegSource.dll more info @ http://forum.doom9.org/showthread.php?t=127037
# GetSystemEnv.dll more info @ http://avisynth.org/stickboy
LoadPlugin("FFMpegSource.dll")
LoadPlugin("GetSystemEnv.dll")
Function A2DVideoSource(string VideoSource, string "CacheFolder", bool "debug")
{
CacheFolder = default(CacheFolder, GetSystemEnv("temp"))
debug = default(debug, false)
Try {
SourceStr = "A2DVideoSource: AVISource"
Video = AVISource(VideoSource, audio = false)
}
Catch(Err_Msg) {
Try {
SourceStr = "A2DVideoSource: DirectShowSource"
Video = DirectShowSource(VideoSource, convertfps = true, audio = false)
}
Catch(Err_Msg) {
SourceStr = "A2DVideoSource: FFmpegSource"
Video = FFmpegSource(VideoSource, vtrack = -1, atrack = -2, vcachefile = CacheFolder + "\A2DFFV_" + String(Rand()) + ".cache")
}
}
Video = (debug == true) ? Subtitle(Video.Info(), SourceStr, font = "courier new", size = 16, align = 1) : Video
return(Video)
}
Function A2DAudioSource(string AudioSource, string "CacheFolder")
{
CacheFolder = default(CacheFolder, GetSystemEnv("temp"))
Try {
Audio = DirectShowSource(AudioSource, video = false)
}
Catch(Err_Msg) {
Audio = FFAudioSource(AudioSource, atrack = -1, acachefile = CacheFolder + "\A2DFFA1_" + String(Rand()) + ".cache", acachefile2 = CacheFolder + "\A2DFFA2_" + String(Rand()) + ".cache")
}
return(Audio)
}
I hope it can be useful for somebody
;)
Bye
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.