视频图像处理系列索引 || Arcgis/Engine/Server开发索引 || Web Map Gis开发索引 || jquery表格组件 JQGrid索引
WPF MVVM模式开发实现简明教程索引 || ArcGIS Runtime WPF(.net C#)开发简明教程索引

SDL 显示解码后的yuv12数据

在上篇h264解码为yuv12后http://jhlong12345.blog.163.com/blog/static/1230631292015725115058709/

,需要显示出来,使用sdl比较方便,网上没C#的例子,全是C++的,

SDL_LockYUVOverlay(overlay);

    memcpy(overlay->pixels[0], y_video_data, w * h);

    memcpy(overlay->pixels[1], u_video_data, w * h / 4);

    memcpy(overlay->pixels[2], v_video_data, w * h / 4);

 

    SDL_UnlockYUVOverlay(overlay);

 

 

这里贴出来研究很久才做出来的C#代码

 

if (H264Dec.Hi264DecAU(_decHandle, pH264Data, frameLen, 0, ref _decodeFrame, 0) == 0)

            {

                IntPtr[] ips = new IntPtr[3] { _decodeFrame.pY, _decodeFrame.pV,_decodeFrame.pU }; //U(Cb)分量 V(Cr)分量

                object obj = Marshal.PtrToStructure(yuv, typeof(Sdl.SDL_Overlay)); //在I420格式中,U平面紧跟在Y平面之后,然后才是V平面(即:YUV);但YV12则是相反(即:YVU)

                Sdl.SDL_Overlay overlayYuv = (Sdl.SDL_Overlay)obj;

                Sdl.SDL_LockYUVOverlay(yuv);

 

                GCHandle hObject = GCHandle.Alloc(ips, GCHandleType.Pinned);

                IntPtr pObject = hObject.AddrOfPinnedObject();

                overlayYuv.pixels = pObject;

 

                Marshal.StructureToPtr(overlayYuv, yuv, true);

                Sdl.SDL_UnlockYUVOverlay(yuv);

 

                Sdl.SDL_DisplayYUVOverlay(yuv, ref rect);

                //画点文字图形啥的

                Sdl.SDL_Flip(surfacePtr);

                Sdl.SDL_UpdateRect(surfacePtr, 0, 0, rect.w, rect.h);

 

if (hObject.IsAllocated)

                    hObject.Free();

}

 

 

其中 IntPtr yuv = Sdl.SDL_CreateYUVOverlay(widthheightSdl.SDL_YV12_OVERLAYsurfacePtr);

posted @ 2016-04-26 09:50  jhlong  阅读(1341)  评论(0编辑  收藏  举报
海龙的博客 jhlong@cnblogs 版权所有© 转载请注明链接.有用请推荐一下
代码全部经过本人测试,但不保证复制粘贴就正常运行,更不保证能解决你的问题,请结合前后代码及描述理解后修改和使用