资源简介
Qt基于librtmp推送H.264
详见博客:http://blog.csdn.net/caoshangpa/article/details/53125949
代码片段和文件信息
#include “crtmpstream.h“
#include “SpsDecode.h“
#ifdef WIN32
#include
#endif
CRTMPStream::CRTMPStream(void)
{
#ifdef WIN32
WSADATA wsaData;
WSAStartup(MAKEWORD(1 1) &wsaData);
#endif
nalhead_pos=0;
m_nFileBufSize=BUFFER_SIZE;
m_pFileBuf=(unsigned char*)malloc(BUFFER_SIZE);
m_pFileBuf_tmp=(unsigned char*)malloc(BUFFER_SIZE);
m_pRtmp = RTMP_Alloc();
RTMP_Init(m_pRtmp);
}
CRTMPStream::~CRTMPStream(void)
{
#ifdef WIN32
WSACleanup();
#endif
}
bool CRTMPStream::Connect(const char* url)
{
if(RTMP_SetupURL(m_pRtmp (char*)url)<0)
{
RTMP_Free(m_pRtmp);
return FALSE;
}
RTMP_EnableWrite(m_pRtmp);
if(RTMP_Connect(m_pRtmp NULL)<0)
{
RTMP_Free(m_pRtmp);
return FALSE;
}
if(RTMP_ConnectStream(m_pRtmp0)<0)
{
RTMP_Close(m_pRtmp);
RTMP_Free(m_pRtmp);
return FALSE;
}
return TRUE;
}
void CRTMPStream::Disconnect()
{
if(m_pRtmp)
{
RTMP_Close(m_pRtmp);
RTMP_Free(m_pRtmp);
m_pRtmp = NULL;
}
if (m_pFileBuf != NULL)
{
free(m_pFileBuf);
}
if (m_pFileBuf_tmp != NULL)
{
free(m_pFileBuf_tmp);
}
}
int CRTMPStream::SendPacket(unsigned int nPacketTypeunsigned char *dataunsigned int sizeunsigned int nTimestamp)
{
if(m_pRtmp == NULL)
{
return FALSE;
}
RTMPPacket* packet;
packet = (RTMPPacket *)malloc(RTMP_HEAD_SIZE+size);
memset(packet0RTMP_HEAD_SIZE);
packet->m_body = (char *)packet + RTMP_HEAD_SIZE;
packet->m_nBodySize = size;
memcpy(packet->m_bodydatasize);
packet->m_hasAbsTimestamp = 0;
packet->m_packetType = nPacketType;
packet->m_nInfoField2 = m_pRtmp->m_stream_id;
packet->m_nChannel = 0x04;
packet->m_headerType = RTMP_PACKET_SIZE_LARGE;
if (RTMP_PACKET_TYPE_AUDIO ==nPacketType && size !=4)
{
packet->m_headerType = RTMP_PACKET_SIZE_MEDIUM;
}
packet->m_nTimeStamp = nTimestamp;
int nRet =0;
if (RTMP_IsConnected(m_pRtmp))
{
nRet = RTMP_SendPacket(m_pRtmppacketTRUE); /*TRUE为放进发送队列FALSE是不放进发送队列直接发送*/
}
free(packet);
return nRet;
}
bool CRTMPStream::SendH264Packet(unsigned char *dataunsigned int sizebool bIsKeyframeunsigned int nTimeStamp)
{
if(data == NULL && size<11)
{
return false;
}
unsigned char *body = (unsigned char*)malloc(size+9);
memset(body0size+9);
int i = 0;
if(bIsKeyframe)
{
body[i++] = 0x17;// 1:iframe 7:AVC
body[i++] = 0x01;// AVC NALU
body[i++] = 0x00;
body[i++] = 0x00;
body[i++] = 0x00;
// NALU size
body[i++] = size>>24 &0xff;
body[i++] = size>>16 &0xff;
body[i++] = size>>8 &0xff;
body[i++] = size&0xff;
// NALU data
memcpy(&body[i]datasize);
SendVideoSpsPps(metaData.PpsmetaData.nPpsLenmetaData.SpsmetaData.nSpsLennTimeStamp);
}
else
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 25821394 2016-11-07 12:00 TestRTMP\480320.264
文件 26408 2016-11-08 11:51 TestRTMP\crtmpstream.cpp
文件 4502 2016-10-31 09:53 TestRTMP\crtmpstream.h
文件 1264640 2016-10-20 17:04 TestRTMP\debug\TestRTMP.exe
文件 2101248 2016-10-20 17:04 TestRTMP\debug\testrtmp.pdb
文件 5475 2010-07-01 03:58 TestRTMP\include\amf.h
文件 2539 2010-07-01 03:58 TestRTMP\include\bytes.h
文件 8264 2010-07-01 03:58 TestRTMP\include\dh.h
文件 9575 2010-07-01 03:58 TestRTMP\include\dhgroups.h
文件 31323 2010-07-01 03:58 TestRTMP\include\handshake.h
文件 1637 2010-07-01 03:58 TestRTMP\include\http.h
文件 1905 2010-07-01 03:58 TestRTMP\include\log.h
文件 9537 2010-07-01 03:58 TestRTMP\include\rtmp.h
文件 3938 2016-10-20 16:45 TestRTMP\include\rtmp_sys.h
文件 16122906 2016-10-21 10:20 TestRTMP\lib\librtmpWindows.lib
文件 523 2016-11-11 10:06 TestRTMP\main.cpp
文件 25351 2016-10-21 14:25 TestRTMP\Makefile
文件 16067 2016-10-21 14:25 TestRTMP\Makefile.Debug
文件 15058 2016-10-21 14:25 TestRTMP\Makefile.Release
文件 11114 2016-11-08 15:55 TestRTMP\release\crtmpstream.obj
文件 2764 2016-11-11 10:06 TestRTMP\release\main.obj
文件 1036800 2016-11-11 10:06 TestRTMP\release\TestRTMP.exe
文件 638 2016-11-11 10:06 TestRTMP\release\TestRTMP.exe.em
文件 7992 2016-11-08 16:52 TestRTMP\spsdecode.h
文件 331 2016-10-20 17:37 TestRTMP\TestRTMP.pro
文件 78682 2016-11-11 10:18 TestRTMP\TestRTMP.pro.user
文件 78682 2016-10-27 09:29 TestRTMP\TestRTMP.pro.user.93c588c
目录 0 2016-10-20 17:04 TestRTMP\debug
目录 0 2016-10-18 14:21 TestRTMP\include
目录 0 2016-10-20 17:35 TestRTMP\lib
............此处省略5个文件信息
相关资源
- h.264和mpeg-4视频压缩--欧阳合译中文清
- QCefView.zip
- Qt书籍大全
- cef_binary_78.3.9+gc7345f2+chromium-78.0.3904.
- Qt实现的百度在线地图与离线地图利用
- 嵌入式Qt开发项目教程
- Qt+Creator快速入门part1
- QT实现的Opencv图像处理、点云显示、演
- QTCAD源代码
- texstudio-2.12.22-win-portable-qt5.zip
- Basler相机实时图像显示--Qt代码
- Qt Creator快速入门_第三版 完整版
- Qt Creator快速入门-第2版qt4.8-PDF(书签
- pyqt5思维导图与笔记
- 基于QT的socket TCP通信原创
- QT5.9Samp.7z
- 贪吃蛇源码版
- qt-creator-opensource-windows-x86-3.2.2.exe
- OpenCV 3和Qt5计算机视觉应用开发.zip
- Qt实现的简易局域网聊天室的Demo
- OpenCASCADE读取igs和step的
- QT 4.8.4 64位版本-4
- qt-vs-addin-1.1.7.exe
- Qt及Qt Quick开发实战精解
- QT+OpenCV+VS Gerber光绘文件识别2
- QT TCP文件传输
- QT下多线程 UDP socket
- Linux_Qt_5.5.1_64
- VTK8.0 and VTK8.1
- Qt5.12.3 vs2017 32bit QtWebEngine支持mp4播放
评论
共有 条评论