Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen Revision Vorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
pub:linux-webcam [2013/06/14 11:45]
Marco Krage
pub:linux-webcam [2014/03/16 22:25] (aktuell)
Marco Krage
Zeile 1: Zeile 1:
 ====== Linux Webcam ====== ====== Linux Webcam ======
-  * fswebcam http://www.slblabs.com/2012/09/26/rpi-webcam-stream/+<del>Live Bild</del>
  
-<html> +===== Live Image =====
-<div class="repo-file" data-user="sinky" data-repo="raspberrypi-webcam"></div> +
-</html>+
  
 +  - motion saves image every 15 seconds to ''/var/www/webcam/lastsnap.jpg''
 +  - after that ''on_picture_save'' command [[http://www.lavrsen.dk/foswiki/bin/view/Motion/ConfigOptionOnPictureSave|from motion.conf]] runs ''webcam-cleanup.sh''
 +  - this script copies ''lastsnap.jpg'' to ''live.jpg'', writes a timestamp to ''/var/www/webcam/lastsnap.txt'' and sets the rights so the webserver can access ''live.jpg'' 
 +  - index.html displays the ''live.jpg'' and every 5 seconds the ''lastsnap.txt'' is fetched via ajax. If this timestamp changed, the ''live.jpg'' is reloaded with [[http://stackoverflow.com/a/1077051|cache breaker]]
  
-===== webcam.sh ===== +===== Archiving =====
-This script saves a fullsize image to /archiv named with current timestamp. At the same time a smaller image is saved to live.jpg for live view. +
-<code bash webcam.sh> +
-#!/bin/bash +
-# Aufloesungen Logitech C270 +
-# 1280 x 720 // 800 x 438 // 720 x 394 +
-SAVEPATH="/var/www/webcam" +
-TIMESTAMP="$(date "+%s")"+
  
-#Save live image and archiv +  - crontab runs ''webcam-archiv.sh'' every 15 minutes from 5 to 21 o'Clock 
-fswebcam -v --title "my-azur.de" --timestamp "%Y-%m-%d %H:%M:%S (%Z)" -S 2 -r 1280x720 ${SAVEPATH}/archiv/${TIMESTAMP}.jpg --scale 720x394 ${SAVEPATH}/live_pre.jpg+  it copys the ''live.jpg'' to the ''archiv/<current-timestamp>.jpg''
  
-#copy pre live image to real live image +===== Zeitraffer ===== 
-cp ${SAVEPATH}/live_pre.jpg ${SAVEPATH}/live.jpg+<code bash>ffmpeg -r 30 -i input%03d.jpg -codec copy output.mkv</code> 
 +Die Framerate gibt ''-r'' an. Bilder müssen fortlaufend und lückenlos im Format ''input000.jpg'' bekannt sein.
  
-#set rights 
-sudo chown www-data.users ${SAVEPATH}/archiv/${TIMESTAMP}.jpg 
-sudo chmod 774 ${SAVEPATH}/archiv/${TIMESTAMP}.jpg 
  
-#delete old archiv images, but kepp the last 1440 images +===== Sourcecode on GitHub =====
-(ls -t ${SAVEPATH}/archiv/*.jpg |head -n 1440;ls ${SAVEPATH}/archiv/*.jpg)|sort|uniq -u|xargs rm +
-</code>+
  
-===== Crontab ===== +https://github.com/sinky/raspberrypi-webcam 
-Whe webcam script runs every minute from 8am to 6pm +<html
-<code bash Crontab>* 8-18 * * * /home/pi/webcam.sh</code> +<div class="repo-filedata-user="sinkydata-repo="raspberrypi-webcam"></div>
- +
-===== index.html =====  +
-Does the browser magic  +
-<code html index.html><!DOCTYPE html> +
-<html lang="de"> +
-<head> +
-  <meta charset="utf-8" /> +
-  <title>Webcam</title> +
-  <meta name="viewport" content="width=device-width, initial-scale=1.0"> +
- <!--[if IE]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]--> +
-  <style>     +
-  img { max-width: 100%; height: auto; }   +
-  p { margin-top: 0; } +
-  .hide { display: none; }   +
-  </style> +
-</head> +
-<body>  +
-<div class="pageid="wrapper"+
-  <h1>Webcam</h1> +
-  <p>by <a href="http://my-azur.de/" target="_blank">my-azur.de</a></p> +
-  <div class="live"> +
-    <img src="live.jpg" alt="Live" title="Webcam Live" border="0" id="liveimage" /> +
-    <p><small>Automatic reload every <span id="liveReloadTime">X</span> seconds</small></p> +
-  </div>   +
-  <h2>Timeline</h2> +
-  <div id="timeline"></div> +
-</div> +
-<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> +
-<script> +
-var liveReloadTime = 5000 // reload live image every x second +
-  , count = 0 // counter for timeline +
-$(document).ready(function(){ +
-  /* = Live +
-   * ----------------------------------------------------*/ +
-  jQuery('#liveReloadTime').text(liveReloadTime/1000); +
-    +
-  setInterval(reloadLive,liveReloadTime); +
-  function reloadLive(){ // set (new) live image every x second +
-    var timestamp = new Date().getTime(); +
-    //Query('#liveimage').attr('src', 'live.jpg?'+timestamp); +
- //console.log('Live: reload: live.jpg?'+timestamp); +
- jQuery('#liveimage').attr('src', 'live.jpg'); +
-    console.log('Live: reload: live.jpg'); +
-  } +
- +
-  /* = Timeline +
-   * ----------------------------------------------------*/ +
-   +
-  $.getJSON('archiv.php?callback=?',+
-    n: '100' +
-  }, function(archiv) { +
-    console.log(archiv); +
-    addTimelineImage(archiv); // add first timeline image +
-    setInterval(function(){ addTimelineImage(archiv); },200); // on scroll add timeline image +
-  }); // END: getJSON     +
-   +
-  function addTimelineImage(archiv) { +
-     if(count < archiv.length && jQuery(window).scrollTop() + jQuery(window).height() > jQuery(document).height() - 500) { +
-         var img = jQuery('<img src="archiv/'+archiv[count]+'"/>'); +
-         jQuery('#timeline').append(img);    +
-         count++; +
-     } +
-  } +
-                               +
-}); // END jQuery.ready        +
-</script> +
-</body>+
 </html> </html>
-</code> 
- 
-===== archiv.php ===== 
-Returns a json encoded array with (n) last images of archiv/ 
-<code php archiv.php><? 
-$path = "./archiv/"; 
- 
-$dh  = opendir($path); 
-while (false !== ($filename = readdir($dh))) { 
-  if (preg_match('&\.(jpg|jpeg|gif|png)$&is', $path.$filename)) { 
-    $archiv[] = $filename; 
-  } 
-} 
-natsort($archiv); 
-$archiv = array_reverse($archiv); 
- 
-echo $_GET['callback']."(".json_encode($archiv).")"; 
-</code> 
pub/linux-webcam.1371203146.txt.gz · Zuletzt geändert: 2013/12/06 19:12 (Externe Bearbeitung)