digitalFAQ.com Forums [Archives]

digitalFAQ.com Forums [Archives] (http://www.digitalfaq.com/archives/)
-   Avisynth Scripting (http://www.digitalfaq.com/archives/avisynth/)
-   -   Avisynth: Trim and ConditionalFilter? (http://www.digitalfaq.com/archives/avisynth/12752-avisynth-trim-conditionalfilter.html)

Mental 10-27-2004 06:26 PM

Avisynth: Trim and ConditionalFilter?
 
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 :(

Dialhot 10-28-2004 03:29 AM

Re: Trim and ConditionalFilter
 
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)


Mental 10-28-2004 04:21 AM

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.

Dialhot 10-28-2004 04:33 AM

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).

incredible 10-28-2004 04:47 AM

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).

Mental 10-28-2004 06:00 AM

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.

Dialhot 10-28-2004 06:02 AM

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.

incredible 10-28-2004 06:20 AM

Show us your ACTUAL FULL script, maybe you assignet already your videodata to a variable so trim has to be assignet different

Mental 10-28-2004 06:29 AM

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.

Dialhot 10-28-2004 08:54 AM

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.

Mental 10-28-2004 05:06 PM

So it isn`t possible with trim to return the most recent frame to use in comparisons?

incredible 10-29-2004 02:04 AM

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.

muaddib 10-29-2004 02:40 AM

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?

Dialhot 10-29-2004 02:49 AM

Quote:

Originally Posted by muaddib
Is that correct?

I think so.

incredible 10-29-2004 04:27 AM

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"

incredible 10-29-2004 04:33 AM

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 ;-)

muaddib 10-29-2004 10:29 AM

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"? :roll:
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! :wink:

incredible 10-29-2004 10:38 AM

Ähhhmmmm .... :banghead:

Yep, ... the one which is cuttet will be the one frame ahead. :)

Mental 10-30-2004 11:27 AM

I`ve just got on my pc and seen all these replies - brilliant :D

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 :)

Mental 10-31-2004 07:34 AM

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 :!:


All times are GMT -5. The time now is 06:50 PM  —  vBulletin © Jelsoft Enterprises Ltd

Site design, images and content © 2002-2020 The Digital FAQ, www.digitalFAQ.com
Forum Software by vBulletin · Copyright © 2020 Jelsoft Enterprises Ltd.