private unsafe void DecodeAllFramesToImages() { using (var vsd = new VideoStreamDecoder(device)) { //Console.WriteLine($"codec name: {vsd.CodecName}"); var info = vsd.GetContextInfo(); info.ToList().ForEach(x => Console.WriteLine($"{x.Key} = {x.Value}")); var sourceSize = vsd.FrameSize; var sourcePixelFormat = vsd.PixelFormat; var destinationSize = sourceSize; var destinationPixelFormat = AVPixelFormat.AV_PIX_FMT_BGR24; using (var vfc = new VideoFrameConverter(sourceSize, sourcePixelFormat, destinationSize, destinationPixelFormat)) { var frameNumber = 0; while (vsd.TryDecodeNextFrame(out var frame) && activeThread) { var convertedFrame = vfc.Convert(frame); Bitmap bitmap; bitmap = new Bitmap(convertedFrame.width, convertedFrame.height, convertedFrame.linesize[0], System.Drawing.Imaging.PixelFormat.Format24bppRgb, (IntPtr)convertedFrame.data[0]); BitmapToImageSource(bitmap); frameNumber++; } } } }
private static IReadOnlyDictionary <string, string> GetDecoderInfo(VideoStreamDecoder vsd) { _EnsureBinariesAreSet(); var info = vsd.GetContextInfo(); var dict = new Dictionary <string, string>(); dict["CodecName"] = vsd.CodecName; foreach (var kvp in info) { dict[kvp.Key] = kvp.Value; } return(dict); }
private Texture2D DecodeFrameToTexture2D(String filename, int frameIndex = 10, AVHWDeviceType HWDevice = AVHWDeviceType.AV_HWDEVICE_TYPE_NONE) { using (var vsd = new VideoStreamDecoder(filename, HWDevice)) { Debug.Log($"codec name: {vsd.CodecName}"); var info = vsd.GetContextInfo(); info.ToList().ForEach(x => Debug.Log($"{x.Key} = {x.Value}")); var sourceSize = vsd.FrameSize; var sourcePixelFormat = HWDevice == AVHWDeviceType.AV_HWDEVICE_TYPE_NONE ? vsd.PixelFormat : GetHWPixelFormat(HWDevice); var destinationSize = sourceSize; var destinationPixelFormat = AVPixelFormat.AV_PIX_FMT_BGR24; using (var vfc = new VideoFrameConverter(sourceSize, sourcePixelFormat, destinationSize, destinationPixelFormat)) { var currentFrame = 0; while (vsd.TryDecodeNextFrame(out var frame) && _isRunning) { Debug.Log($"Processing frame: {currentFrame}"); var avframe = vfc.Convert(frame); if (OnFrameRendered != null) { byte[] imageData; vsd.AvFrameToImageByteArray(avframe, out imageData); OnFrameRendered(imageData); } if (currentFrame == frameIndex) { Debug.Log($"Saving frame: {frameIndex}"); return(vsd.AVFrameToTexture2D(avframe)); } currentFrame++; } return(new Texture2D(4, 4)); } } }
private unsafe void DecodeAllFramesToImages(object state) { try { using (var decoder = new VideoStreamDecoder(url, videoInputType)) { videoInfo = decoder.GetVideoInfo(); var info = decoder.GetContextInfo(); info.ToList().ForEach(x => Console.WriteLine($"{x.Key} = {x.Value}")); var sourceSize = decoder.FrameSize; var sourcePixelFormat = hwDeviceType == AVHWDeviceType.AV_HWDEVICE_TYPE_NONE ? decoder.PixelFormat : GetHWPixelFormat(hwDeviceType); var destinationSize = sourceSize; var destinationPixelFormat = AVPixelFormat.AV_PIX_FMT_BGR24; using (var vfc = new VideoFrameConverter(sourceSize, sourcePixelFormat, destinationSize, destinationPixelFormat)) { while (decoder.TryDecodeNextFrame(out var frame) && isDecodingEvent.WaitOne()) { var convertedFrame = vfc.Convert(frame); Bitmap bt = new Bitmap(convertedFrame.width, convertedFrame.height, convertedFrame.linesize[0], System.Drawing.Imaging.PixelFormat.Format24bppRgb, (IntPtr)convertedFrame.data[0]); if (isEncodingThreadRunning) { decodedFrameQueue.Enqueue(convertedFrame); } BitmapToImageSource(bt); } } } } catch (ApplicationException e) { Console.WriteLine(e.Message); } catch (ObjectDisposedException e) { Console.WriteLine(e.Message); } }
private unsafe void DecodeAllFramesToImages(string url) { using (VideoStreamDecoder vsd = new VideoStreamDecoder(url)) { IReadOnlyDictionary <string, string> info = vsd.GetContextInfo(); System.Drawing.Size sourceSize = vsd.FrameSize; AVPixelFormat sourcePixelFormat = vsd.PixelFormat; Size destinationSize = sourceSize; AVPixelFormat destinationPixelFormat = AVPixelFormat.AV_PIX_FMT_BGR24; using (VideoFrameConverter vfc = new VideoFrameConverter(sourceSize, sourcePixelFormat, destinationSize, destinationPixelFormat)) { AVFrame frame = default(AVFrame); vsd.TryDecodeNextFrame(out frame); AVFrame convertedFrame = vfc.Convert(frame); using (Bitmap bitmap = new Bitmap(convertedFrame.width, convertedFrame.height, convertedFrame.linesize[0u], PixelFormat.Format24bppRgb, (IntPtr)(void *)convertedFrame.data[0u])) { this.Image = Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions()); } } } }
private unsafe void DecodeAllFramesToImages() { _filepath = "test.mxf"; String filepath = ""; if (!String.IsNullOrEmpty(_filepath)) { filepath = _filepath; } else { return; } using (var vsd = new VideoStreamDecoder(filepath)) { var info = vsd.GetContextInfo(); info.ToList().ForEach(x => Console.WriteLine($"{x.Key} = {x.Value}")); var sourceSize = vsd.FrameSize; var sourcePixelFormat = vsd.PixelFormat; var destnationSize = sourceSize; var destinationPixelFormat = AVPixelFormat.AV_PIX_FMT_BGR24; using (var vfc = new VideoFrameConveter(sourceSize, sourcePixelFormat, destnationSize, destinationPixelFormat)) { var frameNumber = 0; while (vsd.TryDecodeNextFrame(out var frame) && activeThread) { var convertedFrame = vfc.Convert(frame); Bitmap bitmap; bitmap = new Bitmap(convertedFrame.width, convertedFrame.height, convertedFrame.linesize[0], System.Drawing.Imaging.PixelFormat.Format24bppRgb, (IntPtr)convertedFrame.data[0]); frameNumber++; } } } }
private unsafe void DecodeAllFramesToImages() { //video="웹캠 디바이스 이름" //string url = "video=AVerMedia GC550 Video Capture"; //sample rtsp source //string url = "rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov"; using (var vsd = new VideoStreamDecoder(url, type)) { var info = vsd.GetContextInfo(); enCodecInfo = vsd.GetCodecInfo(); info.ToList().ForEach(x => Console.WriteLine($"{x.Key} = {x.Value}")); sourceSize = vsd.FrameSize; destinationSize = sourceSize; var sourcePixelFormat = vsd.PixelFormat; var destinationPixelFormat = AVPixelFormat.AV_PIX_FMT_BGR24; using (var vfc = new VideoFrameConverter(sourceSize, sourcePixelFormat, destinationSize, destinationPixelFormat)) { while (vsd.TryDecodeNextFrame(out var frame) && activeThread) { var convertedFrame = vfc.Convert(frame); Bitmap bitmap = new Bitmap(convertedFrame.width, convertedFrame.height, convertedFrame.linesize[0], System.Drawing.Imaging.PixelFormat.Format24bppRgb, (IntPtr)convertedFrame.data[0]); if (activeEncodingThread) { decodedFrameQueue.Enqueue(convertedFrame); } //display video image BitmapToImageSource(bitmap); } } } }