Log in

View Full Version : Problems with turnleft() and turnright()


snowcrash
23rd April 2004, 03:18
I've been using these filters to rotate some video that I shot sideways and I'm running into some problems.

First of all, they are rotating the video in the opposite direction that they're supposed to. At Avisynth.org, it says that "TurnLeft rotates the clip 90 degrees counterclock wise, and TurnRight rotates the clip 90 degrees clock wise." Well for me they do just the opposite, and I'm seeing this with both AviSource and DirectShowSource input files.

Secondly, whenever I use Turnleft (which in my case rotates the video 90 deg clockwise), I get a strip of a few pixels on the left showing what should be on the right side of the video frame. Using Turnright, I don't get the stray strip of pixels. You can see this best with the following example screenshots (this source clip was previously rotated at a strange angle from within Premiere). The source video in this case is DV-AVI 720x480 NTSC and my AVS scripts just look like this:

DirectshowSource("Beach.avi")
Turnleft()

DirectshowSource("Beach.avi")
Turnright()

original http://s92093572.onlinehome.us/images/original.jpg
turnleft http://s92093572.onlinehome.us/images/turnleft.jpg turnright http://s92093572.onlinehome.us/images/turnright.jpg

Turnright gives a clean result but it's rotating the wrong way, so I need to clear up this problem with Turnleft. Can anyone help me with this?

Edit: I'm using AviSynth 2.54

Mug Funky
23rd April 2004, 10:46
hmm... it's a bit roundabout, but:

turnright().fliphorizontal().flipvertical()

stickboy
23rd April 2004, 10:54
Hm... looks like TurnLeft/TurnRight are broken for YUY2 and YV12. They work fine in RGB24 and RGB32.

scharfis_brain
23rd April 2004, 10:59
to show its behavior more, just use:

x=avisource("blabla.avi")
y=x.turnleft().turnright()
subtract(x,y)


theoretically both (x and y) has to be the same. but they aren't

sh0dan
23rd April 2004, 19:23
Confirmed. I corrected YV12 and YUY2 (which both turned the wrong way), but haven't had time to do RGB yet. All routines have an off by one error when turning left.

stickboy
23rd April 2004, 20:38
Originally posted by scharfis_brain
x=avisource("blabla.avi")
y=x.turnleft().turnright()
subtract(x,y)

theoretically both (x and y) has to be the same. but they aren't Not in YUY2. :p

snowcrash
24th April 2004, 01:46
Originally posted by sh0dan
Confirmed. I corrected YV12 and YUY2 (which both turned the wrong way), but haven't had time to do RGB yet. All routines have an off by one error when turning left.

Are you saying you fixed the problem already? Will we see the fix in the next version of Avisynth? And what about the Turnleft error, there's nothing you can do for that? I just need a bit of clarification about what you said here. Thanks.

Chez_Wimpy
27th April 2004, 08:54
If I use the turnleft() function, the left most verical column of pixels seems borrowed from the right, if I use turnright().fliphorizontal().flipvertical(), the top most horizontal column seems displaced from the bottom. I haven't found a turn or flip combination yet that yeilds an error free result.

Not sure which version this was broken in, I do believe I once used it quite frequently.:confused:

snowcrash
28th April 2004, 11:54
Originally posted by Chez_Wimpy

Not sure which version this was broken in, I do believe I once used it quite frequently.:confused:

So are you saying that these filters worked properly at one time? They turned the correct way and the Turnleft pixel strip bug wasn't there?

sh0dan
28th April 2004, 16:44
They haven't been touched all the time it has been in AviSynth, so I very much expect it to be present in all versions.

TurnRight (as the only one) works in RGB mode.

Code is fixed in CVS.

IanB
4th July 2004, 10:36
Dear all,

Problem 1:- Trying to use different colour spaces in the same script with turnleft/right causes various problems. (crashes/wrong output/GPF). Try :-BlankClip(100, PixelType="YUY2")
A=ConvertToRGB32().TurnLeft()
B=TurnLeft().ConvertToRGB32()
StackHorizontal(A, Subtract(A, B), B)

Problem 2:- TurnLeft() with YUY2 is 1 pixel low.

I have fixed sources, turn.h and turnfunc.cpp, for both these bugs. I've commit'd the changes into CVS.

IanB

Bidoche
5th July 2004, 08:51
@IanB

So you finally reached the point where you commit the fix yourself to the cvs :)

If you could be interested in helping port filters to avs 3.0, please let me know.

IanB
6th July 2004, 00:43
@Bidoche

When I get the training wheels :eek: off, I'll try to put some cycles your way.

IanB:cool:

AVIL
31st July 2005, 17:36
Hi all,

I am using turnright/turnleft on a interlaced source (YUY2, tff). I've found that both filter duplicates first field chroma (U and V planes ) on every frame. Instead of turn the chroma of both fields and produce rotated frame, it rotate only the chroma of the first field and copy it to the second field.

IanB
1st August 2005, 06:42
I am using turnright/turnleft on a interlaced source (YUY2, tff). I've found that both filter duplicates first field chroma (U and V planes ) on every frame. Instead of turn the chroma of both fields and produce rotated frame, it rotate only the chroma of the first field and copy it to the second field.Yes, it is a problem with the 2:1 horizontal chroma subsampling.

For the chroma data only11 . 13 . 15 . 17 .
21 . 23 . 25 . 27 .
31 . 33 . 35 . 37 .
41 . 43 . 45 . 47 .if pure right rotated would become, Note no chroma for even lines, chroma for every column41 31 21 11
. . . .
43 33 23 13
. . . .
45 35 25 15
. . . .
47 37 27 17
. . . .but when resampled becomes (define A#B operator to be (A+B)/2)(41#31) . (21#11) .
(41#31) . (21#11) .
(43#33) . (23#13) .
(43#33) . (23#13) .
(45#35) . (25#15) .
(45#35) . (25#15) .
(47#37) . (27#17) .
(47#37) . (27#17) .So as you can see although both fields have the same chroma data it is in fact a blend of the data from both fields.

Here are 2 solutions :-

1. Write your own YUY2 interlace rotate. See filters/turnfunc.cpp for the existing code.

2.AssumeTFF() # or AssumeBFF() to suit your source
Bob() # Probably best to use one of the Smart Bob'ers available
TurnRight()
SeparateFields()
SelectEvery(4, 0, 3) # or (4, 1, 2)
Weave()

Note: Converting to RGB is not an option as you will still end up with blended chroma from the 2 fields, just like you have now.

IanB

AVIL
1st August 2005, 19:57
@IanB

Thanks for your info. I’ve understand the problem. At this moment, I can’t create my own routines (Microsoft’s compiler environment is not easy/nor cheap). Knowing the true reason, I’ve found an alternative: separating the fields before rotating and weaving after. As an example I wrote the script:

setmemorymax(128)
a=avisource("e:\bvi_v2.avi").assumetff().crop(256,0,256,0,align=true).separatefields()
v=a.turnleft().turnright().weave().assumetff()
stackhorizontal(a,v,subtract(a,v))

The comparision is almost exact (little differences).

Best regards.

IanB
2nd August 2005, 16:15
@Avil,

There is a free version of the MS C++ compiler available. It is quite good for compiling pluggins. Search this forum for "free compiler".

Unfortunatly every 90 rotate of YUY2 data causes a 50% loss of chroma resolution. Your turnleft().turnright() example will reduce the resolution to 25%.

I assume you now understand why a simple separatefields().turnleft().weave() will not work, and why you need to Bob().

Also crop(...., align=true) cause the resultant frames to be copied, rather than just have their pointers adjusted (near zero cpu cost). You should only need it when precedeing an intensive MMX/SSE filter that performs badly with unaligned data.

IanB