/// <summary> /// Initializes static members of the <see cref="Utilities"/> class. /// Initializes the <see cref="Utilities"/> class. /// </summary> static Utilities() { H264Frames = new ConcurrentDictionary <int, List <H264Frame> >(); foreach (var videoFormatEntry in Service.Instance.Configuration.H264FileLocations) { var videoFormat = videoFormatEntry.Value; var fileReader = new H264FileReader( videoFormatEntry.Key, (uint)videoFormat.Width, (uint)videoFormat.Height, videoFormat.FrameRate); var listOfFrames = new List <H264Frame>(); var totalNumberOfFrames = fileReader.GetTotalNumberOfFrames(); Trace.TraceInformation($"Found the fileReader for the format with id: {videoFormat.GetId()} and number of frames {totalNumberOfFrames}"); for (int i = 0; i < totalNumberOfFrames; i++) { H264Frame frame = new H264Frame(); fileReader.GetNextFrame(frame); listOfFrames.Add(frame); } H264Frames.TryAdd(videoFormat.GetId(), listOfFrames); } }
/// <summary> /// Initializes static members of the <see cref="Utilities"/> class. /// Initializes the <see cref="Utilities"/> class. /// </summary> static Utilities() { H264Frames = new ConcurrentDictionary <int, List <H264Frame> >(); IDictionary <string, VideoFormat> H264FileLocations = new Dictionary <string, VideoFormat>(); H264FileLocations = new Dictionary <string, VideoFormat>(); H264FileLocations.Add("output720p.264", VideoFormat.H264_1280x720_30Fps); H264FileLocations.Add("output180p.264", VideoFormat.H264_320x180_15Fps); H264FileLocations.Add("output360p.264", VideoFormat.H264_640x360_30Fps); H264FileLocations.Add("mle1080p15vbss_2500Kbps.264", VideoFormat.H264_1920x1080_15Fps); foreach (var videoFormatEntry in H264FileLocations) { var videoFormat = videoFormatEntry.Value; var fileReader = new H264FileReader( videoFormatEntry.Key, (uint)videoFormat.Width, (uint)videoFormat.Height, videoFormat.FrameRate); var listOfFrames = new List <H264Frame>(); var totalNumberOfFrames = fileReader.GetTotalNumberOfFrames(); Trace.TraceInformation($"Found the fileReader for the format with id: {videoFormat.GetId()} and number of frames {totalNumberOfFrames}"); for (int i = 0; i < totalNumberOfFrames; i++) { H264Frame frame = new H264Frame(); fileReader.GetNextFrame(frame); listOfFrames.Add(frame); } H264Frames.TryAdd(videoFormat.GetId(), listOfFrames); } }
public override Thread DecodingThread() { // Dequeue decoded frames return(new Thread(() => { while (true) { // Dequeue decoded Frames int ret = DequeueDecodedFrame(out byte[][] yuvData, out int[] lineSizes); if (ret == 0) { FrameDecoded?.Invoke(new YUVFrame(yuvData, lineSizes)); } // Enqueue encoded packet H264Frame frame = null; try { if (encodedDataQueue.Count > 0) { frame = encodedDataQueue.Dequeue(); if (frame != null) { EnqueuePacketForDecoding(frame.RawData); } } } catch (InvalidOperationException e) { Debug.WriteLine($"FFmpegVideo Loop: {e}"); } } })); }
public void FeedVideoData(H264Frame data) { if (Initialized) { _videoQueue.PushFront(data.RawData); } else if (data.ContainsIFrame) { Initialize(); _videoQueue.PushFront(data.RawData); } }
public void ConsumeVideoData(Packets.VideoData data) { H264Frame frame = _videoAssembler.AssembleVideoFrame(data); if (frame != null) { /* TODO: Use this.. on main thread * if (_videoCodec == null && * (frame.PrimaryType == NalUnitType.SEQUENCE_PARAMETER_SET || * frame.PrimaryType == NalUnitType.PICTURE_PARAMETER_SET)) * { * SetupVideo((int)_videoFormat.Width, * (int)_videoFormat.Height, * frame.GetSpsDataPrefixed(), * frame.GetPpsDataPrefixed()); * } * if (_videoCodec != null) * { * _videoFrameQueue.Enqueue(frame); * } */ _videoFrameQueue.Enqueue(frame); } }
public void PushData(H264Frame data) => encodedDataQueue.Enqueue(data);