3.17.1 Export Video


Version Info

Minimum Origin Version Required: Origin 9 SR0

Example

The example will create a new matrixbook, set its values, and plot the values as a contour graph. The program will then loop for fifty times. For each iteration it will adjust the matrix values, update the graph, and add the updated graph to the video as a frame. So when the code finished running, a video with fifty frames will be created.


To specify the codecs, please refer to FourCC Table.

#include <Origin.h>
#include <..\OriginLab\VideoWriter.h>

int VideoWriter_Ex1()
{
	// Create a new Matrixbook.
	MatrixPage mp;
	if( !mp.Create("origin.otm") )
		return -1;
	MatrixLayer ml(mp.GetName());
	if( !ml )
		return -2;
	MatrixObject mo(ml, 0);
	if( !mo )
		return -3;

	// Initialize the matrix data.
	string strFormula = "i*sin(1*x)-j*cos(y/1)";
	if( mo.SetFormula(strFormula, 2, -1, -1, TRUE) )
		mo.ExecuteFormula();

	// Create a new graph and plot the matrix as a contour plot.
	GraphPage gp;
	if( !gp.Create("contour.otp") )
		return -4;
	GraphLayer gl(gp.GetName());
	if( !gl )
		return -5;
	gl.AddPlot(mo, IDM_PLOT_CONTOUR);

    // Define the codec
    // You can not expect all codecs to be available on all computers.
    // Here are a few examples:
    // int codec = CV_FOURCC(0,0,0,0); // No compression, can create large files.
// int codec = CV_FOURCC(1,0,0,0); // Microsoft Run Length Encoded
       int codec = CV_FOURCC('D', 'I', 'V', 'X'); // MPEG-4 codec
      
	// Create a VideoWriter object.
	VideoWriter vw;
	int err = vw.Create("D:\\testVideoWriter.avi", codec, 15, 1024, 768);
	if( 0 == err )
	{
		// Create a string with LabTalk code that will be called
		// inside the loop.  The script will pause execution until
		// the graph window as finished redrawing.  This allows
		// watching the animation while creating the video file.
		string strLT;
		strLT.Format("sec -pw %s", gp.GetName());

		for( double a = 1; a <= 1.5; a += 0.01 )
		{
			// Update the matrix data.
			strFormula.Format("i*sin(%f*x)-j*cos(y/%f)+grnd()", a, a);
			if( mo.SetFormula(strFormula, 2, -1, -1, TRUE) )
				mo.ExecuteFormula();
			gl.Rescale(); // Rescale the plot.
	 
			// Wait for graph window to redraw.
			LT_execute(strLT);

			// Write the graph to the video as a single frame.
			err = vw.WriteFrame(gp);
			if( err )
				break;
		}

        // Release the video object when finished.
	    vw.Release(); 
	}

	return err;
}