metaRTC3.0集成ffmpeg实现webrtc推拉流

概述

ffmpeg是一个强大的音视频处理软件,处理各种音视频的编解码和传输等,里面还集成有ffplay播放器等。metaRTC3.0新版本支持静态编译集成到ffmpeg,实现 ffmpeg从流媒体服务器SRS和ZLM的webrtc推拉流,实现ffmpeg的p2p拉流。

 下载源码

GitHub - metartc/ffmpeg-metartc: 集成到ffmpeg的metaRTChttps://github.com/metartc/ffmpeg-metartcffmpeg-metartc: 集成到ffmpeg里的metaRTChttps://gitee.com/metartc/ffmpeg-metartc

https://github.com/metartc/metaRTChttps://github.com/metartc/metaRTChttps://github.com/metartc/metaRTCmetaRTC: metaRTC为嵌入式版本的webrtchttps://gitee.com/metartc/metaRTChttps://gitee.com/metartc/metaRTC

git clone https://github.com/metartc/ffmpeg-metartc.git

git clone https://gitee.com/metartc/ffmpeg-metartc.git

git clone https://github.com/metartc/metaRTC.git

git clone https://gitee.com/metartc/metaRTC.git

编译

将libssl.a/libcrypto.a/libsrtp2.a/libspeexdsp.a/libmetartccore3.a放到metartc3文件夹里

#注意:下面的路径/path/metartc3修改为本机路径
 ./configure --enable-libx264 --enable-gpl --extra-libs='-L/path/metartc3 -lmetartccore3 -lspeexdsp -lpthread -lsrtp2 -lssl -lcrypto -ldl'
make

集成说明

新增文件:

libavformat/webrtc_demuxer.c

libavformat/yang_h264_initExtra.h

libavformat/YangMetaConnection.h //metaRTC头文件

修改文件:

libavformat/util.c

libavcodec/h264dec.c

修改部分有//add metartc注释

 增加了x264的支持,修改ffmpeg.c文件,开发者可以在此增加其他编码的支持。

		if(ost->enc_ctx->codec_id==AV_CODEC_ID_H264&&memcmp(oc->ctx->filename,"webrtc",6)==0){
			 ost->enc_ctx->pix_fmt = AV_PIX_FMT_YUV420P;
			  av_dict_set(&ost->encoder_opts, "preset", "superfast", 0);
			  av_dict_set(&ost->encoder_opts, "tune", "zerolatency", 0);
			  av_dict_set(&ost->encoder_opts, "profile", "baseline", 0);
			
        	  ost->enc_ctx->profile = FF_PROFILE_H264_CONSTRAINED_BASELINE;//:FF_PROFILE_HEVC_MAIN;
        	  ost->enc_ctx->level=31;
        	  ost->enc_ctx->max_b_frames=0;
			  ost->enc_ctx->has_b_frames=0;		
        }

流媒体服务器

流媒体服务器支持SRS和ZLM,也支持从p2p拉流。

在文件webrtc_demuxer.c和webrtc_muxer.c中可修改流媒体服务支持

运行

推流命令

ffmpeg ......-acodec opus -strict -2 -ar 48000 -f webrtc webrtc://192.168.0.1/live/livestream

拉流命令

ffplay webrtc://127.0.0.1/live/livestream

p2p拉流命令

ffplay webrtc://127.0.0.1:1988/live/livestream

猜你喜欢

转载自blog.csdn.net/m0_56595685/article/details/124366760