public void TestEncode() { AVLog.Callback += (level, msg) => Console.WriteLine(level + ": " + msg); AVLog.Level = (int)AVLogLevel.Trace; _codecContext.Open2(AVCodec.FindDecoder(_codecContext.CodecId)); AVPacket packet; var frame = new AVFrame(); var codec = AVCodec.FindEncoderByName("png"); var encodeContext = new AVCodecContext(codec) { PixelFormat = AVPixelFormat.RGB24, Width = _codecContext.Width, Height = _codecContext.Height }; encodeContext.Open2(codec); var convContext = SWSContext.GetContext(_codecContext.Width, _codecContext.Height, AVPixelFormat.YUV420P, AVPixelFormat.RGB24); var convBuffer = new AVPicture(AVPixelFormat.RGB24, _codecContext.Width, _codecContext.Height).AsFrame(); int frameCounter = 0; int readCounter = 0; while ((packet = _formatContext.ReadFrame()) != null) { if (packet.StreamIndex != 0) { continue; } bool pic = _codecContext.DecodeVideo2(packet, frame); if (!pic) { continue; } readCounter++; convContext.Scale(frame, convBuffer, 0, _codecContext.Height); var outPacket = encodeContext.EncodeVideo2(convBuffer); if (outPacket != null) { frameCounter++; // for checking the frames, not part of normal test //var data = new byte[outPacket.Size]; //Marshal.Copy(outPacket.Data, data, 0, data.Length); //File.WriteAllBytes((frameCounter++) + ".png", data); } } Assert.AreEqual(readCounter, frameCounter); Assert.AreEqual(245, readCounter); encodeContext.Close(); _codecContext.Close(); }
public static bool Fill(AVPicture picture, SByteBuffer buffer, AutoGen.AVPixelFormat format, int width, int height) { return FFmpegInvoke.avpicture_fill(picture.NativeObj, buffer.NativeObj, format, width, height) == 0; }