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
Register FAQ Calendar Today's Posts Search

Reply
 
Thread Tools Search this Thread Display Modes
Old 27th December 2018, 11:12   #1  |  Link
StaceyG
Registered User
 
Join Date: Dec 2018
Posts: 6
Duplicating part of an avi frame

Is there a filter like FreezeFrame that can replace part of a frame? Say the upper 50%.
StaceyG is offline   Reply With Quote
Old 27th December 2018, 15:00   #2  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,829
It's easy to do yourself. The following takes the top half of 50 frames from "A" and stacks them onto the bottom half of 50 different frames from "B" (assuming both were 720p before cropping). I'm just making stuff up to offer examples, not knowing exactly what you're wanting to achieve. "A" and "B" could be taken from the same source, if that's the sort of thing you want to do.

A = AVISource(Video.avi)
B = AVISource(AnotherVideo.avi)
C = A.Crop(0,0,0-360).Trim(100,149)
D = B.Crop(0,360,0,0).Trim(730,779)
StackVertical(C,D)

Or there's Overlay(). It doesn't require the videos to have the same dimensions or frame rate etc. Once again I'm just offering an imaginary scenario.
The following resizes a 720p video to half it's original size (VideoA), adds borders to the width to make it 1280x360, and overlays it onto another 720p video (VideoB). By default the overlayed video is positioned at the top/left corner of the base video.

VideoA = AVISource(Video.avi).Spline36Resize(640,360).AddBorders(320,0,320,0)
VideoB = AVISource(AnotherVideo.avi).Spline36Resize(1280,720)
Overlay(VideoB, VideoA)

Last edited by hello_hello; 27th December 2018 at 15:13.
hello_hello is offline   Reply With Quote
Old 27th December 2018, 16:37   #3  |  Link
johnmeyer
Registered User
 
Join Date: Feb 2002
Location: California
Posts: 2,695
If I understand your request, what you are trying to do is usually called "compositing," which means combining something else with a video frame. This "something else" can be a graphic (like text in a TV news lower third); it can be another video (like the "Brady Bunch" video wall); it can be part of the previous scene (like what happens during a crossfade between two scenes; etc.

There are thousands of other examples, such as fixing a glitch on one frame by overlaying (and moving, if needed) part of a previous frame.

Most of these examples are trivial to do in any competent NLE (Non-Linear Editor). AVISynth can do them as well, but is a poor choice for any of the examples I just cited. However, which tool is best depends on what you are trying to accomplish. Perhaps you can provide a little more detail about what you are trying to do.

Last edited by johnmeyer; 27th December 2018 at 16:40.
johnmeyer is offline   Reply With Quote
Old 30th December 2018, 20:18   #4  |  Link
manono
Moderator
 
Join Date: Oct 2001
Location: Hawaii
Posts: 7,406
Quote:
Originally Posted by StaceyG View Post
Is there a filter like FreezeFrame that can replace part of a frame? Say the upper 50%.
Similar to hello_hello's solution:

###To freezeframe only a part of a frame over a range of frames:
#A=Last
#B=A.FreezeFrame(35605,35609,35605)##range of frames to freezeframe
#B=B.Crop(0,0,0,-240)#freezeframe the top half of a 480p frame
#C=Overlay(A,B,0,0)
#ReplaceFramesSimple(A,C,Mappings="[35605 35609] ")#ReplaceFramesSimple is a part of stickboy's RemapFrames
manono is offline   Reply With Quote
Old 22nd January 2019, 08:37   #5  |  Link
StaceyG
Registered User
 
Join Date: Dec 2018
Posts: 6
Thank you hello_hello, johnmeyer and manono. I wanted to replace the top part of bad frame -- as opposed to the entire frame:
A = FreezeFrame(A,100,100,101).
Using the suggested approach, I replaced the problem part of the frame with
A = Trim(A,0,99) ++ StackVertical(Crop(A,0,0,0,-288).Trim(101,101),Crop(A,0,288,0,0).Trim(100,100)) ++ Trim(A,101,0)
StaceyG is offline   Reply With Quote
Old 22nd January 2019, 16:24   #6  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Quote:
A = Trim(A,0,99) ++ StackVertical(Crop(A,0,0,0,-288).Trim(101,101),Crop(A,0,288,0,0).Trim(100,100)) ++ Trim(A,101,0)
Does that work OK ?
Code:
Crop(A,0,0,0,-288)    # Crop 288 off bottom
...
Crop(A,0,288,0,0)    #Crop 288 off top
If works, then must be height=512.

Better would be (if 288 amount to chop off bottom)
Code:
BOTCROP=288
Crop(A,0,0,0,-BOTCROP)            # Crop  bottom
...
Crop(A,0,A.Height-BOTCROP,0,0)    # Crop top
Or specifiying 288 from top (if 288 amount to chop off top)
Code:
TOPCROP=288
Crop(A,0,0,0,-(A.Height-TOPCROP))  # Crop bottom
...
Crop(A,0,TOPCROP,0,0)              # crop top
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 22nd January 2019 at 21:33.
StainlessS is offline   Reply With Quote
Old 22nd January 2019, 22:25   #7  |  Link
LemMotlow
Registered User
 
Join Date: Jul 2011
Location: Tennessee, USA
Posts: 266
I've done this often. Use part of one frame to replace part of other frames. Lots of ways to do it, I guess. Usually I use this on small segments of bigger files, then join the repaired segment later. And usually I have to do this by making "repair patches" on a number of frames, sometimes dozens.

Assume 1280x720p frame. Replace frame 100 with top 100 pixels of frame 101.

Code:
A1=last
B=A1.FreezeFrame(100,100,101).Crop(0,0,0,-620)  #<- Create repair "patch", 1280x100
C=Overlay(A1,B,x=0,y=0)                         #<- Overlay "B" patch over frames.
A2=ReplaceFramesSimple(A1,C,mappings="100")     #<- new video with repaired frame 100.

return A2
You can also create a video that contains only 1 repair frame and use that frame to replace any number of other frames in an original video, using "RemapFrames". http://avisynth.nl/index.php/RemapFrames#RemapFrames

My $.02 USD (0.0176 EUR)

Last edited by LemMotlow; 22nd January 2019 at 22:38.
LemMotlow is offline   Reply With Quote
Old 23rd January 2019, 04:22   #8  |  Link
StaceyG
Registered User
 
Join Date: Dec 2018
Posts: 6
Thank you StainlessS and LemMotlow, including a variable for the patch height is a great idea:

PATCHHEIGHT=288
A = Trim(A,0,99) ++ StackVertical(Crop(A,0,0,0,-(A.Height-PATCHHEIGHT)).Trim(101,101),Crop(A,0,PATCHHEIGHT,0,0).Trim(100,100)) ++ Trim(A,101,0)

Plus Overlay does make it simpler. (For larger files, making the changes to a segment and applying it at the end with ReplaceFramesSimple will be very useful):

PATCHHEIGHT=288
A = Overlay(A,FreezeFrame(A,100,100,101).Crop(0,0,0,-(A.Height-PATCHHEIGHT)),0,0)
StaceyG is offline   Reply With Quote
Old 26th January 2019, 17:54   #9  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Incidentally, if you just wanted to Interpolate [whole] frames/ranges rather than just replace a part of frames/ranges, you might try Morpheus,
(you might not want this if your bad frames precede or follow a cut/scene change, [where you would get a blend]).

Code:
#Import(".\Morpheus.avs") # or put in plugins dir

Colorbars(Pixel_type="YV12").KillAudio.ShowFrameNumber
INCLUSIVE=True
SHOW=True

INCLUSIVE_CMD="""*  # <<<<==== Asterisk(Star) is first character, ie is a String Command, else is a Filename.
    10 11           # This Is a Comment, Interpolate range 10 to 11, 2 frames, SPACE separator
    15              # single frame at 15
    20 -2           # two frames at 20
    30,31           # comma separator, 30 to 31
"""
EXCLUSIVE_CMD="""*  # <<<<==== Asterisk(Star) is first character, ie is a String Command, else is a Filename.
    9  12           # Same results as above but specifying source frames for interpolation rather than interpolated frames (MUST BE PAIRS).
    14 16
    19 22
    29,32
"""

# Select Inclusive or Exclusive CMD depending upon value of INCLUSIVE
CMD = (INCLUSIVE) ? INCLUSIVE_CMD : EXCLUSIVE_CMD

Morpheus(CMD,Inclusive=INCLUSIVE,Show=SHOW)
Might be more convenient.
Morpheus:- https://forum.doom9.org/showthread.p...98#post1859298
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 26th January 2019 at 18:21.
StainlessS is offline   Reply With Quote
Old 28th January 2019, 07:22   #10  |  Link
manono
Moderator
 
Join Date: Oct 2001
Location: Hawaii
Posts: 7,406
Quote:
Originally Posted by StainlessS View Post
Incidentally, if you just wanted to Interpolate [whole] frames/ranges rather than just replace a part of frames/ranges...
Interpolation of parts of frames individually or over a series of frames is just as easy as freeze-framing parts of frames over a series of frames.
manono is offline   Reply With Quote
Old 28th January 2019, 13:23   #11  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Quote:
Originally Posted by manono View Post
Interpolation of parts of frames individually or over a series of frames is just as easy as freeze-framing parts of frames over a series of frames.
No doubt.
Suggestion may or may not be more convenient, the ranges in supplied script were just from an existing demo, was only intended to show acceptable CMD format for Morpheus.
EDIT: Also, single frame CMD file for Morpheus could quite easily be machine generated (depending upon being able to machine identify bad frames).
If the problem is some crud before/after scene change (from film source, glue and stuff), then interpolation probably not a viable option.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 28th January 2019 at 13:30.
StainlessS is offline   Reply With Quote
Old 28th January 2019, 20:15   #12  |  Link
manono
Moderator
 
Join Date: Oct 2001
Location: Hawaii
Posts: 7,406
Quote:
Originally Posted by StainlessS View Post
Suggestion may or may not be more convenient,,,
Looked kind of complicated to me. I prefer ReplaceFramesMC used as so:

A=ReplaceFramesMC(35170,3)###Interpolate 3 frames beginning wirh #35170
A=A.Crop(450,0,0,-300)###Interpolates only top right side of frame
Overlay(Last,A,450,0)###overlay interpolated portion onto original frame


The function:

######################################################

function ReplaceFramesMC(clip Source, int N, int "X")
{
# N is number of the 1st frame in Source that needs replacing.
# X is total number of frames to replace
#e.g. ReplaceFramesMC(101, 5) would replace 101,102,103,104,105 , by using 100 and 106 as reference points for mflowfps interpolation

X = Default(X, 1)

start=Source.trim(N-1,-1) #one good frame before, used for interpolation reference point
end=Source.trim(N+X,-1) #one good frame after, used for interpolation reference point

start+end
AssumeFPS(1) #temporarily FPS=1 to use mflowfps

super = MSuper(pel=2, hpad=0, vpad=0, rfilter=4)
backward_1 = MAnalyse(super, chroma=false, isb=true, blksize=16, searchparam=3, plevel=0, search=3, badrange=(-24))
forward_1 = MAnalyse(super, chroma=false, isb=false, blksize=16, searchparam=3, plevel=0, search=3, badrange=(-24))
backward_2 = MRecalculate(super, chroma=false, backward_1, blksize=8, searchparam=1, search=3)
forward_2 = MRecalculate(super, chroma=false, forward_1, blksize=8, searchparam=1, search=3)
backward_3 = MRecalculate(super, chroma=false, backward_2, blksize=4, searchparam=0, search=3)
forward_3 = MRecalculate(super, chroma=false, forward_2, blksize=4, searchparam=0, search=3)
MBlockFps(super, backward_3, forward_3, num=X+1, den=1, mode=0)

AssumeFPS(FrameRate(Source)) #return back to normal source framerate for joining
Trim(1, framecount-1) #trim ends, leaving replacement frames

Source.trim(0,-N) ++ last ++ Source.trim(N+X+1,0)
}




######################################################
#
# Insert missing frames
#
######################################################

function InsertFramesMC(clip Source, int N, int "X")
{
# Insert X motion interpolated frames at N
# N is the insertion point
# X is the number of frames to insert
# the frames will be interpolated with Source frames N-1 and N as references

X = Default(X, 1)

loop(Source, X+1, N, N)
ReplaceFramesMC(N, X)
}

######################################################

function ReplaceFrameNext(clip Source, int N)
{
# Replace frame at N with frame at N+1
# N is the frame to replace
# with frame at N+1

loop(Source, 0, N, N)
loop(last, 2, N, N)
}

######################################################

function ReplaceFramePrev(clip Source, int N)
{
# Replace frame at N with frame at N-1
# N is the frame to replace
# with frame at N-1

loop(Source, 0, N, N)
loop(last, 2, N-1, N-1)
}

######################################################


jagabo at Videohelp.com wrote it based on, I think, a similar function he found here on Doom9. It has other uses as well. Virtually any filter can be made to work on parts of a frame. And, if worse comes to worst, one can always create a mask for filtering more precisely the parts of a frame needing filtering.

Quote:
If the problem is some crud before/after scene change (from film source, glue and stuff)...
The story of my life. With jagabo's help I developed FreezeFrameMC:

#FreezeFrame(clip clip, int first-frame, int last-frame, int source-frame)

### This function FreezeFrames 1, 2 or 3 frames either before (B) or after (A) a scene change
### Then one appropriate frame will be interpolated to get rid of the slight 'stutter'
### duplicate frames might create. The interpolater is Gavino's 'FixBadFRames' filter,
### included here. Required are MVTools2.dll, RemapFrames.dll, and the FreezeFrameMC.avs.
### Much thanks go out to jagabo at videohelp.com who pointed me in the right direction
### when I immediately got stuck (having never written a function before).

###Usage FFA2(242) - Freezes 2 frames After a scene change beginning with frame number 242 immediately after the change with the second one interpolated
###Usage FFB1(397) - Freezes and interpolates 1 frame Before a scene change using frame number 397, the one just before the scene change



function FixBadFrames(clip c, string frames) {
# Replace each frame from a list of 'bad' frames by using MFlowInter to interpolate
# between the nearest pair of 'good' frames
c
sup = MSuper()
bv = MAnalyse(sup, isb=true, delta=2)
fv = MAnalyse(sup, isb=false, delta=2)
candidates = MFlowInter(sup, bv, fv, time=50.0, ml=100).DuplicateFrame(0)
ReplaceFramesSimple(candidates, mappings=frames)
}

#Usage FixBadFrames("34 64 96")

###Freezes the two frames before a scene change and then interpolates the first of the two
function FFB1(clip Source, int N)
{
FreezeFrame(Source, N-1,N,N-1)
FixBadFrames(String(N-1))
}

###Freezes the two frames after a scene change and then interpolates the second of the two
function FFA1(clip Source, int N)
{
FreezeFrame(Source, N,N+1,N+1)
FixBadFrames(String(N+1))
}

###Freezes the three frames before a scene change and then interpolates the first of the three
function FFB2(clip Source, int N)
{
FreezeFrame(Source, N-2,N,N-2)
FixBadFrames(String(N-2))
}

###Freezes the three frames after a scene change and then interpolates the third of the three
function FFA2(clip Source, int N)
{
FreezeFrame(Source, N,N+2,N+2)
FixBadFrames(String(N+2))
}

###Freezes the four frames before a scene change and then interpolates the fourth of the four
function FFB3(clip Source, int N)
{
FreezeFrame(Source, N-3,N,N-3)
FixBadFrames(String(N-3))
}

###Freezes the four frames after a scene change and then interpolates the fourth of the four
function FFA3(clip Source, int N)
{
FreezeFrame(Source, N,N+3,N+3)
FixBadFrames(String(N+3))
}


Up to 4 frames before and/or after a scene change can be frozen/interpolated. It also saves on all the writing required to use Freezeframe alone.

Last edited by manono; 28th January 2019 at 20:26.
manono is offline   Reply With Quote
Old 28th January 2019, 20:50   #13  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
I used to use stuff like that, but had a clip (~ 2010) where needed about 2000 hand edits (glue and stuff), and those type functions would crap out after about 70 replacements (crash).
Morpheus, should easily handle thousands of interpolations, without crashing.

Code:
#Import(".\Morpheus.avs") # or put in plugins dir as an avsi

Colorbars(Pixel_type="YV12").KillAudio.ShowFrameNumber

SHOW=True
Morpheus(".\InterpFrames.txt",show=SHOW)
It dont look that complicated.

EDIT: Where InterpFrames.txt file might contain eg
Code:
10
20
30
50
110
1001
1005
1023
10000
10010
EDIT: The multi-instance style functions (eg Morpheus) can provide both a Multi-instance capable script function where globals are necessary (without interfering with each other),
and also a convenient and easy way to have eg GScript, ScripClip and double quoted strings all in same function.
EDIT: Avs does not support 5 sets of double quotes as used in some languages, eg BASIC I think. Avs supports only triple sets of double quotes which can make life difficult.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 29th January 2019 at 18:12.
StainlessS is offline   Reply With Quote
Reply


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 03:04.


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