• 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);

  • 相关阅读:
    [PoC]某B2B网站的一个反射型XSS漏洞
    Python中的基本语句
    视频: 千重浪Linux系统调试技术培训 03-01_Basic-CPU-Register
    POJ 2955 Brackets (区间dp 括号匹配)
    LeetCode 146 LRU Cache
    Poj1734题解
    Python
    小胖说事29-----iOS中Navigation中左滑pop页面的三种方法
    深入理解javascript之原型
    android 弹幕评论效果
  • 原文地址:https://www.cnblogs.com/jhlong/p/5433859.html
Copyright © 2020-2023  润新知