ireader/media-server

repository·master·Indexed 23 days ago

https://github.com/ireader/media-server

A collection of C++ libraries for high-performance media streaming, protocol handling, and container manipulation. It includes specialized libraries such as libflv, librtmp, libmpeg, librtp, librtsp, libhls, libdash, libmov, libmkv, libsip, and libhttp, supporting protocols like RTMP, RTSP, HLS, and DASH, as well as containers including FLV, MP4, and MKV.

Tokens
1.3K
Snippets
5
Records
8
Agent score
86%

What's inside ireader-media-server

  1. Identify supported media protocols and libraries

    master

    The media-server repository provides several specialized libraries for handling different streaming protocols and container formats:

    • libflv: Handles FLV file I/O and bitstream filtering (Annex-B $\leftrightarrow$ MP4, ADTS $\leftrightarrow$ ASC). Supports H.264/H.265/H.266/AV1/VP8/VP9/VP10 video and AAC/MP3/G.711/Opus audio.
    • librtmp: Provides RTMP client (publish/play) and RTMP server (live/VOD) capabilities.
    • libmpeg: Handles ITU-T H.222.0 PS/TS read/write with support for H.264/H.265/H.266 and various audio codecs.
    • librtp: Implements RFC3550 RTP/RTCP with support for various video/audio codecs and RTP Header Extensions.
    • librtsp: Implements RFC2326 RTSP and RFC4566 SDP.
    • libhls: Provides M3U8 generation, TS and fMP4 segmenting, and Master/Playlist parsing.
    • libdash: Supports ISO/IEC 23009-1 MPEG-DASH (static/VOD and dynamic/live) and MPD v3/v4 parsing.
    • libmov: Handles ISO/IEC 14496-12 MP4/fMP4 read/write, including MP4 faststart.
    • libmkv: Supports MKV/WebM file I/O and live streaming.
    • libsip: Provides SIP user-agent (UAC/UAS) functionality with ICE support.
    • libhttp: An asynchronous I/O based HTTP Server, Client, and Cookie management (part of the ireader/sdk).
  2. Compile and run media-server on Linux

    master

    Recommended GCC version: >= 4.8.

    Follow these steps to compile the dependencies and the main project:

    1. Compile dependencies: Navigate to the sdk and avcodec directories and run make.
    2. Compile media-server: Navigate to the media-server directory and run make.
    3. Run tests: Navigate to the test directory within media-server, compile the tests, and run specific test cases using the -c flag.

    Make Options:

    • make RELEASE=1: Compiles the release library (default is debug).
    • make PLATFORM=arm-hisiv100nptl-linux: Performs cross-compilation for the specified platform.
    # 1. Compile dependencies
    cd src/sdk 
    make clean && make
    cd src/avcodec
    make clean && make
    
    # 2. Compile media-server
    cd src/media-server
    make clean && make
    
    # 3. Run tests
    cd src/media-server/test
    make clean && make
    
    # Run a specific test case (e.g., rtsp_example)
    ./debug.linux/test -c rtsp_example
  3. Download the media-server source code and dependencies

    master

    To build the media-server, you must clone the main repository and its required dependency repositories into the same parent directory. For example, if you use a src directory, all repositories should reside directly under src/.

    # Main repository
    git clone https://github.com/ireader/media-server.git
    # Dependency repositories
    git clone https://github.com/ireader/sdk.git
    git clone https://github.com/ireader/avcodec.git
    git clone https://github.com/ireader/3rd.git
  4. Build the media-server libraries using Make

    master

    The media-server project uses make for building. By default, it builds in debug mode. You can specify a release build or target a specific platform for cross-compilation.

    Build Commands

    • Standard build (Debug):
      make clean && make
    • Release build:
      make RELEASE=1
    • Cross-compilation (Example for ARM):
      make PLATFORM=arm-hisiv100nptl-linux
    make clean && make
  5. Fix shared library loading errors on Linux

    master

    If you encounter the error error while loading shared libraries: [libaio.so]: cannot open shared object file: No such file or directory when running the compiled binaries, you need to update your LD_LIBRARY_PATH to include the library directory.

    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:../../sdk/libaio/debug.linux
  6. Pack MPEG-TS streams using the TS packer API

    master

    To pack MPEG-TS streams, you must define a mpeg_ts_func_t structure containing function pointers for allocation, writing, and freeing, then initialize the stream with mpeg_ts_create. You can then write data using mpeg_ts_write and finally clean up with mpeg_ts_destroy.

    struct mpeg_ts_func_t h;
    h.alloc = ts_alloc;
    h.write = ts_write;
    h.free = ts_free;
    
    void* ts = mpeg_ts_create(&h, fp);
    
    while(1)
    {
    	mpeg_ts_write(param, avtype, pts, dts, data, bytes);
    }
    
    mpeg_ts_destroy(ts);