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(); } }
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 !!!"); }