海思3518EV200 SDK中获取和保存H.264码流详解
1 /****************************************** 2 step 2: Start to get streams of each channel. 3 ******************************************/ 4 while (HI_TRUE == pstPara->bThreadStart) 5 { 6 FD_ZERO(&read_fds); 7 for (i = 0; i < s32ChnTotal; i++) 8 { 9 FD_SET(VencFd[i], &read_fds); 10 } 11 12 TimeoutVal.tv_sec = 2; 13 TimeoutVal.tv_usec = 0; 14 s32Ret = select(maxfd + 1, &read_fds, NULL, NULL, &TimeoutVal);//select非阻塞 15 if (s32Ret < 0) 16 { 17 SAMPLE_PRT("select failed!\n"); 18 break; 19 } 20 else if (s32Ret == 0) 21 { 22 SAMPLE_PRT("get venc stream time out, exit thread\n"); 23 continue; 24 } 25 else 26 { 27 for (i = 0; i < s32ChnTotal; i++) 28 { 29 if (FD_ISSET(VencFd[i], &read_fds)) 30 { 31 /******************************************************* 32 step 2.1 : query how many packs in one-frame stream. 33 *******************************************************/ 34 memset(&stStream, 0, sizeof(stStream)); 35 s32Ret = HI_MPI_VENC_Query(i, &stStat); 36 if (HI_SUCCESS != s32Ret) 37 { 38 SAMPLE_PRT("HI_MPI_VENC_Query chn[%d] failed with %#x!\n", i, s32Ret); 39 break; 40 } 41 42 /******************************************************* 43 step 2.2 :suggest to check both u32CurPacks and u32LeftStreamFrames at the same time,for example: 44 if(0 == stStat.u32CurPacks || 0 == stStat.u32LeftStreamFrames) 45 { 46 SAMPLE_PRT("NOTE: Current frame is NULL!\n"); 47 continue; 48 } 49 *******************************************************/ 50 if(0 == stStat.u32CurPacks) 51 { 52 SAMPLE_PRT("NOTE: Current frame is NULL!\n"); 53 continue; 54 } 55 /******************************************************* 56 step 2.3 : malloc corresponding number of pack nodes. 57 *******************************************************/ 58 stStream.pstPack = (VENC_PACK_S*)malloc(sizeof(VENC_PACK_S) * stStat.u32CurPacks); 59 if (NULL == stStream.pstPack) 60 { 61 SAMPLE_PRT("malloc stream pack failed!\n"); 62 break; 63 } 64 65 /******************************************************* 66 step 2.4 : call mpi to get one-frame stream 67 *******************************************************/ 68 stStream.u32PackCount = stStat.u32CurPacks; 69 s32Ret = HI_MPI_VENC_GetStream(i, &stStream, HI_TRUE); 70 if (HI_SUCCESS != s32Ret) 71 { 72 free(stStream.pstPack); 73 stStream.pstPack = NULL; 74 SAMPLE_PRT("HI_MPI_VENC_GetStream failed with %#x!\n", \ 75 s32Ret); 76 break; 77 } 78 79 /******************************************************* 80 step 2.5 : save frame to file 81 *******************************************************/ 82 s32Ret = SAMPLE_COMM_VENC_SaveStream(enPayLoadType[i], pFile[i], &stStream); 83 if (HI_SUCCESS != s32Ret) 84 { 85 free(stStream.pstPack); 86 stStream.pstPack = NULL; 87 SAMPLE_PRT("save stream failed!\n"); 88 break; 89 } 90 /******************************************************* 91 step 2.6 : release stream 92 *******************************************************/ 93 s32Ret = HI_MPI_VENC_ReleaseStream(i, &stStream); 94 if (HI_SUCCESS != s32Ret) 95 { 96 free(stStream.pstPack); 97 stStream.pstPack = NULL; 98 break; 99 } 100 /******************************************************* 101 step 2.7 : free pack nodes 102 *******************************************************/ 103 free(stStream.pstPack); 104 stStream.pstPack = NULL; 105 } 106 }
重点在这里,调用API获取H.264视频流并保存
1 /******************************************************* 2 step 2.4 : call mpi to get one-frame stream 3 *******************************************************/ 4 stStream.u32PackCount = stStat.u32CurPacks; 5 s32Ret = HI_MPI_VENC_GetStream(i, &stStream, HI_TRUE); 6 if (HI_SUCCESS != s32Ret) 7 { 8 free(stStream.pstPack); 9 stStream.pstPack = NULL; 10 SAMPLE_PRT("HI_MPI_VENC_GetStream failed with %#x!\n", \ 11 s32Ret); 12 break; 13 } 14 15 /******************************************************* 16 step 2.5 : save frame to file 17 *******************************************************/ 18 s32Ret = SAMPLE_COMM_VENC_SaveStream(enPayLoadType[i], pFile[i], &stStream); 19 if (HI_SUCCESS != s32Ret) 20 { 21 free(stStream.pstPack); 22 stStream.pstPack = NULL; 23 SAMPLE_PRT("save stream failed!\n"); 24 break; 25 }
1)HI_MPI_VENC_GetStream(i, &stStream, HI_TRUE);
HiMPP IPC V2.0 媒体处理软件开发参考P540
2)s32Ret = SAMPLE_COMM_VENC_SaveStream(enPayLoadType[i], pFile[i], &stStream);
posted on 2018-11-24 21:06 平凡的世界&&技术博客 阅读(1032) 评论(0) 编辑 收藏 举报