TheRain
User
 Fresh Boarder
| Posts: 3 |   |
|
Can you help me with AvDn C# and mpeg encoding? - 2007/08/17 16:29
Hey Daniel,
I'm trying to encode 24-bit RBG frames, frame by frame into MPEG, but I'm getting an memory access violation and can't figure out why. Can you take a look at my code and see if you can find the reason? The RGB data being passed to the AvFrame here is valid 24-bit RGB data. I've checked it and even checked that valid 24-bit RGB data is being filled in to the AvFrame structure by accessing the memory at avframe.GetData0();
It is the last line, the EncodeVideo line that is causing the exception. "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
Almost forgot to mention. It's opening an MPEG-1 file to set the codec... which I'm sure is not the best way, but it seemed like it should work.
Here is my code
| Code: | AvDn.AvDnFrame avFrame = new AvDnFrame();
AvDnCodec avCodec;
AvDnCodecContext avCodecContext;
IntPtr output = Marshal.AllocHGlobal(200000);
AvDn.AvDnUtils.RegisterAll();
AvDnFormatContext avfmnt = new AvDnFormatContext("sample.mpg");
avfmnt.FindStreamInfo();
avCodecContext = avfmnt.GetCodecContextForStream(0);
avCodecContext.BitRate = 400000;
avCodecContext.PixFmt = Av.PIX_FMT_RGB24;
avCodecContext.Width = 320;
avCodecContext.Height = 240;
avCodecContext.SetTimeBase(1, 25);
avCodecContext.GopSize = 15;
avCodecContext.MbDecision = 2;
avCodecContext.OpenEncoder();
avFrame.FillPicStruct(RAWRGB.Scan0, Av.PIX_FMT_RGB24, 320, 240);
int size = avCodecContext.EncodeVideo(output, 200000, avFrame);
// Here's where it breaks
|
Any advice you can give would be greatly appreciated.
|