Bug #369

Aspect Ratio Rounding Error

Added by hermitemp-mailinator-com - over 1 year ago. Updated about 1 year ago.

Status:New Start Date:11/14/2010
Priority:High Due date:
Assigned to:- % Done:

50%

Category:video_output
Target version:rev15 Estimated time:1.00 hour

Description

See forum post: http://tracker.sttz.ch/boards/1/topics/308

The aspect ratio of videos is being passed into the function in MPlayerVideoRenderer.m:

(int) startWithWidth:(int)width withHeight:(int)height withBytes:(int)bytes withAspect:(int)aspect {

as an integer (multiplied by 100 to give 2 decimal places).

For 16:9 video this is passed as 177, which becomes 1.77f when divided by 100.

image_aspect = image_aspect/100;

The width of the video is calculated from the aspect ratio here:

    [self callDelegateWithSelector:@selector(startRenderingWithSize:)
                                             andObject:[NSValue valueWithSize:NSMakeSize((image_height*image_aspect), image_height)]];

But with only two digits of precision, 720*1.77 = 1274.4, which accounts for the observed width discrepancy.

Simply supplying image_width instead of image_height*image_aspect corrected the problem for me, but I have not tested a wide range of aspect ratios or scales (like full screen).

That seems to fix the problem, but then I noticed my video was coming out at 1279x720 - still 1px short!

So I made the following change to FINALLY get 720p video.

In the file VideoOpenGLView.m, on line ~360 I added the bolded portion:
win_frame.size.width += 1 + floorf(video_size.height*video_aspect*zoomFactor) - mov_frame.size.width;

The changes I have made work for the two videos I have tried, and there is likely a better place to make the correction, but I would very much appreciate this fix to make it into r15.

History

Updated by hermitemp-mailinator-com - over 1 year ago

I had added debugging comments while tracking down the problem, so I couldn't give accurate line numbers, but I got the source again to make myself a fresh app (that I will use for myself until r15), so I'll post line numbers for your convenience.

The call to [self callDelegateWithSelector:@selector(startRenderingWithSize:) etc. is on line 219 of MPlayerVideoRenderer.m inside function startWithWidth.

The +1px increase to window width is on line 363 of VideoOpenGLView.m inside function resizeView.

Updated by Hermi G about 1 year ago

UPDATE 3: After yet further investigation I have figured out why the width was set 1px too large to begin with. The function renderOpenGL in MPlayerVideoRenderer.m sets the openGL texture onto which the video is rendered based on the variable NSRect textureFrame which contains floats. The glVertex2i() function takes integer types, and a rounding error was causing the OpenGL texture to occasionally be 1 px too small, leaving a black line on the right side of the player. The 1px extra width of the OpenGLView in the Player.xib would appear to correct this, but only intermittently, causing a corresponding missing column of pixels (which update 2 sought to correct) when the rounding error did not manifest. The solution is to replace the calls to glVertex2i with glVertex2f. In conclusion: updates 2 & 3 together completely solve the '1 pixel' problem! (for good this time?)

UPDATE 2: After further investigation I have determined that while my solution did properly set the window size, the VideoOpenGLView was still one pixel too large. To fix this, open Player.xib, click on the Video Open GL View and change it's size from 566 to 565 to match the Player Window's size.

Update 1 and original text removed for being completely wrong and misleading.

Also available in: Atom PDF