private void ConvertFile(FileDesc file) { file.Status = FileStatus.Converting; _stateProgress = 0; UpateUI(); try { //ConverterV1(file); ConverterV2(file); file.Status = FileStatus.Converted; } catch (FFMpegCore.Exceptions.FFMpegException ex) { file.Status = FileStatus.Fail; file.Error = ex.Message + "\r\n" + ex.FfmpegErrorOutput.Replace("\n", "\r\n"); } catch (Exception ex) { file.Status = FileStatus.Fail; file.Error = ex.Message; } UpateUI(); }
private FileViewDesc GetViewDesc(FileDesc file) { return(new FileViewDesc { Id = file.Id.ToString(), Name = file.Name, Size = file.Size / 1024 + " KB", Status = file.Status.ToString() }); }
private void lvFiles_SelectedIndexChanged(object sender, EventArgs e) { if (lvFiles.SelectedIndices.Count > 0) { var item = lvFiles.Items[lvFiles.SelectedIndices[0]]; int fileId = int.Parse(item.SubItems[0].Text); _stateSelectedFile = _files.First(f => f.Id == fileId); } else { _stateSelectedFile = null; } UpateUI(); }
private void AddFile(string path) { var file = new FileDesc { Id = fileId++, PathIn = path, PathOut = GetPathOut(path), Name = System.IO.Path.GetFileName(path), Size = new FileInfo(path).Length, Status = FileStatus.Wait }; _files.Add(file); UpateUI(); }
private void ConverterV2(FileDesc file) { FFMpegOptions.Configure(new FFMpegOptions { RootDirectory = @"D:\Git\RocketMov\RocketMov\ffmpeg" }); var fileInfo = FFProbe.Analyse(file.PathIn); FFMpegArguments .FromFileInput(file.PathIn) .OutputToFile(file.PathOut, true, options => options .WithVideoCodec(VideoCodec.LibX264) .WithConstantRateFactor(21) .WithAudioCodec(AudioCodec.Aac) .WithVideoBitrate(_convertOptions.Bitrate) .WithFastStart() .Scale(_convertOptions.Width, _convertOptions.Height) .UsingThreads(4)) .NotifyOnProgress(onConvertProgress, fileInfo.Duration) .CancellableThrough(out _cancelConvertion) .ProcessSynchronously(); }
private void ConverterV1(FileDesc file) { var conversionOptions = new ConversionOptions { //MaxVideoDuration = TimeSpan.FromSeconds(30), //VideoAspectRatio = VideoAspectRatio.R16_9, CustomHeight = 1280, CustomWidth = 720, VideoSize = MediaToolkit.Options.VideoSize.Custom, VideoBitRate = 4 * 1024 }; using (var engine = new Engine(@"F:\Pictures\Tmp\Converter\ffmpeg.exe")) { engine.CustomCommand("-threads 4"); engine.ConvertProgressEvent += Engine_ConvertProgressEvent; engine.ConversionCompleteEvent += Engine_ConversionCompleteEvent; //engine.f engine.Convert(new MediaFile(file.PathIn), new MediaFile(file.PathOut), conversionOptions); } }