Navigace

Complete guide to make video from photo in linux

Take a photo, send to web by curl

#mount -t tmpfs -o size=200m tmpfs /home/pi/ram
path="/mnt/ram/"
cd $path

time=$(date +%Y%m%d%H%M%S)
#echo $time

# time=$(date +%Y%m%d%H%M%S)

# for ((i=0; i<=12; i++))
# do
    # gphoto2 --capture-image-and-download --set-config exposurecompensation=$i --filename $time-expos-$i-.jpg
    # curl --form "fileupload=@$time-expos-$i-.jpg" http://fileupload.example.com/
# done

# for ((i=1; i<=53; i++))
# do
    # gphoto2 --capture-image-and-download --set-config aperture=$i --filename $time-apert-$i-.jpg
    # curl --form "fileupload=@$time-apert-$i-.jpg" http://fileupload.example.com/
# done

# for ((i=3; i<=75; i++))
# do
    # gphoto2 --capture-image-and-download --set-config shutterspeed=$i --filename $time-shutt-$i-.jpg
    # curl --form "fileupload=@$time-shutt-$i-.jpg" http://fileupload.example.com/
# done

gphoto2 --capture-image-and-download --set-config shutterspeed=3 --filename $time.jpg

while :
do
  curl --form "fileupload=@$time.jpg" http://fileupload.example.com/
  ret=$?
  #echo $ret >> log.txt
  if [ "$ret" -eq "0" ]; then
    #ls -la $time.jpg >> log.txt
    break;
  else
    echo "$time.jpg - upload error" >> log.txt
    #break;
    sleep 450 # wait 4 connection
  fi
done
rm $time.jpg
# jpeg2hdrgen $time-3.jpg $time-4.jpg $time-5.jpg $time-6.jpg $time-7.jpg > _dsc.hdrgen

Import picture in PHP script

<?php
$allowedExts = array("gif", "jpeg", "jpg", "png", "txt");
$temp = explode(".", $_FILES["fileupload"]["name"]);
$extension = end($temp);
// print '<pre>';
//print_r($extension);
// print_r($_FILES);
// print '</pre>';
if (in_array($extension, $allowedExts))
  {
  // echo "1";
  if ($_FILES["fileupload"]["error"] > 0)
    {
	// echo "2";
    // echo "Return Code: " . $_FILES["fileupload"]["error"] . "<br>";
    }
  else
    {
	// echo "3";
    // echo "Upload: " . $_FILES["fileupload"]["name"] . "<br>";
    // echo "Type: " . $_FILES["fileupload"]["type"] . "<br>";
    // echo "Size: " . ($_FILES["fileupload"]["size"] / 1024) . " kB<br>";
    // echo "Temp file: " . $_FILES["fileupload"]["tmp_name"] . "<br>";

    if (file_exists("upload/" . $_FILES["fileupload"]["name"]))
      {
      // echo $_FILES["fileupload"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["fileupload"]["tmp_name"],
      "upload/" . $_FILES["fileupload"]["name"]);
      // echo "Stored in: " . "upload/" . $_FILES["fileupload"]["name"];
	  echo "1";
      }
    }
  }
else
  {
  echo "Invalid file";
  }
?>

Rename files + add time label into picture

#!/bin/bash
echo "File in $1 sort to  directory $1_sorted (symbolic links). Output film $1.avi"
echo "avconv -r 25 -i $1_sorted/%09d.jpg -c:v libx264 ${1%?}.avi"
echo "(C)Continue / (E)Exit"

while :
do
    read -t 1 -n 1 key
    if [[ $key = c ]]
    then
        break
    fi
    if [[ $key = e ]]
    then
		echo "--- Exit ---"
        exit
    fi
done
x=1;
echo "--- Continue ---"
mkdir $1_sorted
rm $1_sorted/*
for f in $1/*.jpg; do

  year=`echo ${f##*/} | awk '{print substr($0, length($0)-17, 4)}'`;
  month=`echo ${f##*/} | awk '{print substr($0, length($0)-13, 2)}'`;
  day=`echo ${f##*/} | awk '{print substr($0, length($0)-11, 2)}'`;
  hour=`echo ${f##*/} | awk '{print substr($0, length($0)-9, 2)}'`;
  minute=`echo ${f##*/} | awk '{print substr($0, length($0)-7, 2)}'`;
  second=`echo ${f##*/} | awk '{print substr($0, length($0)-5, 2)}'`;
  #echo $f;  echo $year/$month/$day $hour:$minute $second;
  #ln $f $1_sorted/`printf %09d $x`.jpg;
  #cp $f $1_sorted/`printf %09d $x`.jpg;

 # apt-get install libavcodec-extra-53
 # avconv -codecs | grep "264"
  convert $f -gravity SouthEast -pointsize 40 -fill white -annotate +30+30 "$year/$month/$day $hour:$minute $second" $1_sorted/`printf %09d $x`.jpg 
  let "x+=1"; 
done
avconv -r 25 -i $1_sorted/%09d.jpg -c:v libx264 ${1%?}.avi
echo "--- Done ---"

crontab -e

* 3-22 * * * /mnt/ram/cap.sh
* 3-22 * * * sleep 15 && /mnt/ram/cap.sh
* 3-22 * * * sleep 30 && /mnt/ram/cap.sh
* 3-22 * * * sleep 45 && /mnt/ram/cap.sh

nano /etc/rc.local

...
cp /home/pi/garden/cap.sh /mnt/ram/

exit 0

nano /etc/fstab

tmpfs /mnt/ram tmpfs defaults,noatime,mode=1777,nosuid,size=200M 0 0