Skip to content

Instantly share code, notes, and snippets.

@joe-scotto
Last active October 6, 2023 00:18
Show Gist options
  • Save joe-scotto/d7082e9283e2476a6b8d6be027f41313 to your computer and use it in GitHub Desktop.
Save joe-scotto/d7082e9283e2476a6b8d6be027f41313 to your computer and use it in GitHub Desktop.
A script for checking if clips are VFR or not. Requires ffmpeg and ZSH to work.
#!/bin/zsh
# set -euxo
# Text modifiers
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
YELLOW='\033[1;33m'
NC='\033[0m'
BOLD=$(tput bold)
REGULAR=$(tput sgr0)
# Make directory for today
today=`date +%d%m%y`
mkdir -p /tmp/vfr-info/$today
# Totals
vfr_clips=0
cfr_clips=0
vfr_clip_names=""
cfr_clip_names=""
output_log=""
total_clips=0
check_clip () {
echo "${NC}${BOLD}Checking ${YELLOW}$1${NC}...${REGULAR}"
timestamp=`date +%s`
tmp_filename="${timestamp}_${1%.*}"
tmp=/tmp/vfr-info/$today/$tmp_filename
total_clips=$((total_clips+1))
sleep 1
ffmpeg -i $1 -vf vfrdet -an -f null - 2>&1 | >> $tmp
item=`cat $tmp | grep Parsed | cut -d "]" -f 2`
vfr_frames=`cat $tmp | grep Parsed | cut -d "]" -f 2 | cut -d "(" -f 2 | cut -d "/" -f 1`
cfr_frames=`cat $tmp | grep Parsed | cut -d "]" -f 2 | cut -d "(" -f 2 | cut -d "/" -f 2 | cut -d ")" -f 1`
max_delay=`cat $tmp | grep Parsed | cut -d " " -f 11`
all_frames=$vfr_frames+$cfr_frames
# Other metadata
fps=`cat $tmp | grep sensorFPS | cut -d ":" -f 2 | head -n 1`
if [ -z "$fps" ]; then
fps=""
else
fps=" ${BLUE}fps:${fps}"
fi
# Check if clip is VFR or CFR
if [ $vfr_frames = "0" ]; then
# Clip is CFR
cfr_clips=$((cfr_clips+1))
if [[ $cfr_clip_names == "" ]]; then
cfr_clip_names+="$1"
else
cfr_clip_names+=", $1"
fi
echo ${GREEN}$1\(${YELLOW}$((all_frames))${GREEN}\):${NC}$item"\n${REGULAR}"
# Log clip
output_log+="$1($((all_frames))):$item\n"
else
# Clip is VFR
vfr_clips=$((vfr_clips+1))
if [[ $vfr_clip_names == "" ]]; then
vfr_clip_names+="$1"
else
vfr_clip_names+=", $1"
fi
echo ${RED}$1\(${YELLOW}$((all_frames))${RED}\):${NC}$item ${CYAN}${BOLD}"Estimated desync: $((max_delay*vfr_frames))ms\n${REGULAR}"
# Log clip
output_log+="$1($((all_frames))):}$item Estimated desync: $((max_delay*vfr_frames))ms\n"
fi
}
# Run script
if [ $# -eq 0 ]; then
# echo "Getting VFR info for all files in current directory..."
setopt CSH_NULL_GLOB
# Loop through all clips in current directory
for i in *.mov *.mp4 *.MOV *.MP4;
do
check_clip $i
done
else
# echo "Getting VFR info for ${YELLOW}$1"
check_clip $1 "no"
fi
echo "${GREEN}${BOLD}Total CFR clips: ${REGULAR}${cfr_clips}/${total_clips} (${cfr_clip_names})"
echo "${RED}${BOLD}Total VFR clips: ${REGULAR}${vfr_clips}/${total_clips} (${vfr_clip_names})"
[ -e vfr-info.log ] && rm vfr-info.log
echo $output_log >> vfr-info.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment