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群讨論