FFMPEG RTMP 在 Ubuntu 14.0.4 上的 red5pro 模块中不起作用

Posted

技术标签:

【中文标题】FFMPEG RTMP 在 Ubuntu 14.0.4 上的 red5pro 模块中不起作用【英文标题】:FFMPEG RTMP not working in my red5pro module on Ubuntu 14.0.4 【发布时间】:2018-01-22 23:35:48 【问题描述】:

以下命令在我的 java 模块中不起作用(这会从实时流中获取快照并保存) Runtime.getRuntime().exec("ffmpeg -i \"rtmp://127.0.0.1:1935/live/mytest live=1 timeout=2\" -f image2 -vframes 1 /snaps/testo.jpg");

如果我在 Ubuntu 14.0.4 控制台上使用相同的命令,它可以工作。在 Window 上的 red5pro 模块中使用相同的命令,但在 Ubuntu 上却没有。

当我使用 String[] execStr = "/usr/local/bin/ffmpeg","-i","rtmp://127.0.0.1:1935/live/mytest","live=1","timeout=2", "-f","image2","-vframes","1","/snaps/tt.jpg"; ProcessBuilder pb = new ProcessBuilder("ffmpeg -i rtmp://localhost/live/mytest live=1 timeout=2 -f image2 -vframes 1 /snaps/testo.jpg");

它总是抛出找不到流(在 red5pro 控制台中)

【问题讨论】:

我认为你的问题是"rtmp://127.0.0.1:1935/live/mytest","live=1","timeout=2"。您可能会将其组合为一个参数,如 "rtmp://127.0.0.1:1935/live/mytest live=1 timeout=2" 我想我确实尝试过,但让我再试一次 现在当我这样做时,我得到以下错误--->RTMP_ReadPacket,未能读取 RTMP 数据包头--->rtmp://127.0.0.1:1935/live/mytest live=1 timeout =2:处理输入时发现无效数据 也试试这个:rtmp://127.0.0.1:1935/live/mytest?live=1&timeout=2 现在说:--->rtmp server sent error 以下是我的代码 String[] execStr = "/usr/bin/ffmpeg", "-i", "rtmp://127.0. 0.1:1935/live/mytest?live=1&timeout=2", "-f", "image2","-vframes", "1","/snaps/ff.jpg"; ProcessBuilder pb = new ProcessBuilder(execStr); pb.redirectErrorStream(true);进程 p = pb.start(); BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));字符串 line2 = null; while ((line2 = in.readLine()) != null) System.out.println("--->"+line2); if (p.waitFor() == 0) 【参考方案1】:

我不懂 Java(除了一点点,我对 FFmpeg 有经验)但我认为你应该这样编写代码:

String[] execStr = "/usr/local/bin/ffmpeg", "-i", "rtmp://127.0.0.1:1935/live/mytest", "live=1", "timeout=2", "-f", "image2", "-vframes", "1", "/snaps/tt.jpg";
ProcessBuilder pb = new ProcessBuilder(execStr);

或者像这样:

String[] execStr = "/usr/local/bin/ffmpeg", "-i", "\"rtmp://127.0.0.1:1935/live/mytest live=1 timeout=2\"", "-f", "image2", "-vframes", "1", "/snaps/tt.jpg";
ProcessBuilder pb = new ProcessBuilder(execStr);

我从这里检查过: https://docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html

【讨论】:

我确实尝试过。你提到了每个参数之间的空格,是的,我试过了,但没有运气。这里提到了同样的问题:***.com/questions/22909434/… 我将不得不为此工作,但以下是错误 rtmp 发送的错误。 NetStrea.Play.StreamNotFound。不存在这样的目录(当我们使用引号时)。发现连接关闭时标头无效(当我们不使用 live=1 时表示流是实时的)

以上是关于FFMPEG RTMP 在 Ubuntu 14.0.4 上的 red5pro 模块中不起作用的主要内容,如果未能解决你的问题,请参考以下文章

Python 通过ffmpeg实现实时推流(ubuntu20.04+ffmpeg+nginx)

FFmpeg命令读取RTMP流如何设置超时时间

使用FFMPEG在windows平台下推rtmp流

命令行利用ffmpeg实现rtmp推流《转》

ffmpeg udp 直播发布到 rtmp

ffmpeg - 通过 RTMP 连续文件流式传输