EasyStream介绍
EasyStream SDK使用
EasyStream系列1之rtsp转rtmp
EasyStream系列2之rtmp转rtsp
EasyStream系列3之rtsp转rtsp
EasyStream系列4之rtmp转rtmp
EasyStream系列5之本地文件转rtsp
EasyStream系列6之本地文件转rtmp
EasyStream系列7之录制rtsp流
EasyStream系列8之录制rtmp流
EasyStream系列9之directshow转rtsp
EasyStream系列10之directshow转rtmp
EasyStream系列11之录制directshow视频
所有网络流转换通用SDK EasyStream
如上图所示,EasyStream的sdk包含两部分,一部分是拉流的sdk,另一部分是推流的sdk。sdk内部通过url标识来自动判断推,拉流的协议。
拉流sdk
主要负责获取rtsp,rtmp,本地视频等音视频数据,调用者通过视频流回调函数获取音视频数据。
#ifndef _Pull_Stream_API_H
#define _Pull_Stream_API_H
#include "StreamType.h"
typedef int (STREAM_API_APICALL *PullStreamCallBack)(Pull_Stream_Handle handle,char *pBuf,int nlen,STREAM_FRAME_INFO *pInfo,void *pContext);
typedef int (STREAM_API_APICALL *PullStreamEventCallBack)(Pull_Stream_Handle handle,PULL_EVENT_TYPE event,void *pContext);
//拉流初始化,整个进程只调用一次
STREAM_API int STREAM_API_APICALL PULL_StreamInit();
//打开流,purl可以是rtmp,rtsp,本地mp4或ts
STREAM_API int STREAM_API_APICALL PULL_OpenStream(Pull_Stream_Handle *handle, char *purl);
//关闭流
STREAM_API int STREAM_API_APICALL PULL_CloseStream(Pull_Stream_Handle handle);
//设置音视频数据流回调
STREAM_API int STREAM_API_APICALL PULL_SetStreamCallback(Pull_Stream_Handle handle,PullStreamCallBack pCallback,void* pContext);
//设置音视频流事件回调(上下线通知)
STREAM_API int STREAM_API_APICALL PULL_SetStreamEventCallback(Pull_Stream_Handle handle,PullStreamEventCallBack pCallback,void* pContext);
//获取上下文参数,供PUSH相关函数(PUSH_Init)使用
STREAM_API void * STREAM_API_APICALL PULL_GetPullContext(Pull_Stream_Handle handle);
//获取视频参数信息
STREAM_API int STREAM_API_APICALL PULL_GetVideoInfo(Pull_Stream_Handle handle, STREAM_VIDEO_INFO &videoInfo);
//获取音频参数信息
STREAM_API int STREAM_API_APICALL PULL_GetAudioInfo(Pull_Stream_Handle handle, STREAM_AUDIO_INFO &audioInfo);
#endif
推流SDK
主要负责将获取到的音视频流数据以rtsp,rtmp方式推送到流媒体服务器上,或者保存到本地。
#ifndef _Push_Stream_API_H
#define _Push_Stream_API_H
#include "StreamType.h"
typedef int (STREAM_API_APICALL *PushStreamEventCallBack)(Push_Stream_Handle handle,PUSH_EVENT_TYPE event,void* pContext);
//推送初始化,整个进程只调用一次
STREAM_API int STREAM_API_APICALL PUSH_StreamInit();
//设置推送地址,注意pullcontext是PULL_GetPullContext获取到的上下文
STREAM_API bool STREAM_API_APICALL PUSH_Init(Push_Stream_Handle *handle,char*pDest,void *pullContext);
//设置推送事件,推送过程中服务器掉线或上线都有提示
STREAM_API int STREAM_API_APICALL PUSH_SetEventCallback(Push_Stream_Handle handle,PushStreamEventCallBack pCallback,void *pullContext);
//推送视频
STREAM_API bool STREAM_API_APICALL PUSH_PushVideoData(Push_Stream_Handle handle,char *pBuffer,int nlen,long long pts,long long dts,bool bKey);
//推送音频
STREAM_API bool STREAM_API_APICALL PUSH_PushAudioData(Push_Stream_Handle handle,char *pBuffer,int nlen,long long pts,long long dts);
//释放资源
STREAM_API bool STREAM_API_APICALL PUSH_Uninit(Push_Stream_Handle handle);
#endif
sdk如何使用?
sdk使用方法非常简单,详见如下代码。使用者只需要使用一套sdk,就能完成rtsp,rtmp,本地文件之间的相互转发。
#include "PullStreamAPI.h"
#include "PushStreamAPI.h"
Pull_Stream_Handle pullHandle = NULL;
Pull_Stream_Handle pullHandle2 = NULL;
Push_Stream_Handle pushHandle = NULL;
Push_Stream_Handle pushHandle2 = NULL;
int STREAM_API_APICALL StreamCallBack(Pull_Stream_Handle handle,char *pBuf,int nlen,STREAM_FRAME_INFO *pInfo,void *pContext);
int _tmain(int argc, _TCHAR* argv[])
{
//初始化
PUSH_StreamInit();
PULL_StreamInit();
//拉流
int nret = PULL_OpenStream(&pullHandle,"rtmp://live.hkstv.hk.lxdns.com/live/hks");
//推流(保存到本地)
PUSH_Init(&pushHandle,"1.ts",PULL_GetPullContext(pullHandle));
//从回调中获取拉流数据
PULL_SetStreamCallback(pullHandle,StreamCallBack,NULL);
getchar();
return ;
}
int STREAM_API_APICALL StreamCallBack(Pull_Stream_Handle handle, char *pBuf,int nlen,STREAM_FRAME_INFO *pInfo ,void *pContext)
{
if (handle == pullHandle)
{
char buf[] ={};
sprintf(buf,"======type:%d,size:%d,key:%d\n",pInfo->streamType,nlen,pInfo->bKey);
printf(buf);
if (pInfo->streamType == emStreamVideo)
{
//推送视频数据
PUSH_PushVideoData(pushHandle,pBuf,nlen,pInfo->pts,pInfo->dts,pInfo->bKey);
}
else if (pInfo->streamType == emStreamAudio)
{
//推送音频数据
PUSH_PushAudioData(pushHandle,pBuf,nlen,pInfo->pts,pInfo->dts);
}
}
return ;
}
软件下载地址
http://download.csdn.net/download/sunxiaopengsun/10244537
sdk下载地址
http://download.csdn.net/download/sunxiaopengsun/10244548
欢迎加入qq 136414264群讨论