Skip to content

Instantly share code, notes, and snippets.

@alessaba
Created February 6, 2025 11:39
Show Gist options
  • Save alessaba/15dad31023e4b593ee817c347cfa6099 to your computer and use it in GitHub Desktop.
Save alessaba/15dad31023e4b593ee817c347cfa6099 to your computer and use it in GitHub Desktop.
Extract WWDC Titles from session videos
#!/bin/zsh
# Folder path containing the videos
folder_path="/Volumes/Alessaba/WWDC/2025"
timestamp_titolo='00:00:02'
# Extract frame from video
extract_frame() {
local video_path=$1
local image_path=$2
ffmpeg -ss $timestamp_titolo -i "$video_path" -frames:v 1 -q:v 2 "$image_path" > /dev/null
}
# Perform OCR and extract title
perform_ocr_and_extract_title() {
local image_path=$1
local text=$(tesseract "$image_path" stdout)
local title=$(echo "$text" | head -4 | tail -2) # Verificare che l'OCR corrisponda. Nel 2024 era la 4a riga
echo "$title"
}
# Process each video in the folder
for video_file in "$folder_path"/*.mp4; do
if [[ -f "$video_file" ]]; then
image_path="${video_file%.*}.png"
extract_frame "$video_file" "$image_path"
title=$(perform_ocr_and_extract_title "$image_path")
if [[ -n "$title" ]]; then
new_video_path="${folder_path}/${title}.mp4"
mv "$video_file" "$new_video_path"
fi
rm "$image_path"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment