Beispiel #1
0
        //private static void NewMethod1()
        //{

        //    var flags = DeviceCreationFlags.VideoSupport |
        //    DeviceCreationFlags.BgraSupport |
        //    DeviceCreationFlags.Debug;

        //    var device = new SharpDX.Direct3D11.Device(SharpDX.Direct3D.DriverType.Hardware, flags);
        //    using (var multiThread = device.QueryInterface<SharpDX.Direct3D11.Multithread>())
        //    {
        //        multiThread.SetMultithreadProtected(true);
        //    }


        //    System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(@"D:\Temp\4.bmp");
        //    Texture2D rgbTexture = DxTool.GetTexture(bmp, device);

        //    var bufTexture = new Texture2D(device,
        //        new Texture2DDescription
        //        {
        //                        // Format = Format.NV12,
        //            Format = SharpDX.DXGI.Format.B8G8R8A8_UNorm,
        //            Width = 1920,
        //            Height = 1080,
        //            MipLevels = 1,
        //            ArraySize = 1,
        //            SampleDescription = { Count = 1 },
        //        });

        //    device.ImmediateContext.CopyResource(rgbTexture, bufTexture);

        //    var processor = new MfVideoProcessor(null);
        //    var inProcArgs = new MfVideoArgs
        //    {
        //        Width = 1920,
        //        Height = 1080,
        //        Format = SharpDX.MediaFoundation.VideoFormatGuids.Argb32,
        //    };

        //    var outProcArgs = new MfVideoArgs
        //    {
        //        Width = 1920,
        //        Height = 1080,
        //        Format = SharpDX.MediaFoundation.VideoFormatGuids.NV12,//.Argb32,
        //    };

        //    processor.Setup(inProcArgs, outProcArgs);
        //    processor.Start();


        //    var msEncoder = new MfH264EncoderMS();

        //    var encArgs = new MfVideoArgs
        //    {
        //        Width = 1920,
        //        Height = 1080,
        //        FrameRate = 30,
        //        Format = SharpDX.MediaFoundation.VideoFormatGuids.NV12,

        //    };

        //    msEncoder.Setup(encArgs);

        //    msEncoder.Start();

        //    var rgbSample = MediaFactory.CreateVideoSampleFromSurface(null);

        //    // Create the media buffer from the texture
        //    MediaFactory.CreateDXGISurfaceBuffer(typeof(Texture2D).GUID, bufTexture, 0, false, out var mediaBuffer);

        //    using (var buffer2D = mediaBuffer.QueryInterface<Buffer2D>())
        //    {
        //        mediaBuffer.CurrentLength = buffer2D.ContiguousLength;
        //    }

        //    rgbSample.AddBuffer(mediaBuffer);

        //    var ffEncoder = new H264Encoder();
        //    ffEncoder.Setup(new VideoEncoderSettings
        //    {
        //        Width = encArgs.Width,
        //        Height  = encArgs.Height,
        //        FrameRate = 30,
        //    });

        //    while (true)
        //    {
        //        rgbSample.SampleTime = 0;
        //        rgbSample.SampleDuration = 0;

        //       var result = processor.ProcessSample(rgbSample, out var nv12Sampel);

        //        if (result)
        //        {
        //            using (var buffer = nv12Sampel.ConvertToContiguousBuffer())
        //            {
        //                var ptr = buffer.Lock(out var maxLen, out var curLen);
        //                ffEncoder.Encode(ptr, curLen, 0);

        //                buffer.Unlock();
        //            }


        //            //result = msEncoder.ProcessSample(nv12Sampel, out var outputSample);

        //            //if (result)
        //            //{

        //            //}

        //        }

        //        nv12Sampel?.Dispose();

        //        Thread.Sleep(300);
        //    }



        //    //Console.ReadKey();
        //    //Console.WriteLine("-------------------------------");
        //    //return;
        //}

        private static void NewMethod()
        {
            Guid CColorConvertDMO  = new Guid("98230571-0087-4204-b020-3282538e57d3");
            Guid VideoProcessorMFT = new Guid("88753B26-5B24-49BD-B2E7-0C445C78C982");


            Guid NVidiaH264EncoderMFT   = new Guid("60F44560-5A20-4857-BFEF-D29773CB8040");
            Guid IntelQSVH264EncoderMFT = new Guid("4BE8D3C0-0515-4A37-AD55-E4BAE19AF471");

            //ArrayList inputTypes = new ArrayList();
            //ArrayList outputTypes = new ArrayList();

            //MFInt inputTypesNum = new MFInt();
            //MFInt outputTypesNum = new MFInt();
            //IntPtr ip = IntPtr.Zero;

            var result = MfApi.MFTGetInfo(CColorConvertDMO, out string pszName,
                                          out IntPtr ppInputTypes, out uint inputTypesNum,
                                          out IntPtr ppOutputTypes, out uint outputTypesNum,
                                          out IntPtr ppAttributes);

            if (result == MediaToolkit.NativeAPIs.HResult.S_OK)
            {
                MediaAttributes mediaAttributes = new MediaAttributes(ppAttributes);
                Console.WriteLine(MfTool.LogMediaAttributes(mediaAttributes));

                Console.WriteLine("InputTypes-------------------------------------");
                MarshalHelper.PtrToArray(ppInputTypes, (int)inputTypesNum, out MFTRegisterTypeInfo[] inputTypes);

                foreach (var type in inputTypes)
                {
                    var majorType = type.guidMajorType;
                    var subType   = type.guidSubtype;

                    //Console.WriteLine(MfTool.GetMediaTypeName(majorType));

                    Console.WriteLine(MfTool.GetMediaTypeName(subType));
                }

                Console.WriteLine("");

                Console.WriteLine("OutputTypes-------------------------------------");
                MarshalHelper.PtrToArray(ppOutputTypes, (int)outputTypesNum, out MFTRegisterTypeInfo[] outputTypes);


                foreach (var type in outputTypes)
                {
                    var majorType = type.guidMajorType;
                    var subType   = type.guidSubtype;

                    //Console.WriteLine(MfTool.GetMediaTypeName(majorType));

                    Console.WriteLine(MfTool.GetMediaTypeName(subType));
                }
            }
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
            return;
        }