Log in

View Full Version : A strange merge task; interleave 2 videos


TCmullet
5th October 2018, 14:20
I've pondered this for ages, but can't even be sure it's possible. I don't know the guts of Avisynth well enough, nor all the functions well. Can some of the brains out here think of a way to do this? If I have 2 videos, A is 60 fps and B is 30 fps: (but I think the framerates are FYI-only and not really relevant to the discussion)

Video A: frames 0,1,2,3,4,5,6...
Video B: frames 0,1,2,3,4,5,6...

I want to create an output video where the sequence is:

B0,A1,B1,A3,B2,A5,B3,A7 etc.

What fragment of code could do this??????

videoh
5th October 2018, 14:27
The pattern for the As is pretty obvious but the pattern for the Bs is not fully clear. Are you dropping every 4th B out of 5 or something else? After you state it clearly it should be easy to implement with SelectEvery() and Interleave(), e.g., assuming you did mean to drop every 4th B out of 5:

A = A.SelectEvery(2,1)
B = B.SelectEvery(5,0,1,2,4)
Interleave(B,A)

TCmullet
5th October 2018, 14:48
No, i didn't mean to drop any of B. I corrected the typo (changed B4 to B3). I want every frame from video B but only every OTHER frame from video A.

videoh
5th October 2018, 15:02
A = A.SelectEvery(2,1) # or SelectOdd()
Interleave(B,A)

TCmullet
5th October 2018, 15:28
WOW! So simple! Thank you!

Just if anyone is curious, I intend to use this to attempt a salvage of sorts. I have good quality videos, say 720p30, but low res versions at 360p60. I am gambling that if I can save the frames from the 360p edition that were dropped in the 720p edition, massage them a little, that maybe the viewing experience will be acceptable, in spite of a sort of flicker that will be there. Those resolutions were just examples. I have many cases of progressive video, high quality (and/or resolution) and a lower resolution but interlaced edition. The conversion of interlaced back to p60 is easy with DGBob, which I do all the time. I hate throwing away temporal information. The question will be whether or not the eye and brain can accept a 60 fps sequence where every other frame is a little fuzzier.

StainlessS
5th October 2018, 15:44
GamMatch may come in handy if color schemes are a bit different.

https://forum.doom9.org/showthread.php?p=1846751#post1846751

johnmeyer
5th October 2018, 16:17
I haven't seen the two clips, but my vote would simply be to use the better, lower frame rate source, and live with the slight judder. I think you'll find that you'll never be able to match the two clips over the entire length of the video and as a result will have to spend a huge amount of time re-aligning the two clips at each point where they go out of sync. The sync problem happens because of how the clips get captured, how they each might have been edited, and because almost every scheme of delivering video ends up dropping or adding a field or frame here or there.

StainlessS
5th October 2018, 16:41
I haven't seen the two clips, but my vote would simply be to use the better, lower frame rate source, and live with the slight judder. I think you'll find that you'll never be able to match the two clips over the entire length of the video and as a result will have to spend a huge amount of time re-aligning the two clips at each point where they go out of sync. The sync problem happens because of how the clips get captured, how they each might have been edited, and because almost every scheme of delivering video ends up dropping or adding a field or frame here or there.

I cannot disagree, best usage of GamMatch that I have actually used was to replace a logo, was indistinguishable from presumable original.

TCmullet
2nd January 2019, 13:38
I haven't seen the two clips, but my vote would simply be to use the better, lower frame rate source, and live with the slight judder. I think you'll find that you'll never be able to match the two clips over the entire length of the video and as a result will have to spend a huge amount of time re-aligning the two clips at each point where they go out of sync. The sync problem happens because of how the clips get captured, how they each might have been edited, and because almost every scheme of delivering video ends up dropping or adding a field or frame here or there.
This is why I decided at one point, when capturing both versions, to do NO editing of either so that maybe (hopefully) I won't have much realigning to do because of (as you say) a field or frame was dropped by one of them.

TCmullet
4th January 2019, 23:33
GamMatch may come in handy if color schemes are a bit different.

https://forum.doom9.org/showthread.php?p=1846751#post1846751
I'm confused. That page shows 4 images. How is GamMatch different than me adjusting hue for one of them and switching back and forth between the two source (2 frames next to each other in my Vdub timeline), and working til the colors match? And where is the correct GamMatch version? Does it require using "histograms" (which I've never seen)?

I have my interleave working rather nicely. To fix the worse one's color, I did this:

tweak(hue=10.0,sat=1.0,bright=0.0,cont=1)

Brightness flicker during playback shows me I need to adjust bright and/or cont.
I experimented first with brightness and ultimately left it at 0.0. Contrast down to 0.95
Then sat down to 0.0930.

tweak(hue=10.0,sat=0.930,bright=-0.0,cont=0.95)

Will GamMatch help me do this more easily, and maybe with more precision?

For Bri and Con, I used a Vdub filter Color Tools, Waveform Monitor for visual confirmation of tweaked values. My low res source (from which I'm steeling the missing fields (turned into frames by my DVR) obviously is fuzzier and therefore the white and black levels are impossible to match exactly with it's sharper highres neighbor frames. But it's certainly an improvement over nothing. And when you play it back at 60fps, I can't really see much flicker. (But CAN see slight diffs when moving manually frame to frame.)

StainlessS
5th January 2019, 04:35
Here is best demo of using GamMatch:- https://forum.doom9.org/showthread.php?p=1825391#post1825391
GamMatch (NOT GAMMAC) is used to match two histograms.

EDIT: Also see here:- https://forum.doom9.org/showthread.php?p=1846751#post1846751

EDIT: GamMatch v0.04 In my mediafire account seems to be most recent.

TCmullet
5th January 2019, 05:55
Thanks, but even your read me file is totally "losing". There needs to be a step by step instructions for how to use it. In those discussion threads, everyone's talking about things but they already know how to use it, so that never comes up. You assume everyone knows what a histogram even is. (I've heard of it in the Vdub realm but never messed with it. I do see where histograms in Avisynth are discussed here:)
http://avisynth.nl/index.php/Histogram

So if you care to write up something, I will surely read it and be grateful. If not, well I'm still grateful you've given as much as you have.

StainlessS
5th January 2019, 06:50
FIX_DC = False # Set True to color Correct low res DC via GamMac
BLUR_DC = True # Denoise via blur(get rid of hi/low sparkles)
STACK = True

Avisource("...").ConvertToRGB24.KillAudio
BAD=Last # THIS IS YOUR BAD COLOR CLIP

DC=Avisource("...") # Good color low rez, eg crap cropped off
DC=(BLUR_DC) ? DC.Blur(0.2) : DC # Kill hi/lo sparkles (or some denoiser)

FDC= (FIX_DC) ? DC.GamMac(Th=0.0,Show=false) : DC # Color correct low res DC, Add any additional args for GamMac, See GamMac
#Return FDC # Mod args to GamMac and view if uncommented
# Use a demo GamMac script with identical DC if you need mess about further with GamMac args.

FINAL=BAD.GamMatch(FDC,Th=0.0,Show=False) # Match colors (you dont need know anything about histograms)
# You basically dont need know much at all about GamMatch, set Th=0.0 and probably nothing else.
# you can also piss around with RedMul etc if you really want to make small corrections,
# but you probably will not.

TOP=StackHorizontal(TSub(BAD,"BadColor source.",true),
\ TSub(DC.Spline36Resize(width,Height),"DC Low res"))
BOT=StackHorizontal(TSub(FDC.Spline36Resize(width,Height),"DC Low rez with any color cast FIXED by GamMac"),
\ TSub(FINAL,"BadColor.GamMatch(DC.GamMac)"))
(STACK) ? StackVertical(TOP,BOT) : FINAL
return Last


# Stack Overhead Subtitle Text, with optional FrameNumber shown.
Function TSub(clip c,string Tit,Bool "ShowFrameNo"){
c.BlankClip(height=20)
(Default(ShowFrameNo,False))?ScriptClip("""Subtitle(String(current_frame,"%.f] """+Tit+""""))"""):Subtitle(Tit)
Return StackVertical(c).AudioDubEx(c)
}


I always think that the best person to write a guide is the user, I look forward to seeing what you come up with. :)

EDIT: You can use your eg A or B clip as BAD clip (you decide which is worse color) and the other as DC clip (BAD will be matched to GOOD),
the frames will of course not match exactly, but I have used GamMatch of longish sections of clip matched to a single frame,
so matching your A and B clips should be quite effective. If your good clip is already without problems then you will not need to use GamMac
to fix DC color cast.

If you post samples of both clips I'll take a look (have them already processed and waiting for the interleave thing [as suggested by VideoH]).
I should have went back and read the op, forgot that you have this weird interleave thing in mind, post a couple of samples and I'll try figure it out further if necessary.
EDIT: Also say which is your preferred color clip. (Maybe about 50 -> 100 frames of each clip, skip any audio).

StainlessS
5th January 2019, 09:14
TC, sorry, I had forgotten totally about your interleave thing in OP, no wonder you found it confusing.
Hope below can clear a few things up, done in demo form, using JohnMeyer Parade clip.


BIsGoodColor = True # If True, then Lets pretend A is BAD color, else B is BAD
SIMULATE_BAD = True # If True, then one of the clips is simulated BAD color (BIsGoodColor selects good/bad)
FIX_GOOD = True # Set True to color Correct GOOD color via GamMac
STACK = 2 # STACK=0=FINAL, 1=ORG + RESULT(with flickering ORG if simulated), 2=Stack 4 window
# Stack4 window shows Even/Odd Frames ie half framerate, others true framerate.
##################
AviSource("D:\Parade.avi").ConvertToRGB24.KillAudio
A=SelectEven # Your A and B clips
B=SelectOdd
A=A.Trim(0,-B.FrameCount) # Ensure same number of frames, else error in GamMatch

BAD = (BIsGoodColor) ? A : B # THIS IS YOUR BAD COLOR CLIP
RED=BAD.ShowRed(Pixel_Type="Y8").Levels( 0,0.8,255, 8,247,coring=false)
GRN=BAD.ShowGreen(Pixel_Type="Y8").Levels(0,1.5,255,12,223,coring=false)
BLU=BAD.ShowBlue(Pixel_Type="Y8").Levels( 0,2.0,255,32,239,coring=false)
BAD=(SIMULATE_BAD) ? MergeRGB(RED,GRN,BLU,pixel_Type="RGB24") : BAD
GOOD = (BIsGoodColor) ? B : A
ORG=(BIsGoodColor)?Interleave(BAD,GOOD):Interleave(GOOD,BAD)


FGOOD= (FIX_GOOD) ? GOOD.GamMac(DC=GOOD.Blur(0.2),Th=0.0,Show=false) : GOOD


RESULT=BAD.GamMatch(FGOOD,Th=0.0,Show=False) # Match colors (you dont need know anything about histograms)
# You basically dont need know much at all about GamMatch, set Th=0.0 and probably nothing else.
# you can also piss around with RedMul etc if you really want to make small corrections,
# but you probably will not [EDIT: you want both good & bad exactly same so RedMul etc is superfluous].


TOP=StackHorizontal(TSub(BAD,(BIsGoodColor?"BAD (A Even)":"BAD (B Odd)")+(SIMULATE_BAD?" SIMULATED BAD":""),true),
\ TSub(GOOD,BIsGoodColor?"GOOD (B Odd)":"GOOD (A Even)"))
BOT=StackHorizontal(TSub(FGOOD,(FIX_GOOD)?"FGOOD with color cast FIXED by GamMac":"FGOOD (not fixed)"),
\ TSub(RESULT,"BAD.GamMatch(FGOOD)"))

FINAL = ((BIsGoodColor) ? Interleave(RESULT,FGOOD) : Interleave(FGOOD,RESULT) )

(STACK==0)
\ ? FINAL
\ : (STACK==1) ? StackVertical(TSub(ORG,"Src"),TSub(FINAL,"Final Result"))
\ : StackVertical(TOP,BOT)
return Last

# Stack Overhead Subtitle Text, with optional FrameNumber shown.
Function TSub(clip c,string Tit,Bool "ShowFrameNo"){
c.BlankClip(height=20)
(Default(ShowFrameNo,False))?ScriptClip("""Subtitle(String(current_frame,"%.f] """+Tit+""""))"""):Subtitle(Tit)
Return StackVertical(c).AudioDubEx(c)
}


EDIT: JohnMeyer clip:- https://forum.doom9.org/showthread.php?p=1737852#post1737852

EDIT:
https://i.postimg.cc/JsbPZBS3/TCC.jpg (https://postimg.cc/JsbPZBS3)
EDIT: Diagonal opposites are same frame (Even/Odd).
Bottom right, is top left color matched to the bottom left(which was color caste fixed by GamMac from the top right frame).

EDIT: To use with your A & B clips, assign both A(Even) and B(Odd), Switch SIMULATE_BAD=False, select which is good/bad by setting BIsGoodColor, try with/without FIX_GOOD setting. Sorted.