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

Reply
 
Thread Tools Search this Thread Display Modes
Old 21st November 2008, 13:17   #1  |  Link
MrC
AVStoDVD Dev
 
MrC's Avatar
 
Join Date: Apr 2006
Location: Italy
Posts: 1,291
Universal Source functions

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:

Code:
# 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
__________________
MrC

AVStoDVD Homepage
AVStoDVD @ Doom9 Forum
MrC is offline   Reply With Quote
Old 22nd November 2008, 00:28   #2  |  Link
Myrsloik
Professional Code Monkey
 
Myrsloik's Avatar
 
Join Date: Jun 2003
Location: Ikea Chair
Posts: 1,920
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.
__________________
VapourSynth - proving that scripting languages and video processing isn't dead yet
Myrsloik is offline   Reply With Quote
Old 23rd November 2008, 13:56   #3  |  Link
MrC
AVStoDVD Dev
 
MrC's Avatar
 
Join Date: Apr 2006
Location: Italy
Posts: 1,291
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.

Quote:
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?

Quote:
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.

Quote:
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
__________________
MrC

AVStoDVD Homepage
AVStoDVD @ Doom9 Forum
MrC is offline   Reply With Quote
Old 24th November 2008, 09:16   #4  |  Link
Myrsloik
Professional Code Monkey
 
Myrsloik's Avatar
 
Join Date: Jun 2003
Location: Ikea Chair
Posts: 1,920
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?
__________________
VapourSynth - proving that scripting languages and video processing isn't dead yet
Myrsloik is offline   Reply With Quote
Old 24th November 2008, 09:59   #5  |  Link
MrC
AVStoDVD Dev
 
MrC's Avatar
 
Join Date: Apr 2006
Location: Italy
Posts: 1,291
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:

Code:
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
__________________
MrC

AVStoDVD Homepage
AVStoDVD @ Doom9 Forum
MrC is offline   Reply With Quote
Old 24th November 2008, 14:03   #6  |  Link
Comatose
Registered User
 
Join Date: Dec 2007
Posts: 639
Quote:
Originally Posted by Myrsloik View Post
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
Comatose is offline   Reply With Quote
Old 30th November 2008, 14:52   #7  |  Link
MrC
AVStoDVD Dev
 
MrC's Avatar
 
Join Date: Apr 2006
Location: Italy
Posts: 1,291
Finally I have come out with this script:

Code:
# 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
__________________
MrC

AVStoDVD Homepage
AVStoDVD @ Doom9 Forum
MrC is offline   Reply With Quote
Reply

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 22:57.


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