I thought I’d follow up on my post of a little while ago about the drivers for the Trendnet TV-IP400W Pan-Tilt-Zoom camera. I wrote a ruby driver for this thing, which makes it trivial to control the camera from any Ruby application. It’s just a single Ruby file, and though I’ve entertained the thought of figuring out how to pour it into a gem and publish it to the plugin repository, I’d probably only do that if there are a significant amount of people interested in using it and/or contributing to it.
As with the old Perl driver for Zoneminder (which I’ve been told doesn’t work anymore with the latest version of ZM, since the interfaces for the PTZ drivers have completely changed), this driver only controls the pan and tilt functions of the camera. Actually, you can also put it in swing mode and store or access preset positions, but none of the available functions actually do anything with the video stream. The video can simply be accessed at:
http://yourcam/image.jpg to grab a single frame of the current camera view
http://yourcam/video.cgi to get the mjpeg stream from the camera
There’s no real zoom control since the cam only has a digital zoom, which I believe is implemented in the client software only (so there’s no way to actually have it stream a zoomed image to your client).
Okay, onto the example script now. The code below demonstrates how to use all the features of the camera driver.
require 'Ip400.rb'
# substitute your host IP address or name and port number here.
# If you have turned off access control, you can simply use:
# ptz = Ip400.new("192.168.0.140")
# if your camera is accessible at a port other than 80, simply
# specify the address like this: "192.168.0.140:90"
ptz = Ip400.new("192.168.0.140", "ruby", "ybur")
# go to the home position
ptz.home
sleep 3
# pan right 3 steps
ptz.pan(3, Ip400::RIGHT)
sleep 3
# pan left 5 steps
ptz.pan(5, Ip400::LEFT)
sleep 3
# tilt up 3 steps
ptz.tilt(3, Ip400::UP)
sleep 3
# tilt down 3 steps
ptz.tilt(3, Ip400::DOWN)
sleep 3
# pan and tilt at the same time
ptz.move(4, Ip400::RIGHT, 2, Ip400::DOWN)
sleep 3
# go to 1 of the 24 preset positions
ptz.goto_preset(1)
sleep 3
# visit all preset positions with about 5 second intervals
ptz.swing_preset
sleep 20
ptz.stop_swing # stop the swing mode again
# go into continuous scan mode (scan left and right with 1 second intervals)
ptz.swing_scan
sleep 10
ptz.stop_swing # don't forget this!
# get the current absolute position of the camera
pos = ptz.abs_position
# store this position at preset 15
ptz.set_preset(pos['pan'], pos['tilt'], "myposition", 15)
These examples should get even a Ruby novice going pretty quickly, and the Ip400.rb driver class can be used in or outside of a Rails app. The camera you’re controlling can be in a different room or even in a different country.
I’m releasing it under the MIT license so it’s open for further hacking. If you end up using this code anywhere I’d love to hear from you, and I’ll release it as a real Ruby plugin if enough people show interest.
Have fun!
January 25th, 2009 on 11:06 pm
Hi peter im using TV-Ip410W camera and i cant use the cgi command /mjpeg.cfgi this is the complete cgi command http://myserver/cgi/mjpg/mjpeg.cgi can you please help me on this?
Thank You
January 25th, 2009 on 11:11 pm
The TV-IP410 has completely new firmware so I wouldn’t expect any of the TV-IP400 commands to work on the 410. I don’t have this camera so I’m afraid I can’t help you here.
October 26th, 2009 on 6:26 am
Could help me witha little information?
Here it goes: I’m trying to access the mjpeg video stream from the camera using: http://mycamIp/video.cgi, but, when I call that address on my IE, it opens a download screen asking if I want to download the video.cgi file. How can I fix it??
HOw can I see the mjpeg from this cgi??
Thanks for your help
Allan
June 10th, 2011 on 9:16 pm
Thanks for the ruby script, it was just what I was looking for.
I just bought the Trentnet IP400 on Ebay and was disappointed it didn’t have a auto pan mode. I’d like to coordinate frame capture at each of several positions. I suppose there would be several ways to do that in Ruby but this is my first Ruby experience so it may take me a while to figure it out.