static void ThreadProc1(object state) { ManualResetEvent event1 = (ManualResetEvent)state; try { ImageToVideo converter = new ImageToVideo(); converter.RegistrationName = "demo"; converter.RegistrationKey = "demo"; Array x = Enum.GetValues(typeof(PanZoomEffectType)); foreach (string file in Directory.GetFiles(@".\images")) { Slide slide = converter.AddImageFromFileName(file); slide.Duration = 3000; slide.PanZoomEffect = (PanZoomEffectType)x.GetValue((new Random()).Next(8)); slide.InEffect = TransitionEffectType.teFade; slide.InEffectDuration = 250; slide.OutEffect = TransitionEffectType.teFade; slide.OutEffectDuration = 250; } converter.OutputVideoFileName = "result1.wmv"; converter.OutputWidth = 800; converter.OutputHeight = 600; converter.RunAndWait(); System.Runtime.InteropServices.Marshal.ReleaseComObject(converter); Console.WriteLine("First thread finished."); } catch (Exception e) { Console.WriteLine("Error: " + e.ToString()); } finally { event1.Set(); } }
static void Main(string[] args) { try { Console.WriteLine("Converting JPG slides to video, please wait..."); for (int i = 0; i < 5; i++) { // Create BytescoutImageToVideoLib.ImageToVideo object instance ImageToVideo converter = new ImageToVideo(); // Activate the component converter.RegistrationName = "demo"; converter.RegistrationKey = "demo"; // Set output video size converter.OutputWidth = 640; converter.OutputHeight = 480; // Add images and set duration and effects for every slide Slide slide; slide = converter.AddImageFromFileName("..\\..\\..\\..\\slide1.jpg"); slide.Duration = 3000; // 3000ms = 3s slide.InEffect = TransitionEffectType.teFade; slide.OutEffect = TransitionEffectType.teFade; Release(slide); // useful to decrease memory consumption during the batch conversion but not critical slide = converter.AddImageFromFileName("..\\..\\..\\..\\slide2.jpg"); slide.Duration = 3000; slide.InEffect = TransitionEffectType.teWipeLeft; slide.OutEffect = TransitionEffectType.teWipeRight; Release(slide); slide = converter.AddImageFromFileName("..\\..\\..\\..\\slide3.jpg"); slide.Duration = 3000; slide.InEffect = TransitionEffectType.teWipeLeft; slide.OutEffect = TransitionEffectType.teWipeRight; Release(slide); // Set output video file name converter.OutputVideoFileName = "result" + i + ".wmv"; // Run the conversion converter.RunAndWait(); Console.WriteLine("Created " + converter.OutputVideoFileName); // CRITICAL! // Releases all resources consumed during the conversion Release(converter); } Console.WriteLine("Done. Press any key to continue.."); Console.ReadKey(); } catch (Exception e) { Console.WriteLine("Error: " + e.ToString()); Console.WriteLine("\nPress any key to exit"); Console.ReadKey(); } }
static void Main(string[] args) { Console.WriteLine("Converting JPG slides to video, please wait..."); // Create BytescoutImageToVideoLib.ImageToVideo object instance ImageToVideo converter = new ImageToVideo(); // Activate the component converter.RegistrationName = "demo"; converter.RegistrationKey = "demo"; // Add images and set the duration for every slide Slide slide; slide = converter.AddImageFromFileName("..\\..\\..\\..\\slide1.jpg"); slide.Duration = 3000; // 3000ms = 3s slide = converter.AddImageFromFileName("..\\..\\..\\..\\slide2.jpg"); slide.Duration = 3000; slide = converter.AddImageFromFileName("..\\..\\..\\..\\slide3.jpg"); slide.Duration = 3000; // Set output video size converter.OutputWidth = 640; converter.OutputHeight = 480; // Set output video file name converter.OutputVideoFileName = "result.wmv"; Console.WriteLine("Conversion started. Hit a key to abort..."); // 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."); } // Release resources System.Runtime.InteropServices.Marshal.ReleaseComObject(converter); // Open the result video file in default media player Process.Start("result.wmv"); Console.WriteLine("\nPress any key to exit..."); Console.ReadKey(); }
static void Main(string[] args) { try { Console.WriteLine("Converting JPG slides to video with 70 advanced 3D effects variations, please wait..."); // Create BytescoutImageToVideoLib.ImageToVideo object instance ImageToVideo converter = new ImageToVideo(); // Activate the component converter.RegistrationName = "demo"; converter.RegistrationKey = "demo"; // Enable transition effects for the first first slide converter.UseInEffectForFirstSlide = true; converter.Slides.DefaultSlideDuration = 1000; converter.Slides.DefaultSlideEffectDuration = 500; bool bChangeSlide = true; // temporary variable to change slides // now try all 70 advanced 3D transition effects from 70 to 140 for (int i = 67; i < 140; i++) { // Add slide image, set the duration Slide slide = null; if (!bChangeSlide) { slide = converter.AddImageFromFileName("..\\..\\..\\..\\slide1.jpg"); } else { slide = converter.AddImageFromFileName("..\\..\\..\\..\\slide2.jpg"); } bChangeSlide = !bChangeSlide; // switch to use another slide next tim slide.InEffect = (TransitionEffectType)i; // effect index } // Set output video size converter.OutputWidth = 320; converter.OutputHeight = 240; // Set output video file name converter.OutputVideoFileName = "result.wmv"; // Run the conversion converter.RunAndWait(); // Release resources System.Runtime.InteropServices.Marshal.ReleaseComObject(converter); converter = null; // Open the result video file in default media player Process.Start("result.wmv"); Console.WriteLine("Done. Press any key to continue..."); Console.ReadKey(); } catch (Exception e) { Console.WriteLine("Error: " + e.ToString()); Console.WriteLine("\nPress any key to exit."); Console.ReadKey(); } }
private static bool createTmpGifImage(string kw) { /*DirectoryInfo directory = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory + "uploads\\" + kw); * Random rnd1 = new Random(); * AnimatedGifEncoder e = new AnimatedGifEncoder(); * * * e.Start(AppDomain.CurrentDomain.BaseDirectory + "\\uploads\\tmp.gif"); * * e.SetRepeat(0); * e.SetDelay(1000); * e.SetSize(640, 480); * foreach (System.IO.FileInfo file in directory.GetFiles()) * { * Console.WriteLine(file.Name); * Image newImage = ScaleImage(Image.FromFile(AppDomain.CurrentDomain.BaseDirectory + "uploads\\" + kw + "\\" + file.Name), 640, 480); //Image.FromFile(AppDomain.CurrentDomain.BaseDirectory + "uploads\\" + kw + "\\" + file.Name); * e.AddFrame(newImage); * } * * * * * e.Finish(); * if (System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\uploads\\tmp.gif")) { return true; }*/ Console.Write("Converting JPG slides into video, please wait.."); // Create BytescoutImageToVideoLib.ImageToVideo object instance ImageToVideo converter = new ImageToVideo(); // Activate the component converter.RegistrationName = "demo"; converter.RegistrationKey = "demo"; // Add images and set the duration for every slide Slide slide; DirectoryInfo directory = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory + "uploads\\" + kw); foreach (System.IO.FileInfo file in directory.GetFiles()) { try { slide = (Slide)converter.AddImageFromFileName(AppDomain.CurrentDomain.BaseDirectory + "uploads\\" + kw + "\\" + file.Name); slide.Duration = 3000; // 3000ms = 3s } catch (Exception ex) { // } } /*slide = (Slide) converter.AddImageFromFileName("..\\..\\..\\..\\slide1.jpg"); * slide.Duration = 3000; // 3000ms = 3s * * slide = (Slide) converter.AddImageFromFileName("..\\..\\..\\..\\slide2.jpg"); * slide.Duration = 3000; * * slide = (Slide) converter.AddImageFromFileName("..\\..\\..\\..\\slide3.jpg"); * slide.Duration = 3000;*/ // Set output video size converter.OutputWidth = 640; converter.OutputHeight = 480; // Set output video file name converter.OutputVideoFileName = AppDomain.CurrentDomain.BaseDirectory + "video/" + FirstUpper(kw) + ".wmv"; // Run the conversion converter.RunAndWait(); Console.WriteLine("Conversion is done. Press any key to continue.."); //Console.ReadKey(); // Open the result video file in default media player //Process.Start(AppDomain.CurrentDomain.BaseDirectory + "video/" + FirstUpper(kw) + ".wmv"); return(true); }
private void btnCreateMovie_Click(object sender, EventArgs e) { if (!_imageToVideo.IsRunning) { SaveFileDialog dlg = new SaveFileDialog(); dlg.Filter = "WMV files (*.wmv)|*.wmv|AVI files (*.avi)|*.avi|All files (*.*)|*.*"; if (tabControl2.SelectedIndex == 0) { dlg.DefaultExt = "*.wmv"; dlg.FilterIndex = 1; } else { dlg.DefaultExt = "*.avi"; dlg.FilterIndex = 2; } dlg.FileName = "movie"; dlg.Title = "Save generated video as"; if (String.IsNullOrEmpty(Settings.Default.LastUsedFolder2)) { Settings.Default.LastUsedFolder2 = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); } dlg.InitialDirectory = Settings.Default.LastUsedFolder2; if (dlg.ShowDialog() == DialogResult.OK) { Settings.Default.LastUsedFolder2 = Path.GetDirectoryName(dlg.FileName); int intValue; float floatValue; _imageToVideo.AutoFitImages = cbAutoFitImages.Checked; _imageToVideo.KeepAspectRatio = cbKeepAspectRatio.Checked; _imageToVideo.BackgroundColor = (uint)ColorTranslator.ToOle(btnBackgroundColor.BackColor); if (tbBackgroundImage.Text.Length > 0) { _imageToVideo.SetBackgroundPictureFileName(tbBackgroundImage.Text); } if (int.TryParse(tbMovieWidth.Text, out intValue)) { _imageToVideo.OutputWidth = intValue; } if (int.TryParse(tbMovieHeight.Text, out intValue)) { _imageToVideo.OutputHeight = intValue; } if (tbAudioTrack.Text.Length > 0) { _imageToVideo.ExternalAudioTrackFromFileName = tbAudioTrack.Text; } _imageToVideo.CurrentAudioCodec = cmbAviAudioCodecs.SelectedIndex; _imageToVideo.CurrentVideoCodec = cmbAviVideoCodecs.SelectedIndex; _imageToVideo.CurrentWMVAudioCodec = cmbWmvAudioCodecs.SelectedIndex; _imageToVideo.CurrentWMVAudioFormat = cmbWmvAudioFormats.SelectedIndex; _imageToVideo.CurrentWMVVideoCodec = cmbWmvVideoCodecs.SelectedIndex; if (int.TryParse(tbBitrate.Text, out intValue)) { _imageToVideo.WMVVideoBitrate = intValue * 1024; } if (float.TryParse(tbFPS.Text, out floatValue)) { _imageToVideo.FPS = floatValue; } _outputFile = dlg.FileName; _imageToVideo.OutputVideoFileName = _outputFile; _imageToVideo.SetProgressNotifyWindow(Handle.ToInt32(), WM_CONVERSION_PROGRESS, 0); _imageToVideo.Slides.Clear(); foreach (ListViewItem item in lvInputFiles.Items) { SlideOptions slideInfo = (SlideOptions)item.Tag; Slide slide = _imageToVideo.AddImageFromFileName(slideInfo.ImageFile); slide.Duration = slideInfo.SlideDuration; slide.RotationAngle = slideInfo.SlideRotation; slide.VisualEffect = slideInfo.VisualEffect; slide.Effect = slideInfo.VisualEffectTransition; slide.EffectDuration = slideInfo.VisualEffectDuration; slide.InEffect = slideInfo.RandomTransitionEffectBefore ? GetRandomEffect() : slideInfo.TransitionEffectBefore; slide.InEffectDuration = slideInfo.TransitionEffectBeforeDuration; slide.OutEffect = slideInfo.RandomTransitionEffectAfter ? GetRandomEffect() : slideInfo.TransitionEffectAfter; slide.OutEffectDuration = slideInfo.TransitionEffectAfterDuration; } _imageToVideo.Run(); toolStripStatusLabel1.Text = "Generating video..."; btnCreateMovie.Text = "Stop"; btnCreateMovie.Image = Resources.stop; } } else { // Stop generation _imageToVideo.Stop(); // wait a bit the converter finished and released resources while (_imageToVideo.IsRunning) { Thread.Sleep(200); } toolStripStatusLabel1.Text = "Interrupted by user."; btnCreateMovie.Text = "Create Movie"; btnCreateMovie.Image = Resources.film; toolStripProgressBar1.Value = 0; } }