Esempio n. 1
0
        private void SaveCurrentBitmapToFile(string filePath, ImageFormat format, bool createForensicIntegrityLog)
        {
            if (_ffmpegResult != null && _ffmpegResult.SourcePacket != null && _ffmpegResult.Bitmap != null)
            {
                _ffmpegResult.Bitmap.Save(filePath, format);

                if (createForensicIntegrityLog)
                {
                    if (_ffmpegResult.SourcePacket != null)
                    {
                        IResultNode    headerSourceResult = _ffmpegResult.HeaderSource ?? _ffmpegResult.SourcePacket;
                        ICodecDetector codecDetector      = headerSourceResult.Detectors.FirstOrDefault() as ICodecDetector;
                        if (codecDetector == null)
                        {
                            return;
                        }
                        // FIXME: The detectors of the video headers cannot be determined (for forensic logging purposes)!!
                        IDataPacket usedBitmapHeaders = codecDetector.GetVideoHeaders(headerSourceResult);

                        string logFileName = string.Format("{0}.csv", filePath);
                        using (FileStream fs = new FileStream(logFileName, FileMode.Create, FileAccess.Write, FileShare.Read))
                        {
                            IDataPacket allUsedBitmapNodes = _ffmpegResult.SourcePacket;
                            // Prefix with bitmap headers (if any)
                            if (usedBitmapHeaders != null)
                            {
                                allUsedBitmapNodes = usedBitmapHeaders.Append(allUsedBitmapNodes);
                            }
                            // Append child nodes and determine detectors that were used
                            var detectors = new HashSet <IDetector>(_ffmpegResult.SourcePacket.Detectors);
                            foreach (var dataPacket in _ffmpegResult.SourcePacket.Children)
                            {
                                allUsedBitmapNodes = allUsedBitmapNodes.Append(dataPacket);
                                foreach (IDetector detector in dataPacket.Detectors)
                                {
                                    detectors.Add(detector);
                                }
                            }
                            _forensicIntegrityLog.Log(allUsedBitmapNodes, detectors, filePath, fs, ForensicLogType.ConvertedData);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Can't save integrity log. There is no packetdata available for the active bitmap.", "Save Integrity Log", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            else
            {
                MessageBox.Show("There is no frame opened, can't save empty frame to image.", "Save Image", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Esempio n. 2
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);
        }
Esempio n. 3
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 GetVideoHeaders(IResultNode headerPacket)
 {
     return(_codecDetector.GetVideoHeaders(headerPacket));
 }