Search code examples
httpstreamingvlc

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:

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. That utilizes a whole CPU core on my server all the time.

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!


Solution

  • 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 - e.g. for Node: Execute a command line binary with 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