当前位置:   article > 正文

ffmpeg多路同时推流_ffmpeg 推流

ffmpeg 推流

一、ffmpeg常见使用方法

1.1利用FFMPEG命令进行文件分割

1.2转换格式

1.3推流配置

方法一:ngnix(不推荐,推流不好使)

方法二:srs(强烈推荐)

1.4查看nginx启动是否成功

二、ffmpeg推流——>ngnix

单路推流

多(大于两路)路同时推流:

方法一:

方法二:-map

被主进程调用推流脚本后台推流

杀死进程

三、推送h.264编码的flv视频

环境搭建需要x264安装

多路推流执行脚本

一、ffmpeg常见使用方法

后端推流,使用ffmpeg将本地视频推送至ngnix,再拉流,单独推送一路简单,但同时推送多路网上没找到相关的介绍,本文使用ffmpeg的“-map“方法解决了。

1.1利用FFMPEG命令进行文件分割

ffmpeg -ss 00:00:00 -i input.mp4 -c copy -t 60 output.mp4

或者

ffmpeg -ss 00:04:10 -i JC-02.flv -c copy -t 00:30:00 JC-02-output.flv

-ss 表示视频分割的起始时间,-t 表示分割时长,同时也可以用 00:01:00表示

注意 :-ss 要放在 -i 之前

1.2转换格式

ffmpeg -i JC-02.flv JC-02-output.mp4

1

1.3推流配置

方法一:ngnix(不推荐,推流不好使)

下载配置不再说明,网上一堆

配置文件主要是

ngnix.conf

  1. user root;
  2. worker_processes 6;
  3. error_log logs/error.log;
  4. #error_log logs/error.log notice;
  5. #error_log logs/error.log info;
  6. #pid logs/nginx.pid;
  7. events {
  8. worker_connections 65535;
  9. }
  10. rtmp {
  11. server {
  12. listen 1935;
  13. chunk_size 4096;
  14. application live {
  15. live on;
  16. record off;
  17. }
  18. }
  19. }
  20. http {
  21. include mime.types;
  22. default_type application/octet-stream;
  23. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  24. # '$status $body_bytes_sent "$http_referer" '
  25. # '"$http_user_agent" "$http_x_forwarded_for"';
  26. #access_log logs/access.log main;
  27. sendfile on;
  28. #tcp_nopush on;
  29. #keepalive_timeout 0;
  30. keepalive_timeout 65;
  31. #gzip on;
  32. server {
  33. listen 10025;
  34. #server_name localhost;
  35. root /root/smart_transport-deploy/digital_twin_2022_01_12_img;
  36. #charset koi8-r;
  37. #access_log logs/host.access.log main;
  38. #location / {
  39. # root html;
  40. # index index.html index.htm;
  41. #}
  42. #error_page 404 /404.html;
  43. # redirect server error pages to the static page /50x.html
  44. #error_page 500 502 503 504 /50x.html;
  45. location = /50x.html {
  46. root html;
  47. }
  48. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  49. #
  50. #location ~ \.php$ {
  51. # proxy_pass http://127.0.0.1;
  52. #}
  53. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  54. #
  55. #location ~ \.php$ {
  56. # root html;
  57. # fastcgi_pass 127.0.0.1:9000;
  58. # fastcgi_index index.php;
  59. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  60. # include fastcgi_params;
  61. #}
  62. # deny access to .htaccess files, if Apache's document root
  63. # concurs with nginx's one
  64. #
  65. #location ~ /\.ht {
  66. # deny all;
  67. #}
  68. }
  69. # another virtual host using mix of IP-, name-, and port-based configuration
  70. #
  71. #server {
  72. # listen 8000;
  73. # listen somename:8080;
  74. # server_name somename alias another.alias;
  75. # location / {
  76. # root html;
  77. # index index.html index.htm;
  78. # }
  79. #}
  80. # HTTPS server
  81. #
  82. #server {
  83. # listen 443 ssl;
  84. # server_name localhost;
  85. # ssl_certificate cert.pem;
  86. # ssl_certificate_key cert.key;
  87. # ssl_session_cache shared:SSL:1m;
  88. # ssl_session_timeout 5m;
  89. # ssl_ciphers HIGH:!aNULL:!MD5;
  90. # ssl_prefer_server_ciphers on;
  91. # location / {
  92. # root html;
  93. # index index.html index.htm;
  94. # }
  95. #}
  96. }

启动nginx:

/usr/local/nginx-1.18.0/sbin/nginx -c /usr/local/nginx-1.18.0/conf/nginx.conf

查看nginx启动是否成功:

 netstat -an | grep 1935

如果出现则成功

杀死nginx:

killall nginx

方法二:srs(强烈推荐)

配置启动srs:

  1. git clone -b develop ossrs/srs &&
  2. cd srs/trunk && ./configure && make && ./objs/srs -c conf/srs.conf

启动srs(默认端口1935):

./objs/srs -c ./conf/srs.conf

查看1935端口推流情况:

lsof -i:1935

1.4查看nginx启动是否成功:

netstat -an | grep 1935

如果有信息则成功

二、ffmpeg推流——>ngnix

单路推流

  1. ffmpeg -re -stream_loop -1 -i /root/video/flv/JC-02-output.flv -vcodec copy -acodec copy -f flv -y rtmp://your_ip/live/JC-02
  2. ffmpeg -re -stream_loop -1 -i /root/video/flv/JC-03-output.flv -vcodec copy -acodec copy -f flv -y rtmp://your_ip/live/JC-03

多(大于两路)路同时推流:

方法一:

  1. -nostdin
  2. nohup ffmpeg -nostdin -re -i /root/smart_transport-deploy/video/flv/JC-02-output.flv -vcodec copy -acodec copy -f flv -y rtmp://your_ip/live/JC-02 >> /dev/null 2>&1 &
  3. nohup ffmpeg -nostdin -re -i /root/smart_transport-deploy/video/flv/JC-03-output.flv -vcodec copy -acodec copy -f flv -y rtmp://your_ip/live/JC-03 >> /dev/null 2>&1 &
  4. nohup ffmpeg -nostdin -re -i /root/smart_transport-deploy/video/flv/JC-06-02-output.flv -vcodec copy -acodec copy -f flv -y rtmp://your_ip/live/JC-06-02 >> /dev/null 2>&1 &
  5. nohup ffmpeg -nostdin -re -i /root/smart_transport-deploy/video/flv/JC-20-01-output.flv -vcodec copy -acodec copy -f flv -y rtmp://your_ip/live/JC-20-01 >> /dev/null 2>&1 &
  6. 设置输入重定向 </dev/null
  7. nohup ffmpeg -re -i /root/smart_transport-deploy/video/flv/JC-02-output.flv -vcodec copy -acodec copy -f flv -y rtmp://your_ip/live/JC-02 >> /dev/null 2>&1 </dev/null &
  8. nohup ffmpeg -re -i /root/smart_transport-deploy/video/flv/JC-03-output.flv -vcodec copy -acodec copy -f flv -y rtmp://your_ip/live/JC-03 >> /dev/null 2>&1 </dev/null &
  9. nohup ffmpeg -re -i /root/smart_transport-deploy/video/flv/JC-06-02-output.flv -vcodec copy -acodec copy -f flv -y rtmp://your_ip/live/JC-06-02 >> /dev/null 2>&1 </dev/null &
  10. nohup ffmpeg -re -i /root/smart_transport-deploy/video/flv/JC-20-01-output.flv -vcodec copy -acodec copy -f flv -y rtmp://your_ip/live/JC-20-01 >> /dev/null 2>&1 </dev/null &
  11. ffmpeg -re -stream_loop -1 -i /root/video/flv/JC-02-output.flv -re -stream_loop -1 -i /root/video/flv/JC-03-output.flv -map 0:v -map 0:a -c:v:0 copy -c:a:0 copy -f flv -y rtmp://your_ip/live/JC-02 -map 1:v -map 1:a -c:v:0 copy -c:a:0 copy -f flv -y rtmp://your_ip/live/JC-03

方法二:-map

ffmpeg -re -stream_loop -1 -i /root/video/flv/JC-02-output.flv  -re -stream_loop -1 -i /root/video/flv/JC-03-output.flv -map 0:v -map 0:a -c:v:0 copy -c:a:0 copy  -f flv -y rtmp://your_ip/live/JC-02 -map 1:v -map 1:a -c:v:0 copy -c:a:0 copy -f flv -y rtmp://your_ip/live/JC-03

被主进程调用推流脚本后台推流

可参考: ffmpeg使用nohup &在后台运行时挂起问题解决

ffmpeg -re -stream_loop -1 -i /root/video/flv/JC-02-output.flv  -re -stream_loop -1 -i /root/video/flv/JC-03-output.flv -map 0:v -map 0:a -c:v:0 copy -c:a:0 copy  -f flv -y rtmp://your_ip/live/JC-02 -map 1:v -map 1:a -c:v:0 copy -c:a:0 copy -f flv -y rtmp://your_ip/live/JC-03

杀死进程

ps -ef | grep ffmpeg | grep smart_transport-deploy | grep -v grep | awk -F ' ' '{print $2}' | xargs kill -9

三、推送h.264编码的flv视频

环境搭建需要x264安装

link

CentOS7.5 安装 ffmpeg4.2

多路推流执行脚本:

  1. nohup ffmpeg -re -i /root/smart_transport-deploy/video/flv/JC-02-output.flv -vcodec libx264 -acodec libx264 -f flv -y rtmp://your_ip/live/JC-02 >> /dev/null 2>&1 </dev/null &
  2. nohup ffmpeg -re -i /root/smart_transport-deploy/video/flv/JC-03-output.flv -vcodec libx264 -acodec libx264 -f flv -y rtmp://your_ip/live/JC-03 >> /dev/null 2>&1 </dev/null &
  3. nohup ffmpeg -re -i /root/smart_transport-deploy/video/flv/JC-06-02-output.flv -vcodec libx264 -acodec libx264 -f flv -y rtmp://your_ip/live/JC-06-02 >> /dev/null 2>&1 </dev/null &
  4. nohup ffmpeg -re -i /root/smart_transport-deploy/video/flv/JC-20-01-output.flv -vcodec libx264 -acodec libx264 -f flv -y rtmp://your_ip/live/JC-20-01 >> /dev/null 2>&1 </dev/null &

版权声明:本文为CSDN博主「startLight2019」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。

原文链接:ffmpeg多路同时推流_startLight2019的博客-CSDN博客_ffmpeg无缝推流多个视频

★文末名片可以免费领取音视频开发学习资料,内容包括(FFmpeg ,webRTC ,rtmp ,hls ,rtsp ,ffplay ,srs)以及音视频学习路线图等等。

见下方!↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/174883
推荐阅读
相关标签
  

闽ICP备14008679号