private static void PhotoFinish(VideoFileReader reader, VideoFileWriter writer, BackgroundWorker renderWorker) { var numberOfFrames = (int)reader.FrameCount; var width = reader.Width; var height = reader.Height; if (numberOfFrames > width) //if user want -> fit to original width { numberOfFrames = width; } //writer.Width = numberOfFrames; //rewrite for change resolution, open file in method for (var x = 0; x < width; x++) { var convertedBitmap = new FastBitmap(new Bitmap(numberOfFrames, height)); //photofinish одновременная обработка нескольких кадров convertedBitmap.LockBits(); for (var f = 0; f < numberOfFrames; f++) { FastBitmap currentBitmap; try { currentBitmap = new FastBitmap(reader.ReadVideoFrame(f)); } catch (Exception ignored) { break; } currentBitmap.LockBits(); for (var y = 0; y < height; y++) { convertedBitmap.SetPixel(f, y, currentBitmap.GetPixel(x, y)); } currentBitmap.DisposeSource(); } convertedBitmap.UnlockBits(); writer.WriteVideoFrame(convertedBitmap.GetSource()); AppForm.PreviewBitmap = (Bitmap)convertedBitmap.GetSource().Clone(); convertedBitmap.DisposeSource(); renderWorker.ReportProgress(FastUtils.FastRoundInt(x * 1000.0 / width)); } }
private static void OpenFileButtonHandler() { if (OpenFile.ShowDialog() != DialogResult.OK) { return; } Reader.Close(); // close prev videos Reader.Dispose(); Reader = new VideoFileReader(); Writer.Close(); Writer.Dispose(); Writer = new VideoFileWriter(); VideoName = ("" + OpenFile.SafeFileName).Replace("" + Path.GetExtension(OpenFile.FileName), ""); VideoPath = Path.GetDirectoryName(OpenFile.FileName) + @"\";//задаем название и путь к файлу VideoExtension = Path.GetExtension(OpenFile.FileName); ChosenFile.Text = OpenFile.FileName; Reader.Open(OpenFile.FileName); //открываем файл Writer.BitRate = Reader.BitRate; //конфигурируем writer Writer.VideoCodec = VideoCodec.Mpeg4; //Reader videoCodec Writer.FrameRate = Reader.FrameRate; Writer.Height = Reader.Height; Writer.Width = Reader.Width; Writer.Open(GetNameToSave(VideoPath, VideoName, VideoExtension)); TimeLine.Value = 0; //настраиваем временную линию TimeLine.Maximum = (int)Reader.FrameCount; TimeLine.TickFrequency = FastUtils.FastRoundInt((double)Reader.FrameRate); TimeLineEnd.Text = TimeSpan.FromSeconds(Reader.FrameCount / (double)Reader.FrameRate).ToString(@"hh\:mm\:ss\.ff"); Distorter.ResetMaxMinValues(); DrawImage(PreviewPictureBox, //if enable start button? because multiplierFrom can be bad Distorter.RunOneFrame(Reader, 0, MultiplierFrom, MultiplierTo, Function , PreviewPictureBox.Width, PreviewPictureBox.Height)); //рисуем 0 кадр EnableStartButton(StartButton, TimeLine); //пробуем включить кнопку старт }