<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="it">
	<id>https://wiki.montellug.it/index.php?action=history&amp;feed=atom&amp;title=Streaming_palio</id>
	<title>Streaming palio - Cronologia</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.montellug.it/index.php?action=history&amp;feed=atom&amp;title=Streaming_palio"/>
	<link rel="alternate" type="text/html" href="index.php?title=Streaming_palio&amp;action=history"/>
	<updated>2026-04-26T15:16:27Z</updated>
	<subtitle>Cronologia della pagina su questo sito</subtitle>
	<generator>MediaWiki 1.35.14</generator>
	<entry>
		<id>index.php?title=Streaming_palio&amp;diff=6200&amp;oldid=prev</id>
		<title>Mesfet: script per la spedizione e gestione delle immagini del palio</title>
		<link rel="alternate" type="text/html" href="index.php?title=Streaming_palio&amp;diff=6200&amp;oldid=prev"/>
		<updated>2006-09-08T16:32:56Z</updated>

		<summary type="html">&lt;p&gt;script per la spedizione e gestione delle immagini del palio&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Nuova pagina&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{msg:navmenu}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Trasmissione del Palio di Vidor in streaming =&lt;br /&gt;
&lt;br /&gt;
Di seguito sono riportati alcuni script e note per poter eseguire la trasmissione di immagini grabbate ogni tot secondi dalla videocamera o webcam, upload in FTP, gestione di una coda di immagini e riproduzione web delle immagini in sequenza.&lt;br /&gt;
&lt;br /&gt;
== Acquisizione di immagini e trasmissione in FTP ==&lt;br /&gt;
=== Acquisizione da dispositivo IEEE1394 ===&lt;br /&gt;
Le videocamere solitamente dispongono di una porta firewire per la comunicazione con un PC.&lt;br /&gt;
Utilizzando dvgrab e ncftpput è possibile inviare le immagini acquisite ogni intervallo di tempo ad un sito FTP per poterle inserire in una coda da cui saranno poi recuperate per la visualizzazione nel web.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# palio.sh&lt;br /&gt;
# Invia ogni INTERVAL secondi una immagine grabbata da firewire&lt;br /&gt;
&lt;br /&gt;
INTERVAL=10             # seconds between grabbed photos&lt;br /&gt;
# FTP server parameters&lt;br /&gt;
HOST=123.456.789.123    # FTP server hostname&lt;br /&gt;
USERNAME=xxxxxx         # user which access on the FTP server&lt;br /&gt;
PASSWORD=XXXXXX         # user's password&lt;br /&gt;
DIR=www                 # directory where the following file should be placed&lt;br /&gt;
#FILENAME=image1.jpg    # intermedio&lt;br /&gt;
FILENAME=image2.jpg     # arrivo&lt;br /&gt;
&lt;br /&gt;
cd /tmp&lt;br /&gt;
filename=&amp;quot;/tmp/image&amp;quot;&lt;br /&gt;
# killall dvgrab&lt;br /&gt;
killall -9 dvgrab 2&amp;gt;/dev/null&lt;br /&gt;
sleep 1&lt;br /&gt;
# start background grabbing every 10 seconds (--every 250)&lt;br /&gt;
dvgrab --noavc --format jpeg --jpeg-quality 50 \&lt;br /&gt;
  --jpeg-width 352 --jpeg-height 288 --jpeg-deinterlace --jpeg-overwrite \&lt;br /&gt;
  --every $(( $INTERVAL * 25 )) $filename &amp;amp;&lt;br /&gt;
&lt;br /&gt;
#main loop&lt;br /&gt;
while [ 1 ]; do&lt;br /&gt;
  if [ -f $filename.jpg ]; then&lt;br /&gt;
    # Image grabbed: wait 1 second to be sure the image file is closed&lt;br /&gt;
    sleep 1&lt;br /&gt;
    mv $filename.jpg $FILENAME&lt;br /&gt;
    # send the image to the FTP server&lt;br /&gt;
    ncftpput -u $USERNAME -p $PASSWORD $HOST $DIR $FILENAME&lt;br /&gt;
    rm $FILENAME&lt;br /&gt;
  fi&lt;br /&gt;
  sleep 1&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scripts da utilizzare nel server ==&lt;br /&gt;
=== Script che controlla le immagini da riprodurre nel web ===&lt;br /&gt;
Il seguente script organizza una coda di immagini e le visualizza, con un opportuno ritardo per consentire una approssimativa sincronizzazione fra le immagini e l'audio che verrà trasmesso mediante shoutcast o icecast.&lt;br /&gt;
&lt;br /&gt;
Le immagini vengono inoltre backuppate per utilizzi futuri.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
#! /bin/bash&lt;br /&gt;
#ftpinfilectl&lt;br /&gt;
#Controlla le immagini imageN.jpg e le rinomina in cimageN.jpg quando&lt;br /&gt;
#la loro dimensione rimane costante per 3 secondi.&lt;br /&gt;
QUEUESECONDS=80&lt;br /&gt;
IMAGEAGESECONDS=43200&lt;br /&gt;
HOMEDIR=/home/palio&lt;br /&gt;
WORKDIR=$HOMEDIR/www&lt;br /&gt;
BINDIR=$HOMEDIR/bin&lt;br /&gt;
BACKUPDIR=$WORKDIR/backup&lt;br /&gt;
QUEUEDIR=$WORKDIR/queue&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function managefile () {&lt;br /&gt;
  file=&amp;quot;image$1.jpg&amp;quot;&lt;br /&gt;
  if [ -r $file -a -s $file ]; then&lt;br /&gt;
    newsize=&amp;quot;`ls -l $file|awk '{print $5}'`&amp;quot;&lt;br /&gt;
    if [ $newsize -eq ${size[$1]} ]; then&lt;br /&gt;
#file completed?&lt;br /&gt;
      count[$1]=$(( ${count[$1]}+1 ))&lt;br /&gt;
      if [ ${count[$1]} -ge 3 ]; then&lt;br /&gt;
        # new image&lt;br /&gt;
        # backup image&lt;br /&gt;
        if [ ! -f /tmp/ftpin$1.count ]; then&lt;br /&gt;
          num=0&lt;br /&gt;
        else&lt;br /&gt;
          num=`cat /tmp/ftpin$1.count`&lt;br /&gt;
        fi&lt;br /&gt;
        num=`echo $num+0.00001|bc`&lt;br /&gt;
        echo $num &amp;gt;/tmp/ftpin$1.count&lt;br /&gt;
        basename=`echo $file|cut -d . -f 1`&lt;br /&gt;
        ext=`echo $file|cut -d . -f 2`&lt;br /&gt;
        cp $file $BACKUPDIR/$basename$num.$ext&lt;br /&gt;
        # insert image in the input queue&lt;br /&gt;
        mv $file $QUEUEDIR/$basename$num.$ext&lt;br /&gt;
         count[$1]=0&lt;br /&gt;
        size[$1]=0&lt;br /&gt;
      fi&lt;br /&gt;
    else&lt;br /&gt;
#new size differ&lt;br /&gt;
#echo &amp;quot;newsize=$newsize&amp;quot;&lt;br /&gt;
      size[$1]=$newsize&lt;br /&gt;
      count[$1]=0&lt;br /&gt;
    fi&lt;br /&gt;
  else&lt;br /&gt;
# file does not exists&lt;br /&gt;
#echo &amp;quot;file $file does not exists&amp;quot;&lt;br /&gt;
    count[$1]=0&lt;br /&gt;
    size[$1]=0&lt;br /&gt;
  fi&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function readqueue () {&lt;br /&gt;
  # read image queue and write images to cimage$1.jpg&lt;br /&gt;
  infile=&amp;quot;`ls $QUEUEDIR/image$1*.jpg 2&amp;gt;/dev/null|head -n 1`&amp;quot;&lt;br /&gt;
  if [ -n &amp;quot;$infile&amp;quot; ]; then&lt;br /&gt;
    if [ `$BINDIR/filedatecmp.tcl $infile` -ge $QUEUESECONDS ]; then&lt;br /&gt;
#echo &amp;quot;copy $infile in cimage$1.jpg&amp;quot;&lt;br /&gt;
      cp $infile $WORKDIR/cimage$1.jpg&lt;br /&gt;
      rm $infile&lt;br /&gt;
    fi&lt;br /&gt;
  fi&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function imageage () {&lt;br /&gt;
  if [ -f cimage$1.jpg ]; then&lt;br /&gt;
    if [ `$BINDIR/filedatecmp.tcl cimage$1.jpg` -ge $IMAGEAGESECONDS ]; then&lt;br /&gt;
      rm cimage$1.jpg&lt;br /&gt;
    fi&lt;br /&gt;
  fi&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
OLDDIR=&amp;quot;`pwd`&amp;quot;&lt;br /&gt;
cd $WORKDIR&lt;br /&gt;
&lt;br /&gt;
count[1]=0;count[2]=0&lt;br /&gt;
size[1]=0;size[2]=0&lt;br /&gt;
&lt;br /&gt;
while [ 1 ]; do&lt;br /&gt;
  #backup image, if any&lt;br /&gt;
  managefile 1&lt;br /&gt;
  managefile 2&lt;br /&gt;
  #show new image, if any, from the queue&lt;br /&gt;
  readqueue 1&lt;br /&gt;
  readqueue 2&lt;br /&gt;
  #if cimage* is very old, remove it&lt;br /&gt;
  imageage 1&lt;br /&gt;
  imageage 2&lt;br /&gt;
  #import sql database&lt;br /&gt;
  if [ -f $HOMEDIR/palio.sql.bz2 ]; then&lt;br /&gt;
    if [ `$BINDIR/filedatecmp.tcl $HOMEDIR/palio.sql.bz2` -ge 30 ]; then&lt;br /&gt;
      bzcat $HOMEDIR/palio.sql.bz2 |mysql -u palio --password=150673 palio&lt;br /&gt;
      rm $HOMEDIR/palio.sql.bz2&lt;br /&gt;
    fi&lt;br /&gt;
  fi&lt;br /&gt;
  sleep 1&lt;br /&gt;
done&lt;br /&gt;
cd $OLDDIR&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Il file ''ftpinfilectl'' necessita di uno script TCL aggiuntivo, ''filedatecmp.tcl'' sottoriportato, per misurare l'età di ciascuna immagine.&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
#!/usr/bin/tclsh&lt;br /&gt;
# filedatecmp.tcl&lt;br /&gt;
# syntax: $0 filename&lt;br /&gt;
# Return amount of seconds from mtime of filename and current date&lt;br /&gt;
puts [expr [clock seconds] - [file mtime [lindex $argv 0]]]&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mesfet</name></author>
	</entry>
</feed>