Exemplo n.º 1
0
        public VideoGridMaker(FFmpegContext context)
        {
            _context = context;

            _ioThread = new Thread(IoThread)
            {
                IsBackground = true
            };
            _ioThread.Start();

            _makeThread = new Thread(MakeThread)
            {
                IsBackground = true
            };
            _makeThread.Start();
        }
Exemplo n.º 2
0
        public bool Decode(ref H264PictureInfo pictureInfo, ISurface output, ReadOnlySpan <byte> bitstream)
        {
            Surface outSurf = (Surface)output;

            if (outSurf.RequestedWidth != _oldOutputWidth ||
                outSurf.RequestedHeight != _oldOutputHeight)
            {
                _context.Dispose();
                _context = new FFmpegContext(AVCodecID.AV_CODEC_ID_H264);

                _oldOutputWidth  = outSurf.RequestedWidth;
                _oldOutputHeight = outSurf.RequestedHeight;
            }

            Span <byte> bs = Prepend(bitstream, SpsAndPpsReconstruction.Reconstruct(ref pictureInfo, _workBuffer));

            return(_context.DecodeFrame(outSurf, bs) == 0);
        }
        /// <summary>
        /// Эта функция загружает
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        internal bool Load(FFmpegContext context)
        {
            var info           = context.GetVideoInformationExtractor();
            var durationResult = info.GetContainerDuration(_fileName);

            if (durationResult.Result != null)
            {
                return(false);
            }

            int count    = _parameters.XCount * _parameters.YCount + 1;
            var duration = durationResult.Result.Value;
            var timePart = TimeSpan.FromSeconds((duration.TotalSeconds / count));


            TimeSpan time           = TimeSpan.Zero;
            var      frameExtractor = context.GetVideoFramesExtractor();

            for (int y = 0; y < _parameters.YCount; y++)
            {
                for (int x = 0; x < _parameters.XCount; x++)
                {
                    time += timePart;
                    var         frameResult = frameExtractor.GetFrameDataForVideoFile(_fileName, time);
                    BitmapImage img         = new BitmapImage();
                    img.BeginInit();
                    img.StreamSource = new MemoryStream(frameResult.Result);
                    img.EndInit();
                    img.Freeze();
                    _times[x, y] = time;
                    _grid[x, y]  = img;
                }
            }

            return(true);
        }