0

directshow.netを使用することで、ビデオを録画できます。録画では、このサンプルグラバーを構成するためにテキストオーバーレイを実行し、buffercbメソッドでフレームを処理しています。ここにコードがあります。

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;
    }

私の問題は、プログラムを起動するとプレビューウィンドウにテキストオーバーレイが表示されますが、記録されたファイルを開くとテキストオーバーレイが続行されないことです。一部のフレームが欠落していると思います。一部のフレームではオーバーレイが表示されますが、続行されません。そのフリック。誰か助けてもらえますか?

4

1 に答える 1

0

わかりました私は問題を手に入れました!!

上記のコードでは、BufferCB は現在のビデオ フレームを処理するのに時間がかかりすぎます。そのようなものは、フレーム A がまだ途中のプロセスであり、プロセスが完了したフレーム B が入る前です。

BufferCBでの処理を最小限に抑えるために、ビットマップ画像が設定されている場所を削除しました。このコード行を関数に入れました

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);

この関数は、media.run が呼び出される前に呼び出されます。

于 2012-06-29T12:59:42.917 に答える