Example #1
0
 private void DeleteTempFolder(string tempFolder)
 {
     try
     {
         OutPut.Insert(0, "Removing temporary folder ..");
         Directory.Delete(tempFolder, true);
     }
     catch (Exception ex)
     {
         OutPut.Insert(0, "Error :" + ex.Message);
     }
 }
Example #2
0
        private void GenerateMp4(string tempFolder)
        {
            try
            {
                string ffmpegPath = Path.Combine(Settings.ApplicationFolder, "ffmpeg.exe");
                if (!File.Exists(ffmpegPath))
                {
                    MessageBox.Show("ffmpeg not found! Please reinstall the application.");
                    return;
                }

                string parameters = @"-r {0} -i {1}\img00%04d.jpg -c:v libx264 -vf fps=25 -pix_fmt yuv420p";
                if (VideoType.Name.StartsWith("4K"))
                {
                    parameters = @"-r {0} -i {1}\img00%04d.jpg -c:v libx265 -vf fps=25";
                }
//                parameters += string.Format("-s {0}x{1}", Width, Height);
                if (Preview)
                {
                    parameters += " -vf scale=400:264";
                }
                else
                {
                    parameters += string.Format(" -vf scale={0}:{1}", Width, Height);
                }
                parameters += " {2}";
                OutPut.Insert(0, "Generating video ..... ");
                Process newprocess = new Process();
                Progress             = 0;
                ProgressMax          = (MaxValue - MinValue) * 25 / Fps;
                newprocess.StartInfo = new ProcessStartInfo()
                {
                    FileName               = ffmpegPath,
                    Arguments              = string.Format(parameters, Fps, tempFolder, OutPutFile),
                    UseShellExecute        = false,
                    WindowStyle            = ProcessWindowStyle.Minimized,
                    CreateNoWindow         = true,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true
                };
                newprocess.Start();
                newprocess.OutputDataReceived += newprocess_OutputDataReceived;
                newprocess.ErrorDataReceived  += newprocess_OutputDataReceived;
                newprocess.BeginOutputReadLine();
                newprocess.BeginErrorReadLine();
                newprocess.WaitForExit();
            }
            catch (Exception exception)
            {
                OutPut.Insert(0, "Converting error :" + exception.Message);
            }
        }
Example #3
0
 private void newprocess_OutputDataReceived(object sender, DataReceivedEventArgs e)
 {
     try
     {
         lock (_locker)
         {
             OutPut.Insert(0, e.Data);
             //frame=   20 fps= 12 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A
             if (e.Data != null && e.Data.StartsWith("frame="))
             {
                 var s = e.Data.Substring(7, 5).Trim();
                 int i = 0;
                 if (int.TryParse(e.Data.Substring(7, 5).Trim(), out i))
                 {
                     Progress = i;
                 }
             }
         }
     }
     catch (Exception)
     {
     }
 }
Example #4
0
 private void GenerateGif(string tempFolder)
 {
     try
     {
         Progress = 0;
         var files            = Directory.GetFiles(tempFolder);
         AnimatedGifEncoder e = new AnimatedGifEncoder();
         e.Start(OutPutFile);
         e.SetDelay(1000 / Fps);
         //-1:no repeat,0:always repeat
         e.SetRepeat(0);
         for (int i = 0, count = files.Length; i < count; i++)
         {
             Progress++;
             e.AddFrame(Image.FromFile(files[i]));
         }
         e.Finish();
     }
     catch (Exception ex)
     {
         OutPut.Insert(0, "Converting error :" + ex.Message);
     }
 }
Example #5
0
        private void _backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            RaisePropertyChanged(() => IsBusy);
            RaisePropertyChanged(() => IsFree);


            string tempFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            try
            {
                if (!Directory.Exists(tempFolder))
                {
                    Directory.CreateDirectory(tempFolder);
                }
            }
            catch (Exception exception)
            {
                OutPut.Add(exception.Message);
                return;
            }

            Thread.Sleep(500);
            CurrentImages = 0;
            TotalImages   = ServiceProvider.Settings.DefaultSession.Files.Count;
            int counter = 0;

            ProgressMax = MaxValue - MinValue;
            Progress    = 0;
            for (int i = MinValue; i < MaxValue; i++)
            {
                if (_backgroundWorker.CancellationPending)
                {
                    DeleteTempFolder(tempFolder);
                    OutPut.Insert(0, "Operation CANCELED !!!");
                    return;
                }

                try
                {
                    Progress++;
                    FileItem item    = ServiceProvider.Settings.DefaultSession.Files[i];
                    string   outfile = Path.Combine(tempFolder, "img" + counter.ToString("000000") + ".jpg");
                    if (TransformBefor && !Preview)
                    {
                        AutoExportPluginHelper.ExecuteTransformPlugins(item, _config, item.FileName, outfile);
                        CopyFile(outfile, outfile);
                    }
                    else
                    {
                        if (Preview)
                        {
                            BitmapLoader.Instance.GenerateCache(item);
                            File.Copy(item.SmallThumb, outfile);
                        }
                        else
                        {
                            CopyFile(item.FileName, outfile);
                        }
                    }
                    //outfile =
                    if (!TransformBefor)
                    {
                        AutoExportPluginHelper.ExecuteTransformPlugins(item, _config, outfile, outfile);
                    }
                    OutPut.Insert(0, "Procesing file " + item.Name);
                    counter++;
                }
                catch (Exception exception)
                {
                    OutPut.Add(exception.Message);
                }
            }
            switch (VideoType.Extension)
            {
            case ".mp4":
                GenerateMp4(tempFolder);
                break;

            case ".gif":
                GenerateGif(tempFolder);
                break;
            }


            DeleteTempFolder(tempFolder);
            Progress = ProgressMax;
            OutPut.Insert(0, "DONE !!!");
            if (Preview)
            {
                PlayVideo();
            }
        }
Example #6
0
        private void _backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            RaisePropertyChanged(() => IsBusy);
            RaisePropertyChanged(() => IsFree);


            string tempFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
            string ffmpegPath = Path.Combine(Settings.ApplicationFolder, "ffmpeg.exe");

            if (!File.Exists(ffmpegPath))
            {
                MessageBox.Show("ffmpeg not found! Please reinstall the application.");
                return;
            }

            try
            {
                if (!Directory.Exists(tempFolder))
                {
                    Directory.CreateDirectory(tempFolder);
                }
            }
            catch (Exception exception)
            {
                OutPut.Add(exception.Message);
                return;
            }

            Thread.Sleep(500);
            CurrentImages = 0;
            TotalImages   = ServiceProvider.Settings.DefaultSession.Files.Count;
            int counter = 0;

            ProgressMax = MaxValue - MinValue;
            Progress    = 0;
            for (int i = MinValue; i < MaxValue; i++)
            {
                if (_backgroundWorker.CancellationPending)
                {
                    DeleteTempFolder(tempFolder);
                    OutPut.Insert(0, "Operation CANCELED !!!");
                    return;
                }

                try
                {
                    Progress++;
                    FileItem item    = ServiceProvider.Settings.DefaultSession.Files[i];
                    string   outfile = Path.Combine(tempFolder, "img" + counter.ToString("000000") + ".jpg");
                    if (TransformBefor)
                    {
                        AutoExportPluginHelper.ExecuteTransformPlugins(item, _config, item.FileName, outfile);
                        CopyFile(outfile, outfile);
                    }
                    else
                    {
                        CopyFile(item.FileName, outfile);
                    }
                    //outfile =
                    if (!TransformBefor)
                    {
                        AutoExportPluginHelper.ExecuteTransformPlugins(item, _config, outfile, outfile);
                    }
                    OutPut.Insert(0, "Procesing file " + item.Name);
                    counter++;
                }
                catch (Exception exception)
                {
                    OutPut.Add(exception.Message);
                }
            }

            try
            {
                string parameters = @"-r {0} -i {1}\img00%04d.jpg -c:v libx264 -vf fps=25 -pix_fmt yuv420p {2}";
                if (VideoType.Name.StartsWith("4K"))
                {
                    parameters = @"-r {0} -i {1}\img00%04d.jpg -c:v libx265 -vf fps=25 {2}";
                }
                OutPut.Insert(0, "Generating video ..... ");
                Process newprocess = new Process();
                Progress             = 0;
                ProgressMax          = (MaxValue - MinValue) * 25 / Fps;
                newprocess.StartInfo = new ProcessStartInfo()
                {
                    FileName               = ffmpegPath,
                    Arguments              = string.Format(parameters, Fps, tempFolder, OutPutFile),
                    UseShellExecute        = false,
                    WindowStyle            = ProcessWindowStyle.Minimized,
                    CreateNoWindow         = true,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true
                };
                newprocess.Start();
                newprocess.OutputDataReceived += newprocess_OutputDataReceived;
                newprocess.ErrorDataReceived  += newprocess_OutputDataReceived;
                newprocess.BeginOutputReadLine();
                newprocess.BeginErrorReadLine();
                newprocess.WaitForExit();
            }
            catch (Exception exception)
            {
                OutPut.Insert(0, "Converting error :" + exception.Message);
            }

            DeleteTempFolder(tempFolder);

            OutPut.Insert(0, "DONE !!!");
        }