text overlay issue?

走远了吗. 提交于 2019-12-11 14:07:58

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/11156654/text-overlay-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!