Handling Motion JPEG video streams with pharo smalltalk
Saturday, April 13, 2013
Playing around with Zinc’s streaming entities I looked for a source of streaming data. A never ending streaming source are video streams. So I implemented a very simple Motion JPEG reader using Pharo Smalltalk. It does not use any plugins. Just plain smalltalk and a stock pharo image.
Use your pharos monticello browser to add the following repository and open it.
MCHttpRepository location: 'http://www.min.at/prinz/repo/mjpeg' user: '' password: ''
Update:
Some people have reported hat they cannot load the package into their image. Opening a monticello browser, adding a new http repository with +Repository and pasting the code snippet above and then opening the repository works as expected. Alternatively you can download the package using this link and open it from a local directory repository.
Update 2:
As noted by Sven Van Caekenberghe the mime type for .mcz monticello archives is now set to application/x-monticello in the webserver response. So now there should not be any format errors. Thanks for this hint.
Update 3:
Cédrick Béler modified the source to work under Pharo 7. Thanks for that. The new version can be found in the repo.
It consists of just one class Mjpeg.
| cam | " Create a new MJPEG stream from a given url " cam := Mjpeg fromUrl: 'http://218.219.210.174:86/mjpg/video.mjpg?camera=1'. " Start reading the stream and displaying it in a window " cam start. " Start capturing the stream frame by frame to disk " cam startCapture: 'c:/temp/test'. " Returns true if the stream is started (reading or " " capturing), false otherwise " cam isRunning. " Stop reading the stream and close the camera window " cam stop. " Stop capturing " cam stopCapture.
There are two example class methods availabe.
" Sample of a webcam stream from Tokyo " Mjpeg exampleTokyo. " Webcam from Vienna " Mjpeg exampleVienna.
Performance of this simple implementation is quite good. The Tokyo example used the stream available at http://218.219.210.174:86/mjpg/video.mjpg?camera=1. Playing this stream with Pharo has no impact on CPU usage whereas playing the same stream with Chrome has a noticeable effect on CPU usage.