rtsp视频流问题
你好。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;
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;
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 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 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.url = (char*)"rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov";
ffrtsp_get.ffrtsp_get_info.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 补传图片
这个看起来像分辨率字节对齐问题,需要 16 字节对齐,例如 1080 -> 1088 板蓝根 发表于 2021-11-19 14:24
这个看起来像分辨率字节对齐问题,需要 16 字节对齐,例如 1080 -> 1088
那这个在那地方设置,我这是直接取rtsp数据流,然后将数据发送到解码器通道 你把回调函数 printf 打印log 发一下,另外你是怎么预览的,预览的设置成 1920x1088 试一下,如果可以上传一下nv12文件 你好,我这个回调函数只执行了一次,是因为什么,看着感觉rtsp连接是正常的
Opening connection to 192.168.1.198, port 8554...
...remote connection opened
Sending request: DESCRIBE rtsp://192.168.1.198:8554/H264_stream_0 RTSP/1.0
CSeq: 2
User-Agent: ffrtspGet (LIVE555 Streaming Media v2015.06.21)
Accept: application/sdp
Received 468 new bytes of response data.
Received a complete DESCRIBE response:
RTSP/1.0 200 OK
CSeq: 2
Date: Thu Feb 17 11:34:57 2022
Server: rtsp_demo
Content-Type: application/sdp
Content-Length: 337
v=0
o=- 0 0 IN IP4 0.0.0.0
s=rtsp_demo
t=0 0
a=control:rtsp://192.168.1.198:8554/H264_stream_0
a=range:npt=0-
m=video 0 RTP/AVP 96
c=IN IP4 0.0.0.0
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1;sprop-parameter-sets=Z03AH42NUCACa8sIAAADAAgAAAMB5HhEI1A=,aM48gA==
a=control:rtsp://192.168.1.198:8554/H264_stream_0/track1
: Got a SDP description:
v=0
o=- 0 0 IN IP4 0.0.0.0
s=rtsp_demo
t=0 0
a=control:rtsp://192.168.1.198:8554/H264_stream_0
a=range:npt=0-
m=video 0 RTP/AVP 96
c=IN IP4 0.0.0.0
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1;sprop-parameter-sets=Z03AH42NUCACa8sIAAADAAgAAAMB5HhEI1A=,aM48gA==
a=control:rtsp://192.168.1.198:8554/H264_stream_0/track1
: Initiated the "video/H264" subsession (client ports 60910-60911)
Sending request: SETUP rtsp://192.168.1.198:8554/H264_stream_0/track1 RTSP/1.0
CSeq: 3
User-Agent: ffrtspGet (LIVE555 Streaming Media v2015.06.21)
Transport: RTP/AVP;unicast;client_port=60910-60911
Received 188 new bytes of response data.
Received a complete SETUP response:
RTSP/1.0 200 OK
CSeq: 3
Date: Thu Feb 17 11:34:57 2022
Session: 12345B01
Transport: RTP/AVP;ssrc=22345B01;unicast;client_port=60910-60911;server_port=49152-49153
Server: rtsp_demo
: Set up the "video/H264" subsession (client ports 60910-60911)
: Created a data sink for the "video/H264" subsession
Sending request: PLAY rtsp://192.168.1.198:8554/H264_stream_0 RTSP/1.0
CSeq: 4
User-Agent: ffrtspGet (LIVE555 Streaming Media v2015.06.21)
Session: 12345B01
Range: npt=0.000-
Received 98 new bytes of response data.
Received a complete PLAY response:
RTSP/1.0 200 OK
CSeq: 4
Date: Thu Feb 17 11:34:57 2022
Session: 12345B01
Server: rtsp_demo
: Started playing session...
FFRKMedia_Vdec_SendFFRKMedia_Vdec_Send
页:
[1]