|
发表于 2021-11-18 14:54:18
浏览:7095
|
回复:5
打印
只看该作者
[复制链接]
楼主
你好。
1、在ff官方示例rkmedia_rtspget_vdec_test示例的基础上,把rtsp解码的视频流直接保存为NV12格式图片。打开后正上方显示不对,麻烦看下什么原因,测试代码以及图片如下:
- #include <assert.h>
- #include <fcntl.h>
- #include <pthread.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_vdec.h"
- #include "ffrtsp/ffrtsp.hh"
- static bool quit = false;
- static void sigterm_handler(int sig) {
- fprintf(stderr, "signal %d\n", sig);
- quit = true;
- }
- unsigned long long getCurrentTime()
- {
- struct tm t;
- char date_time[64];
- struct timespec time = { 0, 0 };
- clock_gettime(CLOCK_REALTIME, &time);
- clock_gettime(CLOCK_REALTIME, &time);
- strftime(date_time, sizeof(date_time), "%Y-%m-%d %H:%M:%S", localtime_r(&time.tv_sec, &t));
- printf("CLOCK_REALTIME : date_time=%s, tv_nsec=%ld\n", date_time, time.tv_nsec);
- return(unsigned long long )((time.tv_sec*1000*1000*1000+time.tv_nsec)/1000000);
- }
- int FFRKMedia_Vdec_Send(u_int8_t* framebuff,unsigned framesize,bool * pquit,int cur_chn)
- {
- //RTSP流数据送到decode通道
- MEDIA_BUFFER mb = RK_MPI_MB_CreateBuffer(framesize, RK_FALSE, 0);
- RK_MPI_MB_SetSize(mb, framesize);
- memcpy(RK_MPI_MB_GetPtr(mb) ,framebuff , framesize);
- RK_MPI_MB_SetSize(mb, framesize);
- RK_MPI_SYS_SendMediaBuffer(RK_ID_VDEC, 0, mb);
- RK_MPI_MB_ReleaseBuffer(mb);
- if (quit)
- *pquit = true;
- }
- void vdec_packet_cb(MEDIA_BUFFER mb) {
- // decode 流媒体数据为NV12
- int ret;
- static RK_U32 jpeg_id = 0;
- MB_IMAGE_INFO_S stImageInfo = {0};
- ret = RK_MPI_MB_GetImageInfo(mb, &stImageInfo);//指定图像中获取图像信息 ,宽高,图片格式
- if (ret) {
- printf("Get image info failed! ret = %d\n", ret);
- RK_MPI_MB_ReleaseBuffer(mb);
- return ;
- }
- printf("Get Frame:ptr:%p, fd:%d, size:%zu, mode:%d, channel:%d, "
- "timestamp:%lld, ImgInfo:<wxh %dx%d, fmt 0x%x>\n",
- RK_MPI_MB_GetPtr(mb), RK_MPI_MB_GetFD(mb), RK_MPI_MB_GetSize(mb),
- RK_MPI_MB_GetModeID(mb), RK_MPI_MB_GetChannelID(mb),
- RK_MPI_MB_GetTimestamp(mb), stImageInfo.u32Width,
- stImageInfo.u32Height, stImageInfo.enImgType);
- char jpeg_path[128];
- sprintf(jpeg_path, "/userdata/data/test_yuv%d.yuv", jpeg_id);
- FILE *file = fopen(jpeg_path, "w");
- if (file) {
- fwrite(RK_MPI_MB_GetPtr(mb), 1, RK_MPI_MB_GetSize(mb), file);
- fclose(file);
- }
- RK_MPI_MB_ReleaseBuffer(mb);
- jpeg_id++;
- }
- int main(int argc, char *argv[])
- {
- int ret=0;
-
- signal(SIGINT, sigterm_handler);
-
- RK_MPI_SYS_Init();//初始化 MPI 系统
- //设置decode属性
- VDEC_CHN_ATTR_S stVdecAttr;
- stVdecAttr.enCodecType = RK_CODEC_TYPE_H264;
- stVdecAttr.enMode = VIDEO_MODE_STREAM;
- stVdecAttr.enDecodecMode = VIDEO_DECODEC_HADRWARE;
- ret = RK_MPI_VDEC_CreateChn(0, &stVdecAttr);
- if (ret) {
- printf("Create Vdec[0] failed! ret=%d\n", ret);
- return -1;
- }
- //设置decode有数据时 回调
- MPP_CHN_S VdecChn; //定义模块设备通道结构体。
- VdecChn.enModId = RK_ID_VDEC;
- VdecChn.s32DevId = 0;
- VdecChn.s32ChnId = 0;
- ret = RK_MPI_SYS_RegisterOutCb(&VdecChn, vdec_packet_cb); //注册数据输出回调。
- if (ret) {
- printf("ERROR: register output callback for Vdec[0] error! ret=%d\n", ret);
- return 0;
- }
-
- //设置流媒体参数
- struct FFRTSPGet ffrtsp_get;
- ffrtsp_get.callback = FFRKMedia_Vdec_Send;
- ffrtsp_get.count = 1;
- //测试url
- // ffrtsp_get.ffrtsp_get_info[0].url = (char*)"rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov";
- ffrtsp_get.ffrtsp_get_info[0].url = (char*)"rtsp://admin:12345678@192.168.1.77";
- ffrtspGet(ffrtsp_get);
- while(!quit)
- {
- sleep(1);
- }
- //释放资源
- RK_MPI_VDEC_DestroyChn(0);
- return 0;
- }
复制代码
C:\data\微信截图_20211118145328.png |
|