Example #1
0
        public void ReportFastTime(int currentFrame)
        {
            var timeLeft = new TimeSpan();
            var now      = DateTime.Now.Ticks;

            if (_previousTime != 0)
            {
                if (_averageTicks == 0)
                {
                    _startTime    = now;
                    _averageTicks = now - _previousTime;
                    timeLeft      = new TimeSpan(_averageTicks * (_numberOfFrames - currentFrame - 1));
                }
                else
                {
                    var delta = FastUtils.FastAbs((int)(_averageTicks - (now - _previousTime)));
                    if (delta > 250000 && delta < 1500000)
                    {
                        _averageTicks = (_averageTicks + (now - _previousTime)) / 2;
                    }
                    timeLeft = new TimeSpan(_averageTicks * (_numberOfFrames - currentFrame - 1));
                }
            }
            Console.Write($"\rProgress: {Math.Round((double)currentFrame / (_numberOfFrames - 1) * 100, 2)}%, Time left: {timeLeft}, Frame: {currentFrame + 1}/{_numberOfFrames}                        ");
            if (currentFrame + 1 == _numberOfFrames)
            {
                Console.WriteLine($"\nDone. Total time elapsed: {new TimeSpan(now - _startTime)}");
                ResetAverageTime();
            }
            _previousTime = now;
        }
Example #2
0
        /// <summary>
        /// Calculates remaining and elapsed time.
        /// </summary>
        /// <param name="currentFrame">Frame number.</param>
        public Tuple <TimeSpan, TimeSpan> GetTimeElapsed(int currentFrame)
        {
            var timeLeft = new TimeSpan();
            var now      = DateTime.Now.Ticks;

            if (_previousTime != 0)
            {
                if (_averageTicks == 0)
                {
                    _startTime    = now;
                    _averageTicks = now - _previousTime;
                    timeLeft      = new TimeSpan(_averageTicks * (_numberOfFrames - currentFrame - 1));
                }
                else
                {
                    var delta = FastUtils.FastAbs((int)(_averageTicks - (now - _previousTime)));
                    if (delta > 250000 && delta < 1500000)
                    {
                        _averageTicks = (_averageTicks + (now - _previousTime)) / 2;
                    }
                    timeLeft = new TimeSpan(_averageTicks * (_numberOfFrames - currentFrame - 1));
                }
            }
            _previousTime = now;
            return(new Tuple <TimeSpan, TimeSpan>(timeLeft, new TimeSpan(now - _startTime)));
        }
Example #3
0
        public static void Run(string videoPath, string videoName)
        {
            var reader = new VideoFileReader();

            reader.Open(videoPath + videoName);
            var writer         = new VideoFileWriter();
            var numberOfFrames = (int)reader.FrameCount;
            var probeBitmap    = new FastBitmap(reader.ReadVideoFrame(0));

            probeBitmap.LockBits();
            var maxValues = CalcMaxValues(probeBitmap.Width, probeBitmap.Height);
            var maxX      = maxValues.Item1;
            var maxY      = maxValues.Item2;

            //Console.WriteLine($"{maxX}:{maxY}");
            writer.Height     = probeBitmap.Height;
            writer.Width      = probeBitmap.Width;
            writer.FrameRate  = 30;
            writer.VideoCodec = VideoCodec.Mpeg4;
            writer.BitRate    = reader.BitRate;
            writer.Open(videoPath + "out.avi");
            for (var t = 70; t < numberOfFrames; t++)
            {
                var        convertedBitmap = new FastBitmap(new Bitmap(probeBitmap.Width, probeBitmap.Height));
                FastBitmap currentBitmap;
                try
                {
                    currentBitmap = new FastBitmap(reader.ReadVideoFrame(t));
                }
                catch (Exception ignored)
                {
                    break;
                }
                convertedBitmap.LockBits();
                currentBitmap.LockBits();
                for (var x = 0; x < probeBitmap.Width; x++)
                {
                    for (var y = 0; y < probeBitmap.Height; y++)
                    {
                        var pixel = ConvertToPolar(x - probeBitmap.Width / 2, y - probeBitmap.Height / 2);
                        var convX = FastUtils.FastAbs((int)(pixel.Item2 / maxY * (probeBitmap.Width - 1)));
                        var convY = FastUtils.FastAbs((int)(pixel.Item1 / maxX * (probeBitmap.Height - 1)));
                        convertedBitmap.SetPixel(convX, convY, currentBitmap.GetPixel(x, y));
                    }
                }
                Stopwatch sw = new Stopwatch();
                sw.Start();
                for (int i = 0; i < 4; i++)
                {
                    convertedBitmap = CompleteBitmap(convertedBitmap);
                }
                sw.Stop();
                Console.WriteLine(sw.Elapsed);
                currentBitmap.UnlockBits();
                currentBitmap.DisposeSource();
                convertedBitmap.GetSource().Save(videoPath + "test.png");
                break;
                //convertedBitmap.RotateFlip(RotateFlipType.RotateNoneFlipX);
                writer.WriteVideoFrame(convertedBitmap.GetSource());
                convertedBitmap.DisposeSource();
            }
            probeBitmap.UnlockBits();
            writer.Flush();
        }