How to show SWF to WMV conversion progress with SWF To Video SDK (VB, C#)

  • Home
  • /
  • Articles
  • /
  • How to show SWF to WMV conversion progress with SWF To Video SDK (VB, C#)

This sample shows how to display SWF to WMV video conversion progress with Bytescout SWF To Video SDK in Visual Basic and C#.

Visual Basic

        
' x64 IMPORTANT NOTE: set CPU to x86 to build in x86 mode. WHY? Because flash is not supported on x64 platform currently at all

Imports System.Diagnostics
Imports System.Threading
Imports BytescoutSWFToVideoLib

Class Program
	Friend Shared Sub Main(args As String())
		' Create an instance of SWFToVideo ActiveX object
		Dim converter As New SWFToVideo()

		' Set debug log
		'converter.SetLogFile("log.txt");

		' Register SWFToVideo
		converter.RegistrationName = "demo"
		converter.RegistrationKey = "demo"

		' Set the converter to the live data conversion mode
		' (it will fully load the embedded video stream before the conversion)
		converter.SWFConversionMode = SWFConversionModeType.SWFWithLiveData

		' set input SWF file 
		converter.InputSWFFileName = "shapes.swf"

		' set output AVI or WMV video filename
		converter.OutputVideoFileName = "result.wmv"

		' Don't let it run infinitely
		converter.ConversionTimeOut = 5000
		' 5000ms = 5 seconds 
		' set FPS 
		converter.FPS = 29.97F

		' Set output movie dimensions 
		converter.OutputWidth = 320
		converter.OutputHeight = 240

		' Run the conversion
		converter.Run()

		' Show conversion progress:

		Dim i As Integer = 0
		Dim spin As Char() = New Char() {"|"C, "/"C, "-"C, ""C}

		While Not Console.KeyAvailable AndAlso converter.IsRunning
			Dim progress As Single = converter.ConversionProgress
            Console.WriteLine([String].Format("Converting images {0}% {1}", progress, spin(i)))
            Console.CursorTop -= 1
            i = i + 1
            i = i Mod 4
            Thread.Sleep(50)
		End While

		If converter.IsRunning Then
            converter.Stop()
			Console.WriteLine("Conversion aborted by user.")
		Else
			Console.WriteLine("Conversion competed successfully.")
		End If

		' Open the result in default media player
		Process.Start("result.wmv")

		Console.WriteLine()
		Console.WriteLine("Hit any key...")
		Console.ReadKey()
	End Sub
End Class
          
      

C#

        
// x64 IMPORTANT NOTE: set CPU to x86 to build in x86 mode. WHY? Because flash is not supported on x64 platform currently at all

using System;
using System.Diagnostics;
using System.Threading;
using BytescoutSWFToVideoLib;

namespace ConversionProgress
{
	class Program
	{
		static void Main(string[] args)
		{
			// Create an instance of SWFToVideo ActiveX object
			SWFToVideo converter = new SWFToVideo();

			// Set debug log
			//converter.SetLogFile("log.txt");

			// Register SWFToVideo
			converter.RegistrationName = "demo";
			converter.RegistrationKey = "demo";

			// Set the converter to the live data conversion mode
			// (it will fully load the embedded video stream before the conversion)
			converter.SWFConversionMode = SWFConversionModeType.SWFWithLiveData;

			// set input SWF file 
			converter.InputSWFFileName = "shapes.swf";

	        // set output AVI or WMV video filename
        	converter.OutputVideoFileName = "result.wmv";
		
			// Don't let it run infinitely
			converter.ConversionTimeOut = 5000; // 5000ms = 5 seconds 

			// set FPS 
			converter.FPS = 29.97f;

			// Set output movie dimensions 
			converter.OutputWidth = 320;
			converter.OutputHeight = 240;

			// Run the conversion
			converter.Run();

			// Show conversion progress:

			int i = 0;
			char[] spin = new char[] { '|', '/', '-', '\' };

			while (!Console.KeyAvailable && converter.IsRunning)
			{
				float progress = converter.ConversionProgress;
				Console.WriteLine(String.Format("Converting images {0}% {1}", progress, spin[i++]));
				Console.CursorTop--;
				i %= 4;
				Thread.Sleep(50);
			}

			if (converter.IsRunning)
			{
				converter.Stop();
				Console.WriteLine("Conversion aborted by user.");
			}
			else
			{
				Console.WriteLine("Conversion competed successfully.");
			}

			// Open the result in default media player
			Process.Start("result.wmv");

			Console.WriteLine();
			Console.WriteLine("Hit any key...");
			Console.ReadKey();
		}
	}
}

          
      
prev
next