Log in

View Full Version : Replace repeated frames


prot88
24th September 2006, 00:09
Hello,
(sorry for my poor english)
I search a way to "repair" a video with random repeated frames.

This video has been made with a webcam set to 15 fps. But during the capture, the camera stops for 3 to 5 frames when it correct automaticaly brightness and contrast.

I have found Dynapel "motion perfect" normally designed to rebuild missing frames processing a morphing.

But it doesn't work... hours and hours of setting didn't help me. Dynapel don't answers to my emails.

I decide to find another way and AVISynth seems to be a very powerfull tool. But it's not very easy to me to begin Avisynth scripting with such an hard exercice!

I desperately not found the same request in this forum.

So, can someone help me to start this script:

Frames:
12344456788889ABCDDDDEF

-found frame 4 repeated 2 times
-"recalculate" the 2 frames doing an interpolation between 4 and 5

-found frame 8 repeated 3 times
-"recalculate" the 3 frames doing an interpolation between 8 and 9
... etc

sample of the video to correct:

http://www.protois.com/picsUpload/medias/climb.avi

THANKS !!!

Guest
24th September 2006, 13:20
Get a new webcam that isn't so stupid!

There is an active thread similar to this but it adddresses only one missing frame and uses very complex scripting.

http://forum.doom9.org/showthread.php?t=116167

prot88
24th September 2006, 13:32
sure ! ;)
But I can't go 4 weeks back to redo this trackday with a new webcam...

So I have to manage with this #!?!!#! broken video.

Thanks for the link, I'll study it.

:thanks:

prot88
24th September 2006, 14:16
seems to be for a different problem.

I think I must start with a repeated frame detection but I did not found a correct filter to do that.

I found a lot of "motion detection". Can I use it inverting the function i.e: detect frames with NO motion ?

After that, I will search the way to replace this frames.

Guest
24th September 2006, 15:12
seems to be for a different problem. That's what I warned you: "similar to this but it addresses only one missing frame". I was trying to show you how complex a problem you have on your hands.

I think I must start with a repeated frame detection but I did not found a correct filter to do that. You can use the Dup() to obtain a list of duplicates.

prot88
24th September 2006, 15:35
Yes, I have succeded for selecting duplicate frame with a similar function: getdup.

Avisource("climb2.avi")
loadplugin("GetDups.dll")
AssumeTFF()
GetDups()
AssumeFps(15)

This script provide a video with ONLY the first duplicated frame = a very fast video not synchronized with the original one.

.... I am thinking about a way to use that... not easy

prot88
24th September 2006, 16:31
I found the way to recalculate bad frames:

--------------------------------------------------
To recreate bad frames by interpolation with MVFlowInter:

backward_vectors = source.MVAnalyse(isb = true, truemotion=true, pel=2, delta=2, idx=1)
forward_vectors = source.MVAnalyse(isb = false, truemotion=true, pel=2, delta=2, idx=1)
inter = source.MVFlowInter(backward_vectors, forward_vectors, time=50, ml=70, idx=1)
# Assume bad frames 50 and 60
source.trim(0,49) ++ inter.trim(49,-1) \
++ source.trim(51,59) ++ inter.trim(59,-1) ++ source.trim(61,0)
-----------------------------------------------------

but I still must find a function to give me the number of the wrong frames (in the example: frame 50 and 60)

Neron2 : what dup() function returns ????

Guest
24th September 2006, 16:36
You can make it spit out a log file indicating duplicates that you would then have to parse as needed.

prot88
24th September 2006, 17:28
I tested it.
It detect duplicate frame perfectly and a function (blend) can blend duplicate frame each others (to reduce noise)

but there is no parameter to blend this :

Frames : 12345666789

blend 5 and 7 and replace 666 by the result. (dup blends the three frame 6)

I look at the source and I think a little modification is possible changing the range of blending. But I don't know how to recompile that into a single DLL :(

With that, my problem is fixed.

prot88
24th September 2006, 19:10
???!!???
Is there a link to download debugview ?
I cant find it.

It's for have a log file from dup.

Thanks

prot88
24th September 2006, 19:19
ok, installed debugview.
I have now a list of repeated frame.

.... working.....

prot88
24th September 2006, 23:03
ARG!!!

I did not manage to use MVtools.

I have downloaded it, put everything on "plugins" directory

I have tried this script:
--------------------------------------------------------
Avisource("climb2.avi")
loadplugin("C:\Program Files\AviSynth 2.5\plugins\MVTools.dll")
backward_vectors = MVAnalyse(isb = true, truemotion=true, pel=2, delta=2, idx=1)
forward_vectors = MVAnalyse(isb = false, truemotion=true, pel=2, delta=2, idx=1)
inter = MVFlowInter(backward_vectors, forward_vectors, time=50, ml=70, idx=1)
# Assume bad frames 50 and 60
source.trim(0,49) ++ inter.trim(49,-1) \
++ source.trim(51,59) ++ inter.trim(59,-1) ++ source.trim(61,0)
---------------------------------------------------

I have an error "Avisynth open failure - Loadplugin: unable to load c:\program... ...MVTools.dll"

I think I have the wrong syntax.

Someone to help me ???
I am near to resolve my problem !!!!!!

foxyshadis
24th September 2006, 23:13
You downloaded it from here, right? http://avisynth.org.ru/fizick.html And you have avisynth 2.56 or 2.57, correct? (Confirm with Version().) Those are the only things I can figure that would cause that.

prot88
25th September 2006, 10:07
Yes, I have downloaded MVTools from this url.
My avisynth version: 2.57

prot88
25th September 2006, 18:21
Fixed, i have resintalled both avisynth and MVtools.

But, I have never done a script with MVTools so... errors, errors, errors....

I dont know the correct syntax and I don't really understand all parameters (noob noob noob !)

My wish:
I have the possibility to create the script with all the frames to recalculate.

But, first, I must succed with a simple script like the example provided with MVtools.

This one don't works:

------------------------------------------
Avisource("climb.avi")
source="climb.avi"
backward_vectors = source.MVAnalyse(isb = true, truemotion=true, pel=2, delta=2, idx=1)
forward_vectors = source.MVAnalyse(isb = false, truemotion=true, pel=2, delta=2, idx=1)
inter = source.MVFlowInter(backward_vectors, forward_vectors, time=50, ml=70, idx=1)
# Assume bad frames 50 and 60
source.trim(0,49) ++ inter.trim(49,-1) \
++ source.trim(51,59) ++ inter.trim(59,-1) ++ source.trim(61,0)
---------------------------------------------------

not better with this one:

------------------------------------------
Avisource("climb.avi")
backward_vectors = MVAnalyse(isb = true, truemotion=true, pel=2, delta=2, idx=1)
forward_vectors = MVAnalyse(isb = false, truemotion=true, pel=2, delta=2, idx=1)
inter = MVFlowInter(backward_vectors, forward_vectors, time=50, ml=70, idx=1)
# Assume bad frames 50 and 60
source.trim(0,49) ++ inter.trim(49,-1) \
++ source.trim(51,59) ++ inter.trim(59,-1) ++ source.trim(61,0)
---------------------------------------------------


Can a regular MVTools user modify my script (AND MY GOAL WILL BE REACHED :D ) ????

Thanks

Fizick
25th September 2006, 19:46
source=Avisource("climb.avi")
backward_vectors = source.MVAnalyse(isb = true, truemotion=true, pel=2, delta=2, idx=1)
forward_vectors = source.MVAnalyse(isb = false, truemotion=true, pel=2, delta=2, idx=1)
inter = source.MVFlowInter(backward_vectors, forward_vectors, time=50, ml=70, idx=1)
# Assume bad frames 50 and 60
source.trim(0,49) ++ inter.trim(49,-1) \
++ source.trim(51,59) ++ inter.trim(59,-1) ++ source.trim(61,0)

prot88
25th September 2006, 19:55
YEAHHHHHHHHHHHHHHHH!

It works !!
Thanks thanks.

I will build my script and apply it to my entire video.

After... perhaps 30 hours of search... it works

:D :D :D :D :D :D :D

prot88
26th September 2006, 09:55
Processed video:

http://video.google.com/videoplay?docid=-9166866564834753954&hl=en

:thanks:

Fizick
26th September 2006, 15:55
prot88,
post your final script

prot88
26th September 2006, 20:44
So,

original video:

320x240 - 15 fps, real-time compressed in divx 5.2 with many,many dropped frame.

1 - resized to 640x480, saved in DIVX 5.2 4000 kb. Dropped frames are replaced by repeated frame.

2- first script: catch repeated frames
-------------------------------------------------
Avisource("video.avi")
loadplugin("Dup.dll")
Dup(threshold=1,debug=true, show=true, copy=true, blend=true)
-------------------------------------------

result saved (avi.log) with debugview:

------------------------------------------------------
00000000 0.00000000 [3388] 00EDAD00->CAVIStreamSynth::QueryInterface() (video) {00020022-0000-0000-c000-000000000046} (IAVIStreaming)
00000001 0.00004467 [3388] 00EDAD00->CAVIStreamSynth::AddRef() (video) gRefCnt=5, m_refs=2
00000002 0.00008460 [3388] 00EDAD00->CAVIStreamSynth::Begin(0, 4996, 1000) (video)
00000003 0.00012429 [3388] 00EDAD00->CAVIStreamSynth::Release() (video) gRefCnt=4, m_refs=1
00000004 0.04678084 [3388] Dup: frm 0: Using frm 0
00000005 0.06692830 [3388] Dup: blending 1 into 2
00000006 0.06790905 [3388] Dup: frm 1: Using frm 2
00000007 0.06961765 [3388] Dup: frm 2: Using frm 2
00000008 0.09618336 [3388] Dup: frm 3: Using frm 3
00000009 0.10703723 [3388] Dup: frm 4: Using frm 4
00000010 0.12510701 [3388] Dup: frm 5: Using frm 5
00000011 0.14455637 [3388] Dup: frm 6: Using frm 6
00000012 0.16586012 [3388] Dup: frm 7: Using frm 7
00000013 0.18351060 [3388] Dup: frm 8: Using frm 8
00000014 0.24459673 [3388] Dup: blending 9 into 11
00000015 0.24463129 [3388] Dup: blending 10 into 11
00000016 0.24561180 [3388] Dup: frm 9: Using frm 11
00000017 0.24710248 [3388] Dup: frm 10: Using frm 11
00000018 0.24848810 [3388] Dup: frm 11: Using frm 11
00000019 0.26503155 [3388] Dup: frm 12: Using frm 12
... etc
-------------------------------------------------------

Avi.log analyzed ( detect "blending" to extract repeated frames number) by a simple QBasic program :
------------------------------------------------
PRINT "demarrage...."
DIM debut(2000) AS STRING
DIM fin(2000) AS STRING
gg = 1
OPEN "c:\avisynth\avi.log" FOR INPUT AS #1
DO UNTIL EOF(1) = -1
LINE INPUT #1, texte$
FOR i = 1 TO LEN(texte$) - 8
IF MID$(texte$, i, 8) = "blending" THEN
gg = gg + 1

trans$ = MID$(texte$, i + 9, LEN(texte$))

FOR j = 1 TO LEN(trans$) - 4
IF MID$(trans$, j, 4) = "into" THEN x = j - 1
NEXT j


ttd$ = LEFT$(trans$, x - 1)
ttf$ = MID$(trans$, x + 6, LEN(trans$))

debut$(gg) = ttd$
fin$(gg) = MID$(ttf$, 1, (LEN(ttf$) - 1))

END IF

NEXT i
LOOP

FOR i = 1 TO gg
IF fin$(i + 1) = fin$(i) THEN
debut$(i + 1) = debut$(i)
END IF
NEXT i


FOR i = 1 TO gg
IF fin$(i + 5) = fin$(i) AND debut$(i + 5) = debut$(i) THEN
fin$(i + 5) = ""
debut$(i + 5) = ""
END IF
IF fin$(i + 4) = fin$(i) AND debut$(i + 4) = debut$(i) THEN
fin$(i + 4) = ""
debut$(i + 4) = ""
END IF
IF fin$(i + 3) = fin$(i) AND debut$(i + 3) = debut$(i) THEN
fin$(i + 3) = ""
debut$(i + 3) = ""
END IF
IF fin$(i + 2) = fin$(i) AND debut$(i + 2) = debut$(i) THEN
fin$(i + 2) = ""
debut$(i + 2) = ""
END IF
IF fin$(i + 1) = fin$(i) AND debut$(i + 1) = debut$(i) THEN
fin$(i + 1) = ""
debut$(i + 1) = ""
END IF
NEXT i

OPEN "c:\avisynth\batch.avs" FOR OUTPUT AS #2

PRINT #2, "source=AVISource("; CHR$(34); "video.avi"; CHR$(34); ")"
PRINT
PRINT #2, "backwards_vectors = source.MVAnalyse(isb=true,blksize=4, truemotion=false,pel=2, search=3, searchparam=3, delta=1,idx=1)"
PRINT #2, "forward_vectors = source.MVAnalyse(isb=false,blksize=4, truemotion=false, pel=2, search=3, searchparam=3, delta=1, idx=1)"
PRINT #2, "inter = source.MVFlowInter(backwards_vectors, forward_vectors, time=50, ml=1,idx=1)"

fr = 0

FOR i = 1 TO gg
IF fin$(i) <> "" THEN
strng$ = debut$(i)
valeurd = 0
FOR x = LEN(strng$) TO 1 STEP -1
valeurd = valeurd + ((ASC(MID$(strng$, x, 1)) - 48) * (10 ^ (LEN(strng$) - x)))
NEXT x
strng$ = fin$(i)
valeurf = 0
FOR x = LEN(strng$) TO 1 STEP -1
valeurf = valeurf + ((ASC(MID$(strng$, x, 1)) - 48) * (10 ^ (LEN(strng$) - x)))
NEXT x
valeurf = valeurf + 1


PRINT #2, "source.trim("; fr; ","; valeurd; ") ++";
FOR ss = 1 TO (valeurf - valeurd - 1)
PRINT #2, "inter.trim("; valeurf - 1; ",-1) ++";
NEXT ss
PRINT #2, "\"
fr = valeurf

END IF
NEXT i
PRINT #2, "source.trim("; fr; ",30000)"
CLOSE #2
CLOSE #1
PRINT "fini."
----------------------------------------------------------

result (final script):
-------------------------------------------------------
source=AVISource("video.avi")
backwards_vectors = source.MVAnalyse(isb=true,blksize=4, truemotion=false,pel=2, search=3, searchparam=3, delta=1,idx=1)
forward_vectors = source.MVAnalyse(isb=false,blksize=4, truemotion=false, pel=2, search=3, searchparam=3, delta=1, idx=1)
inter = source.MVFlowInter(backwards_vectors, forward_vectors, time=50, ml=1,idx=1)
source.trim( 0 , 1 ) ++inter.trim( 2 ,-1) ++\
source.trim( 3 , 9 ) ++inter.trim( 11 ,-1) ++inter.trim( 11 ,-1) ++\
source.trim( 12 , 17 ) ++inter.trim( 19 ,-1) ++inter.trim( 19 ,-1) ++\
source.trim( 20 , 25 ) ++inter.trim( 26 ,-1) ++\
source.trim( 27 , 40 ) ++inter.trim( 42 ,-1) ++inter.trim( 42 ,-1) ++\
source.trim( 43 , 48 ) ++inter.trim( 50 ,-1) ++inter.trim( 50 ,-1) ++\
source.trim( 51 , 64 ) ++inter.trim( 66 ,-1) ++inter.trim( 66 ,-1) ++\
source.trim( 67 , 72 ) ++inter.trim( 73 ,-1) ++\
source.trim( 74 , 141 ) ++inter.trim( 142 ,-1) ++\
source.trim( 143 , 149 ) ++inter.trim( 150 ,-1) ++\
source.trim( 151 , 157 ) ++inter.trim( 158 ,-1) ++\
source.trim( 159 , 172 ) ++inter.trim( 173 ,-1) ++\
source.trim( 174 , 188 ) ++inter.trim( 189 ,-1) ++\
source.trim( 190 , 218 ) ++inter.trim( 219 ,-1) ++\
source.trim( 220 , 249 ) ++inter.trim( 250 ,-1) ++
...
...
...
source.trim( 4863 , 4931 ) ++inter.trim( 4933 ,-1) ++inter.trim( 4933 ,-1) ++\
source.trim( 4934 ,30000)
----------------------------------------------------

This script only replace the FIRST repeated frames.
If the video still countains repeated frame, you must do the process again (it will recalculate the SECOND repeated frames)

Guest
26th September 2006, 21:02
Your tenacity and resourcefulness is impressive and admirable.

Fizick
26th September 2006, 21:52
btw, getdups can produce log file too.
GetDups(show=2,log=1, logfname="d:\Capture\log.txt")
frames with diffference 0.0 is duplicates