{"id":149,"date":"2013-03-25T01:01:24","date_gmt":"2013-03-25T01:01:24","guid":{"rendered":"http:\/\/www.nicassio.it\/daniele\/blog\/?p=149"},"modified":"2015-02-09T00:58:12","modified_gmt":"2015-02-09T00:58:12","slug":"raspberry-pi-shotter-0-1","status":"publish","type":"post","link":"http:\/\/www.nicassio.it\/daniele\/blog\/?p=149","title":{"rendered":"Raspberry PI Shotter 0.1"},"content":{"rendered":"<p><a href=\"http:\/\/www.nicassio.it\/daniele\/blog\/wp-content\/uploads\/2013\/03\/20130325_014112.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-151\" src=\"http:\/\/www.nicassio.it\/daniele\/blog\/wp-content\/uploads\/2013\/03\/20130325_014112-300x225.jpg\" alt=\"20130325_014112\" width=\"300\" height=\"225\" srcset=\"http:\/\/www.nicassio.it\/daniele\/blog\/wp-content\/uploads\/2013\/03\/20130325_014112-300x225.jpg 300w, http:\/\/www.nicassio.it\/daniele\/blog\/wp-content\/uploads\/2013\/03\/20130325_014112-1024x768.jpg 1024w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nThe Shotter is one of my first project I used the Raspberry for, and the idea is very simple: using a Raspberry PI and a webcam to take a photo every\u00a0<em>n<\/em> seconds, and eventually mounting a video from the taken frames.<\/p>\n<p>I made this with one of my PIs, and i configured it to automatically start taking the photos when I plug a usb drive, and to save the photos directly to the key. If you want to stop it, you just unplug the usb key or switch off the power. The photos are saved with an alphabetical friendly format, that is a increasing number padded with zeros: &#8216;00000001.jpg&#8217;, &#8216;00000002.jpg&#8217;, &#8230; This makes easy to make the final video, for example with <em>mencoder:\u00a0<\/em><\/p>\n<blockquote><p>mencoder &#8220;mf:\/\/*.jpg&#8221; -mf fps=10 -o test.avi -ovc lavc -lavcopts vcodec=msmpeg4v2:vbitrate=800<\/p><\/blockquote>\n<p>The photos have a small size, about 70-80KB, so that a 1Gb usb key can handle <strong>more than one\u00a0day\u00a0<\/strong>of photos taken every 10 seconds.<\/p>\n<p>I also added a led to the PI, which it&#8217;s blinking when the PI is waiting for the timeout to expire, just to say that everything is working fine (it&#8217;s been very useful while debugging).<\/p>\n<p>Here are some videos I made with my shotter:<\/p>\n<p><iframe loading=\"lazy\" src=\"http:\/\/www.youtube.com\/embed\/-1cCl-4LHKw\" width=\"420\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><br \/>\n<iframe loading=\"lazy\" src=\"http:\/\/www.youtube.com\/embed\/Rd1aIelD3_E\" width=\"420\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p>I think it&#8217;s great for taking photos during a party (I did it but I won&#8217;t publish the video here \ud83d\ude42 )<\/p>\n<p>Here&#8217;s a stupid python code to do the job (launched by a usbmount script, see <a href=\"http:\/\/www.nicassio.it\/daniele\/blog\/?p=114\" target=\"_blank\">this other post<\/a>\u00a0where I explain something more about usbmount or just search the Internet)<\/p>\n<p>&nbsp;<\/p>\n<pre>import sys\r\nimport time\r\nimport os\r\nimport RPi.GPIO as GPIO\r\n\r\nGPIO.setmode(GPIO.BOARD)\r\nGPIO.setup(22,GPIO.OUT)\r\n\r\ndef getIndex():\r\n    try:\r\n        f = open('\/home\/pi\/shotter_service\/index', 'r')\r\n        text = f.read()\r\n        f.close()\r\n        index = int(text)\r\n    except:\r\n        index = 0\r\n        setIndex(0)\r\n    return index\r\n\r\ndef setIndex(index):\r\n    f = open('\/home\/pi\/shotter_service\/index', 'w')\r\n    f.write(str(index))\r\n    f.close()\r\n\r\ndef padding(what, length):\r\n    what = str(what)\r\n    for i in range(length - len(what)):\r\n        what = \"0\" + what\r\n    return what\r\n\r\ndev = 0\r\nsecs = 10\r\nversion = \"0.1\"\r\nindex = getIndex()\r\n\r\nstate = False\r\n\r\nif len(sys.argv) &gt; 1:\r\n  dev = int(sys.argv[1])\r\n\r\nif len(sys.argv) &gt; 2:\r\n  secs = int(sys.argv[2])\r\nwhile True:\r\n  setIndex(index+1)\r\n  print \"Current Index is \" + str(index)\r\n  os.system(\"fswebcam -r 640x480 -S 15 --subtitle \"Daniele Nicassio's Projects\" --banner-colour 80000000 --line-colour 00FFFFFF --title \"Raspberry PI Shotter \"+version+\"\" --info \"http:\/\/www.nicassio.it\/daniele\/blog\" --no-timestamp --jpeg 95 -d \/dev\/video\"+str(dev) + \" --save \/media\/usb0\/\"\"+padding(index, 10)+\".jpg\"\")\r\n  os.system(\"sync\")\r\n  index += 1\r\n  for i in range(secs):\r\n    state = not state\r\n    GPIO.output(22, state)\r\n    time.sleep(1)<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Shotter is one of my first project I used the Raspberry for, and the idea is very simple: using a Raspberry PI and a webcam to take a photo every\u00a0n seconds, and eventually mounting a video from the taken frames. I made this with one of my PIs, and i configured it to automatically &hellip; <a href=\"http:\/\/www.nicassio.it\/daniele\/blog\/?p=149\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Raspberry PI Shotter 0.1<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[9],"tags":[],"_links":{"self":[{"href":"http:\/\/www.nicassio.it\/daniele\/blog\/index.php?rest_route=\/wp\/v2\/posts\/149"}],"collection":[{"href":"http:\/\/www.nicassio.it\/daniele\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.nicassio.it\/daniele\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.nicassio.it\/daniele\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.nicassio.it\/daniele\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=149"}],"version-history":[{"count":2,"href":"http:\/\/www.nicassio.it\/daniele\/blog\/index.php?rest_route=\/wp\/v2\/posts\/149\/revisions"}],"predecessor-version":[{"id":391,"href":"http:\/\/www.nicassio.it\/daniele\/blog\/index.php?rest_route=\/wp\/v2\/posts\/149\/revisions\/391"}],"wp:attachment":[{"href":"http:\/\/www.nicassio.it\/daniele\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=149"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.nicassio.it\/daniele\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=149"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.nicassio.it\/daniele\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=149"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}