來自rtmpdump.c
rtmpdump 可使用命令
直播流
rtmpdump.exe -o savename.flv -r rtmp://127.0.0.1/live/testlive -v
點播流
rtmpdump.exe -o savename.flv -r rtmp://127.0.0.1/vod/test.flv
直播需要加-v參數(shù)
下面是從中提取的代碼,進行直播或點播流的錄制
服務(wù)器使用FMS測試通過
crtmpserver需注意超時設(shè)置
#include <stdlib.h>#include <string.h>#include <math.h>#include <stdio.h>#include <signal.h> #include <stdint.h>#include "librtmp/rtmp_sys.h"#include "librtmp/log.h"#pragma comment(lib,"ws2_32.lib")#pragma comment(lib,"librtmp.lib")int InitSockets(){ WORD version; WSADATA wsaData; version = MAKEWORD(1, 1); return (WSAStartup(version, &wsaData) == 0);}void CleanupSockets(){ WSACleanup();}int main(){ InitSockets(); RTMP rtmp={0}; RTMP_Init(&rtmp); rtmp.Link.timeout=25;//超時設(shè)置 //由于crtmpserver是每個一段時間(默認8s)發(fā)送數(shù)據(jù)包,需大于發(fā)送間隔才行 bool bLiveStream=true;//是否直播 if (bLiveStream) { RTMP_SetupURL(&rtmp,"rtmp://127.0.0.1:1935/live/testlive"); //設(shè)置直播標志 rtmp.Link.lFlags|=RTMP_LF_LIVE; }else { RTMP_SetupURL(&rtmp,"rtmp://127.0.0.1:1935/vod/test.flv"); } RTMP_SetBufferMS(&rtmp, 3600*1000);//1hour if(!RTMP_Connect(&rtmp,NULL)) { printf("Connect Server Err\n"); WSACleanup(); return -1; } if(!RTMP_ConnectStream(&rtmp,0)) { printf("Connect stream Err\n"); RTMP_Close(&rtmp); WSACleanup(); return -1; } int buffsize=1024*1024*10; char*buff=(char*)malloc(buffsize); double duration=-1; int nRead; FILE*fp=fopen("aaa.flv","wb"); long countbuffsize=0; //它直接輸出的就是FLV文件,包括FLV頭,可對流按照flv格式解析就可提前音頻,視頻數(shù)據(jù) while(nRead=RTMP_Read(&rtmp,buff,buffsize)) { fwrite(buff,1,nRead,fp); if (!bLiveStream&&duration<0) { duration = RTMP_GetDuration(&rtmp); printf("duration:%f\n",duration); } countbuffsize+=nRead; printf("\rdownland...:%0.2fkB",countbuffsize*1.0/1024); } fclose(fp); free(buff); buff=NULL; RTMP_Close(&rtmp); WSACleanup(); return 0;}
代碼下載:
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請
點擊舉報。