# How to connect to a video stream?

Is there a way to get a current frame from video streams (especially from RTSP streams)?

I would like to connect to a camera in my local network and get a snapshot from it to do some further analysis as I would do with ImageCapture[] or CurrentImage[] normally.

Thanks.

• In theory this might (or might not) work: check VLC (in partcular cvlc) documentation on how to send decoded output to a pipe. Create a named pipe (if you're on a Unix-like system), and pipe the output in there. Use Mathematica's BinaryRead or related functions to read frames one by one. Mathematica has no builtin functionality to read from video streams. This is what'd I look into first if I really had to do this, but honestly, it's a long shot. – Szabolcs Jul 9 '15 at 13:21
• There is no built-in functionality, but you can build the functionality necessary by using the stream methods introduced in v9. I have not used them, but there is a tutorial. – rcollyer Jul 9 '15 at 14:35
• @Szabolcs So I've managed to get decoded stream using VLC from the RSTP. Could you please elaborate on how to work with this stream in Mathematica? – mikeonly Jul 9 '15 at 16:45
• I use ffmpeg to stream raw data (sequential rgb int array) to TCP/IP socket and then read the data from a Java process. I process it and then do the same thing in the other direction to create a new movie. I assume you could do the same thing with Mathematica using JLink. I'm not putting this as an answer because there are too many unanswered details. It's just one possible direction. – user9444 Jul 14 '15 at 22:52

I did an implementation for capturing from an RTSP using FFMPEG (via RunProcess):

capture = CaptureFromIPCamera[
"D:\\ffmpeg\\bin\\ffmpeg.exe",
"rtsp://10.6.149.218/live.sdp"
]


You can get this function from my Prototypes paclet:

PacletInstall @ "https://github.com/arnoudbuzing/prototypes/releases/download/v0.2.9/Prototypes-0.2.9.paclet"


Or, if you prefer, you can just copy this one function from this source file:

https://github.com/arnoudbuzing/prototypes/blob/master/Prototypes/Image.wl#L41

The function works by simply calling the FFMPEG binary from the Wolfram Language with the right options to sample one image from an RTSP stream, and then importing that image. The implementation can probably be improved a lot, for example by directly importing from FFMPEG's standard output.