示例#1
0
        /// <summary>
        /// Discards all packet data buffered by this instance.
        /// </summary>
        public void DiscardBufferedData()
        {
            foreach (var packet in BufferedPackets)
            {
                packet.Wipe();
                packet.Dispose();
            }

            BufferedPackets.Clear();
        }
        /// <summary>
        /// Writes the specified frame to this stream.
        /// </summary>
        /// <param name="frame">The media frame.</param>
        public void Push(TFrame frame)
        {
            ffmpeg.avcodec_send_frame(CodecPointer, frame.Pointer)
            .ThrowIfError("Cannot send a frame to the encoder.");

            if (ffmpeg.avcodec_receive_packet(CodecPointer, packet) == 0)
            {
                packet.RescaleTimestamp(CodecPointer->time_base, TimeBase);

                if (CodecPointer->coded_frame->key_frame == 1)
                {
                    packet.IsKeyPacket = true;
                }

                OwnerFile.WritePacket(packet);
            }

            packet.Wipe();
        }
示例#3
0
        /// <summary>
        /// Reads the next packet from the specified stream.
        /// </summary>
        /// <param name="streamIndex">Index of the stream.</param>
        /// <returns>The read packet as <see cref="MediaPacket"/> object.</returns>
        public MediaPacket ReadNextPacket(int streamIndex)
        {
            if (canReusePacket)
            {
                canReusePacket = false;
                if (packet.StreamIndex != streamIndex)
                {
                    packet.Wipe();
                }
                else
                {
                    return(packet);
                }
            }

            GetPacketFromStream(streamIndex);

            return(packet);
        }