hi3516 rtmpdump


原文链接: hi3516 rtmpdump

第一篇博客,简单记录最近关于rtmp的移植于使用,参考了雷大神的文章 RTMPdump 使用说明     在此说明,感谢分享

zlib

git clone https://github.com/madler/zlib.git -b v1.2.11 --depth=1
CHOST=arm-himix200-linux ./configure --static  --prefix=${PWD}/../../

make

openssl

wget https://www.openssl.org/source/openssl-1.0.2u.tar.gz
tar -zxf openssl-1.0.2u.tar.gz

cd ./openssl-1.0.2u/
./Configure linux-armv4 no-asm no-shared --prefix=${PWD}/../../ --cross-compile-prefix=arm-himix200-linux-
``

librtmp

git clone git://git.ffmpeg.org/rtmpdump --depth=1

vi rtmpdump/librtmp/Makefile


prefix=${PWD}/../../..

XCFLAGS=-I./include
XCFLAGS+=-I../../include
XCFLAGS+=-I../../../include

XLDFLAGS=-L./lib
XLDFLAGS+=-L../../lib
XLDFLAGS+=-L../../../lib
# CROSS_COMPILE=arm-himix200-linux-

1 diff --git a/librtmp/Makefile b/librtmp/Makefile
2 index 2c1c790..e7b81fb 100644
3 --- a/librtmp/Makefile
4 +++ b/librtmp/Makefile
5 @@ -1,6 +1,10 @@
6 VERSION=v2.4
7
8 prefix=/usr/local
9 +prefix=${PWD}/../../..
10 +XCFLAGS=-I../../../include
11 +XLDFLAGS=-L../../../lib
12 +CROSS_COMPILE=arm-himix200-linux-
13
14 incdir=$(prefix)/include/librtmp

———移植———————————————————————————————————————————————————————————

rtmpdump 官网(http://rtmpdump.mplayerhq.hu/)上的打包版本都比较低,
源码下载
git clone git://git.ffmpeg.org/rtmpdump

make SYS=posix CROSS_COMPILE=arm-hisiv300-linux- INC=-I/usr/include

rtmpdump 依赖库有 zlib 和  openssl(或者是POLARSSL  GNUTLS,这三个都是ssl协议库目前流行的就是openssl了 ),

arm-himix200-linux-gcc -Wall -I../../../include -DRTMPDUMP_VERSION=\"v2.4\" -DUSE_OPENSSL -O2 -fPIC -c -o rtmp.o rtmp.c
In file included from handshake.h:86:0,

             from rtmp.c:152:

dh.h: In function 'DHInit':
dh.h:256:12: error: dereferencing pointer to incomplete type 'DH {aka struct dh_st}'
MP_new(dh->g);

解决方法: 仔细核对编译路径,一定是路径出问题了。

XCFLAGS=-I../include #增加编译选项,包括依赖库的路径
XLDFLAGS=-L../lib #增加交叉编译工具链选项

2、zlib的移植

下载连接 http://www.zlib.net/   
http://zlib.net/zlib-1.2.8.tar.gz

git clone https://github.com/madler/zlib.git -b v1.2.11 --depth=1

# export PATH=$(pwd)/raspberrypi/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin:$PATH

CHOST=arm-himix200-linux ./configure --static  --prefix=../libz # 默认:--prefix=/usr/local/

make

git clone https://github.com/madler/zlib.git -b v1.2.11 --depth=1

Cross compile zlib with shared & static lib
Setup config >> libz.a libz.so

$ CHOST=arm-hisiv400-linux-gcc ./configure –-prefix=$HOME/openssh/package/zlib

  1. Cross compile zlib with static lib
    Setup config >> libz.a
    $ ./configure --static –prefix=$HOME/openssh/package/zlib/
    Edit Makefile

$ vi Makefile

  1. Find and replace the following:

    CC=arm-hisiv400-linux-gcc
    LDSHARED=arm-hisiv400-linux-gcc
    CPP=arm-hisiv400-linux-gcc -E
    AR=arm-hisiv400-linux-ar
    RANLIB=arm-hisiv400-linux-ranlib

  2. Complie and install zlib

$ make
$ make install

3、rtmpdump 移植

git clone git://git.ffmpeg.org/rtmpdump --depth=1

rtmp源码包一共有两个Makefile,分别修改他们 
make CROSS_COMPILE=arm-none-linux- INC=-I/my/cross/includes

1.修改编译 librtmp

$vi librtmp/Makefile
prefix=${PWD}/..
XCFLAGS=-I/home/ubuntu/cpp/3rdpart/libssl/include -I/home/ubuntu/cpp/3rdpart/libz/include  #增加编译选项,包括依赖库的路径
XLDFLAGS=-L/home/ubuntu/cpp/3rdpart/libssl/lib -L/home/ubuntu/cpp/3rdpart/libz/lib #增加交叉编译工具链选项
XCFLAGS=-I../../../include
XLDFLAGS=-L../../../lib
CROSS_COMPILE=arm-himix200-linux-

修改编译 rtmpdump

修改根目录下的Makefile 
$vi Makefile

prefix=${PWD}/output
XCFLAGS=-I./include
XLDFLAGS=-Llib -L/home/ubuntu/cpp/3rdpart/libssl/lib -L/home/ubuntu/cpp/3rdpart/libz/lib 
CROSS_COMPILE=arm-himix200-linux-

本地编译可能需要dl库,增加链接库选项{
#LIB_OPENSSL=-lssl -lcrypto $(LIBZ)
LIB_OPENSSL=-lssl -lcrypto $(LIBZ) -ldl
}

修改

修改完后直接 make   ; make install

———简单使用———————————————————————————————————————————————————————

my_rtmpTest.c

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<netdb.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
 
#include "librtmp/rtmp.h"
#include "librtmp/log.h"
 
int printfAVal(const AVal al)
{
	int i = 0;
	for(i = 0;i <al.av_len;i++)
		printf("%c",al.av_val[i]);
	printf("\n");
}
 
const char RTMPProtocolStringsLower_1[][7] = {
  "rtmp",
  "rtmpt",
  "rtmpe",
  "rtmpte",
  "rtmps",
  "rtmpts",
  "",
  "",
  "rtmfp"
};
 
#define DEF_TIMEOUT	30	/* seconds */
 
 
int main(int argc,char * argv[])
{
	int Ret = -1;
	RTMP my_rtmp;
	AVal Host, App, Playpath;
	unsigned int Port = 0;
	int Protocol = RTMP_PROTOCOL_UNDEFINED;
	
	AVal sockshost = { 0, 0 };
	AVal tcUrl = { 0, 0 };
	AVal swfUrl = { 0, 0 };
	AVal pageUrl = { 0, 0 };
	AVal auth = { 0, 0 };
	AVal swfSHA256Hash = { 0, 0 };
	AVal flashVer = { 0, 0 };
	AVal subscribepath = { 0, 0 };
	AVal usherToken = { 0, 0 };
	uint32_t swfSize = 0;
	uint32_t dSeek = 0; 	  // seek position in resume mode, 0 otherwise
	int bLiveStream = FALSE;  // is it a live stream? then we can't seek/resume
	uint32_t dStopOffset = 0;
	long int timeout = DEF_TIMEOUT;   // timeout connection after 120 seconds
 
	
	int fd = 0;
 
	char *input_rtmp_url = NULL;
	char RTMP_RUL[] = "rtmp://live.hkstv.hk.lxdns.com/live/hks";
	if(argv[1]==NULL){
		input_rtmp_url = RTMP_RUL;
	}else{
		input_rtmp_url = argv[1];
	}
		
	printf("run %s\n",(char*)argv[0]);
	printf("input_rtmp_url == %s\n",input_rtmp_url);
 
 
 
	RTMP_Init(&my_rtmp);
 
	//InitSockets();
	
	Ret = RTMP_ParseURL(input_rtmp_url, &Protocol, &Host, &Port,
		&Playpath, &App);
	if(Ret == TRUE){
		printfAVal(Host);
		printfAVal(App);
		printfAVal(Playpath);
		printf("%d\n",Port);
	}else{
		printf("url(%s) con`t parsed!\n",input_rtmp_url);\
		goto EXIT;
	}
	
	if (Port == 0)
	  {
		if (Protocol & RTMP_FEATURE_SSL)
	  Port = 443;
		else if (Protocol & RTMP_FEATURE_HTTP)
	  Port = 80;
		else
	  Port = 1935;
	  }
 
	if (tcUrl.av_len == 0)
	  {
		tcUrl.av_len = strlen(RTMPProtocolStringsLower_1[Protocol]) +
		  Host.av_len + App.av_len + sizeof("://:65535/");
		tcUrl.av_val = (char *) malloc(tcUrl.av_len);
		if (!tcUrl.av_val)
		  return -1;
		tcUrl.av_len = snprintf(tcUrl.av_val, tcUrl.av_len, "%s://%.*s:%d/%.*s",
			 RTMPProtocolStringsLower_1[Protocol], Host.av_len,
			 Host.av_val,Port, App.av_len, App.av_val);
	  }
	
	RTMP_SetupStream(&my_rtmp,
			 Protocol,
			 &Host,
			 Port,
			 &sockshost,
			 &Playpath,
			 &tcUrl,
			 &swfUrl,
			 &pageUrl,
			 &App,
			 &auth,
			 &swfSHA256Hash,
			 swfSize,
			 &flashVer,
			 &subscribepath,
			 &usherToken,
			 dSeek,
			 dStopOffset,bLiveStream, timeout);
 
	RTMP_Connect(&my_rtmp,NULL);
 
	RTMP_ConnectStream(&my_rtmp,dSeek);
 
 
	fd = open("test.flv",O_CREAT|O_RDWR);
	
	if(fd){
		char buf[1024*1024] = {0};
		while(1){
			memset(buf,0,1024*1024);
			Ret = RTMP_Read(&my_rtmp,buf,1024*1024);
			printf("read size %d\n",Ret);
			if(Ret <= 0)
				break;
			else{
				write(fd,buf,Ret);
			}
		}
	}
EXIT:
	if(fd)
		close(fd);
	RTMP_Close(&my_rtmp);
	return 0;
}

编译方法

arm-linux-gcc my_rtmpTest.c -g -static -I.//home/arm_install//include -L./home/arm_install/lib -lrtmp -lssl -lcrypto -lz -ldl  -o my_rtmp
————————————————
版权声明:本文为CSDN博主「Chengkai」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/chengkai
/article/details/52061960

`