前言:和另一篇基于media-server简单的rtsp服务端实现一样,同样是是基于media-server简单的实现rtmp服务端,使用vs2015编译过后,运行程序,使用vlc播放rtmp://127.0.0.1:1935/live/1即可。
源码下载: 优快云:简单的rtmp服务端实现, 百度云盘:链接: https://pan.baidu.com/s/1Vn59SDSiwcL6vhWcInBmew 提取码: 62ju 。工程包中有media-server编译好的库,有视频源,设置vs编译通过即可运行。
源码:主函数文件 rtmpserver.cpp
#include <iostream>
#include "rtmpsession.h"
#pragma comment(lib, "winmm.lib")
#pragma comment(lib, "Iphlpapi.lib")
#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "librtmp.lib")
#pragma comment(lib, "libflv.lib")
SOCKET Listener = 0;
std::vector<RtmpSessionPtr> AllRtspSession;
int ListenLocalSvc(int port);
int main()
{
std::cout << "hello rtmp server!" << std::endl;
if (0 > ListenLocalSvc(1935) ||
0 > RtmpSession::ReadSourceStream("miniH264.h264"))
{
return -1;
}
struct rtmp_server_handler_t handler;
handler.send = rtmp_handler_send;
handler.onplay = rtmp_handler_onplay;
handler.onseek = rtmp_handler_onseek;
handler.onpause = rtmp_handler_onpause;
handler.onaudio = rtmp_handler_onaudio;
handler.onvideo = rtmp_handler_onvideo;
handler.onscript = rtmp_handler_onscript;
handler.onpublish = rtmp_handler_onpublish;
handler.ongetduration = rtmp_handler_ongetduration;
unsigned int startTime, usedTime;
while (true)
{
sta