PDA

View Full Version : Reverse Field Dominance within a Single Clip


rec
8th January 2011, 20:29
Here's a bizarre problem - the field dominance changes many times within a single clip, and naturally, I want to fix it.

First a little background. The clips in question come from a Panasonic GH2, a new camera that puts out an extremely high quality video picture. It records AVCHD to an SD card. No problem there. But, when we hook up an external device to record uncompressed video out the HDMI port, we have trouble.

Internally, the camera records 1080 59.94i, but the signal coming out the HDMI port is 1080 60.00i. Don't ask me why, it just is. I have verified that the camera inserts a duplicate field every 1002 fields.

Here's what I've worked out so far.

Step 1:
AssumeTFF()
SeparateFields()

Step 2:
tdecimate(mode=0,cycleR=1,cycle=1002)

Step 2 removes the duplicate fields and sets the speed to 29.97. All well and good.

But, when I go to re-interlace, the field dominance flips every 501 frames. This is the obvious result of the camera throwing in extra single fields. But, how do I flip these sections back?

Also, does anyone have an idea how to combine Step 1 and Step 2 into a single script?

:thanks:

2Bdecided
10th January 2011, 16:52
Steps 1 and 2 in the same script is easy - just type them both into one script!

However the main problem you're trying to solve sounds impossible. There are plenty of solutions (e.g. dropping the video down by one line), but they won't work for continuous video like you have.

Cheers,
David.

rec
11th January 2011, 00:07
However the main problem you're trying to solve sounds impossible.

Cheers,
David.

What? AVISynth people don't know the meaning of the word impossible! :D

manono
11th January 2011, 08:12
There's nothing wrong with reversing the field dominance periodically. I've seen it in retail DVDs. It's one way to convert 24fps film to 25fps PAL, by adding a frame every second, but in the form of a field every half second. So, you get half a second of progressive frames followed by half a second of interlaced frames for the whole movie. Of course, you don't notice that when watching the DVD on a TV set. In my opinion there's nothing to fix.

rec
11th January 2011, 08:50
There's nothing wrong with reversing the field dominance periodically. I've seen it in retail DVDs. It's one way to convert 24fps film to 25fps PAL, by adding a frame every second, but in the form of a field every half second. So, you get half a second of progressive frames followed by half a second of interlaced frames for the whole movie. Of course, you don't notice that when watching the DVD on a TV set. In my opinion there's nothing to fix.

If you saw the footage, you would know there is definitely something to fix! Basically, every other 17 seconds the picture becomes unwatchable, because the second field (time-wise) is being displayed before the first field.

If it was the entire clip, it would be an easy fix. But, how do you deal with sections of a clip that are like this? Perhaps 'field dominance' is the incorrect term?

manono
11th January 2011, 10:34
Oh, so it plays all jerky for half the video, like two-steps-forward-and-one-step-back? Then I misunderstood and I apologize. I don't know how to correct something like that but perhaps Gavino or someone else does.

Gavino
11th January 2011, 12:37
If the pattern is completely regular, perhaps stickboy's ApplyEvery (http://avisynth.org/stickboy/ApplyEvery.zip) function could be used in conjunction with a suitable processing function for each section.

2Bdecided
11th January 2011, 13:09
I don't think there is a suitable processing function for each section! Well, not simply...

It depends on exactly what the camera is outputting. I think the original clip already includes exactly what a TV will display if you put this on a DVD with correctly flagged field order - the DVD player will insert an extra field at the change to "catch-up" - which is what's in the footage.

To avoid the extra field, and to avoid changing the field dominance, and to avoid converting the field dominance by moving the footage down one line, you need the other field for all those fields after the switch (until the next switch).

so the camera captures TF, BF, TF, BF then insterts a duplicate TF, then has BF, TF, BF, TF
You want to keep TF, BF, TF, BF, dump the duplicate TF, then have the image content in the subsequent BF but as a TF. At that moment in time, the camera didn't capture a TF!

The way you could do it is to deinterlace the swapped parts with a really nice deinterlacer (e.g. tgmc), then re-interlace the result using the correct field order - i.e. throwing away all the original information and only keeping the "created" lines. That's one way to get a TF from a BF. That would work, but it could be slow, and it's hardly great to throw away all the original data (though tgmc's "interpolation" is spectacularly good).


Here's a thought though: how on earth can the camcorder do what I've just suggested? During the period where the field order is reversed, it's supposedly sending TF, BF, TF, BF to its AVCHD encoder, while sending BF, TF, BF, TF to its HDMI port. Which means it's capturing complete progressive frames, and interlacing them in opposite ways for two different outputs (i.e. the lines sent to AVCHD are discarded for HDMI, and the lines sent to HDMI are discarded for AVCHD).

Can it really be doing this?

I think we need a sample - a simultaneous AVCHD and HDMI capture of the same live event (with lots of movement and details).

Cheers,
David.
P.S. I could be very wrong! ;)

rec
12th January 2011, 06:53
I tried ApplyEvery, but it turns out the sections of reversed fields are not evenly spaced. They vary anywhere in length from 270 to 829 frames.

The function that I need to apply is simply 'swapfields'.

So, I guess the solution boils down to this...

1) Detect when the fields switch
2) Apply 'swapfields' at that point
3) Detect when the fields switch again
4) Stop applying 'swapfields'

Repeat


To 2Bdecided - Thanks for your thoughts. The situation is actually not that complicated. The camera is recording fine internally. It's only adding in the duplicate fields through the HDMI port. The whole idea is to undo that damage. All the information is there.

I can post some footage if anyone wants to have a crack at it.

Alex_ander
12th January 2011, 09:56
The function that I need to apply is simply 'swapfields'.


You said the problem was in wrong field order for some parts. But that function deals with a different thing (which could result from some mistake): it geometrically changes fields position within a frame (moves top field to bottom).

rec
12th January 2011, 18:52
You said the problem was in wrong field order for some parts. But that function deals with a different thing (which could result from some mistake): it geometrically changes fields position within a frame (moves top field to bottom).

Yes, that's exactly what the problem is. Perhaps I didn't express myself well (it's been known to happen).

2Bdecided
14th January 2011, 13:55
If it's as you say, you just need to use applyrange to swapfields. There's no automatic way to detect field dominance, so unless there's some pattern to the changes you're going to have to find them all manually.

However the problem that solves is not the one you described(!), so if it doesn't work, you probably need to post a sample.

Cheers,
David.

rec
14th January 2011, 21:41
If it's as you say, you just need to use applyrange to swapfields. There's no automatic way to detect field dominance, so unless there's some pattern to the changes you're going to have to find them all manually.

Cheers,
David.

I'm almost home. Using applyrange was good for testing proof of concept. It turns out I need to apply both swapfields and ReverseFieldDominance to correct the bad sections.

The last hurdle is to auto-detect when the fields switch, because there is no set pattern. There must be some way to do it. In fact, I wouldn't be surprised if somebody's already done it. Some use of the ConditionalFilter, perhaps?