首页 > 学院 > 开发设计 > 正文

rtmpdump 捕获 rtmp视频数据 本地存储为 flv文件

2019-11-06 09:34:35
字体:
来源:转载
供稿:网友

1、rtmpdump相关参考

rtmpdump 实现 flv视频数据的rtmp推流功能http://blog.csdn.net/ternence_hsu/article/details/58594687

2、rtmpdump 捕获 rtmp视频数据 本地存储为 flv文件

Makefile
#!/bin/shINCLUDE = /ternence/test/rtmpdump/LIB_DIR = /ternence/test/rtmpdump/librtmp/LDFLAGS = -lrtmpSRC=rtmp_recv.call:$(SRC)	gcc -g -Wall $(SRC) -o target -I $(INCLUDE) -L $(LIB_DIR)  $(LDFLAGS)

rtmp_recv.c

#include <stdio.h>#include <stdlib.h>#include <string.h>#include "librtmp/rtmp_sys.h"#include "librtmp/log.h"#define SAVE_FILE_NAME  "receive.flv"#define RTMP_SERVER_URL "rtmp://172.16.1.65:1935/vod/mp4:sample.mp4"int InitSockets(){    /*	Word version;	WSADATA wsaData;	version = MAKEWORD(1, 1);	return (WSAStartup(version, &wsaData) == 0);    */    return 0;}void CleanupSockets(){	//WSACleanup();}int main(int argc, char* argv[]){	InitSockets();		//double duration=-1;	int nRead;	//is live stream ?	int bLiveStream=1;			int bufsize=1024*1024*10;				char *buf=(char*)malloc(bufsize);	memset(buf,0,bufsize);	long countbufsize=0;		FILE *fp=fopen(SAVE_FILE_NAME,"wb");	if (!fp){		RTMP_LogPRintf("Open File Error./n");		CleanupSockets();		return -1;	}		/* set log level */	//RTMP_LogLevel loglvl=RTMP_LOGDEBUG;	//RTMP_LogSetLevel(loglvl);	RTMP *rtmp=RTMP_Alloc();	RTMP_Init(rtmp);	//set connection timeout,default 30s	rtmp->Link.timeout=10;		if(!RTMP_SetupURL(rtmp,RTMP_SERVER_URL))	{		RTMP_Log(RTMP_LOGERROR,"SetupURL Err/n");		RTMP_Free(rtmp);		CleanupSockets();		return -1;	}	if (bLiveStream){		rtmp->Link.lFlags|=RTMP_LF_LIVE;	}		//1hour	RTMP_SetBufferMS(rtmp, 3600*1000);				if(!RTMP_Connect(rtmp,NULL)){		RTMP_Log(RTMP_LOGERROR,"Connect Err/n");		RTMP_Free(rtmp);		CleanupSockets();		return -1;	}	if(!RTMP_ConnectStream(rtmp,0)){		RTMP_Log(RTMP_LOGERROR,"ConnectStream Err/n");		RTMP_Close(rtmp);		RTMP_Free(rtmp);		CleanupSockets();		return -1;	}	while(nRead=RTMP_Read(rtmp,buf,bufsize)){		fwrite(buf,1,nRead,fp);		countbufsize+=nRead;		RTMP_LogPrintf("Receive: %5dByte, Total: %5.2fkB/n",nRead,countbufsize*1.0/1024);	}	if(fp)		fclose(fp);	if(buf){		free(buf);	}	if(rtmp){		RTMP_Close(rtmp);		RTMP_Free(rtmp);		CleanupSockets();		rtmp=NULL;	}		return 0;}下载:

http://download.csdn.net/detail/ternence_hsu/9766463


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表