Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Still a work in progress!
- # Pseudocode:
- # Go to the folder NIH2018_Data/Video
- # for s from 1 to 5:
- # Enter the folder /Session + s + /
- # for every file ending with the .MP4 extension
- # Split the file name by "_" and store the first string in a var called name
- # if name starts with "p0"
- # cd to /Users/$USER/Desktop/ExtractedVidFrames/Banneker/Session$s/$name
- # else if name starts with "p1"
- # cd to /Users/$USER/Desktop/ExtractedVidFrames/JFK/Session$s/$name
- # else
- # cd to /Users/$USER/Desktop/ExtractedVidFrames/Unknown/Session$s/$name
- #
- # for every subfolder:
- # check if "training.txt" exists in the folder and store bool in var called "filtered"
- # if filtered is false:
- # run Filtering program to filter the newly created frames (thus saving space)
- # echo Re-filtered $fileName!
- # else
- # echo $fileName is already filtered
- # echo Done with Session $s!
- # Note: this script requires the following programs to be installed and aliased:
- # ffmpeg as ffmpeg
- # ffprobe as ffprobe
- # c# as dotnet
- pathToAllVids="/Volumes/My Passport/Dropbox (MIT)/NIH2018_Data/Video"
- pathToFilterPrgm="/Users/$USER/Desktop/Yaseen script files/Filtering/"
- pathToExtractedVids="/Volumes/My Passport/ExtractedVidFrames"
- continue=true
- cd "$pathToAllVids"
- #this is needed for the fileName for-loop
- shopt -s nullglob
- for s in `seq 1 5`;
- do
- if [ "$continue" = true ] ; then
- cd "$pathToAllVids/Session$s/"
- for fileName in *.mp4 *.MP4; do
- #split name and store into #splitName:
- OIFS=$sFS
- IFS='_' read -r -a splitName <<< "$fileName"
- IFS=$OIFS
- #store first element into $name:
- name=${splitName[0]}
- frameDir=""
- if [[ $name == p0* ]]; then
- cd "$pathToExtractedVids"/Banneker/Session$s/$name/
- frameDir="$pathToExtractedVids/Banneker/Session$s/$name"
- elif [[ $name == p1* ]]; then
- cd "$pathToExtractedVids"/JFK/Session$s/$name/
- frameDir="$pathToExtractedVids/JFK/Session$s/$name"
- else
- cd "$pathToExtractedVids"/Unknown/Session$s/$name/
- frameDir="$pathToExtractedVids/Unknown/Session$s/$name"
- fi
- duration=$(ffprobe -v error -select_streams v:0 -show_entries stream=duration -of default=noprint_wrappers=1:nokey=1 "$pathToAllVids/Session$s/$fileName")
- #cd "$pathToFilterPrgm"
- for d in */ ; do
- #echo "$frameDir/$d"
- if [ ! -f $frameDir/$d/library.txt ]; then
- count=$(ls $frameDir/$d/*.bmp | wc -l)
- if (( $(echo "$count < 900" | bc -l) )); then
- if (( $(echo "$duration >= 300.0" | bc -l) )); then
- startTime=0
- durationTime=0
- if (( $(echo "$duration > 420.0" | bc -l) )); then
- startTime=120.0
- durationTime=300.0
- elif (( $(echo "$duration > 300.0" | bc -l) )); then
- startTime=$(echo "($duration - 300.0)/2" | bc -l)
- durationTime=300.0
- else
- startTime=0
- durationTime=$duration
- fi
- echo $frameDir/$d has not been filtered, is at least 5 min in length, and has $count bmp files \(needs 900\)
- ffmpeg -ss $startTime -i "$pathToAllVids/Session$s/$fileName" -t $durationTime -vf fps=3,scale=iw/2:ih/2 "$frameDir/frame%05d.bmp" -hide_banner
- echo Done processing $fileName!
- #echo "$pathToAllVids/Session$s/$fileName"
- fi
- fi
- else
- clear
- #echo "There is a training.txt file in $frameDir/$d so we're good."
- #$fileName is already filtered
- fi
- done
- done
- echo Done with all the videos in Session $s!
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement