SJM
27th June 2010, 23:04
I have an application that used DirectShow.net to play videos with a bitmap overlay. It has the ability to pause, step forward and step backward. I use the AviSynth script to deinterlace the video:
DirectShowSource("filename.avi")
separateFields
bilinearResize(720,480)
When I play a video with a bitmap overlay and the avisynth script, the video jumps ahead approx 100 frames when I pause the video. The video does not jump if I use avisynth and do not overlay the bitmap. The video also does not jump if I overlay the bitmap and do not use avisynth.
I loooked at the current Position values when I paused the video with and without the bitmap overlay. If I pause the video at the same spot, the current position with the bitmap overlay is much larger than when I pause without the bitmap overlay.
If I stop the video, mediaControl.Stop(), the next call to Pause, Run or SetPositions makes the video jump ahead.
The code to play the video and overlay the bitmap was extracted from the dxtext DirectShow.net sample . See ISampleGrabber code below. If I comment out the line:
g.DrawImage(bitmapOverlay, 0, 0, bitmapOverlay.Width, bitmapOverlay.Height);
the video does not skip ahead.
Any ideas on how to fix this?
Thank you for your help
int ISampleGrabberCB.BufferCB(double SampleTime, IntPtr pBuffer, int BufferLen)
{
Graphics g;
// display line
if (vidXLine > 0)
{
// get the current video frame
Bitmap vidbuf;
vidbuf = new Bitmap(vidWidth, vidHeight, vidStride,
PIXELFORMAT, pBuffer);
// get the drawing graphic of the bitmap overly
bitmapOverlay = new Bitmap(vidWidth, vidHeight, PIXELFORMAT);
g = Graphics.FromImage(bitmapOverlay);
g.Clear(System.Drawing.Color.Transparent);
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
//draw a line on the graphic
Pen myPen = new Pen(Color.Yellow, 2);
g.DrawLine(myPen, vidLine_X1, 4, vidLine_X2, vidHeight);
myPen.Dispose();
g.Dispose();
// 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
g = Graphics.FromImage(vidbuf);
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();
bitmapOverlay.Dispose();
vidbuf.Dispose();
}
return (0)
}
DirectShowSource("filename.avi")
separateFields
bilinearResize(720,480)
When I play a video with a bitmap overlay and the avisynth script, the video jumps ahead approx 100 frames when I pause the video. The video does not jump if I use avisynth and do not overlay the bitmap. The video also does not jump if I overlay the bitmap and do not use avisynth.
I loooked at the current Position values when I paused the video with and without the bitmap overlay. If I pause the video at the same spot, the current position with the bitmap overlay is much larger than when I pause without the bitmap overlay.
If I stop the video, mediaControl.Stop(), the next call to Pause, Run or SetPositions makes the video jump ahead.
The code to play the video and overlay the bitmap was extracted from the dxtext DirectShow.net sample . See ISampleGrabber code below. If I comment out the line:
g.DrawImage(bitmapOverlay, 0, 0, bitmapOverlay.Width, bitmapOverlay.Height);
the video does not skip ahead.
Any ideas on how to fix this?
Thank you for your help
int ISampleGrabberCB.BufferCB(double SampleTime, IntPtr pBuffer, int BufferLen)
{
Graphics g;
// display line
if (vidXLine > 0)
{
// get the current video frame
Bitmap vidbuf;
vidbuf = new Bitmap(vidWidth, vidHeight, vidStride,
PIXELFORMAT, pBuffer);
// get the drawing graphic of the bitmap overly
bitmapOverlay = new Bitmap(vidWidth, vidHeight, PIXELFORMAT);
g = Graphics.FromImage(bitmapOverlay);
g.Clear(System.Drawing.Color.Transparent);
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
//draw a line on the graphic
Pen myPen = new Pen(Color.Yellow, 2);
g.DrawLine(myPen, vidLine_X1, 4, vidLine_X2, vidHeight);
myPen.Dispose();
g.Dispose();
// 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
g = Graphics.FromImage(vidbuf);
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();
bitmapOverlay.Dispose();
vidbuf.Dispose();
}
return (0)
}