[Mono-osx] Render QTMovie in a background thread on OpenGL texture
De Santis Luca
farolfo at hotmail.com
Thu Apr 6 20:06:03 UTC 2017
I'm trying to make a video player that renders on an OpenGL texture. I want to make a portable application so I'm using OpenTK, and on MacOS I'm trying to use QTMovie to draw the video frame in a texture (on Windows I use VLC and works well, on Linux I'm try to use GStremer).
The video is rendered correctly, but I think there is a problem when try to get frames from QTMovie because this operation occurs in a thread that is not the main application thread.
The audio and video tracks are very slow, and many frame are skipped.
To rendere video I use two functions:
public void UpdateTexture()
{
double td=(double)mMovie.CurrentTime.TimeValue/(double)mMovie.Duration.TimeValue;
this.MoviePosition=(int)((double)this.MovieDuration*td);;
this.frameCount=(int)((1000/(double)this.frameRate)*(double)this.MoviePosition);
if(this.frameCount!=this.lastFrameCount)
{
this.lastFrameCount=this.frameCount;
using(var imageData=mMovie.CurrentFrameImage.AsTiff())
{
var imgRep=NSBitmapImageRep.ImageRepFromData(imageData)asNSBitmapImageRep;
var imageProps=newNSDictionary();
var data=imgRep.RepresentationUsingTypeProperties(NSBitmapImageFileType.Bmp,imageProps);
this.tetxure1.CreateTextureFromBitmap(newBitmap(data.AsStream()));
}
}
}
public void DrawImage(System.Drawing.RectangletmpRect,intBlendValue)
{
if(!this.isOpen)
return;
this.UpdateTexture();
GL.MatrixMode(MatrixMode.Texture);
GL.LoadIdentity();
GL.MatrixMode(MatrixMode.Modelview);
GL.Enable(EnableCap.CullFace);
GL.Enable(EnableCap.Texture2D);
GL.Enable(EnableCap.Blend);
GL.BlendFunc(BlendingFactorSrc.SrcAlpha,BlendingFactorDest.OneMinusSrcAlpha);
GL.BindTexture(TextureTarget.Texture2D,this.tetxure1.TextureID);
GL.Begin(BeginMode.Quads);
PointF Pt1=Scr2OpenGL(tmpRect.Left,tmpRect.Bottom);
GL.TexCoord2(0.0f,1.0f);GL.Vertex2(Pt1.X,Pt1.Y);
PointF Pt2=Scr2OpenGL(tmpRect.Right,tmpRect.Bottom);
GL.TexCoord2(1.0f,1.0f);GL.Vertex2(Pt2.X,Pt2.Y);
PointF Pt3=Scr2OpenGL(tmpRect.Right,tmpRect.Top);
GL.TexCoord2(1.0f,0.0f);GL.Vertex2(Pt3.X,Pt3.Y);
PointF Pt4=Scr2OpenGL(tmpRect.Left,tmpRect.Top);
GL.TexCoord2(0.0f,0.0f);GL.Vertex2(Pt4.X,Pt4.Y);
GL.Disable(EnableCap.Blend);
GL.End();
}
I read that to use QTMovie in a background thread I can follow the instructions in Technical Note TN2138, but I’m not an expert in Cocoa and objC programming and I can't understand how to use it in c #.
Can anyone give me some advice on how to solve this problem?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.dot.net/pipermail/mono-osx/attachments/20170406/6f805b59/attachment.html>
More information about the Mono-osx
mailing list