zoukankan      html  css  js  c++  java
  • 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);

  • 相关阅读:
    在Myeclipse中移除项目对Hibernate的支持
    使用MyEclipse可视化开发Hibernate实例
    利用MyEclipse自动创建PO类、hbm文件(映射文件)、DAO
    Mtk Camera
    Linux问题,磁盘分区打不开了
    Android SDK在线更新镜像服务器大全
    TeamTalk——ubuntu服务端部署
    Nginx
    VCC/AVCC/VDD/AVDD区别
    android studio and sdk mirror for China
  • 原文地址:https://www.cnblogs.com/jhlong/p/5433859.html
Copyright © 2011-2022 走看看