me icon indicating copy to clipboard operation
me copied to clipboard

学习 rtmp 开发 (Part 1: 编译 librtmp)

Open nonocast opened this issue 2 years ago • 0 comments

rtmpdump is a toolkit for RTMP streams. All forms of RTMP are supported, including rtmp://, rtmpt://, rtmpe://, rtmpte://, and rtmps://.

在MacMini M1的macOS上编译还是有点小挑战:

  • git clone git://git.ffmpeg.org/rtmpdump
➜  rtmpdump git:(master) ls
COPYING         README          rtmpdump.1.html rtmpgw.8.html   rtmpsuck.c
ChangeLog       librtmp         rtmpdump.c      rtmpgw.c        thread.c
Makefile        rtmpdump.1      rtmpgw.8        rtmpsrv.c       thread.h
➜  rtmpdump git:(master) 
➜  rtmpdump git:(master) ls librtmp 
COPYING        bytes.h        hashswf.c      librtmp.pc.in  rtmp.c
Makefile       dh.h           http.h         log.c          rtmp.h
amf.c          dhgroups.h     librtmp.3      log.h          rtmp_sys.h
amf.h          handshake.h    librtmp.3.html parseurl.c
  • 当前版本2.4
  • 编译目标: librtmp, rtmpdump, rtmpsvr, rtmpsuck (suck你懂的), librtmp目录对应librtmp lib,而外面就是几个壳,短小精悍
    • rtmpsrv is a stub for a server; it logs the connect and play parameters from a regular client that connects to it. It then invokes rtmpdump with those parameters to retrieve the stream.
    • rtmpsuck is a transparent proxy; it intercepts connections from a client and then makes an outbound connection to the real server. After all handshaking is complete and encryption keys with both sides are negotiated, it records the cleartext stream data into files while relaying the data from the server to the client.
  • librtmp 5个c文件, 6k行c代码, shell 大概4k行c代码

Compile

  • 为了简化编译,根据官网说明可以关闭openssl和zlib,不支持openssl 1.1+,貌似1.0.1可以,但是我在M1上没法编译1.0.1,所以直接在librtmp/Makefile中注释掉CRYPTO=OPENSSL
  • SIZE_MAX未定义,则需要加入#include <limits.h>
  • ld: unknown option: -soname,将-soname改为-install_name
  • ld: library not found for -lssl,注释掉LIB_OPENSSL=-lssl -lcrypto $(LIBZ),让ld不要去link即可
  • make成功后sudo make install
  • 默认在M1上编译出来是arm64,如果需要可以直接在CC中设定gcc -arch x86_64, 两个arch都能编译成功

pkg-config check

~ pkg-config --cflags --libs librtmp
-I/usr/local/include -L/usr/local/lib -lrtmp -lz

clang-format

find . -type f -name "*.h" -o -iname "*.c" | xargs clang-format -i

参考阅读

nonocast avatar May 14 '22 19:05 nonocast