Ejemplo n.º 1
0
        /// <summary>
        /// This method reads the video Data/headers from the file and creates a buffer.
        /// The buffer is added to the '_videoMemoryStreams' Dictionary so it can be used at one of the FFmpeg callback methods.
        /// </summary>
        /// <param name="dataPacket">Contains the frame Data.</param>
        /// <param name="headerPacket">Contains the header Data, when null, dataPacket is used as headersource.</param>
        /// <returns></returns>
        private bool PacketDataToBuffer(IResultNode dataPacket, IResultNode headerPacket)
        {
            // Find current codec detector in packet
            ICodecDetector codecDetector = (ICodecDetector)dataPacket.Detectors.Where(d => d is ICodecDetector).FirstOrDefault();

            if (codecDetector == null)
            {
                return(false);
            }

            // Resolve frame header info
            IDataPacket videoHeaders = codecDetector.GetVideoHeaders(headerPacket);
            IDataPacket videoData    = codecDetector.GetVideoData(dataPacket);

            if (videoData == null)
            {
                return(false);
            }

            // Copy all the Data, both header- and framedata, to a buffer.
            byte[] dataBuf = ReadDataPacket(videoData);
            if (IsH264NalUnitResult(dataPacket))
            {
                // Automatically convert H.264 'NAL unit stream' to 'byte stream', because FFmpeg
                // does not support the 'NAL unit stream' format.
                dataBuf = ConvertH264NalUnitStreamVideoDataToByteStream(dataBuf);
            }
            if (videoHeaders != null)
            {
                byte[] headerData = ReadDataPacket(videoHeaders);
                if (IsH264NalUnitResult(headerPacket))
                {
                    // Automatically convert H.264 'NAL unit stream' to 'byte stream', because FFmpeg
                    // does not support the 'NAL unit stream' format.
                    headerData = ConvertH264NalUnitStreamHeaderDataToByteStream(headerData);
                }

                dataBuf = headerData.Concat(dataBuf).ToArray();
            }

            // Put the Data in a memory stream, used by FFmpeg to read the 'file' from memory.
            lock (_videoMemoryStreams)
            {
                _convertId = _nextConvertId;
                _nextConvertId++;

                _videoMemoryStreams.Add(_convertId, new MemoryStream(dataBuf));
            }
            return(true);
        }
Ejemplo n.º 2
0
 private void AddKeyFramesToList(IResultNode node, KeyFrameList keyFrames)
 {
     if (node.IsKeyframe())
     {
         ICodecDetector detector = node.Detectors.Where(d => d is ICodecDetector).SingleOrDefault() as ICodecDetector;
         keyFrames.Add(new KeyFrame(BuildRangeList(detector.GetVideoHeaders(node)), BuildRangeList(detector.GetVideoData(node))));
     }
     else
     {
         foreach (var childNode in node.Children)
         {
             AddKeyFramesToList(childNode, keyFrames);
         }
     }
 }
 public IDataPacket GetVideoData(IResultNode resultNode)
 {
     return(_codecDetector.GetVideoData(resultNode));
 }