PND4

/dev/notes

Dual-Monitor Toggle

Recently I found myself in need of a way to switch X into single-monitor mode without having to kill the running instance of X, which is fine if you don't have any unsaved work, since it crashes all programs running within X as well.

xrandr

Using xrandr[^1] we are able to dynamically modify our desktop's properties.

OFF

1
xrandr --output DVI-0 --off

ON

1
xrandr --output DVI-0 --left-of VGA-0 --auto

[^1]: Xrandr's Man Page

CLI RTMP Streaming

As of 2013, some streams require the 'ksv'/'k-s-v' patch.. Arch users can use rtmpdump-ksv instead of rtmpdump

Commands

Redirect rtmp port using iptables.

sudo iptables -t nat -A OUTPUT -p tcp --dport 1935 -j REDIRECT

Sniffing for stream parameters.

rtmpsrv

Once you've captured a stream, you can undo the redirection.

sudo iptables -t nat -D OUTPUT -p tcp --dport 1935 -j REDIRECT

Use rtmpdump like so, piping the output to mplayer/vlc

rtmpdump -q -r "rtmpe://origin.hdcast.org:1935/redirect/" -a "redirect/" -f "LNX 11,9,900,152" -W "http://www.udemy.com/static/flash/player5.9.swf" -p "http://www.hdcast.org/embedlive2.php?u=ban5&vw=640&vh=460&domain=www.btsportshd.com" -y "ban5" -b "10000" -v | mplayer -really-quiet -framedrop -

Important options

rtmpdump

  • -r [tcURL ex. "rtmp://stream.url/"]
  • -a [app ex. "redirect/"
  • -y [playpath ex. "freetv4"]
  • -v [live]
  • -b [buffersize ex. "10000"]
  • -W [swfURL ex. "http://stream.url/flash/player5.9.swf"]

mplayer

  • -really-quiet [Suppresses output.]
  • -framedrop [Helps with streams.]
  • - [Plays from stdout.]

Port redirect helper script

I wrote a bash script that takes the hard part, remembering, out of the iptables step.

#!/bin/bash

## PND4
## o1.27.13

success() {
  echo ".. success :)"
}

failure() {
  echo "-- FAILURE :("
}

add-rule() {
  sudo iptables -t nat -A OUTPUT -p tcp --dport 1935 -j REDIRECT
}

del-rule() {
  sudo iptables -t nat -D OUTPUT -p tcp --dport 1935 -j REDIRECT
}

case "$1" in
  start)
    echo "Starting.."
    # also delete rule if it exists for some reason to avoid dupes.
    # always errors out so we ignore it
    del-rule 2>/dev/null
    add-rule
    [ $? -eq 0 ] && success || failure
    ;;
  stop)
    echo "Stopping.."
    del-rule
    [ $? -eq 0 ] && success || failure
    ;;
  *)
    echo "Usage: $0 <start|stop>"
    ;;
esac

Useful Links and References

  1. rtmpsrv tutorial
  2. XBMC: hint on buffer option

Motion Webcam

Webcam Prices

[as of 11.11.2013]

  • 20-23 HD-3000
  • 15-20 Rocketfish 720p RF-HDWEB
  • 17 M$ HD-2300

RasPi Notes

RasPi community has good info on the subject. Should be valid for Pogoplugs too.

A few recommendations I have for streaming USB webcams with linux:

  1. Unless you need the capabilities of motion (that is, you are using the motion detection built in to motion) use mjpgstreamer instead of motion. Motion processes each image to see if pixels have changed, and by default runs a lot of binary morphology on the images (erode, dilate, etc), where mjpgstreamer just streams. On my Pogoplus with four cameras this means the difference between 60%+ cpu utilization versus single digits (and to get down to 60% I had to drop the framerate to 2Hz and go through a bunch of options to turn off as much processing as possible). I have another machine running zoneminder which processes my streams which is why I don't mind forgoing motion detection.

  2. Use MJPEG instead of YUV If you want multiple webcams on a single USB bus this is basically a necessity. Even if you don't it means a lot less data to process. This is the default in mjpgstreamer, in motion set: "v4l2palette 2" in motion.conf

  3. Get a webcam with known support Some webcams have a problem where the request a lot more bandwidth than they need and this means you can't use two at the same time. There is a hack to get around this in YUV mode, but not MJPEG which isn't much of a help. If you are up for hacking the driver yourself it should be possible to skip the BW check and make these work anyway, but that is quite a bit of work.

Cameras that work simultaneously (no bandwidth bug): -Logitech C120 -Logitech C160 -Logitech B500 -Logitech Quickcam E 3500 -Logitech Quickcam Messenger -Microsoft HD-3000 -Microsoft HD-5000 -Rocketfish HD Webcam Pro

Cameras that do not work in multiples (bandwidth bug?): -Logitech C110 -Logitech C310 -Creative Live! Cam Video IM Ultra -HP 2-Megapixel Webcam (RZ406AA)

My current recommendation is probably the HD-3000. It is 720p and can be found for about $20. It does NOT have autofocus which I think is good for a webcam you leave running 24/7. I tried the HD-5000 and it spends a lot of time refocusing. I'm afraid it would break after a few weeks. The C160 is currently the cheapest, about $8 shipped on ebay. Meritline sometimes sells it for $6. The irritating thing about the c120/c160 is that they have a focusing ring you have to adjust. For a security camera I would prefer fixed focus. I buy any webcam I can get at a firesale so I'll keep trying more - I would appreciate results from anyone else as well.

EDIT: Added a few more cameras]

It turns out you can disable autofocus on UVC supported webcams like this:

v4l2-ctl –verbose –set-ctrl=focus_auto=0

At least it works for me on all the AF cameras I have to test (Microsoft & Rocketfish).

Not only is this a good idea for camera longevity (I would think so at least) it helps prevents false motion alarms.

Useful Links and References

  1. eLinux: RasPi Webcam compatibility list