Log in

View Full Version : ReplaceFrameX & InsertFrameX


hello_hello
14th October 2022, 16:27
ReplaceFrameX is an Avisynth function for replacing bad frames. It can't look for bad frames itself, only replace those you tell it to. Frames can be replaced with duplicates, blended versions of the surrounding frames, or by interpolating frames using FrameRateConverter or MVTools2. The default is to replace frames with duplicates.

InsertFrameX is similar to ReplaceFrameX, but new frames are inserted into the video increasing the frame count (ie to add missing frames). There's an additional argument for inserting silent audio to match, although by default any audio is passed through untouched.

StartBlack, EndBlack, ReplaceBlack, AddBlack & AppendBlack are functions for adding black frames.

Usage instructions at the top of each script.

Edit 2023-01-07 Re-uploaded ReplaceFrameX to fix an error when the number of frames to be replaced wasn't specified. The version date remains the same.
ReplaceFrameX 2022-12-17.avsi (https://files.videohelp.com/u/210984/ReplaceFrameX%202022-12-17.avsi)
InsertFrameX 2022-12-17.avsi (https://files.videohelp.com/u/210984/InsertFrameX%202022-12-17.avsi)
Black (Start, End, Replace, Add, Append) 2022-10-16.avsi (https://files.videohelp.com/u/210984/Black%20%28Start_%20End_%20Replace_%20Add_%20Append%29%202022-10-16.avsi)

Some ReplaceFrameX "Blend" and "FRC" examples.

ReplaceFrameX(56488, Mode="Blend", Position=true) - Replacing frame 56488

https://i.ibb.co/886Xdv8/1-Blend.jpg

ReplaceFrameX(56488, Mode="FRC", Position=true) - Replacing frame 56488

https://i.ibb.co/B3G18NS/1-FRC.jpg

ReplaceFrameX(56488, 2, "Blend", Position=true) - Replacing frames 56488 & 56489

https://i.ibb.co/Z6sdHSP/2-Blend.jpg

ReplaceFrameX(56488, 2, "FRC", Position=true) - Replacing frames 56488 & 56489

https://i.ibb.co/GCk1Q1c/2-FRC.jpg

ReplaceFrameX(56488, 3, "Blend", Position=true) - Replacing frames 56488, 56489 & 56490

https://i.ibb.co/nwLMNgk/3-Blend.jpg

ReplaceFrameX(56488, 3, "FRC", Position=true) - Replacing frames 56488, 56489 & 56490

https://i.ibb.co/PGPf42r/3-FRC.jpg

johnmeyer
14th October 2022, 18:51
Thanks! I may have a use for this down the road.

hello_hello
14th October 2022, 19:33
You're welcome.

hello_hello
14th October 2022, 21:40
I just realised the handling of the first couple, and possibly last couple of frames is bad (otherwise it's okay). I'll upload a new version dated 2022-10-16 sometime soon(ish).

coolgit
15th October 2022, 19:30
ReplaceFrameX(56488, Mode="FRC", Position=true) - replacing frame 56488

This version looked great.

hello_hello
16th October 2022, 04:17
This version looked great.

You can thank the author of FrameRateConverter for that.

There's a link for the fixed version dated 2022-10-16 in the opening post.

To atone for my silliness, I've also added a link for some functions for replacing frames with black ones, or appending black frames to the beginning and/or end of the video.

StainlessS
16th October 2022, 05:09
replacing frames with black ones
Replace single frame with previous or next frame is quite handy and easily implemented.
(handy for quite common bad frame before/after scene change)

hello_hello
16th October 2022, 08:08
Yeah, those functions were specifically for messing with black frames. A couple of them are due to my OCD for beginning and ending every encode with a blank frame.

ReplaceFrameX can replace a frame or frames with duplicates (maximum of 3 in succession). It's usually better for animation as there's lots of duplicates anyway.

ReplaceFrameX(56488, 1, Mode="DupP") - Replaces frame 56488 with a duplicate of the previous frame.
ReplaceFrameX(56488, 1, Mode="DupN") - Replaces frame 56488 with a duplicate of the next frame.

StainlessS
16th October 2022, 12:58
Whoa!,
U dont mess about do U. [dat were a bit qwik]

Tanks.

hello_hello
17th October 2022, 08:10
You're welcome, but the duplicate modes already existed. Replacing the first or last frame with a duplicate was something I forgot to check so that was what I had to fix.

hello_hello
5th December 2022, 01:10
I've added a link for a function called InsertFrameX to the opening post. It's quite similar to ReplaceFrameX, but instead of replacing existing frames it inserts new ones.

There's also a link for a new version of ReplaceFrameX dated 2022-12-05. It's functionality hasn't changed but I fixed an error message relating to "out of range" frame numbers.

StainlessS
5th December 2022, 08:57
but instead of replacing existing frames it inserts new ones.
I have not looked at it at all, but might be good idea to point out caveat, where all frames after inserted frame are
shifted 1 frame later, so any subsequent insertions later in clip will be off by 1 with respect to src (then off by 2 etc).

User really needs to do in reverse order, from end, to start, of insertions. (where multiple insertions)

hello_hello
17th December 2022, 01:45
Based on some info posted by poisondeathray and jagabo at VideoHelp I've updated the scripts so there's links to new versions of ReplaceFrameX/InsetFrameX in the opening post.

Added support for Dogway's two flavours of FrameRateConverter, along with new modes for the RIFE presets. I've also added MVTools2 modes based on jagabo's scripts.

Mode = "Dup", "DupP", "DupN", "Blend", "FRC", "FRCEX", "FRCMIX", "MFlow", "MBlock"
Means
Duplicate Previous/Next, Blend, FrameRateConverter, FrameRateConverterEX, FrameRateConverterMIX, MFlowFPS or MBlockFPS (MVTools2).

Preset (for FrameRateConverter) = "Slowest", "Slower", "Slow", "Normal", "Fast", "Faster", "Anime", "Rife", "RifeHQ" or "RifeAnime".

There's updated instructions at the top of each script.

I have not looked at it at all, but might be good idea to point out caveat, where all frames after inserted frame are
shifted 1 frame later, so any subsequent insertions later in clip will be off by 1 with respect to src (then off by 2 etc).

User really needs to do in reverse order, from end, to start, of insertions. (where multiple insertions)

For InsertFrameX the position argument displays the original frame numbers over the video, and after inserting frames it includes a reminder to add the number of inserted frames to the displayed frame number.
ie Frame 4672 (+3)
It's useful if you're inserting frames once, otherwise yes, it might be easier to use a different method for displaying frame numbers and to work backwards.

rgr
17th December 2024, 14:49
RIFE mode is also limited to 3 frames? Can I select the RIFE model?

hello_hello
18th December 2024, 04:42
It's been a long time since I created those functions but I wasn't able to test the RIFE presets at the time, and they require one of Dogway's FrameRateConverter functions to work.
Looking at the functions though, you can select either Mode="FRCEX" or "FRCMIX" and when using one of those modes you can select Preset="Rife", "RifeHQ" or "RifeAnime", but that's the extent of it.

I don't know if Dogway's functions have changed at all since then or if the RIFE presets still work, but let me know if they don't.