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();
        }
Esempio n. 2
0
        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;
            }
        }