13
$\begingroup$

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.

$\endgroup$
4
  • 1
    $\begingroup$ 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. $\endgroup$
    – Szabolcs
    Commented Jul 9, 2015 at 13:21
  • $\begingroup$ 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. $\endgroup$
    – rcollyer
    Commented Jul 9, 2015 at 14:35
  • $\begingroup$ @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? $\endgroup$
    – mikeonly
    Commented Jul 9, 2015 at 16:45
  • $\begingroup$ 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. $\endgroup$
    – user9444
    Commented Jul 14, 2015 at 22:52

1 Answer 1

6
$\begingroup$

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"
]

enter image description here

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.