View Full Version : Trying to replace a bad frame occuring periodically


chilledinsanity
31st October 2013, 03:32
I have an odd situation I'm trying to fix. I have footage at 60fps where every 2322nd frame is distorting (no idea why it's like this, but that's irrelevant). So I want to do the following:

1. Delete every 2322nd the bad frame (2322, 4644, 6966, etc.)
2. Replace each bad frame with either:
A. A copy of the frame that came before it
or
B. A blend of the frame before / after it.

So I want to replace the bad frames with copies of the adjacent ones or a blend (either solution would be acceptable).

I'm unfortunately kind of clueless how to go about this. Could someone recommend a solution for me? (If this needs to be moved to the newbie section, go ahead)

raffriff42
31st October 2013, 04:39
Plenty of good suggestions here: Can FreezeFrame be applied iteratively? (http://forum.doom9.org/showthread.php?t=169583)

chilledinsanity
31st October 2013, 05:51
Well I'm still bending my head around some of the syntax, but yeah, this is definitely what I need, thanks.

poisondeathray
31st October 2013, 06:11
Gavino helped me out with something similar before

(You need stickboy's ApplyEvery.dll )

eg. If you want replace with a duplicate of the frame before, you would pick 2231 for replace. Frame after would be 2233. I'm assuming you're using avisynth numbering (starting at zero)


LoadPlugin("...\ApplyEvery.dll")

WhatEverSource()

replace = last.SelectEvery(2231, 0) # replacement frames

DeleteEvery(2232, 0) # delete bad frames
InterleaveEvery(replace, 2232, 0) # replace deleted frames





Or you can use motion interpolated replacement frames using MVTools2



LoadPlugin("...\ApplyEvery.dll")

WhatEverSource()

last
sup = MSuper()
bv = MAnalyse(sup, isb=true, delta=2)
fv = MAnalyse(sup, isb=false, delta=2)
interpolated = MFlowInter(sup, bv, fv, time=50.0, ml=100).DuplicateFrame(0)
replace = interpolated.SelectEvery(2232, 0) # replacement frames

DeleteEvery(2232, 0) # delete bad frames
InterleaveEvery(replace, 2232, 0) # replace deleted frames

chilledinsanity
31st October 2013, 06:24
I tried the first script and while it got the total frame number correct and deleted the bad frames, the frames it replaced them with were out of sequence (so if someone was moving forward, they would move back one frame, then forward again).

poisondeathray
31st October 2013, 06:29
I tried the first script and while it got the total frame number correct and deleted the bad frames, the frames it replaced them with were out of sequence (so if someone was moving forward, they would move back one frame, then forward again).

Because the first script replaces with a frame before , so you will get a slight stutter. You can choose a frame after. These are for your "2A ."

If you add showframenumber() after the source filter you can check

Also make sure you are using a frame accurate source filter

The 2nd script is more like a blend, but a motion interpolated new synthesized "inbetween" frame . Sometimes the frames are good, but sometimes there are edge morphing artifacts

poisondeathray
31st October 2013, 06:37
I don't get the backward motion. It should only be stutter from a duplicate . Are you sure you are describing it correctly ?

What source filter are you using ?

e.g.



BlankClip(20000)
ShowFrameNumber()

replace = last.SelectEvery(2231, 0) # replacement frames

DeleteEvery(2232, 0) # delete bad frames
InterleaveEvery(replace, 2232, 0) # replace deleted frames



This should show 02230,02231,02231,02233...

chilledinsanity
31st October 2013, 06:37
"showframenumber" helped explain what was going on. The first instance worked properly, the next ones are getting out of sync and pulling the frames too far back. Which number should I change to try and fix that, replace, deleteevery, or interleaveevery?

This is what I've been using:


LoadPlugin("C:\Program Files (x86)\AviSynth 2.5\plugins\mvtools.dll")
LoadPlugin("C:\Program Files (x86)\AviSynth 2.5\plugins\ApplyEvery.dll")
avisource("D:\EDITING\test\main.avi").ConvertToYV12().showframenumber()
replace = last.SelectEvery(2231, 0) # replacement frames

DeleteEvery(2232, 0) # delete bad frames
InterleaveEvery(replace, 2232, 0) # replace deleted frames

poisondeathray
31st October 2013, 06:40
The first instance worked properly, the next ones are getting out of sync and pulling the frames too far back.



So are you saying the sequence is not perfectly repetitive? Because that script won't work if the sequence changes .

You would need another approach . IS there something about these frames that can be the basis of detection ? e.g. very dark, very bright, some type of distinguishing feature ?

chilledinsanity
31st October 2013, 06:45
No, it IS perfectly repetitive, I think there's something in the script I'm doing wrong, one of these numbers is off by 1. It gets reliably more and more out of sync with each occurence using this script:

For instance 1st instance = copy
2nd instance = taking previous frame
3rd instance = taking from 2 frames behind
4th instance = taking from 3 frames behind
etc.

poisondeathray
31st October 2013, 06:49
Also, I think I wrote the wrong numbers .. it's 2322 not 2232 - a bit dyslexic on my part!

But I can reproduce the problem...I 'll take a close look

poisondeathray
31st October 2013, 06:53
ok just set the offset to 1 on the replacement frames with the same frame number. That will give you the frame after . "-1" will give you the frame before



replace = last.SelectEvery(2322, 1) # replacement frames

DeleteEvery(2322, 0) # delete bad frames
InterleaveEvery(replace, 2322, 0) # replace deleted frames

chilledinsanity
31st October 2013, 06:55
Well okay I wasn't 100% honest because I thought it would just confuse things. The original clip I was working with was at 60fps and has the 2322 frame problem, but I've been experimenting on a decimated clip at 30fps where the same thing occurs at 1611 (reliably). So I only copy / pasted your numbers to avoid confusion. Here is my ACTUAL script:

LoadPlugin("C:\Program Files (x86)\AviSynth 2.5\plugins\mvtools.dll")
LoadPlugin("C:\Program Files (x86)\AviSynth 2.5\plugins\ApplyEvery.dll")
avisource("D:\EDITING\carnevil\main.avi").ConvertToYV12().showframenumber()
replace = last.SelectEvery(1160, 0) # replacement frames

DeleteEvery(1161, 0) # delete bad frames
InterleaveEvery(replace, 1161, 0) # replace deleted frames


So something is still off, but it wasn't your number swap.



EDIT:

Damn, I tried adding the "1" it's still doing it.

poisondeathray
31st October 2013, 06:58
^ I posted before your post, the number should be the same (the interval step size) , just change the offset

duplicate frame after



replace = last.SelectEvery(1161, 1) # replacement frames

DeleteEvery(1161, 0) # delete bad frames
InterleaveEvery(replace, 1161, 0) # replace deleted frames





duplicate frame before



replace = last.SelectEvery(1161, -1) # replacement frames

DeleteEvery(1161, 0) # delete bad frames
InterleaveEvery(replace, 1161, 0) # replace deleted frames

chilledinsanity
31st October 2013, 07:01
1 = makes it miss deleting the bad frame in the first instance
-1 = deletes right frame, but frame desync gets pretty extreme (3479 jumps to 3484 for the 3rd instance)

poisondeathray
31st October 2013, 07:02
Look on the replace line, the interval is different. It should be the same as the deleteevery and interleaveevery lines. (1161 for all three, not 1160 for the replace line)

Copy & paste post #14

Sorry for the confusion earlier.

(I know, I know, Gavino is probably face-palming right now :D:D )

chilledinsanity
31st October 2013, 07:04
I missed that. I think that fixed it, I've tested 3 sequences so far and they all look good, thanks a ton.

EDIT:

Wait, damn, I'm seeing some late one that are out of sync again. I doublechecked them against the original clip to see if they were out of sync, it's the bad frames in the same places, I'm not sure what the hell is going on.


It's working through at least half the clip, there must be some strangeness on my end this time. Thanks again for the help.

poisondeathray
31st October 2013, 07:13
I missed that. I think that fixed it, I've tested 3 sequences so far and they all look good, thanks a ton.

EDIT:

Wait, damn, I'm seeing some late one that are out of sync again. I doublechecked them against the original clip to see if they were out of sync, it's the bad frames in the same places, I'm not sure what the hell is going on.


It seems to work ok on blankclip(20000).showframenumber()


2322
4644
6966
9288
11610
13932
16254
.
.



replace = last.SelectEvery(2322, -1) # replacement frames

DeleteEvery(2322, 0) # delete bad frames
InterleaveEvery(replace, 2322, 0) # replace deleted frames