本项目实现了一个python库,基于ffmpeg api函数实现推送rtmp流,实现了音视频同步。
当前 checkout 已包含 LiveTalking 生产修复:NVENC、44.1/48 kHz 双声道 AAC、FFmpeg 8.1 API 和 sample-accurate PTS。视频 frame PTS 使用 1/fps codec time base 下的连续帧序号;音频 frame PTS 使用 1/sample_rate 下的累计采样数;编码 packet 只在写入 muxer 前转换一次到 stream time base。
cmake -S python -B build \
-DPYTHON_EXECUTABLE=/workspace/.venv-nerfstream/bin/python \
-DCMAKE_BUILD_TYPE=Release -G Ninja
cmake --build build -j 4产物内置 /workspace/ffmpeg-8.1-openssl/lib RPATH。生产部署、回滚和至少 120 秒的 RTMP 验收标准见 /workspace/LiveTalking/docs/RTMP_STREAMER_BUILD.md。下方是上游旧环境说明,仅供参考。
下载代码
$ git clone https://github.com/lipku/python_rtmpstream.git
$ cd python_rtmpstream
$ git submodule update --init
安装依赖库
$ pip install wheel
$ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
$ conda install ffmpeg==6
或者 apt install libavcodec-dev libavformat-dev libswscale-dev
修改python/CMakeLists.txt文件, 根据python和ffmpeg安装路径修改如下部分(这一步一定要做,很多错误都是这里没改引起的)
set(PYTHON_EXECUTABLE /opt/anaconda3/envs/python37/bin/python) #python bin dir
include_directories("/opt/anaconda3/envs/python37/include") #ffmpeg include dir
find_library(AVCODEC_LIBRARY avcodec /opt/anaconda3/envs/python37/lib) #ffmpeg lib dir
find_library(AVFORMAT_LIBRARY avformat /opt/anaconda3/envs/python37/lib)
find_library(AVUTIL_LIBRARY avutil /opt/anaconda3/envs/python37/lib)
find_library(SWSCALE_LIBRARY swscale /opt/anaconda3/envs/python37/lib)
如果是python3.10以下,不能用相对路径,需要将如下部分改成绝对路径
include_directories("../streamer")
pybind11_add_module( ../streamer/streamer.cpp)
安装python库
$ cd python
$ pip install .
运行测试程序
$ python test_stream.py
更多详细使用请参考https://github.com/lipku/nerfstream
