简体   繁体   English

按需转码摄像机流

[英]Transcoding camera stream on demand

I am using VLC to transcode the rtsp stream from an IP camera to a http mjpg stream via the following command:我正在使用 VLC 通过以下命令将 rtsp 流从 IP 摄像机转码为 http mjpg 流:

cvlc -vvv -Idummy -q rtsp://user:password@hostname:554 --sout '#transcode{vcodec=MJPG,venc=ffmpeg{strict=1}}:standard{access=http{mime=multipart/x-mixed-replace;boundary=--7b3cc56e5f51db803f790dad720ed50a},mux=mpjpeg,dst=:8081/}'

This works fine.这工作正常。

I do not need to transcode the stream all the time but only a fraction of it.我不需要一直对流进行转码,而只需要对其中的一小部分进行转码。 VLC is transcoding even if no client is connected.即使没有连接客户端,VLC 也在转码。 That utilizes a whole CPU core on my server all the time.这一直在我的服务器上使用整个 CPU 内核。

Is there any possibility to start transcoding only if at least one client is connected and stop transcoding if the last client is disconnected?是否有可能仅在至少一个客户端连接时开始转码并在最后一个客户端断开连接时停止转码?

Thank you very much!非常感谢!

I think you are asking if you can run the command line command above from your server - if so, then it does depend on the server and language, but in general yes, you can.我想您是在问是否可以从您的服务器运行上面的命令行命令 - 如果可以,那么它确实取决于服务器和语言,但通常可以。

Your server logic would be something like:您的服务器逻辑将类似于:

When a client connects:当客户端连接时:

  • if this is the first client, run the command to start the transcoding如果这是第一个客户端,运行命令开始转码
  • provide the link to the stream to the client向客户端提供流的链接

When a client disconnects:当客户端断开连接时:

  • if this is the last client, stop the transcoding如果这是最后一个客户端,则停止转码

There will be a delay for the first client as the stream is buffered, but I am guessing you know that already.由于流被缓冲,第一个客户端会有延迟,但我猜你已经知道了。

The way to run the command will depend on the sever, but you can usually find examples - eg for Node: Execute a command line binary with Node.js运行命令的方式取决于服务器,但您通常可以找到示例 - 例如对于 Node:使用 Node.js 执行命令行二进制文件

If you are using Java, there is a very well know and useful article on running cmd line from Java also - even if you are not using Java it is good reading: https://www.javaworld.com/article/2071275/core-java/when-runtime-exec---won-t.html如果您使用的是 Java,还有一篇关于从 Java 运行 cmd 行的众所周知且有用的文章 - 即使您不使用 Java,这也是一个很好的阅读: https : //www.javaworld.com/article/2071275/core -java/when-runtime-exec---won-t.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM