天天看點

海思h264解碼庫 海思H264解碼庫 hi_h264dec_w.dll 水印問題

海思的dll,解碼h264  解碼後轉出yuv12

dll自己百度下載下傳  hi_h264dec.dll   hi_h264dec_w.dll

調用方法:

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

pH264Data是h264幀的句柄,frameLen是h264幀的長度,_decodeFrame是解碼後的yuv幀

海思H264解碼庫 hi_h264dec_w.dll 水印問題

#region 解碼器相關變量聲明
        /// <summary>
        /// 資料的句柄
        /// </summary>
        /// <summary>
        /// 這是解碼器屬性資訊
        /// </summary>
        public H264Dec.hiH264_DEC_ATTR_S decAttr;
        /// <summary>
        /// 這是解碼器輸出圖像資訊
        /// </summary>
        public H264Dec.hiH264_DEC_FRAME_S _decodeFrame = new H264Dec.hiH264_DEC_FRAME_S();
        /// <summary>
        /// 解碼器句柄
        /// </summary>
        public IntPtr _decHandle;
        static double[,] YUV2RGB_CONVERT_MATRIX = new double[3, 3] { { 1, 0, 1.4022 }, { 1, -0.3456, -0.7145 }, { 1, 1.771, 0 } };
        #endregion
 
#region 解碼器相關初始化,一般在視窗load中進行初始化
            decAttr = new H264Dec.hiH264_DEC_ATTR_S();
            decAttr.uPictureFormat = 0;
            decAttr.uStreamInType = 0;
            decAttr.uPicWidthInMB = (uint)width;
            decAttr.uPicHeightInMB = (uint)height;
            decAttr.uBufNum = 8;
            decAttr.uWorkMode = 16;
            //建立、初始化解碼器句柄
            _decHandle = H264Dec.Hi264DecCreate(ref decAttr);
            #endregion
 
using System;
using System.Runtime.InteropServices;
 
namespace Common
{
    public class H264Dec
    {
        public const int HI_SUCCESS = 0;
 
        public const int HI_FAILURE = -1;
 
        public const int HI_LITTLE_ENDIAN = 1234;
 
        public const int HI_BIG_ENDIAN = 4321;
 
        public const int HI_DECODER_SLEEP_TIME = 60000;
 
        public const int HI_H264DEC_OK = 0;
 
        public const int HI_H264DEC_NEED_MORE_BITS = -1;
 
        public const int HI_H264DEC_NO_PICTURE = -2;
 
        public const int HI_H264DEC_ERR_HANDLE = -3;
 
 
 
        [DllImport("hi_h264dec_w.dll", EntryPoint = "Hi264DecImageEnhance",CallingConvention = CallingConvention.Cdecl)]
        public static extern int Hi264DecImageEnhance(IntPtr hDec, refhiH264_DEC_FRAME_S pDecFrame, uint uEnhanceCoeff);
 
        [DllImport("hi_h264dec_w.dll", EntryPoint = "Hi264DecCreate", CallingConvention =CallingConvention.Cdecl)]
        public static extern IntPtr Hi264DecCreate(ref hiH264_DEC_ATTR_S pDecAttr);
 
        [DllImport("hi_h264dec_w.dll", EntryPoint = "Hi264DecDestroy", CallingConvention =CallingConvention.Cdecl)]
        public static extern void Hi264DecDestroy(IntPtr hDec);
 
 
        [DllImport("hi_h264dec_w.dll", EntryPoint = "Hi264DecGetInfo", CallingConvention =CallingConvention.Cdecl)]
        public static extern int Hi264DecGetInfo(ref hiH264_LIBINFO_S pLibInfo);
 
        /// <summary>
        /// 對輸入的一段碼流進行解碼并按幀輸出圖像
        /// </summary>
        /// <param name="hDec">解碼器句柄</param>
        /// <param name="pStream">碼流起始位址</param>
        /// <param name="iStreamLen">碼流長度</param>
        /// <param name="ullPTS">時間戳資訊</param>
        /// <param name="pDecFrame">圖像資訊</param>
        /// <param name="uFlags">解碼模式 0:正常解碼;1、解碼完畢并要求解碼器輸出殘留圖像</param>
        /// <returns></returns>
        [DllImport("hi_h264dec_w.dll", EntryPoint = "Hi264DecFrame", CallingConvention = CallingConvention.Cdecl)]
        public static extern int Hi264DecFrame(IntPtr hDec, IntPtr pStream, uint iStreamLen, ulong ullPTS, ref hiH264_DEC_FRAME_S pDecFrame, uint uFlags);
 
        [DllImport("hi_h264dec_w.dll", EntryPoint = "Hi264DecAU", CallingConvention =CallingConvention.Cdecl)]
        public static extern int Hi264DecAU(IntPtr hDec, IntPtr pStream, uint iStreamLen,ulong ullPTS, ref hiH264_DEC_FRAME_S pDecFrame, uint uFlags);
        /// <summary>
        /// 解碼器屬性資訊。
        /// </summary>
        [StructLayout(LayoutKind.Sequential)]
        public struct hiH264_DEC_ATTR_S
        {
            /// <summary>
            /// 解碼器輸出圖像格式,目前解碼庫隻支援YUV420圖像格式
            /// </summary>
            public uint uPictureFormat;
            /// <summary>
            /// 輸入碼流格式 0x00: 目前解碼庫隻支援以“00 00 01”為nalu分割符的流式H.264碼流 
            /// </summary>
            public uint uStreamInType;
            /// <summary>
            /// 圖像寬度
            /// </summary>
            public uint uPicWidthInMB;
            /// <summary>
            /// 圖像高度
            /// </summary>
            public uint uPicHeightInMB;
            /// <summary>
            /// 參考幀數目
            /// </summary>
            public uint uBufNum;
            /// <summary>
            /// 解碼器工作模式
            /// </summary>
            public uint uWorkMode;
            /// <summary>
            /// 使用者私有資料
            /// </summary>
            public IntPtr pUserData;
            /// <summary>
            /// 保留字
            /// </summary>
            public uint uReserved;
 
        }
 
        /// <summary>
        /// 解碼器輸出圖像資訊資料結構
        /// </summary>
        [StructLayout(LayoutKind.Sequential)]
        public struct hiH264_DEC_FRAME_S
        {
            /// <summary>
            /// Y分量位址
            /// </summary>
            public IntPtr pY;
            /// <summary>
            /// U分量位址
            /// </summary>
            public IntPtr pU;
            /// <summary>
            /// V分量位址
            /// </summary>
            public IntPtr pV;
            /// <summary>
            /// 圖像寬度(以像素為機關)
            /// </summary>
            public uint uWidth;
            /// <summary>
            /// 圖像高度(以像素為機關)
            /// </summary>
            public uint uHeight;
            /// <summary>
            /// 輸出Y分量的stride (以像素為機關)
            /// </summary>
            public uint uYStride;
            /// <summary>
            /// 輸出UV分量的stride (以像素為機關)
            /// </summary>
            public uint uUVStride;
            /// <summary>
            /// 圖像裁減資訊:左邊界裁減像素數
            /// </summary>
            public uint uCroppingLeftOffset;
            /// <summary>
            /// 圖像裁減資訊:右邊界裁減像素數
            /// </summary>
            public uint uCroppingRightOffset;
            /// <summary>
            /// 圖像裁減資訊:上邊界裁減像素數
            /// </summary>
            public uint uCroppingTopOffset;
            /// <summary>
            /// 圖像裁減資訊:下邊界裁減像素數
            /// </summary>
            public uint uCroppingBottomOffset;
            /// <summary>
            /// 輸出圖像在dpb中的序号
            /// </summary>
            public uint uDpbIdx;
            /// <summary>
            /// 圖像類型:0:幀; 1:頂場; 2:底場 */
            /// </summary>
            public uint uPicFlag;
            /// <summary>
            /// 圖像類型:0:幀; 1:頂場; 2:底場 */
            /// </summary>
            public uint bError;
            /// <summary>
            /// 圖像是否為IDR幀:0:非IDR幀;1:IDR幀
            /// </summary>
            public uint bIntra;
            /// <summary>
            /// 時間戳
            /// </summary>
            public ulong ullPTS;
            /// <summary>
            /// 圖像信号
            /// </summary>
            public uint uPictureID;
            /// <summary>
            /// 保留字
            /// </summary>
            public uint uReserved;
            /// <summary>
            /// 指向使用者私有資料
            /// </summary>
            public IntPtr pUserData;
 
        }
 
 
        /// <summary>
        /// 解碼庫版本、版權和能力集資訊。
        /// </summary>
        [StructLayout(LayoutKind.Sequential)]
        public struct hiH264_LIBINFO_S
        {
            /// <summary>
            /// 主編号
            /// </summary>
            public uint uMajor;
            /// <summary>
            /// 次編号
            /// </summary>
            public uint uMinor;
            /// <summary>
            /// 釋出編号
            /// </summary>
            public uint uRelease;
            /// <summary>
            /// 建構編号
            /// </summary>
            public uint uBuild;
            /// <summary>
            /// 版本資訊
            /// </summary>
            [MarshalAs(UnmanagedType.LPStr)]
            public string sVersion;
            /// <summary>
            /// 版權資訊
            /// </summary>
            [MarshalAs(UnmanagedType.LPStr)]
            public string sCopyRight;
            /// <summary>
            /// 解碼庫能力集
            /// </summary>
            public uint uFunctionSet;
            /// <summary>
            /// 支援的輸出圖像格式
            /// </summary>
            public uint uPictureFormat;
            /// <summary>
            /// 輸入碼流格式
            /// </summary>
            public uint uStreamInType;
            /// <summary>
            /// 最大圖像寬度(以像素為機關)
            /// </summary>
            public uint uPicWidth;
            /// <summary>
            /// 最大圖像高度(以像素為機關)
            /// </summary>
            public uint uPicHeight;
            /// <summary>
            /// 最大參考幀數目
            /// </summary>
            public uint uBufNum;
            /// <summary>
            /// 保留字
            /// </summary>
            public uint uReserved;
 
        }
 
        /// <summary>
        /// 使用者私有資料資訊。
        /// </summary>
        [StructLayout(LayoutKind.Sequential)]
        public struct hiH264_USERDATA_S
        {
            /// <summary>
            /// 使用者資料類型
            /// </summary>
            public uint uUserDataType;
            /// <summary>
            /// 使用者資料長度
            /// </summary>
            public uint uUserDataSize;
            /// <summary>
            /// 使用者資料緩沖區
            /// </summary>
            public IntPtr pData;
            /// <summary>
            /// 指向下一段使用者資料
            /// </summary>
            public IntPtr pNext;
        }
    }
}      

繼續閱讀