Click or drag to resize

Using VideoUltimate in a project

To use VideoUltimate in a project, do the following in Visual Studio:

  1. Make sure you have added references to VideoUltimate assemblies as described here.

  2. Set VideoUltimate's global configuration. For example, you may want to set the license key. Insert the following line into the Application_Start method of your Global.asax.cs for Web projects or Main method for other project types:

    protected void Application_Start(object sender, EventArgs e)
    {
        //Set this property only if you have a valid license key, otherwise do not
        //set it so VideoUltimate runs in trial mode.
        VideoUltimateConfiguration.Current.LicenseKey = "QQJDJLJP34...";
    }

    Alternatively you can specify the configuration in <appSettings> tag of your Web.config (or App.exe.config).

    XML
    <appSettings>
      <add key="VideoUltimate:LicenseKey" value="QQJDJLJP34..." />
    </appSettings>

    As you would notice, VideoUltimate: prefix maps to VideoUltimateConfiguration.Current.

  3. Open one of your class files (eg. Program.cs) and at the top of your file add the necessary namespaces:

    using GleamTech.VideoUltimate;

    Now in some method insert these lines:

    using (var videoFrameReader = new VideoFrameReader(@"C:\Video.mp4"))
    {
        if (videoFrameReader.Read()) //Only if frame was read successfully
        {
            //Get a System.Drawing.Bitmap for the current frame
            //You are responsible for disposing the bitmap when you are finished with it.
            //So it's good practice to have a "using" statement for the retrieved bitmap.
            using (var frame = videoFrameReader.GetFrame())
                //Reference System.Drawing and use System.Drawing.Imaging namespace for the following line.
                frame.Save(@"C:\Frame1.jpg", ImageFormat.Jpeg);
        }
    }

    This will open the source video C:\Video.mp4, read the first frame, and if the frame is read and decoded successfully, it will get a Bitmap instance of the frame and save it as C:\Frame1.jpg.

    Sometimes you may only need to quickly generate a meaningful thumbnail for a video, you can use VideoThumbnailer class for this:

    using (var videoThumbnailer = new VideoThumbnailer(@"C:\Video.mp4"))
    //Generate a meaningful thumbnail of the video and
    //get a System.Drawing.Bitmap with 100x100 maximum size.
    //You are responsible for disposing the bitmap when you are finished with it.
    //So it's good practice to have a "using" statement for the retrieved bitmap.
    using (var thumbnail = videoThumbnailer.GenerateThumbnail(100))
        //Reference System.Drawing and use System.Drawing.Imaging namespace for the following line.
        thumbnail.Save(@"C:\Thumbnail1.jpg", ImageFormat.Jpeg);