Log in

View Full Version : 25i to 24p (removing duplicated frames)


Music Fan
4th January 2018, 18:35
Hi,
I recorded a documentary on tv in PAL region (with a VU+ decoder) and it seems to be actually progressive with a duplicated frame each second (instead of Pal speed-up).
But there is something strange : instead of having a duplicated frame every 25 frames, there is one duplicated frame after 24 frames, then after 25 frames, then again 24, then 25 ...
which means that 2 frames on 49 and not on 50 have to be discarded.
I believe it can be done with TDecimate but how ?

StainlessS
4th January 2018, 18:45
Multidecimate of no use ?

(or my replacement mod Mdec2, support additional colorspaces)



EDIT: Prevoius edit mentioning bug fix was wrong, bugfix I did was actually in the FDecimate source that I converted to
be Multidecimate compatible MDec2, Multidecimate source was actually never published.

SeeMoreDigital
4th January 2018, 19:30
Are you able to upload a short sample of your source?

Music Fan
4th January 2018, 20:39
Yes, here it is ;
https://www.sendspace.com/file/61id8e
The logo of the channel at the beginning is interlaced but everything after is progressive.
I'm also interested in removing pixelation and banding.

manono
5th January 2018, 00:29
I believe it can be done with TDecimate but how ?
TDecimate(Cycle=101,CycleR=2)

I didn't check the sample so if I misunderstood your description (which seems to me to be contradictory), you can see how to change the numbers. Also, the mode using Cycle and CycleR is thoroughly explained in the TDecimate doc.

Music Fan
5th January 2018, 02:45
SIZE="1"]TDecimate(Cycle=101,CycleR=2)[/SIZE]
It's better but there are still some duplicated frames.

I didn't check the sample so if I misunderstood your description (which seems to me to be contradictory)
What seems contradictory ?
I can explain it in another way : instead of having duplicated frames regularly on number 25, 50, 75 ... it's on 25 (0 + 25), 49 (25 + 24), 74 (49 + 25), ...

TDecimate(Cycle=49,CycleR=2) seems ok :)
The new framerate (for avisynth, seen with the info() function) is 23.9796 (yes, 23.9796, not 23.976).

I noticed some ghosting in the original file (which is still there after decimation), look at the car going to the right at 2'53".

manono
5th January 2018, 04:30
What seems contradictory ?

This:

...there is one duplicated frame after 24 frames, then after 25 frames...
That said (to me) 2 dupe frames in 51 frames. 24 + 1 dupe + 25 + 1 dupe = 51. And that means my earlier script was wrong. Don't know why I wrote 101 when I meant to write 51.

And this:

...which means that 2 frames on 49
That says 2 dupe frames in 49 frames.

And, apparently that was what you meant to say and you found the right combination of cycle and dupe frames to remove in that cycle. Maybe I should have checked the sample. :)

Music Fan
5th January 2018, 12:35
And what about the ghosting at 2'53" ? Is it removable ?
My guess is that it wasn't present in the original video and that a bad conversion was made for the TV channel, probably from 29.97i to 23.976p (with a poor de-interlacing causing this ghosting) before to be converted to 25p with duplicated frames (and encoded in 25i for broadcasting).

Should I add AssumeFrameBased() or it doesn't matter ?

Music Fan
5th January 2018, 18:37
I went further in my script frame by frame and it's not that simple : I believed there was an alternance between 24 and 25 (making groups of 49 pictures in which 2 had to be removed) but it's more complicated.
For the second part of the documentary (I gave an extract of the 1st part), I had to cut the beginning (end of the ad) and noted the number of the duplicated frames (I went until #633) ;
trim(45,20244)#20200 frames
#frames to remove : 17, 41, 66, 90, 115, 139, 163, 188, 212, 237, 261, 286, 310, 334, 359, 383, 408, 432, 456, 481, 505, 530, 554, 584, 608, 633 ...
#number of each duplicated frame compared to the previous one : 24 (41-17), 25, 24, 25, 24, 24, 25, 24, 25, 24, 25, 24, 24, 25, 24, 25, 24, 24, 25, 24, 25, 24, 30, 24, 25 ...

As you see, there are sometimes 2 consecutive 24 and even a 30, thus I don't know what to do :confused:
I even found a 21 later (frames 1164 and 1185) :scared:

Is there a way to remove automatically duplicated frames without having to specify values for Cycle and CycleR (maybe with another filter than TDecimate) ?

StainlessS
5th January 2018, 19:08
A number of duplicate removers here:- https://forum.doom9.org/showthread.php?p=1829242#post1829242
but removonig dupes is gonna play havoc with audio, life is very short, dont waste too much time on one clip.
(unless very important to you, or someone else that matters to you).

manono
5th January 2018, 19:53
Yes, StainlessS is correct. Filters such as MultiDecimate and DeDup can remove duplicate frames but you take a chance on losing audio synch. You can name a final framerate with TDecimate and then let it choose the frames to remove to achieve that framerate. A TDecimate line might go something like this:

TDecimate(Mode=2,Rate=23.976,MaxNDL=30,m2PA=True)

Rate is the final framerate you want. MaxNDL defines the max number of frames allowed before removing a frame. m2PA says to look ahead as much as it takes where the default is 100 frames. They're explained in the TDecimate doc.

But it's much better to have some duplicate frames remaining rather than removing unique frames.

Music Fan
5th January 2018, 21:01
Ok, I will have a look at this.

For the sound, I don't believe there will be out of synch because the aim is to recover the original framerate without changing speed. I only try to make the reverse of what has been done (and that's not Pal speed up).

Music Fan
6th January 2018, 00:03
Your script is great :), I only replaced 30 by 31 for MaxNDL because 1 good frame was missing between frames 550 and 610, where there are 30 frames between 2 duplicate frames (554 and 584). Or 29 actually, if we exclude 554 and 584.
But the script is very slow, at least to open it, but I can move quickly from a frame to another once it's opened.

We can also discuss about other problems : ghosting, banding, pixelation ...

manono
6th January 2018, 04:15
Yes, it can take some time to open. As it says about m2PA in the TDecimate doc:

**NOTE: the cycle size could very well be in the 1000's or 10000's, so there is the
possibility setting m2PA=true could mean the processing will stall for quite
some time (5-10 minutes or more) when a new cycle starts!!! Please check the
largest cycle size that will be used using debug=true before setting m2PA=true!

For ghosting I usually see if frame interpolation works, if it's not something SRestore or ExBlend can handle. For banding there are debanding filters, which often means adding noise/grain which makes the video less compressible. For pixelation, I don't know, frame interpolation again, depending on what you mean by the term. My sources are pretty bad (bad field blended VHS tapes) so someone with more experience with your kind of source might show up to help.

Music Fan
6th January 2018, 12:19
Ok.
When you say frame interpolation, do you mean the final framerate wouldn't be 23.976p anymore ?

For ghosting, I don't know if there is anything to do in this case because I'm pretty sure that a bad conversion was done from 29.97i to 23.976p, and there is maybe some irreversible blending.
Here it is (at 2'51" in the extract I uploaded), that's a cropped part of the picture, not resized (click to have full size) ;

https://img15.hostingpics.net/thumbs/mini_204413Bugatticropped.jpg (https://www.hostingpics.net/viewer.php?id=204413Bugatticropped.jpg)

The car is moving quickly but I believe that if it had been filmed in 24p, the result would be different. That's why I think it was originally 29.97i (this is a north american documentary).

For pixelation, I believed Deblock (or Deblock QED) is used, but last time I tried this, it had nearly no effect.
Actually there are few pixelated parts, but I'd like to mitigate them if possible.
I see also some aliasing.

As I'm not expert with filtering, if some people could download and test my video, that would help me .;)

manono
6th January 2018, 20:20
Frame interpolation just creates new frames from the good frames on either side of the bad frame(s). The framecount and framerate remain the same. However, based on your picture alone, when something's moving fast it won't work well as it creates too many artifacts. In such instances I sometimes replace a bad frame with parts of a good one nearby. That is, you could save out the bad frame, replace the blurred car with a 'clean' car from the next frame over or somewhere else, followed by replacing the old frame with the edited one. In principle it's not hard, and just takes some time. The script for frame replacement then might go something like this:

Q=ImageSource("3946.bmp",End=3946).ConvertToYV12()
ReplaceFramesSimple(Last,Q,Mappings="3946")

The frame number is the frame number of the original 'bad' frame being replaced. I give the 'fixed' frame the same number, although you could name it anything you like. You fix it in a photo editing program (I use PhotoFiltre). You need ReplaceFramesSimple, part of stickboy's RemapFrames (http://avisynth.nl/index.php/RemapFrames).

For pixelation, I believed Deblock (or Deblock QED) is used
Deblocking filters are meant to fix macroblocking. That's caused by a video being encoded with bitrate that's too low. YouTube is full of that stuff. I believe the term 'pixelation' is usually meant to refer to something else.

Music Fan
9th January 2018, 10:52
Ok, thus I have to remove macroblocking.
Is there better for this than Deblock QED ?

That is, you could save out the bad frame, replace the blurred car with a 'clean' car from the next frame over or somewhere else, followed by replacing the old frame with the edited one. In principle it's not hard, and just takes some time.
Yes, especially if there are several parts of the video with this problem, and this can't be done automatically.

manono
9th January 2018, 19:46
Well, StainlessS did advise not spending too much time on a video and it's good advice. Yes, we all like to get it right but there comes a point of diminishing returns. Do people notice this blurring when just watching the video, as opposed to going over it frame-by-frame? I go over my own projects three different times frame-by-frame while working on them, but not everyone is so willing.

The few times I've used deblocking filters it's always been Deblock_QED. Make sure not to crop and/or resize before using it. It requires the original block boundaries. And it can be very destructive to detail.