Quantcast Avisynth: Trim and Conditionalfilter? - digitalFAQ.com Forums [Archives]
  #1  
10-27-2004, 06:26 PM
Mental Mental is offline
Free Member
 
Join Date: Sep 2004
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
I found this example on an avisynth site

conditionalfilter(last,last,last.trim(1,0),"YDiffe renceToNext()",">","10", show=true)

It looks like the basis for solving a problem I have involving scene changes, but I always get the error saying "Invalid arguments to function Trim".

As this is copied and pasted exactly from the original and I have the latest avisynth shouldn`t this be working?

It is the trim part causing the problem but I`m unsure why.

What I`m trying to do is compare the difference between two frames and if a difference is found replace the current frame with a previous one (a possible solution to a problem I have mentioned in a seperate post).

Any ideas as to why this is not working?

I`m new to the more complex side of avisynth like this, and can`t seem to figure out whats doing it. If I remove last.trim(1,0) and change it for something I know is okay like video (the variable holding my video footage) the error message changes to saying Conditional Filter has invalid arguments
__________________
Dave
Reply With Quote
Someday, 12:01 PM
admin's Avatar
Site Staff / Ad Manager
 
Join Date: Dec 2002
Posts: 42
Thanks: ∞
Thanked 42 Times in 42 Posts
  #2  
10-28-2004, 03:29 AM
Dialhot Dialhot is offline
Free Member
 
Join Date: May 2003
Posts: 10,463
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Mental
conditionalfilter(last,last,last.trim(1,0),"YDiffe renceToNext()",">","10", show=true)

It looks like the basis for solving a problem I have involving scene changes, but I always get the error saying "Invalid arguments to function Trim".

As this is copied and pasted exactly from the original and I have the latest avisynth shouldn`t this be working?
I'm not sure you can use this exact syntax because "last" is a special clip that change after every intruction, so here it change within the conditionnalfilter itself ! Try to use this :
Code:
clip1=last
clip2=clip1.Trim(1,0)
conditionalfilter(clip1,clip2,clip1,"YDifferenceToNext()",">","10", show=true)
Reply With Quote
  #3  
10-28-2004, 04:21 AM
Mental Mental is offline
Free Member
 
Join Date: Sep 2004
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
It still gives the same error

"Invalid arguments to function Trim" is the error, but I don`t see why although if I cpy and paste scriptclip examples they also give me a similar argument.

Is there a straightforward way, not needing to use trim that could check between current and previous frames?

Thanks.
__________________
Dave
Reply With Quote
  #4  
10-28-2004, 04:33 AM
Dialhot Dialhot is offline
Free Member
 
Join Date: May 2003
Posts: 10,463
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Mental
Is there a straightforward way, not needing to use trim that could check between current and previous frames?
Use Scriptclip and not conditionnalfilter.
You can see how we use it in optimal filter (see sticky post in optimal script section of the forum).
Reply With Quote
  #5  
10-28-2004, 04:47 AM
incredible incredible is offline
Free Member
 
Join Date: May 2003
Location: Germany
Posts: 3,189
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to incredible
Code:
tr=Trim(last,1,0) 
conditionalfilter(last,tr,last,"YDifferenceToNext()",">","10", show=true)
"YDifferenceToNext()",">","10" ....

... does NOT! only detect scenechanges! It also lets get the trimmed stream active if a LUMA change above 10 will happen and thats also very often the case in scenes including much motion! That Workout above even if it would work the way YOU want it, it will mess up your video totally IMHO. Means that your final stream will result in fast motion scenes in a freaky jerkyness,

A real scenechange detector, but its purpose was to write the Scenechanges into a file "Scenechanges.txt"! I did that one some weeks ago as part for a scene pattern detector out of a fieldblended stream.
Do take what you need:

Code:
avisource("Video.avi",false)
pointresize(width/2,height/2).assumefps(250).greyscale().levels(20,1,40,0,255)
ScriptClip("filename = "+chr(34)+"Scenechanges.txt"+chr(34)+chr(13)+\
"diff = YDifferenceFromPrevious()-YDifferencetonext()"+chr(13)+\
"(diff > 15) ? WriteFile(last, filename, "+chr(34)+"current_frame"+chr(34)+",append=true) : last")
Also above you see the work of scriptclip in THIS case as mathematical formulas WITHIN Conditionalfilter() isnt supported (IMHO).
Reply With Quote
  #6  
10-28-2004, 06:00 AM
Mental Mental is offline
Free Member
 
Join Date: Sep 2004
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
It`s weird but neither this example nor the use of scriptclip in the optimal scripts section is working at all, as with the conditional filter I get an error about invalid arguments but it should be working fine

I`ve been trying to get this working for two days now and it seems avisynth is being temperamental and just won`t let me. I shall try again after work, thanks for all the help - it has shown me what should work, it seems to be something stopping it working but if I can find out what it looks like it would work.
__________________
Dave
Reply With Quote
  #7  
10-28-2004, 06:02 AM
Dialhot Dialhot is offline
Free Member
 
Join Date: May 2003
Posts: 10,463
Thanks: 0
Thanked 0 Times in 0 Posts
Try to do a script with ONLY a trim line, just to see if the isn't an issue with all you are doing before the trim in the script.
Reply With Quote
  #8  
10-28-2004, 06:20 AM
incredible incredible is offline
Free Member
 
Join Date: May 2003
Location: Germany
Posts: 3,189
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to incredible
Show us your ACTUAL FULL script, maybe you assignet already your videodata to a variable so trim has to be assignet different
Reply With Quote
  #9  
10-28-2004, 06:29 AM
Mental Mental is offline
Free Member
 
Join Date: Sep 2004
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
I wrote a basic script. This doesn`t work:

film=avisource("C:\AVI\video_data\video.avi")
tr=Trim(last,1,0)
return(tr)

But if I take out the film= so it reads

avisource("C:\AVI\video_data\video.avi")
tr=Trim(last,1,0)
return(tr)

It works but I need to be able to use an assigned name, like film, with trim as the script uses more than one video.

I`m new to complex avisynth scripting so forgive any dumb comments but it appears that what is happening is that "last" works with just one video input like avisource("x.avi") rather than x=avisource("x.avi")?

In that case would it be possible to somehow feed trim the name of a video file to connect with the value of last, something like tr=trim(last(video),1,0) ?

I did try this but as far as I know last can`t have a parameter.

Even if it is not, I do want to say thanks for all the help (and quick replies too) - it is DEFINITELY appreciated - thanks

I forgot to mention I upgraded from avisynth 2.55 to latest alpha in case that helped but didn`t have a different effect.
__________________
Dave
Reply With Quote
  #10  
10-28-2004, 08:54 AM
Dialhot Dialhot is offline
Free Member
 
Join Date: May 2003
Posts: 10,463
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Mental
film=avisource("C:\AVI\video_data\video.avi")
tr=Trim(last,1,0)
return(tr)
This does not work because "film=Avisource(...)" is not a command that instantiate the "last" variable.
You have to use "tr = trim(film,1,0)"

Last is instantiated only if the result of a command is not already set to a variable name.
Reply With Quote
  #11  
10-28-2004, 05:06 PM
Mental Mental is offline
Free Member
 
Join Date: Sep 2004
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
So it isn`t possible with trim to return the most recent frame to use in comparisons?
__________________
Dave
Reply With Quote
  #12  
10-29-2004, 02:04 AM
incredible incredible is offline
Free Member
 
Join Date: May 2003
Location: Germany
Posts: 3,189
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to incredible
If you just load a movie as global like

avisource(xxxxx.xx)

then the that actual frameserved peace of stream will be "last".

film=avisource(xxxxx.xx)

Means you assign the stream to a variable and so you can assign in a specific way commands to specific variables containing streams.
Quote:
So it isn`t possible with trim to return the most recent frame to use in comparisons?
Shure, as pointed out!

film=avisource(xxxxx.xx)
tr=trim(film,1,0)
return tr

Means only your "film" stream will be treaten.
Reply With Quote
  #13  
10-29-2004, 02:40 AM
muaddib muaddib is offline
Free Member
 
Join Date: Jun 2002
Location: So Paulo - Brasil
Posts: 879
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by incredible
film=avisource(xxxxx.xx)
tr=trim(film,1,0)
With this script we have two streams to work with, and the tr stream will be exactly 1 frame ahead of the film stream.
Is that correct?
Reply With Quote
  #14  
10-29-2004, 02:49 AM
Dialhot Dialhot is offline
Free Member
 
Join Date: May 2003
Posts: 10,463
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by muaddib
Is that correct?
I think so.
Reply With Quote
  #15  
10-29-2004, 04:27 AM
incredible incredible is offline
Free Member
 
Join Date: May 2003
Location: Germany
Posts: 3,189
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to incredible
Exact!

So "film" is one frame ahead of "tr" (if its wanted).
Now you can perform comparings or so of these two streams.
OR finally you could let become "tr" as final single video out:

film=avisource(xxxxx.xx)
tr=trim(film,1,0)
return tr # ------- "tr" becomes "last"

or do let a filter of your choice let become "tr"as final single video out:

film=avisource(xxxxx.xx)
tr=trim(film,1,0)
undot(tr) # -------- "tr" becomes "last"!
Bicubicresize(352,480) # from here on as usual avisynth uses "last"
Reply With Quote
  #16  
10-29-2004, 04:33 AM
incredible incredible is offline
Free Member
 
Join Date: May 2003
Location: Germany
Posts: 3,189
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to incredible
A nice tip for comparings!

v= Avisource("MainVideo.avi")
a= v.deen().subtitle("Preview of Deen()",10,10)
b= v.TemporalSoften().subtitle("Preview of TemporalSoften()",10,10)
interleave(a,b)

The interleave command does order the frames of "a" and "b" one by one.
Means:

a_frame1 ---- b_frame1 ---- a_frame2 ---- b_frame2 ---- a_frame3 ---- b_frame3 ... etc.

So you can use that procedure to just use your "frame forward/backward" keys of Vdub for instance to compare both filterings immediately.
Its like in Photoshop layer on/off.


So do forget that "StackHorizontal()" Method which is often used for compare side by side as with the method above your eyes will see directly whats different.
Think about it as using it in Moviestacker Muaddib
Reply With Quote
  #17  
10-29-2004, 10:29 AM
muaddib muaddib is offline
Free Member
 
Join Date: Jun 2002
Location: So Paulo - Brasil
Posts: 879
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by incredible
Exact!So "film" is one frame ahead of "tr" (if its wanted).
Isn't it the opposite?
I mean the "tr" is one frame ahead of "film"?
If we "delete" the first frame of "tr" with "trim", them (thinking film as the source) "film" will be at frame 0 while "tr" will be at frame 1...

Quote:
Originally Posted by incredible
Think about it as using it in Moviestacker Muaddib
Thanks incredible, I will!
Reply With Quote
  #18  
10-29-2004, 10:38 AM
incredible incredible is offline
Free Member
 
Join Date: May 2003
Location: Germany
Posts: 3,189
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to incredible
hhhmmmm .... :banghead:

Yep, ... the one which is cuttet will be the one frame ahead.
Reply With Quote
  #19  
10-30-2004, 11:27 AM
Mental Mental is offline
Free Member
 
Join Date: Sep 2004
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
I`ve just got on my pc and seen all these replies - brilliant

I`m going to read these fully later and work through what`s come up in them, I`ve read through briefly and seen it noticed one film is a frame ahead of the other.

That is right though, the idea is that the difference in motion between two frames adds to the 3D effect and you get proper 3D. Works great but then each scene change has a bright red flash where you see one frame in red from before - hence my trying to get rid of excess red in that frame, or replace it with unchanged (non red) version
__________________
Dave
Reply With Quote
  #20  
10-31-2004, 07:34 AM
Mental Mental is offline
Free Member
 
Join Date: Sep 2004
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Got the script replacing red flashes (scene changes) with the help of all of your suggestions, came up with the following but it still leaves the audio short:

# video is the 3D version of the film
lst=Trim(video,1,0)

x=ConditionalFilter(lst, video, lst.trim(1,0), "VDifferenceToNext()", ">", "16", true)

x=Tweak(x, sat=2,bright=4,cont=2)
audio=SSRC(audio, 48000)
film=audiodub(x, audio)
film=AssumeFPS(film, 25.000, true)
return(film)

Is this because the video is being trimmed? As I understood it this script extract should replace a frame with another rather than delete a frame entirely?

Thanks again for all the help, I couldn`t have got this far without all the help I`ve had - and it`s made me realise avisynth is even more amazing than I thought
__________________
Dave
Reply With Quote
Reply




Similar Threads
Thread Thread Starter Forum Replies Last Post
KVCD: Can't trim file? FFCcottage Video Encoding and Conversion 3 05-04-2007 09:22 AM
Avisynth: Is is possible to use the trim() function with audio supermule Avisynth Scripting 3 09-10-2005 03:05 AM
How can you trim kvcd without screwing it up? phuquehair Video Encoding and Conversion 5 02-01-2005 10:03 AM
Avisynth: Trim? bigggt Avisynth Scripting 13 09-04-2004 03:05 AM
Avisynth: Trim and FadeIn/FadeOut2 J-Wo Avisynth Scripting 3 06-29-2003 10:55 PM

Thread Tools



 
All times are GMT -5. The time now is 02:09 PM  —  vBulletin Jelsoft Enterprises Ltd