您的位置:首页 > 其它

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

2017-02-28 16:39 399 查看

1、rtmpdump相关参考

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

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

Makefile
#!/bin/sh
INCLUDE = /ternence/test/rtmpdump/
LIB_DIR = /ternence/test/rtmpdump/librtmp/
LDFLAGS = -lrtmp

SRC=rtmp_recv.c

all:$(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

4000
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐