directshow.net
text overlay issue?
by using directshow.net i can able to record the video and with recording i am doing text overlay for this i configured sample grabber and in buffercb method i am working on frames here is the code.. int ISampleGrabberCB.BufferCB(double SampleTime, IntPtr pBuffer, int BufferLen) { Graphics g; String s; float sLeft; float sTop; SizeF d; g = Graphics.FromImage(bitmapOverlay); g.Clear(System.Drawing.Color.Transparent); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; // Prepare to put the specified string on the image g.DrawRectangle(System.Drawing.Pens.Transparent, 0, 0, 240 - 1, 176 - 1); g.DrawRectangle(System.Drawing.Pens.Transparent, 1, 1, 240 - 3, 176 - 3); d = g.MeasureString(m_String + "\n" + DateTime.Now.ToString("G"), fontOverlay); sLeft = (240 - d.Width) / 2; sTop = (176 - d.Height) / 2; g.DrawString(m_String + "\n" + DateTime.Now.ToString("G"), fontOverlay, System.Drawing.Brushes.Black, sLeft, sTop, System.Drawing.StringFormat.GenericTypographic); // need to flip the bitmap so it's the same orientation as the // video buffer bitmapOverlay.RotateFlip(RotateFlipType.RotateNoneFlipY); // create and copy the video's buffer image to a bitmap Bitmap v; v = new Bitmap(240, 176, 1056, PixelFormat.Format24bppRgb, pBuffer); g = Graphics.FromImage(v); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; // draw the overlay bitmap over the video's bitmap g.DrawImage(bitmapOverlay, 0, 0, bitmapOverlay.Width, bitmapOverlay.Height); // dispose of the various objects g.Dispose(); v.Dispose(); // Increment frame number. Done this way, frame are zero indexed. m_Count++; return 0; } my problem is,when i start program it shows me text overlay in preview window but when i open recorded file text overlay is not continues..i think i am missing some frames..on some frames overlay is their but its not continues..its flicking. can any one help?
ok i got the problem!! in the above code,BufferCB takes too long time to process the current video frame.its like let frame A is still in middle process before process complete frame B comes in. so to minimize the processing in BufferCB i have remove the where bitmap image is set this line of code i put into an function g = Graphics.FromImage(bitmapOverlay); g.Clear(System.Drawing.Color.Transparent); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; // Prepare to put the specified string on the image g.DrawRectangle(System.Drawing.Pens.Transparent, 0, 0, 240 - 1, 176 - 1); g.DrawRectangle(System.Drawing.Pens.Transparent, 1, 1, 240 - 3, 176 - 3); d = g.MeasureString(m_String + "\n" + DateTime.Now.ToString("G"), fontOverlay); sLeft = (240 - d.Width) / 2; sTop = (176 - d.Height) / 2; g.DrawString(m_String + "\n" + DateTime.Now.ToString("G"), fontOverlay, System.Drawing.Brushes.Black, sLeft, sTop, System.Drawing.StringFormat.GenericTypographic); // need to flip the bitmap so it's the same orientation as the // video buffer bitmapOverlay.RotateFlip(RotateFlipType.RotateNoneFlipY); and this function is called before media.run is called.
Related Links
text overlay issue?
Chaining Shader Effects
MP4 Fast Forward/Rewind
Can I get timecode from directshow video?
Use specific codec or ffdshow folder with DirectShowLib?
File writer filter creating a bigger AVI file then original