代码拉取完成,页面将自动刷新
同步操作将从 吴堉民/demo_h264_rkmedia 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include <assert.h>
#include <fcntl.h>
#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "common/sample_common.h"
#include "rkmedia_api.h"
#include "rkmedia_venc.h"
#if 0
#define DBG(...) do { fprintf(stderr, __VA_ARGS__); } while (0)
#else
#define DBG(...) do {} while (0)
#endif
#define ENABLE_SAVE
#ifdef ENABLE_SAVE
static FILE *g_save_file;
#endif
static MPP_CHN_S stSrcChn;
static MPP_CHN_S stDestChn;
static bool quit = false;
static void sigterm_handler(int sig)
{
fprintf(stderr, "signal %d\n", sig);
quit = true;
}
static void video_packet_cb(MEDIA_BUFFER mb)
{
DBG("Get Video Encoded packet:ptr:%p, fd:%d, size:%zu, mode:%d\n",
RK_MPI_MB_GetPtr(mb), RK_MPI_MB_GetFD(mb), RK_MPI_MB_GetSize(mb),
RK_MPI_MB_GetModeID(mb));
#ifdef ENABLE_SAVE
if (g_save_file)
fwrite(RK_MPI_MB_GetPtr(mb), 1, RK_MPI_MB_GetSize(mb), g_save_file);
#endif
RK_MPI_MB_ReleaseBuffer(mb);
}
int rkmedia_h264_enc_init(int argc, char **argv)
{
int ret = 0;
RK_MPI_SYS_Init();
#ifdef RKAIQ
rk_aiq_working_mode_t hdr_mode = RK_AIQ_WORKING_MODE_NORMAL;
RK_BOOL fec_enable = RK_FALSE;
int fps = 30;
char *iq_file_dir = NULL;
if ((argc > 1) && !strcmp(argv[1], "-h")) {
printf("\n\n/Usage:./%s [--aiq iq_file_dir]\n", argv[0]);
printf("\t --aiq iq_file_dir : init isp\n");
return -1;
}
if (argc == 3) {
if (strcmp(argv[1], "--aiq") == 0) {
iq_file_dir = argv[2];
}
}
SAMPLE_COMM_ISP_Init(hdr_mode, fec_enable, iq_file_dir);
SAMPLE_COMM_ISP_Run();
SAMPLE_COMM_ISP_SetFrameRate(fps);
#else
(void)argc;
(void)argv;
#endif
VI_CHN_ATTR_S vi_chn_attr;
vi_chn_attr.pcVideoNode = "rkispp_scale0";
vi_chn_attr.u32BufCnt = 4;
vi_chn_attr.u32Width = 1920;
vi_chn_attr.u32Height = 1080;
vi_chn_attr.enPixFmt = IMAGE_TYPE_NV12;
vi_chn_attr.enWorkMode = VI_WORK_MODE_NORMAL;
ret = RK_MPI_VI_SetChnAttr(0, 1, &vi_chn_attr);
ret |= RK_MPI_VI_EnableChn(0, 1);
if (ret) {
printf("TEST: ERROR: Create vi[0] error! code:%d\n", ret);
return -1;
}
VENC_CHN_ATTR_S venc_chn_attr;
venc_chn_attr.stVencAttr.enType = RK_CODEC_TYPE_H264;
venc_chn_attr.stVencAttr.imageType = IMAGE_TYPE_NV12;
venc_chn_attr.stVencAttr.u32PicWidth = 1920;
venc_chn_attr.stVencAttr.u32PicHeight = 1080;
venc_chn_attr.stVencAttr.u32VirWidth = 1920;
venc_chn_attr.stVencAttr.u32VirHeight = 1080;
venc_chn_attr.stVencAttr.u32Profile = 77;
venc_chn_attr.stRcAttr.enRcMode = VENC_RC_MODE_H264CBR;
venc_chn_attr.stRcAttr.stH264Cbr.u32Gop = 30;
venc_chn_attr.stRcAttr.stH264Cbr.u32BitRate = 2000000; // 2Mb
venc_chn_attr.stRcAttr.stH264Cbr.fr32DstFrameRateDen = 1;
venc_chn_attr.stRcAttr.stH264Cbr.fr32DstFrameRateNum = 30;
venc_chn_attr.stRcAttr.stH264Cbr.u32SrcFrameRateDen = 1;
venc_chn_attr.stRcAttr.stH264Cbr.u32SrcFrameRateNum = 30;
ret = RK_MPI_VENC_CreateChn(0, &venc_chn_attr);
if (ret) {
printf("TEST: ERROR: Create venc[0] error! code:%d\n", ret);
return -1;
}
#ifdef ENABLE_SAVE
g_save_file = fopen("/data/output.h264", "w");
if (!g_save_file)
printf("#VENC TEST:: Open /data/output.h264 failed!\n");
#endif
MPP_CHN_S stEncChn;
stEncChn.enModId = RK_ID_VENC;
stEncChn.s32DevId = 0;
stEncChn.s32ChnId = 0;
ret = RK_MPI_SYS_RegisterOutCb(&stEncChn, video_packet_cb);
if (ret) {
printf("TEST: ERROR: Register cb for venc[0] error! code:%d\n", ret);
return -1;
}
// Bind VI and VENC
// stSrcChn
stSrcChn.enModId = RK_ID_VI;
stSrcChn.s32DevId = 0;
stSrcChn.s32ChnId = 1;
// stDestChn
stDestChn.enModId = RK_ID_VENC;
stDestChn.s32DevId = 0;
stDestChn.s32ChnId = 0;
ret = RK_MPI_SYS_Bind(&stSrcChn, &stDestChn);
if (ret) {
printf("TEST: ERROR: Bind vi[0] to venc[0] error! code:%d\n", ret);
return -1;
}
printf("%s initial finish\n", __func__);
return 0;
}
void rkmedia_h264_enc_exit(void)
{
#ifdef ENABLE_SAVE
if (g_save_file) {
printf("#VENC TEST:: Close save file!\n");
fclose(g_save_file);
}
#endif
#ifdef RKAIQ
SAMPLE_COMM_ISP_Stop(); // isp aiq stop before vi streamoff
#endif
RK_MPI_SYS_UnBind(&stSrcChn, &stDestChn);
RK_MPI_VENC_DestroyChn(0);
RK_MPI_VI_DisableChn(0, 1);
printf("%s\n", __func__);
}
void demo_running(void)
{
signal(SIGINT, sigterm_handler);
printf("\n\n>>> demo_h264_rkmedia is running...\n");
printf("Press Ctrl + C to exit this program.\n\n");
while(!quit) {
usleep(1000);
}
}
int main(int argc, char **argv)
{
int ret;
ret = rkmedia_h264_enc_init(argc, argv);
if(ret) {
printf("rkmedia_h264_enc_init failed!\n");
return -1;
}
demo_running();
rkmedia_h264_enc_exit();
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。