I am using ffmpeg to play video on iOS 5.0. In my app with ffmpeg decoded video frames and use OpenGL to display it.
But I have a problem I don’t resolve it. Chains logos and subtitles of the video image is displayed in reverse. I think that is the problem of rendering OpenGL 2.0 or ffmpeg decoded.
Can you tell me what is wrong?, and How I can fix it?
Very thanks,
Edit: I change my prepareTExture method with this:
- (void) prepareTextureW: (GLuint) texW textureHeight: (GLuint) texH frameWidth: (GLuint) frameW frameHeight: (GLuint) frameH {
float aspect = (float)frameW/(float)frameH;
float minX=-1.f, minY=-1.f, maxX=1.f, maxY=1.f;
float scale ;
if(aspect>=(float)backingHeight/(float)backingWidth){
// Aspect ratio will retain width.
scale = (float)backingHeight / (float) frameW;
maxY = ((float)frameH * scale) / (float) backingWidth;
minY = -maxY;
} else {
// Retain height.
scale = (float) backingWidth / (float) frameW;
maxX = ((float) frameW * scale) / (float) backingHeight;
minX = -maxX;
}
if(frameTexture) glDeleteTextures(1, &frameTexture);
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &frameTexture);
glBindTexture(GL_TEXTURE_2D, frameTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texW, texH, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, NULL);
verts[0] = maxX;
verts[1] = maxY;
verts[2] = minX;
verts[3] = maxY;
verts[4] = maxX;
verts[5] = minY;
verts[6] = minX;
verts[7] = minY;
float s = (float) frameW / (float) texW;
float t = (float) frameH / (float) texH;
texCoords[0] = 0.f; texCoords[1] = 1.f;
texCoords[2] = 1; texCoords[3] = 1.f;
texCoords[4] = 0.f; texCoords[5] =0;
texCoords[6] = 1; texCoords[7] =0;
mFrameH = frameH;
mFrameW = frameW;
mTexH = texH;
mTexW = texW;
maxS = s;
maxT = t;
// Just supporting one rotation direction, landscape left. Rotate Z by 90 degrees.
matSetRotZ(&rot,M_PI_2);
matMul(&mvp, &rot, &rot);
[self setupShader];
}
And now this is my result: link image
The whole image is mirrored, not just chain logo and subtitles. Looks like wrong texture coordinates to me. Could you please post your drawing code?
EDIT due to question update
Phew I first had to understand what you do there, it’s overly complicated. Just use texture coordinates 0 and 1, don’t try to outsmart yourself by calculating some s, t. Next step. Don’t use a perspective projection, unless you indend to render something in perspective.
Upon your original problem. OpenGL assumes the origin of an image to be in the lower left, while most video formats put the origin into the upper left. What you did was rotating the picture, but while this will turn it upright, it will leave it mirrored. Instead you want to mirror it along the T texture coordinates, which is easily accomplished by using a negative value for t.