How to take a snapshot from a video

Feb 17, 2016 at 3:57 PM
Hi

How can I take a snapshot of the currently playing video? I see an event call "SnapshotTaken", but no function to actually take the snapshot.

Thanks you
Feb 17, 2016 at 6:52 PM
I found it!

In libvlc.net\libvlclibrary.mediaplayer.videocontrols.cs

Add this:
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate int libvlc_video_take_snapshot_signature(IntPtr p_mi, uint num, string psz_filepath, uint i_width, uint i_height);

private readonly libvlc_video_take_snapshot_signature m_libvlc_video_take_snapshot;
public int libvlc_video_take_snapshot(IntPtr p_mi, string psz_filepath, uint i_width, uint i_height)
{
    VerifyAccess();

    return m_libvlc_video_take_snapshot(p_mi, 0, psz_filepath, i_width, i_height);
}
In libvlc.net\libvlclibrary.cs, constructor LibVLCLibrary

Add this:
m_libvlc_video_take_snapshot = (libvlc_video_take_snapshot_signature)LoadDelegate<libvlc_video_take_snapshot_signature>("libvlc_video_take_snapshot");
In libvlc.net\mediaplayer.cs

Add this:
    public int TakeSnapshot(string filepath, uint i_width = 0, uint i_height = 0)
    {
        return m_Library.libvlc_video_take_snapshot(m_MediaPlayerHandle, filepath, i_width, i_height);
    }
And finally call it from a button like this:
    private void TakeSnapShotButton_Click(object sender, RoutedEventArgs e)
    {
        MediaElement.TakeSnapshot(@"C:\Temp\Test.png");
    }
Marked as answer by Pascal77 on 2/17/2016 at 11:52 AM