5

I'd like to insert subtitle into the media file without using Library that provides it automatically(Like a DirectShow)

I used way to draw by using window desktop's drawing handle, but it couldn't work. I think it is because of the speed of update... right? Anyway, is there any function or method to paint over a media file or get their overlay handle?

    [DllImport("user32.dll")]
    static extern IntPtr GetDesktopWindow();

    [DllImport("user32.dll")]
    static extern IntPtr GetDCEx(IntPtr hwnd, IntPtr hrgn, uint flags);

    [DllImport("user32.dll")]
    static extern IntPtr ReleaseDC(IntPtr hwnd, IntPtr hdc);

    public void SubtitleDraw()
    {
        IntPtr hWnd = GetDesktopWindow();
        IntPtr hDc = GetDCEx(hWnd, IntPtr.Zero, 1027);

        Font font1 = new Font("Times New Roman", 24, FontStyle.Regular,GraphicsUnit.Pixel);    
        Point pt = new Point(40, 375);

        PointF pointF1 = new PointF();
        pointF1 = PlayerForm.ActiveForm.PointToScreen(pt);

        Graphics g = Graphics.FromHdc(hDc);
        g.DrawString(SubtitleText, font1, Brushes.Black, pointF1);

        ReleaseDC(hWnd, hDc);
    }
Park Jinsang
  • 59
  • 1
  • 3
  • Could you clarify where the actual media playback is occuring before I answer? Is it within one of your applications forms, or in another process? I ask because the description and code seem a little contradictory. You make reference to not wanting to use a library such as DirectShow, yet you look to a form for coordinates, possibly implying playback is occuring within one of your forms? If so, there should be no need to capture the desktop handle itself. – Frostie Nov 22 '12 at 08:45
  • The media playback I used is included in AudioVideoPlayback of DirectX. Implying playback is out of my forms... it just used control panel as the owner of its site. Actually, I could not understand ur answer that is regarding relationship between process and playbacks' form (becoz Im a novice). – Park Jinsang Dec 10 '12 at 19:29
  • Maybe searching for the words "WPF" and "Adorner" might help you? – juFo Mar 27 '13 at 12:23

1 Answers1

0

You're going to want to research DirectShow and filters if you want to draw on top of a video while playing at any decent framerate. There is some scattered documentation out there for how to interact with DirectShow filter graphs from .NET, but it's pretty scarce.

If you have a video playing in a media control, it will almost always be playing the video in an overlay, so anything you draw "on top" of it will be on top of the control, but still beneath the "overlay" where the real video is playing.

Eric Falsken
  • 4,796
  • 3
  • 28
  • 46