Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new Flash screen video.
        /// </summary>
        /// <param name="parameters">The video parameters.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="parameters"/> is null.</exception>
        public FlashScreenVideo(FlashScreenVideoParameters parameters)
            : base(parameters)
        {
            width                  = parameters.Width;
            height                 = parameters.Height;
            framesPerSecond        = parameters.FramesPerSecond;
            nominalBlockWidth      = parameters.BlockWidth;
            nominalBlockHeight     = parameters.BlockHeight;
            keyFramePeriodInFrames = Math.Max(1, (int)Math.Ceiling(parameters.KeyFramePeriod.TotalSeconds * framesPerSecond));

            cols = (width + nominalBlockWidth - 1) / nominalBlockWidth;
            rows = (height + nominalBlockHeight - 1) / nominalBlockHeight;

            int framePixelsLength = width * height;

            deflater             = new Deflater(parameters.CompressionLevel, false);
            reserveBytesPerFrame = (nominalBlockHeight * nominalBlockWidth * 3 + 2 /*block header size*/ + ZLibWorstCaseInflation) * rows * cols + 4 /*frame header size*/;

            previousFramePixels = new int[framePixelsLength];
            currentFramePixels  = new int[framePixelsLength];
            blockBuffer         = new byte[nominalBlockHeight * nominalBlockWidth * 3];

            flvWriter = new FlvWriter(FlvWriter.FlvFlags.Video);
            var flvMetadata = new FlvWriter.FlvMetadata()
            {
                { "duration", 0.0 },
                { "width", width },
                { "height", height },
                { "framerate", framesPerSecond },
                { "videocodecid", 3 /*screen video*/ },
                { "canSeekToEnd", true }
            };

            flvMetadataUpdater = flvWriter.WriteFlvMetaFrame(flvMetadata, 0);
        }
Ejemplo n.º 2
0
            internal FlvMetadataUpdater WriteTo(FlvWriter writer)
            {
                var offsets = new Dictionary <string, int>();

                writer.WriteAmfData("onMetaData");
                writer.WriteAmfArrayBeginMarker(contents.Count);
                foreach (var pair in contents)
                {
                    writer.WriteAmfStringContent(pair.Key);
                    offsets.Add(pair.Key, writer.bufferOffset);
                    writer.WriteAmfData(pair.Value);
                }
                writer.WriteAmfArrayEndMarker();

                return(new FlvMetadataUpdater(writer, offsets));
            }
Ejemplo n.º 3
0
 internal FlvMetadataUpdater(FlvWriter writer, Dictionary <string, int> offsets)
 {
     this.writer  = writer;
     this.offsets = offsets;
 }