This repository has been archived by the owner. It is now read-only.
Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
cuttlefish-code-nature/split_set.sh
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
62 lines (55 sloc)
1.48 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Splits a cuttlefish dataset in subsets based on the chunktimes file in | |
# that folder. | |
# Copies all files for the times and writes new chunktimes files. | |
# | |
# usage: split_set.sh [--setsize count] <inputfolder> | |
# | |
# splits with a default set size of 50 | |
# | |
# Author: Friedrich Kretschmer <friedrich.kretschmer@brain.mpg.de> | |
# (C) Copyright 2017 Max-Planck Institute for Brain Research | |
setsize=50 | |
for i in "$@" | |
do | |
case $i in | |
--setsize=*) | |
setsize="${i#*=}" | |
shift | |
;; | |
*) | |
input=$i | |
shift | |
;; | |
esac | |
done | |
if [[ -z ${input+x} ]]; then | |
echo "input directory must be specified" | |
exit 1 | |
fi | |
inputdir=${input%.*} | |
inputdir=${inputdir%/} #remove trailing slash | |
chunktimes=$(find $inputdir/*.chunktimes -printf "%f") | |
basename="${chunktimes%.*}" | |
chunktimes="$inputdir/$chunktimes" | |
setidx=1 | |
timeidx=1 | |
targetdir="${inputdir}_set$setidx" | |
mkdir -p $targetdir | |
echo $targetdir | |
if [[ -f $chunktimes ]]; then | |
while read -r start end video_start start_secs end_secs; do | |
chunk="$inputdir/$basename-$start-$end.*" | |
echo $start $end $video_start $start_secs $end_secs >> "$targetdir/$basename.chunktimes" | |
cp $chunk $targetdir | |
if [ $timeidx == $setsize ]; then | |
setidx=$((setidx+1)) | |
timeidx=1 | |
targetdir="${inputdir}_set$setidx" | |
mkdir -p $targetdir | |
else | |
timeidx=$((timeidx+1)) | |
fi | |
done < $chunktimes | |
fi |