예제 #1
0
        public bool playFile(string filename)
        {
            //using (Stream fin = File.OpenRead(filename))
            using (Stream fin = new MemoryStream(File.ReadAllBytes(filename)))
                using (FrameDecoder FrameDecoder = new FrameDecoder(fin))
                {
                    try
                    {
                        while (true)
                        {
                            var picture = FrameDecoder.DecodeFrame();

                            var Width  = picture.imageWidthWOEdge;
                            var Height = picture.imageHeightWOEdge;

                            if (this.frame.ClientSize.Width < Width || this.frame.ClientSize.Height < Height)
                            {
                                this.frame.Invoke((Action)(() =>
                                {
                                    this.frame.ClientSize = new Size(Width, Height);
                                    CenterForm(this.frame);
                                }));
                            }
                            this.frame.CreateGraphics().DrawImage(FrameUtils.imageFromFrameWithoutEdges(picture, Width, Height), Point.Empty);
                        }
                    }
                    catch (EndOfStreamException)
                    {
                    }
                }

            Console.WriteLine("Stop playing video.");

            return(true);
        }
예제 #2
0
        public void AvcDecode(SceMpegAu *MpegAccessUnit, int FrameWidth, GuPixelFormats GuPixelFormat,
                              PspPointer OutputBuffer)
        {
            if (MpegAccessUnit != null)
            {
                *MpegAccessUnit = GetAvcAu(StreamId.Avc);
            }

            while (MpegPsDemuxer.HasMorePackets)
            {
                if (!DecodePsPacket())
                {
                    return;
                }
            }

            if (VideoStream.Length <= 0)
            {
                return;
            }

            // Buffer 1MB
            //if (VideoStream.Length <= 1 * 1024 * 1024) return;

            try
            {
                //if (H264FrameDecoder.HasMorePackets)
                {
                    //Console.WriteLine("VideoStream.Length: {0}", VideoStream.Length);
                    var Frame = H264FrameDecoder.DecodeFrame();

                    ConsoleUtils.SaveRestoreConsoleColor(ConsoleColor.DarkGreen,
                                                         () => { Console.WriteLine("DecodedFrame: {0}", FrameIndex); });

                    var Bitmap = FrameUtils.imageFromFrameWithoutEdges(Frame, FrameWidth, 272);

                    var TempBuffer =
                        new byte[PixelFormatDecoder.GetPixelsSize(GuPixelFormat, Bitmap.Width * Bitmap.Height)];
                    fixed(byte *TempBufferPtr = TempBuffer)
                    {
                        var TempBufferPtr2 = TempBufferPtr;

                        Bitmap.LockBitsUnlock(PixelFormat.Format32bppArgb, (BitmapData) =>
                        {
                            var InputBuffer = (OutputPixel *)BitmapData.Scan0.ToPointer();
                            int Count       = Bitmap.Width * Bitmap.Height;

                            for (int n = 0; n < Count; n++)
                            {
                                var Color        = InputBuffer[n];
                                InputBuffer[n].R = Color.B;
                                InputBuffer[n].G = Color.G;
                                InputBuffer[n].B = Color.R;
                                InputBuffer[n].A = 0xFF;
                            }

                            PixelFormatDecoder.Encode(GuPixelFormat, InputBuffer, TempBufferPtr2,
                                                      Bitmap.Width * Bitmap.Height);
                            PixelFormatDecoder.Encode(PspDisplay.CurrentInfo.PixelFormat, InputBuffer,
                                                      (byte *)Memory.PspAddressToPointerSafe(PspDisplay.CurrentInfo.FrameAddress), 512,
                                                      Bitmap.Width, Bitmap.Height);
                            PspDisplay.CurrentInfo.PlayingVideo = true;
                        });
                        PspDisplay.CurrentInfo.PlayingVideo = true;
                        Memory.WriteBytes(OutputBuffer.Address, TempBufferPtr, TempBuffer.Length);
                        GpuImpl.InvalidateCache(OutputBuffer.Address, TempBuffer.Length);
                    }

                    if (SaveBitmapFrame)
                    {
                        Bitmap.Save(@"c:\temp\frame" + (FrameIndex) + ".png");
                    }
                    FrameIndex++;
                }
                //PixelFormat

                return;
            }
            catch (EndOfStreamException)
            {
                ConsoleUtils.SaveRestoreConsoleColor(ConsoleColor.Red,
                                                     () => { Console.WriteLine("H264FrameDecoder.DecodeFrame: EndOfStreamException"); });
            }
        }