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. Optionally set VideoUltimate's global configuration (if overriding a default value is required). For example, you may want to set the license key.

    For an ASP.NET Core project

    You can specify the configuration in appsettings.json file:

    Json
    {
      //Set this property only if you have a valid license key, otherwise do not
      //set it so VideoUltimate runs in trial mode.
      "VideoUltimate:LicenseKey": "QQJDJLJP34..."
    }
    

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

    Alternatively you can specify the configuration in code, in Configure method of your Startup.cs:

    C#
    //Set this property only if you have a valid license key, otherwise do not
    //set it so DocumentUltimate runs in trial mode.
    VideoUltimateConfiguration.Current.LicenseKey = "QQJDJLJP34...";

    For an ASP.NET Classic (MVC or WebForms) project

    You can specify the configuration in <appSettings> tag of your Web.config.

    XML
    <appSettings>
      <!--
        Set this property only if you have a valid license key, otherwise do not
        set it so VideoUltimate runs in trial mode.
      -->
      <add key="VideoUltimate:LicenseKey" value="QQJDJLJP34..." />
    </appSettings>

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

    Alternatively you can specify the configuration in code, in Application_Start method of your Global.asax.cs:

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

    For other project types

    You can specify the configuration in a static (Shared in VB) method, e.g. in Main method for a Console project:

    static void Main(string[] args)
    {
        //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...";
    }

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