Пример #1
0
        Thread threadPlay;          // Simulates FPS

        private void Form1_Load(object sender, EventArgs e)
        {
            ffmpeg  = new FFmpeg();
            directX = new DirectX(this.Handle); // Parses SampleUI 's Handle for output
            if (!ffmpeg.InitHWAccel(directX._device))
            {
                MessageBox.Show("Failed to Initialize FFmpeg's HW Acceleration"); return;
            }
            if (!ffmpeg.Open(fileToPlay))
            {
                MessageBox.Show("FFmpeg failed to open input"); return;
            }

            threadPlay = new Thread(() =>
            {
                while (true)
                {
                    // FFmpeg HW Decode Frame
                    Texture2D textureHW = ffmpeg.GetFrame();
                    if (textureHW == null)
                    {
                        Console.WriteLine("Empty Texture!"); continue;
                    }

                    // DirectX HW Process & Present Frame
                    directX.PresentFrame(textureHW);

                    Thread.Sleep(41); // Simulates FPS
                }
            });

            threadPlay.SetApartmentState(ApartmentState.STA);
            threadPlay.Start();
        }
Пример #2
0
        Thread threadPlay;          // Fake Play Thread with Sleep

        private void Form1_Load(object sender, EventArgs e)
        {
            ffmpeg  = new FFmpeg(1);
            directX = new DirectX(this.Handle); // Parses SampleUI 's Handle for output

            if (!ffmpeg.Open(fileToPlay))
            {
                MessageBox.Show("Decoder failed to open input"); return;
            }
            if (!ffmpeg.hwAccelStatus)
            {
                MessageBox.Show("FFmpeg failed to initialize D3D11VA device"); return;
            }

            /* FFmpeg  Decode  Frame
             * DirectX Process & Present Frame
             */
            threadPlay = new Thread(() =>
            {
                while (true)
                {
                    // FFmpeg  Decode  Frame
                    IntPtr curFrame = ffmpeg.GetFrame();
                    if (curFrame == IntPtr.Zero && !ffmpeg.hwAccelStatus)
                    {
                        MessageBox.Show("Pixel Format not supported by GPU"); return;
                    }
                    if (curFrame == IntPtr.Zero)
                    {
                        continue;
                    }

                    //DirectX Process & Present Frame
                    directX.PresentFrame(curFrame);

                    // Fake Play Thread with Sleep
                    Thread.Sleep(30);
                }
            });

            threadPlay.SetApartmentState(ApartmentState.STA);
            threadPlay.Start();
        }