Skip to main content

Video from images in a console application

Product: Video Edit SDK .Net. Engine: VideoEditCore (Windows only).

You must set the ConsoleUsage property to "true".

Sample code

using System;
using System.IO;
using VisioForge.Types;
using VisioForge.Types.Output;
using VisioForge.VideoEdit;
using VisioForge.Controls;
using VisioForge.Controls.VideoEdit;

namespace ve_console
{
class Program
{
// Folder contains images
private const string AssetDir = "c:\\samples\\pics\\";

static void Main(string[] args)
{
if (!Directory.Exists(AssetDir))
{
Console.WriteLine(@"Folder with images does not exists: " + AssetDir);
return;
}

var images = Directory.GetFiles(AssetDir, "*.jpg");
if (images.Length == 0)
{
Console.WriteLine(@"Folder with images is empty or do not have files with .jpg extension: " + AssetDir);
return;
}

if (File.Exists(AssetDir + "output.avi"))
{
File.Delete(AssetDir + "output.avi");
}

var ve = new VideoEditCore();

int insertTime = 0;

foreach (string img in images)
{
ve.Input_AddImageFile(img, TimeSpan.FromMilliseconds(2000), TimeSpan.FromMilliseconds(insertTime), VideoEditStretchMode.Letterbox, 0, 640, 480);
insertTime += 2000;
}

ve.Video_Effects_Clear();
ve.Mode = VideoEditMode.Convert;

ve.Video_Resize = true;
ve.Video_Resize_Width = 640;
ve.Video_Resize_Height = 480;

ve.Video_FrameRate = 25;
ve.Video_Renderer = new VideoRendererSettings
{
VideoRenderer = VideoRendererMode.None,
StretchMode = VideoRendererStretchMode.Letterbox
};

var aviOutput = new AVIOutput
{
Video_Codec = "MJPEG Compressor"
};

ve.Output_Format = aviOutput;
ve.Output_Filename = AssetDir + "output.avi";

ve.Video_Effects_Enabled = true;
ve.Video_Effects_Clear();

ve.OnError += VideoEdit1_OnError;
ve.OnProgress += VideoEdit1_OnProgress;

ve.ConsoleUsage = true;

ve.Start();

Console.WriteLine(@"Video saved to: " + ve.Output_Filename);
}

private static void VideoEdit1_OnProgress(object sender, ProgressEventArgs progressEventArgs)
{
Console.WriteLine(progressEventArgs.Progress);
}

private static void VideoEdit1_OnError(object sender, ErrorsEventArgs e)
{
Console.WriteLine(e.Message);
}
}
}

Required redists

  • Video Edit SDK redist x86 x64

How can the required redists be installed or deployed to the user's PC?


Visit our GitHub page to get more code samples.