Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Development

Reply
 
Thread Tools Search this Thread Display Modes
Old 11th March 2010, 23:12   #1  |  Link
Wilbert
Moderator
 
Join Date: Nov 2001
Location: Netherlands
Posts: 6,364
Subframe and SeparateFields

Some questions about Subframe and SeparateFields:

Code:
PVideoFrame SeparateFields::GetFrame(int n, IScriptEnvironment* env) 
{
  PVideoFrame frame = child->GetFrame(n>>1, env);
  if (vi.IsPlanar()) {
    const bool topfield = (child->GetParity(n)+n)&1;
    const int UVoffset = !topfield ? frame->GetPitch(PLANAR_U) : 0;
    const int Yoffset = !topfield ? frame->GetPitch(PLANAR_Y) : 0;
    return env->SubframePlanar(frame,Yoffset, frame->GetPitch()*2, frame->GetRowSize(), frame->GetHeight()>>1,
	                       UVoffset, UVoffset, frame->GetPitch(PLANAR_U)*2);
  }
  return env->Subframe(frame,(GetParity(n) ^ vi.IsYUY2()) * frame->GetPitch(),
                         frame->GetPitch()*2, frame->GetRowSize(), frame->GetHeight()>>1);  
}
Why is it not simply
Code:
if (vi.IsPlanar()) {
  const bool topfield = child->GetParity(n);
  ...
and also
Code:
return env->Subframe(frame, GetParity(n) * frame->GetPitch(),
                         frame->GetPitch()*2, frame->GetRowSize(), frame->GetHeight()>>1);
What's so special with YUY2 compared to RGB?
Wilbert is offline   Reply With Quote
Old 12th March 2010, 12:47   #2  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by Wilbert View Post
Why is it not simply
Code:
if (vi.IsPlanar()) {
  const bool topfield = child->GetParity(n);
  ...
Because relative to child (the source clip), n is the field number, not the frame number.
However, I would expect it to be this->GetParity(n) (or just GetParity(n)) instead. Otherwise, source clips that have gone through a filter that re-orders parity on a per-frame basis (eg SelectEvery) will not give the right results.
Quote:
What's so special with YUY2 compared to RGB?
RGB is stored 'upside-down', so for top fields you want line 1, not line 0.
Gavino is offline   Reply With Quote
Old 12th March 2010, 21:39   #3  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
Code:
const bool topfield = (child->GetParity(n)+n)&1;
Yes this does seem a bit wrong, n exceeds the frame count of the child clip for the second half.

Given the GetParity code is this
Code:
inline bool __stdcall GetParity(int n) { return child->GetParity(n>>1) ^ (n&1); }
and that it is used in the YUY2/RGB cases, I also think just GetParity(n) is what it should be.
IanB is offline   Reply With Quote
Old 13th March 2010, 00:48   #4  |  Link
Wilbert
Moderator
 
Join Date: Nov 2001
Location: Netherlands
Posts: 6,364
It's all tricky stuff, but i agree with both of you. Strange that we didn't notice this before, because you get incorrect results.

Example: source = 2 frames (frame 0 = BFF, frame 1 = TFF):
Code:
2 frames => 4 fields (planar colorformat)
GetParity(n):
output: n=0 => GetParity(n>>1) ^ (n&1) = GetParity(0) ^ 0 = 0 ^ 0 = 0 (correct; since GetParity(0)=0=BFF)
output: n=1 => GetParity(n>>1) ^ (n&1) = GetParity(0) ^ 1 = 0 ^ 1 = 1 (correct)
output: n=2 => GetParity(n>>1) ^ (n&1) = GetParity(1) ^ 0 = 1 ^ 0 = 1 (correct; since GetParity(1)=1=TFF)
output: n=3 => GetParity(n>>1) ^ (n&1) = GetParity(1) ^ 1 = 1 ^ 1 = 0 (correct)

topfield = (child->GetParity(n)+n)&1;
output: n=0 => (0+0)&1 = 0 (correct)
output: n=1 => (1+1)&1 = 0 (wrong)
output: n=2 => (1+2)&1 = 1 (correct)
output: n=3 => (0+3)&1 = 1 (wrong)
You should get duplicate fields then, since the offsets are the same for every frame?

Btw, I still don't understand what happens when SubframePlanar is called. I'm looking at avisynth.cpp, but it is still a mistery. Could you explain it?
Wilbert is offline   Reply With Quote
Old 13th March 2010, 11:41   #5  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by Wilbert View Post
Strange that we didn't notice this before, because you get incorrect results.
Example: source = 2 frames (frame 0 = BFF, frame 1 = TFF) ...
The reason you don't normally see a problem is that your example is unusual. Frame-based clips (the usual source material) normally have the same parity for every frame, since the entire clip is usually TFF or BFF. So GetParity(n) is independent of n and the error makes no difference.

The problem only shows up if an earlier filter has introduced a non-standard parity function, where the parity depends on the frame number.

Last edited by Gavino; 13th March 2010 at 11:43.
Gavino is offline   Reply With Quote
Old 13th March 2010, 14:32   #6  |  Link
Wilbert
Moderator
 
Join Date: Nov 2001
Location: Netherlands
Posts: 6,364
Quote:
The reason you don't normally see a problem is that your example is unusual. Frame-based clips (the usual source material) normally have the same parity for every frame, since the entire clip is usually TFF or BFF. So GetParity(n) is independent of n and the error makes no difference.
Ok, i see.
Wilbert is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:38.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.