iccsa-21-wind

Wind Simulation Using High-Frequency Velocity Component Measurements
git clone https://git.igankevich.com/iccsa-21-wind.git
Log | Files | Refs

extract-frames (1563B)


      1 #!/bin/sh
      2 
      3 cleanup() {
      4     if ! test "$viewer_pid" = 0
      5     then
      6         kill "$viewer_pid"
      7         exit
      8     fi
      9 }
     10 
     11 filename="$1"
     12 # https://superuser.com/questions/650291/how-to-get-video-duration-in-seconds
     13 duration=$(ffprobe -v error -select_streams v:0 -show_entries stream=duration -of default=noprint_wrappers=1:nokey=1 "$filename")
     14 # https://stackoverflow.com/questions/1842634/parse-date-in-bash
     15 date=$(basename "$filename" | sed -rne 's/VID_([0-9]{4})([0-9]{2})([0-9]{2})_([0-9]{2})([0-9]{2})([0-9]{2}).*/\1-\2-\3 \4:\5:\6/p')
     16 echo $date
     17 timestamp=$(date --date="$date" "+%s")
     18 echo $timestamp
     19 tmp=$timestamp
     20 mkdir -p $tmp
     21 # https://stackoverflow.com/questions/50099869/ffmpeg-output-images-filename-with-time-position
     22 for t in $(seq 0 $duration)
     23 do
     24     if test -f $tmp/frame-$t.png
     25     then
     26         continue
     27     fi
     28     ffmpeg -hide_banner -loglevel error -y -ss $t -i "$filename" -vframes 1 $tmp/frame-$t.png
     29     echo "Extracting [$t/$duration]"
     30 done
     31 viewer=0
     32 viewer_pid=0
     33 for t in $(seq 0 $duration)
     34 do
     35     cp $tmp/frame-$t.png $tmp/frame.png
     36     if test "$viewer" = 0
     37     then
     38         sxiv $tmp/frame.png &
     39         viewer_pid=$!
     40         trap cleanup SIGINT
     41         viewer=1
     42     fi
     43     read -p "Velocity [$t/$duration]: " velocity
     44     velocity=$(echo "$velocity" | sed -rne 's/([0-9])([0-9]{2})/\1.\2/p')
     45     current_timestamp=$(expr $timestamp + $t)
     46     echo "$current_timestamp $velocity" | tee -a $timestamp.dat
     47 done
     48 kill $viewer_pid
     49 rm -rf --one-file-system $tmp
     50 #ffmpeg -i ../VID_20210417_083317.mp4 -vf "select=not(mod(n\,30))" -vsync vfr img_%d.png