Log in

View Full Version : Two unusual video processing problems


gamebox
9th October 2015, 22:45
Hello people. :) I need to do two things with my videos, both of which I'm not sure are possible. However, knowing how advanced AviSynth scripting actually is, I might be lucky. :)

First the "simpler" problem - I have a video clip, probably captured from an analogue source of sort, that has an odd framerate of 29.11 or so - probably as a result of capture device (or chip) skipping some frames. The problem with the video is that it is actually a 23.976 fps material and it is recorded with occasional duplicate frames, but those duplicate frames' placement in a stream is not following any obvious rule or pattern. Is there a way to eliminate only those duplicate frames while encoding the video - no matter what the resulting framerate would be? Decomb decimate doesn't help since I can't define any rule or interval.

Second - "the alchemy". :) I have two (re)encodes of the very same video. One is done at 720p but has a very ugly logo, the other is 480p and clean but lower quality (both because of downscaling and worse encoder settings). Can I somehow eliminate the logo in the first video by "overlaying" the appropriate (clean) part of the second clip? I guess it would fit rather well and be almost imperceptible, and if that helps I'm actually reencoding to lower resolution of the two.

Thanks for your time. :)

Motenai Yoda
9th October 2015, 22:57
First one, is vfr? if Yes use directshow(source,fps=30/1.001,convertfps=true) or dss2(source,fps=30/1.001)
then use tdecimate from tivtc or decimate from decomb
if Not try anyway

2nd one, you should make a black mask with only the logo part in white, and merge the two clip, after aligning frames, with that mask using mt_merge(video1, video2, mask, luma=true, u=3, v=3) from masktools2

johnmeyer
9th October 2015, 23:34
Regarding #2: I did exactly the same thing when given a DVD of a French movie with no English subtitles. The only subtitled version ever done was on VHS tape, with hard-coded subtitles. I used my NLE (Vegas) to line up the two versions, and then created a mask, in Vegas, which I turned on and off, (off when no subtitles), and also feathered, so it wasn't too apparent. I don't know how you can do this without being able to use the interactivity of an NLE. Nothing ever stays quite the same from one part of the movie to the next.

Duplicate detection and replacement is relatively straightforward. MugFunky developed code a long time ago. I converted it from MVTools to MVTools2. I've posted this before, but here it is again:

function filldrops (clip c)
{
super=MSuper(c,pel=2)
vfe=manalyse(super,truemotion=true,isb=false,delta=1)
vbe=manalyse(super,truemotion=true,isb=true,delta=1)
filldrops = mflowinter(c,super,vbe,vfe,time=50)
fixed = ConditionalFilter(c, filldrops, c, "YDifferenceFromPrevious()", "lessthan", "0.1")
return fixed
}

I should note, however, that most duplicates are the result of the capture card trying to make up for an earlier frame drop. You can easily replace one of the duplicates with a motion estimated frame (which is what the code above does), but if there is actually a nearby dropped frame, you will have actually not fixed anything. What you need to do instead is delete one of the duplicates and then attempt to find the drop and insert an estimated frame at that point. This is much tougher, but with the help of guru Didée, I managed to come up with some code in this thread:

Automatically fix dups followed (eventually) by drops (http://forum.doom9.org/showthread.php?p=1510780#post1510780)

gamebox
10th October 2015, 00:40
Thank you guys for help so far. :)

Using AviSynth this way is too advanced for me at the moment, so I'm doing some research already. :) I've found a page about MaskTools2 filter with it's options explained, but I currently have problems understanding the mask and how I define it. Do I need to provide pixel coordinates of the logo, or do I create an image file of sort? Also, how and where can I define new, downscaled, resolution for the clip number 1 (containing the logo) in avisynth before feeding it to MaskTools, so both input clips for merging in MaskTools have the same resolution?

Regarding the first clip, it is just a mess. It seems to me a 29.970 fps version of a 23.976 fps film (containing duplicate frames at regular intervals) was digitalized but some frames were discarded in process either because capture hardware was falling behind during the task or because source was damaged (most video capture chips discard frames with damaged sync, like on a video tape). So, some of the missing frames in a resulting video were in fact duplicates in original 29.970 video, while some were not. Your solution, johnmeyer, might help, I'll give it a try as soon as I catch some free CPU cycles. :)

johnmeyer
10th October 2015, 01:12
You might get more ideas if you post a clip.

ajk
12th October 2015, 12:48
I have done that second thing, combining clean and dirty clips, a few times. As long as they are frame accurate copies and their colours match, it's not hard to do. If you can provide short samples of both, it won't be difficult to make a script for you.

gamebox
15th October 2015, 00:27
@ajk: The logo to "cut through" on the first clip is a simple, rectangular shape in the right-top corner, away from the edges of the screen. Finding it's 4 coordinates (pixels defining it) should not be a problem, and I presume that information is sufficient to set up a "mask". That logo is a website's name in a white square with transparent letters and it is added over the video found elsewhere, so that's what I want to remove. That clip containing the logo to cut is 720p and needs to be downscaled first (I presume inside the very script used to blend it with the other clip) and the other is used as is, no changes in resolution.

Regarding the clip with a messed up framerate, I gotta find it first. :) I don't remember it's name at the moment, and have to analyze quite a few clips on my storage frame by frame to locate in which clip I found the problem, but I described what I initially saw. Sorry for being in a mess - I use few (very) cheap/donated old rigs to perform video processing that is actually more appropriate for a modern system.

StainlessS
15th October 2015, 03:33
Probably easiest if you cut out corners of both logo related clips and work soley on those,
can magnify easier and no need to do any colorspace conversions on entire clip area.
When coords properly located and de-logo'd then can just overlay back to original coords
of logo clip.
As said twice already, two sample clips would help in assisting.