资讯动态

ffmpeg结合nginx实现实时屏幕画面推拉流

发布时间:2026/10/1 21:33:48 来源:尧图企业网站定制
我们使用nginx加ffmpeg命令行的方式来实现一下rtmp视频流协议的推流与拉流nginx配置常规的nginx是不支持音视频服务的所以需要先安装一下nginx的rtmp音视频模块安装rtmp子模块命令apt-get install libnginx-mod-rtmp安装完成之后来使用nginx配置一个音视频服务器rtmp服务器配置代码# RTMP server rtmp{ # out_queue 4096; # out_cork 8; # max_streams 128; # timeout 10s; # drop_idle_publisher 15s; server { listen 1935; # server port chunk_size 4096; # The size of the data transfer block application vod { play /etc/nginx/vod; # video file save path } application live { live on; # start live record off; #gop_cache on; #open GOP cache for reducing the wating time for the first picture of video #hls on; # start hls live. This parameter transforms the live broadcast server into a live playback server #wait_key on; # Protect the video slices so that no mosaics are created #hls_path /etc/nginx/m3u8File; # Slice video file location (HLSm3u8 file save path) #hls_fragment 2s; # The length of each video slice #hls_playlist_length 16s; #recorder myRecord{ # record all manual; # record_suffix _.flv; # record_path /etc/nginx/rec; #} #hls_continuous on; # continuous mode #hls_cleanup on; # Delete the excess slices #hls_nested on; # Nested pattern } } }重启nginxservice nginx restartffmpeg推流ffmpeg查看可用设备命令ffmpeg -list_devices true -f dshow -i dummyffmpeg推流命令ffmpeg -f gdigrab -framerate 10 -i desktop -f dshow -i audiovirtual-audio-capturer -f flv rtmp://服务器IP地址:音视频服务器端口/live/流媒体名称这个ffmpeg可以通过命令推流也可以通过代码的方式来实现用代码的方式就需要去了解一下ffmpeg的相关API了我们这里先用命令的方式来实现执行命令后可用看到现在ffmpeg正在往服务器进行推流VLC拉流这里我们使用VLC的开源音视频播放器来进行一下拉流rtmp的拉流链接就是我们执行ffmpeg命令时后面的rtmp链接VLC拉网络流媒体点击媒体→选择打开网络串流→输入我们的rtmp地址点击播放可以看到VLC以及成功拉取到我们的rtmp视频流了到这里ffmpeg结合nginx实现实时屏幕画面推拉流就介绍完了虽然功能实现了但是还存在许多可以优化的地方感谢观看学习大佬们多多指点愿明天的自己会感谢当下的努力

读完文章,也想定制专属网站?

尧图设计师 24 小时内与您沟通定制方案

免费获取报价 →
↑