SigDave

Site Source

Webcam Capture

04 Oct 2014

Due to Reflections Projections we deferred work on DJ Roomba till next week. In the mean time we decided to figure out the best way to capture webcam images for the food button.

Turns out FFMPEG + Video4Linux2 work really well for this.

ffmpeg -f video4linux2 -i /dev/video0 -vframes 2 test%3d.jpeg

The reason for 2 frames is for most cameras the first frame ends up being too dark (the aperture hasn’t been exposed to enough light).

We could then easily upload to twitter as follows:

from subprocess import check_call
from twython import Twython

FFMPEG_CMD = ['ffmpeg',
              '-f' ,'video4linux2',
              '-i',  '/dev/video0',
              '-vframes', '2',
              'img%3d.jpeg']

check_call(FFMPEG_CMD)

twitter = Twython(APP_KEY, APP_SECRET,
                  OAUTH_TOKEN, OAUTH_SECRET)
                  
with open('img002.jpeg', 'rb') as f:
    twitter.update_status_with_media(media=f, status="It's Working!")

Anywho, next week if the Beaglebone comes in we’ll do food button stuff. If not, we’ve got some soldering left for DJ Roomba :p

  • Marcell V.C