使用 FFMPEG 将视频文件连续流式传输到 RTMP 服务器 [英] Using FFMPEG to stream continuously videos files to a RTMP server

查看:33
本文介绍了使用 FFMPEG 将视频文件连续流式传输到 RTMP 服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ffmpeg 将 RTMP 流作为输入或输出处理,并且运行良好.

ffmpeg handles RTMP streaming as input or output, and it's working well.

我想将一些视频(由 python 脚本管理的动态播放列表)流式传输到 RTMP 服务器,我目前正在做一些非常简单的事情:使用 FFMPEG 将我的视频一个一个地流式传输到 RTMP 服务器,但是这会导致每次视频结束时连接中断,当下一个视频开始时,流就准备好了.

I want to stream some videos (a dynamic playlist managed by a python script) to a RTMP server, and i'm currently doing something quite simple: streaming my videos one by one with FFMPEG to the RTMP server, however this causes a connection break every time a video end, and the stream is ready to go when the next video begins.

我想在没有任何连接中断的情况下流式传输这些视频,然后才能正确查看流.

I would like to stream those videos without any connection breaks continuously, then the stream could be correctly viewed.

我使用此命令将我的视频一一串流到服务器

I use this command to stream my videos one by one to the server

ffmpeg -re -y -i myvideo.mp4 -vcodec libx264 -b:v 600k -r 25 -s 640x360 
-filter:v yadif -ab 64k -ac 1 -ar 44100 -f flv 
"rtmp://mystreamingserver/app/streamName"

我在互联网上寻找了很多天的解决方法,我发现有些人谈论在 ffmpeg 中使用命名管道作为输入,我已经尝试过了,但效果不佳因为 ffmpeg 不仅会在新视频到来时关闭 RTMP 流,还会自行关闭.

I looked for some workarounds over the internet for many days, and i found some people talking about using a named pipe as input in ffmpeg, I've tried it and it didn't work well since ffmpeg does not only close the RTMP stream when a new video comes but also closes itself.

有没有办法做到这一点?(使用 ffmpeg 将视频的动态播放列表流式传输到 RTMP 服务器,而不会中断连接

Is there any way to do this ? (stream a dynamic playlist of videos with ffmpeg to RTMP server without connection breaks

推荐答案

更新(因为我无法删除已接受的答案): 正确的解决方案是实现自定义解复用器,类似于连接一个.目前没有其他干净的方法.您必须亲自动手编写代码!

Update (as I can't delete the accepted answer): the proper solution is to implement a custom demuxer, similar to the concat one. There's currently no other clean way. You have to get your hands dirty and code!

下面是一个丑陋的黑客.这是一个非常糟糕的方法,只是不要!

该解决方案使用 concat demuxer 并假设您的所有源媒体文件都使用相同的编解码器.该示例基于 MPEG-TS,但对于 RTMP 也可以这样做.

The solution uses the concat demuxer and assumes all your source media files use the same codec. The example is based on MPEG-TS but the same can be done for RTMP.

  1. 为您的动态播放列表制作一个包含大量入口点列表的播放列表文件,格式如下:

  1. Make a playlist file holding a huge list of entry points for you dynamic playlist with the following format:

<代码>文件item_1.ts"文件item_2.ts"文件item_3.ts"[...]文件'item_[ENOUGH_FOR_A_LIFETIME].ts'

这些文件只是占位符.

制作一个脚本来跟踪您当前的播放列表索引并为 current_index + 1

Make a script that keeps track of you current playlist index and creates symbolic links on-the-fly for current_index + 1

ln -s/path/to/what/to/play/next.ts item_1.ts

ln -s/path/to/what/to/play/next.ts item_2.ts

ln -s/path/to/what/to/play/next.ts item_3.ts

[...]

开始播放ffmpeg -f concat -i playlist.txt -c 复制输出 -f mpegts udp://:

被愤怒的系统管理员追赶和骂人

Get chased and called names by an angry system administrator

这篇关于使用 FFMPEG 将视频文件连续流式传输到 RTMP 服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆