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. |
14th October 2021, 22:00 | #1 | Link |
Registered User
Join Date: Feb 2002
Location: California
Posts: 2,695
|
Script for reliably detecting dropped frames
Dropped frames are common in streamed video and also in screen captures. Many people ask how to fix them. For reference to prior art, here are a few discussions about how to do this:
Dropped frames Automatically fix dups followed (eventually) by drops I created a script which I posted in those threads which sometimes does a good job fixing the problem (yes, there is still an issue with TDecimate, but I think I can fix it). However, even if I come up with a fix to the TDecimate problem it needs a MUCH better method for detecting jumps. It is clear that motion estimation should do a much better job at finding temporal gaps in video than the YDifference method I have been using. To test my first attempt at a motion estimation detection method, I decided to create my own test clip, similar to what poisondeathray did in the first thread linked to above. I wanted a variety of different drop/dup situations, so that's why I'm not using his clip. Here is a link to that tiny 100k video file: https://www.mediafire.com/file/cof5y..._test.mp4/file Here is my first attempt at doing detection using motion estimation: Code:
source = AVISource("e:\fs.avi").ConvertToYV12 super = MSuper(source) backward_vectors = MAnalyse(super, blksize=32, isb = true, delta=1) forward_vectors = MAnalyse(super, blksize=32, isb = false, delta=1) inter = MFlowInter(source,super, backward_vectors, forward_vectors, time=50, ml=70) diff1 = overlay(source,inter, mode="subtract") diff1 = ScriptClip(diff1, "Subtitle(String(Averageluma()))") return diff1 I need help on two things. First, I can't get the estimation to line up. I really don't want to estimate halfway between two frames, but instead want to get the estimate of what the next frame should look like. Using time=100 doesn't do that, so I'm stuck with time=50. Second, I'm not sure Overlay is the best method to compare (subtract) the two frames. I tried mt_makediff, but it didn't do as well. Hopefully someone out there with better skills with MVTools2 can suggest a few changes. I use this tool a lot, but even after fifteen years, and even after many discussions in this forum, I still haven't quite wrapped my head around it. Last edited by johnmeyer; 19th October 2021 at 00:50. |
14th October 2021, 23:38 | #2 | Link | |||
Registered User
Join Date: Mar 2018
Posts: 447
|
Quote:
Quote:
Quote:
It's also possible to get the SAD (sum of absolute differences) of the matched blocks using MVTools MMask kind=1. Those could be compared by getting the average brightness. Brighter than usual could mean a dropped frame. |
|||
15th October 2021, 00:26 | #3 | Link | |||
Registered User
Join Date: Feb 2002
Location: California
Posts: 2,695
|
Quote:
Quote:
Code:
source = AVISource("e:\fs.avi").ConvertToYV12 super = MSuper(source) backward_vectors = MAnalyse(super, blksize=32, isb = true, delta=2) forward_vectors = MAnalyse(super, blksize=32, isb = false, delta=2) inter = MFlowInter(source,super, backward_vectors, forward_vectors, time=50, ml=70) diff1 = overlay(selectevery(source,1,1),inter, mode="subtract") diff1 = ScriptClip(diff1, "Subtitle(String(Averageluma()))") return diff1 Quote:
Code:
source = AVISource("e:\fs.avi").ConvertToYV12 super = MSuper(source) backward_vectors = MAnalyse(super, blksize=32, isb = false, delta=1) inter = MMask(source,backward_vectors,kind=1) diff1 = overlay(selectevery(source,1,1),inter, mode="subtract") diff1 = ScriptClip(diff1, "Subtitle(String(Averageluma()))") return diff1 Last edited by johnmeyer; 15th October 2021 at 00:29. |
|||
15th October 2021, 01:32 | #4 | Link | |
Registered User
Join Date: Sep 2007
Posts: 5,374
|
Quote:
Code:
WhateverSource() source=last super = MSuper(source) backward_vectors = MAnalyse(super, blksize=32, isb = true, delta=2) forward_vectors = MAnalyse(super, blksize=32, isb = false, delta=2) inter = MFlowInter(source,super, backward_vectors, forward_vectors, time=50, ml=70) WhateverSource() source2=last source_even = source2.selecteven() source_odd = source2.selectodd() super_even = MSuper(source_even) backward_vectors = MAnalyse(super_even, blksize=32, isb = true, delta=1) forward_vectors = MAnalyse(super_even, blksize=32, isb = false, delta=1) inter_even = MFlowInter(source_even,super_even, backward_vectors, forward_vectors, time=50, ml=70) super_odd = MSuper(source_odd) backward_vectors = MAnalyse(super_odd, blksize=32, isb = true, delta=1) forward_vectors = MAnalyse(super_odd, blksize=32, isb = false, delta=1) inter_odd= MFlowInter(source_odd,super_odd, backward_vectors, forward_vectors, time=50, ml=70) inter2=interleave(inter_even, inter_odd) subtract(inter, inter2) Levels(127, 1, 129, 0, 255) |
|
15th October 2021, 01:39 | #5 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
Maybe Pel=1 [think default=2, not sure], and/or BlkSize=16.
EDIT: yep, from Old MvTools: "Default is 2 since v1.4.10." so assume mvtools2 is same. Yep, same for mvtools2.
__________________
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; 15th October 2021 at 01:44. |
15th October 2021, 23:33 | #7 | Link | |
Registered User
Join Date: Feb 2002
Location: California
Posts: 2,695
|
Quote:
So, it may not be the explanation, but changing only delta, and nothing else, does break it. I had a long interchange in this forum about six years ago trying to get to the bottom of how the vectors work and what frames are really being used when estimating intermediate frames. I'm going to go back and re-read that entire thread, and then I'm going to carefully read the new MVTools2 documentation. Someone spent quite a bit of time adding information to it, and it looks like there may be a few clues there. I might glance at the source code, as I did yesterday for TDecimate (I've never seen so many If statements in my life). I have written a little C, but not enough to be proficient. However, if the code has a few comments, I may be able to glean a few things. |
|
16th October 2021, 00:08 | #8 | Link |
Registered User
Join Date: Sep 2007
Posts: 5,374
|
To clarify, the n+1 frame is not being interpolated mflowinter when delta=1
A delta of 2 for mflowinter means the n+1 frame is being interpolated. Mvtools2 needs to look at n+2 frame for the foward vector reference in order to interpolate the n+1 frame. A delta of 1 means you're looking at the n+1 frame - the same frame cannot be used as interpolation reference for itself How do you propose to get around "bad" references? They might be placed anywhere in a real-life bad video that has drops/dupes |
16th October 2021, 02:08 | #9 | Link | |
Registered User
Join Date: Feb 2002
Location: California
Posts: 2,695
|
Quote:
If you look at my existing detection logic, I did exactly what I just described (excluding the dup numbers from the comparison logic), and also took care of the other problem, namely that most detection schemes have to be relative to the local video. It is almost never a good idea to just use a fixed, unvarying threshold or detection number. |
|
16th October 2021, 05:35 | #10 | Link | |
Registered User
Join Date: Sep 2007
Posts: 5,374
|
Quote:
Yes, I meant any reference that messes up expected interpolation result - If one or both are flawed (eg. interpolating from wrong frame), you don't get the expected result, and that could result in false positive. But it sounds like you're way past that already, so ignore that and carry on... |
|
18th October 2021, 21:57 | #12 | Link |
Registered User
Join Date: Feb 2002
Location: California
Posts: 2,695
|
Well, the idea didn't work. YDiff produces better results. I'm going to try to fix the TDecimate problem and then post the drop/dup fixer script.
Last edited by johnmeyer; 19th October 2021 at 00:15. |
Thread Tools | Search this Thread |
Display Modes | |
|
|