How to create video stream from frame captures in C#

In this chapter you will find detailed information on how to create a video stream from captured frames in C#. To implement this function, Ozeki Camera SDK has to be installed and a reference to OzekiSDK.dll has to be added to your Visual Studio project.

video stream from captured frames
Figure 1 - Video stream from captured frames in C#

Important: you should study this article in order to find out how to set up your Windows Forms Application correctly.

Getting started

To get started it is recomended to Download and Install the latest version of Ozeki Camera SDK. After installation you can find the example code discussed in this page with the full source code in the following location on your harddisk:

Download Ozeki Camera SDK:
Windows forms version: C:\Program Files\Ozeki\Ozeki SDK\examples\04_ComputerVision\

To compile this example you will need Microsoft Visual Studio installed on your computer.

Corporate use of creating a video stream

Creating a video stream is a widely used method to get customers and maintain their interest in products and businesses. With the help of the video creating function of the Ozeki Camera SDK you can design customized videos from the image frames you wish to use.

From now on, you can easily create short campaign movies or product specific advertisement for your business. You can demonstrate the strength and the advantages of your business and create efficient presentations by using Ozeki Camera SDK.

On top of this the video creating function can also be useful if you wish to supervise areas and territories (where a camera is placed). For example you can create a video from the frames which were taken at a parking area or a similar public place.

Implement video stream from captured frames in C#

You can create a video from the image files stored in your computer. You should provide a time interval which determines the time between the arriving of the 2 image files. The following methods can be applied for the determination of the time interval:

  • SetInterval(double frame, double sec) - In the parameter list we can determine a unique FPS (frames per second) number which determines how the camera will send the images. For instance: 100 frames / 30 seconds
  • SetInterval(TimeSpan) - We can determine a time interval between the 2 frames. For example: new TimeSpan(0,0,1,0) - In this case the camera will forward one frame in a minute

This function of the Ozeki Camera SDK supports several image formats which are the following:
.jpg, .jpeg, .png, .gif, .tiff, .bmp

At the initialization of the instance you should provide the path of the folder to extract the image files.

C# code example for frame capture from an IP camera


using System;
using System.Windows.Forms;
using Ozeki.Media;

namespace Frame_Capture_From_Folder_WF
    public partial class MainForm : Form
        private string _folder;
        private MediaConnector _connector;
        private DrawingImageProvider _provider;

        private FrameCapture _capture;

        public MainForm()

            _connector = new MediaConnector();
            _provider = new DrawingImageProvider();

        private void browseButt_Click(object sender, EventArgs e)
            var fbd = new FolderBrowserDialog();
            if (fbd.ShowDialog() == DialogResult.OK)
                _folder = fbd.SelectedPath;

        private void startButt_Click(object sender, EventArgs e)
            var interval = intervalText.Text;

            if (String.IsNullOrEmpty(interval)) return;

            _capture = new FrameCapture(_folder);

            _connector.Connect(_capture, _provider);

            _capture.SetInterval(new TimeSpan(0,0,0,int.Parse(interval)));


        private void stopButt_Click(object sender, EventArgs e)

            _connector.Disconnect(_capture, _provider);


Code 1 - Code example to create video stream from frame captures in C#


Below you can find the code that belongs to the interface of the previously presented application. With the help of this section your Windows Forms Application will be able to work properly.


namespace Frame_Capture_From_Folder_WF
    partial class MainForm
        private System.ComponentModel.IContainer components = null;

        protected override void Dispose(bool disposing)
            if (disposing && (components != null))

        #region Windows Form Designer generated code

        private void InitializeComponent()
            this._videoViewerWF1 = new Ozeki.Media.VideoViewerWF();
            this.browseButt = new System.Windows.Forms.Button();
            this.startButt = new System.Windows.Forms.Button();
            this.intervalText = new System.Windows.Forms.TextBox();
            this.label1 = new System.Windows.Forms.Label();
            this.stopButt = new System.Windows.Forms.Button();
            // _videoViewerWF1
            this._videoViewerWF1.FlipMode = Ozeki.Media.FlipMode.None;
            this._videoViewerWF1.Location = new System.Drawing.Point(12, 42);
            this._videoViewerWF1.Name = "_videoViewerWF1";
            this._videoViewerWF1.RotateAngle = 0;
            this._videoViewerWF1.Size = new System.Drawing.Size(503, 427);
            this._videoViewerWF1.TabIndex = 0;
            this._videoViewerWF1.Text = "_videoViewerWF1";
            // browseButt
            this.browseButt.Location = new System.Drawing.Point(13, 13);
            this.browseButt.Name = "browseButt";
            this.browseButt.Size = new System.Drawing.Size(75, 23);
            this.browseButt.TabIndex = 1;
            this.browseButt.Text = "Browse";
            this.browseButt.UseVisualStyleBackColor = true;
            this.browseButt.Click += new System.EventHandler(this.browseButt_Click);
            // startButt
            this.startButt.Location = new System.Drawing.Point(94, 13);
            this.startButt.Name = "startButt";
            this.startButt.Size = new System.Drawing.Size(75, 23);
            this.startButt.TabIndex = 2;
            this.startButt.Text = "Start";
            this.startButt.UseVisualStyleBackColor = true;
            this.startButt.Click += new System.EventHandler(this.startButt_Click);
            // intervalText
            this.intervalText.Location = new System.Drawing.Point(259, 15);
            this.intervalText.Name = "intervalText";
            this.intervalText.Size = new System.Drawing.Size(116, 20);
            this.intervalText.TabIndex = 3;
            // label1
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(175, 18);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(68, 13);
            this.label1.TabIndex = 4;
            this.label1.Text = "Interval (sec)";
            // stopButt
            this.stopButt.Location = new System.Drawing.Point(381, 13);
            this.stopButt.Name = "stopButt";
            this.stopButt.Size = new System.Drawing.Size(75, 23);
            this.stopButt.TabIndex = 5;
            this.stopButt.Text = "Stop";
            this.stopButt.UseVisualStyleBackColor = true;
            this.stopButt.Click += new System.EventHandler(this.stopButt_Click);
            // MainForm
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(527, 481);
            this.Name = "MainForm";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Frane capture from folder";


        private Ozeki.Media.VideoViewerWF _videoViewerWF1;
        private System.Windows.Forms.Button browseButt;
        private System.Windows.Forms.Button startButt;
        private System.Windows.Forms.TextBox intervalText;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Button stopButt;

Code 2 - GUI example in C#


This guide demonstrates how you can create video stream from captured frames with your C# camera application. On this page you can find detailed information and a code example to implement your idea. This function works with USB, IP and ONVIF IP cameras as well.

Related pages


  1. What kind of developer environment is needed?

    • Microsoft Visual Studio 2010
    • Microsoft .Net Framework 4.0
    • Internet connection
  2. How can I get the URL of the camera?

    You can get the URL from the producer of the camera.

  3. I have not managed to build the solution. How to solve it?

    • Please set the Target framework property of the project to .NET 4.0.
    • You should add the OzekiSDK.dll to the references of the solution.
    • Please import the missing classes.

More information