├── .gitignore ├── gkrcparams ├── .vscode └── settings.json ├── Makefile ├── Readme.md └── gkrcparams.c /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | compile_flags.txt 3 | -------------------------------------------------------------------------------- /gkrcparams: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIPC/gkrcparams/master/gkrcparams -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "getopt.h": "c" 4 | } 5 | } -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | #TPATH=$(HOME)/git/buildroot_toolchain/hi3516ev200/bin 3 | TPATH=$(HOME)/src/openipc-firmware/output/host/bin 4 | 5 | #MPP=$(HOME)/src/openipc-firmware/output/build/hisilicon-opensdk-c033009fa4551650480604dababcb5a852983593 6 | MPP=$(HOME)/src/silicon_research/sdk/gk7205v300/gmp 7 | 8 | CFLAGS=-I$(MPP)/include 9 | 10 | LDFLAGS=-L$(MPP)/lib_nolog/static 11 | #LDFLAGS=-L/home/home/src/openipc-firmware/output/per-package/hisilicon-osdrv-hi3516ev200/target/usr/lib 12 | 13 | LDLIBS=-lgk_api -lupvqe -ldnvqe -lvoice_engine -lsecurec 14 | 15 | CC=$(TPATH)/arm-openipc-linux-musleabi-gcc 16 | 17 | gkrcparams: 18 | 19 | clean: 20 | -rm gkrcparams *.o 21 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | ![OpenIPC logo][logo] 2 | 3 | ## gkrcparams 4 | **_Tool for changning HiSilicon/Goke encoder params_** 5 | 6 | ### Prepare 7 | To compile download and extract 8 | [this repo](https://github.com/OpenIPC/silicon_research/tree/474850aefa7e0a141d85c91589caab3c68910787/sdk/gk7205v300/gmp), 9 | then change TPATH= and MPP= accordingly. SDK and param details 10 | [here](http://fabemo.ru/pcb/ReleaseDoc_v01/zh/01.software/board/HiMPP%20V4.0%20%E5%AA%92%E4%BD%93%E5%A4%84%E7%90%86%E8%BD%AF%E4%BB%B6%E5%BC%80%E5%8F%91%E5%8F%82%E8%80%83.pdf). 11 | 12 | 13 | ### Sample usage 14 | ``` 15 | gkrcparams --MaxQp 30 --MaxI 2 16 | ``` 17 | 18 | Tested on gk7205v200/gk7205v300 and hi3516ev200/hi3516ev300 19 | 20 | The majestic must running when calling the app. Changes won't persist if majestic is restarted. 21 | 22 | Current options that can be changed 23 | ``` 24 | --MaxI u32MaxIprop[u32MinIprop,100] 25 | --MinI u32MinIprop[1,u32MaxIprop] 26 | --MaxQp u32MaxQp[MinQp, 51] 27 | --MinQp u32MinQp[0, 51] 28 | --MaxReEnc s32MaxReEncodeTimes[0, 3] 29 | --MaxQpD u32MaxQpDelta[0, 4] 30 | --RefreshNum u32RefreshNum (enables IntraRefresh) 31 | --help Display this help 32 | ``` 33 | 34 | - u32MaxIprop 35 | ``` 36 | Maximum ratio of bits allocated to the I-frames and P-frames 37 | Value range: [u32MinIprop,100] 38 | Default value: 100 39 | ``` 40 | 41 | - u32MaxQp 42 | ``` 43 | Maximum QP value of the P-frame and B-frame 44 | Value range: [MinQp, 51] 45 | Default value: 51 46 | ``` 47 | 48 | - u32MinQp 49 | ``` 50 | Minimum QP value of the P-frame and B-frame 51 | Value range: [0, 51] 52 | Default value: 16 53 | ``` 54 | 55 | - s32MaxReEncodeTimes 56 | ``` 57 | Number of times that each frame is re-encoded. The value 0 58 | indicates that the frame is not re-encoded. 59 | Value range: [0, 3] 60 | Default value: 2 61 | ``` 62 | 63 | - u32MaxQpDelta 64 | ``` 65 | Indicates the difference between the maximum QP value of the frame level and the 66 | maximum QP value of the CU level. This is an advanced CVBR parameter. When the 67 | image content is complex, the bit rate control increases the QP value. When the 68 | frame-level QP value is adjusted to the maximum, the bit rate control does not 69 | increase the frame-level QP value. However, the CU/MB-level bit rate control still 70 | takes effect, and the QP value in the strong texture area of the image can be increased. 71 | ``` 72 | 73 | ### ToDo 74 | - Should be possible to link to OpenIPC repo downloaded via BuildRoot process. 75 | 76 | 77 | 78 | 79 | ### Technical support and donations 80 | 81 | Please **_[support our project](https://openipc.org/support-open-source)_** with donations or orders for development or maintenance. Thank you! 82 | 83 | 84 | [logo]: https://openipc.org/assets/openipc-logo-black.svg 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /gkrcparams.c: -------------------------------------------------------------------------------- 1 | #include "type.h" 2 | #include 3 | #include 4 | 5 | int main(int argc, char **argv) 6 | { 7 | 8 | const struct option long_options[] = { 9 | {"MaxI", required_argument, NULL, 'm'}, 10 | {"MinI", required_argument, NULL, 'n'}, 11 | {"MaxQp", required_argument, NULL, 'a'}, 12 | {"MinQp", required_argument, NULL, 'b'}, 13 | {"MaxReEnc", required_argument, NULL, 'c'}, 14 | {"MaxQpD", required_argument, NULL, 'd'}, 15 | {"RefreshNum", required_argument, NULL, 'e'}, 16 | {"help", no_argument, NULL, 'h'}, 17 | {NULL, 0, NULL, 0}}; 18 | 19 | int MaxIprop = -1, MinIprop = -1; 20 | int MaxQp = -1, MinQp = -1, MaxReEnc = -1, MaxQpD = -1, RefreshNum=-1; 21 | 22 | int opt; 23 | int long_index = 0; 24 | while ((opt = getopt_long_only(argc, argv, "", long_options, &long_index)) != -1) 25 | { 26 | switch (opt) 27 | { 28 | case 'm': MaxIprop = atoi(optarg); break; 29 | case 'n': MinIprop = atoi(optarg); break; 30 | case 'a': MaxQp = atoi(optarg); break; 31 | case 'b': MinQp = atoi(optarg); break; 32 | case 'c': MaxReEnc = atoi(optarg); break; 33 | case 'd': MaxQpD = atoi(optarg); break; 34 | case 'e': RefreshNum = atoi(optarg); break; 35 | 36 | case 'h': 37 | default: 38 | printf("Usage: rcparams [OPTIONS][value]\n" 39 | "Where [OPTIONS]:\n" 40 | " --MaxI u32MaxIprop[u32MinIprop,100] \n" 41 | " --MinI u32MinIprop[1,u32MaxIprop] \n" 42 | " --MaxQp u32MaxQp[MinQp, 51] \n" 43 | " --MinQp u32MinQp[0, 51] \n" 44 | " --MaxReEnc s32MaxReEncodeTimes[0, 3] \n" 45 | " --MaxQpD u32MaxQpDelta[0, 4] \n" 46 | " --RefreshNum u32RefreshNum (enables IntraRefresh) \n" 47 | " --help Display this help\n" 48 | "sample: \n" 49 | "rcparams --MaxI 10 --MinI 1 \n"); 50 | exit(1); 51 | } 52 | } 53 | 54 | VENC_RC_PARAM_S params = {0}; 55 | 56 | int ret = GK_API_VENC_GetRcParam(0, ¶ms); 57 | if (ret != GK_SUCCESS){ 58 | fprintf(stderr, "GK_API_VENC_GetRcParam error %d\n", ret); 59 | exit(1); 60 | } 61 | 62 | MaxIprop = (MaxIprop > -1) ? MaxIprop : params.stParamH265CVbr.u32MaxIprop; 63 | MinIprop = (MinIprop > -1) ? MinIprop : params.stParamH265CVbr.u32MinIprop; 64 | fprintf(stderr, "stParamH265CVbr.u32MaxIprop = %d , was %d\n", MaxIprop, params.stParamH265CVbr.u32MaxIprop); 65 | params.stParamH265CVbr.u32MaxIprop = MaxIprop; 66 | 67 | fprintf(stderr, "stParamH265CVbr.u32MinIprop = %d , was %d\n", MinIprop, params.stParamH265CVbr.u32MinIprop); 68 | params.stParamH265CVbr.u32MinIprop = MinIprop; 69 | 70 | MaxQp = (MaxQp > -1) ? MaxQp : params.stParamH265CVbr.u32MaxQp; 71 | MinQp = (MinQp > -1) ? MinQp : params.stParamH265CVbr.u32MinQp; 72 | 73 | fprintf(stderr, "stParamH265CVbr.u32MaxQp = %d , was %d\n", MaxQp, params.stParamH265CVbr.u32MaxQp); 74 | fprintf(stderr, "stParamH265CVbr.u32MinQp = %d , was %d\n", MinQp, params.stParamH265CVbr.u32MinQp); 75 | params.stParamH265CVbr.u32MaxQp = MaxQp; 76 | params.stParamH265CVbr.u32MinQp = MinQp; 77 | 78 | fprintf(stderr, "stParamH265CVbr.bQpMapEn = %d \n", params.stParamH265CVbr.bQpMapEn); 79 | 80 | MaxReEnc = (MaxReEnc > -1) ? MaxReEnc : params.stParamH265CVbr.s32MaxReEncodeTimes; 81 | fprintf(stderr, "stParamH265CVbr.s32MaxReEncodeTimes = %d, was %d \n", MaxReEnc, params.stParamH265CVbr.s32MaxReEncodeTimes); 82 | params.stParamH265CVbr.s32MaxReEncodeTimes = MaxReEnc; 83 | 84 | MaxQpD = (MaxQpD > -1) ? MaxQpD : params.stParamH265CVbr.u32MaxQpDelta; 85 | fprintf(stderr, "stParamH265CVbr.u32MaxQpDelta = %d, was %d \n", MaxQpD, params.stParamH265CVbr.u32MaxQpDelta); 86 | params.stParamH265CVbr.u32MaxQpDelta = MaxQpD; 87 | 88 | fprintf(stderr, "stParamH265CVbr.enQpMapMode = %d \n", params.stParamH265CVbr.enQpMapMode); 89 | fprintf(stderr, "stParamH265CVbr.u32ExtraBitPercent = %d \n", params.stParamH265CVbr.u32ExtraBitPercent); 90 | fprintf(stderr, "stParamH265CVbr.u32LongTermStatTimeUnit = %d \n", params.stParamH265CVbr.u32LongTermStatTimeUnit); 91 | fprintf(stderr, "stParamH265AVbr.u32MaxIprop = %d \n", params.stParamH265AVbr.u32MaxIprop); 92 | 93 | // params.stParamH265CVbr.u32MinQp = 1; 94 | 95 | ret = GK_API_VENC_SetRcParam(0, ¶ms); 96 | if (ret != GK_SUCCESS){ 97 | fprintf(stderr, "GK_API_VENC_SetRcParam error %d\n", ret); 98 | exit(1); 99 | } 100 | 101 | 102 | VENC_INTRA_REFRESH_S stIntraRefresh; 103 | if ((ret = GK_API_VENC_GetIntraRefresh( 0, &stIntraRefresh)) != GK_SUCCESS) { 104 | fprintf(stderr, "Failed GetIntraRefresh %d\n", ret); 105 | exit(1); 106 | 107 | } 108 | 109 | //RefreshNum = (RefreshNum > -1) ? RefreshNum : stIntraRefresh.u32RefreshNum; 110 | 111 | fprintf(stderr, "enIntraRefreshMode = %d , bRefreshEnable = %d, u32ReqIQp= %d\n", 112 | stIntraRefresh.enIntraRefreshMode,stIntraRefresh.bRefreshEnable,stIntraRefresh.u32ReqIQp); 113 | 114 | fprintf(stderr, "stIntraRefresh.u32RefreshNum = %d , was %d\n", (RefreshNum > -1) ? RefreshNum : stIntraRefresh.u32RefreshNum, stIntraRefresh.u32RefreshNum); 115 | 116 | if (RefreshNum>-1){ 117 | stIntraRefresh.u32RefreshNum=RefreshNum; 118 | stIntraRefresh.enIntraRefreshMode=INTRA_REFRESH_ROW; 119 | stIntraRefresh.bRefreshEnable = GK_TRUE; 120 | stIntraRefresh.u32ReqIQp=GK_FALSE; 121 | } 122 | 123 | ret=GK_API_VENC_SetIntraRefresh(0, &stIntraRefresh); 124 | if (ret != GK_SUCCESS) { 125 | fprintf(stderr, "GK_API_VENC_SetIntraRefresh error %d\n", ret); 126 | exit(1); 127 | } 128 | 129 | /* 130 | VENC_INTRA_REFRESH_S stIntraRefresh2 = { 131 | .enIntraRefreshMode = INTRA_REFRESH_ROW, 132 | .u32RefreshNum = 32//chn->size.height / chn->framesInGop, 133 | .bRefreshEnable = GK_TRUE, 134 | .u32ReqIQp = GK_FALSE, 135 | }; 136 | ret = HI_MPI_VENC_SetIntraRefresh( chn->venc_chn, &stIntraRefresh); 137 | */ 138 | 139 | /* 140 | GK_S32 GK_API_VENC_SetIntraRefresh(VENC_CHN VeChn, 141 | const VENC_INTRA_REFRESH_S *pstIntraRefresh); 142 | GK_S32 GK_API_VENC_GetIntraRefresh(VENC_CHN VeChn, 143 | VENC_INTRA_REFRESH_S *pstIntraRefresh); 144 | */ 145 | 146 | 147 | 148 | } 149 | 150 | /* 151 | For __ctype_b*, the decision to replace it by __ctype_b_loc etc. 152 | and disallow any new links against the old type were made because 153 | __ctype_b* does not work together with uselocale(3). 154 | These days, uselocale(3) is used quite often e.g. in libstdc++, 155 | so it is very bad idea to keep using __ctype_b etc. 156 | */ 157 | 158 | __attribute__((visibility("default"))) const unsigned short int *__ctype_b; 159 | 160 | __attribute__((visibility("default"))) int __fgetc_unlocked(FILE *stream) 161 | { 162 | return fgetc(stream); 163 | } 164 | 165 | __attribute__((visibility("default"))) size_t _stdlib_mb_cur_max(void) 166 | { 167 | return 0; 168 | } 169 | --------------------------------------------------------------------------------