Last active
November 17, 2025 16:34
-
-
Save coulterpeterson/d9a0e9b410985759b5d5d06acb3970b0 to your computer and use it in GitHub Desktop.
macOS FFMPEG / Whisper AI video file to transcript script
This file contains hidden or 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 | |
| # Video to Audio Transcription Script | |
| # Converts video files to audio and transcribes using Whisper | |
| # Place this file in /usr/local/bin/video-to-transcript.sh | |
| # Usage (global): video-to-transcript.sh myvideo.mp4 | |
| # Pre-requisites: Install ffmpeg via brew, install whisper into a venv via pip like: | |
| # python3.13 -m venv whisper-env | |
| # source whisper-env/bin/activate | |
| # pip install -U openai-whisper | |
| # Create a zshrc alias `alias whisper='(source ~/whisper-env/bin/activate && whisper)'` (not required for this script, just handy) | |
| set -e # Exit on error | |
| # Check if video file is provided | |
| if [ $# -eq 0 ]; then | |
| echo "Usage: $0 <video-file>" | |
| echo "Example: $0 myvideo.mp4" | |
| exit 1 | |
| fi | |
| VIDEO_FILE="$1" | |
| # Check if video file exists | |
| if [ ! -f "$VIDEO_FILE" ]; then | |
| echo "Error: Video file '$VIDEO_FILE' not found" | |
| exit 1 | |
| fi | |
| # Check if ffmpeg is installed | |
| if ! command -v ffmpeg &> /dev/null; then | |
| echo "Error: ffmpeg is not installed" | |
| echo "Install with: brew install ffmpeg" | |
| exit 1 | |
| fi | |
| # Check if whisper virtual environment exists | |
| WHISPER_VENV="$HOME/whisper-env" | |
| if [ ! -d "$WHISPER_VENV" ]; then | |
| echo "Error: whisper virtual environment not found at $WHISPER_VENV" | |
| echo "Install with: python -m venv ~/whisper-env && source ~/whisper-env/bin/activate && pip install openai-whisper" | |
| exit 1 | |
| fi | |
| # Get the base filename without extension and the directory | |
| BASENAME=$(basename "$VIDEO_FILE") | |
| BASENAME_NO_EXT="${BASENAME%.*}" | |
| VIDEO_DIR=$(dirname "$VIDEO_FILE") | |
| # Create transcripts folder | |
| TRANSCRIPTS_DIR="${VIDEO_DIR}/${BASENAME_NO_EXT}-transcripts" | |
| mkdir -p "$TRANSCRIPTS_DIR" | |
| AUDIO_FILE="${TRANSCRIPTS_DIR}/${BASENAME_NO_EXT}.mp3" | |
| echo "Converting video to audio..." | |
| echo "Input: $VIDEO_FILE" | |
| echo "Output: $AUDIO_FILE" | |
| # Convert video to audio using ffmpeg | |
| ffmpeg -i "$VIDEO_FILE" -vn -acodec libmp3lame -q:a 2 "$AUDIO_FILE" -y | |
| if [ ! -f "$AUDIO_FILE" ]; then | |
| echo "Error: Audio conversion failed" | |
| exit 1 | |
| fi | |
| echo "Audio conversion complete!" | |
| echo "" | |
| echo "Starting transcription with Whisper..." | |
| # Activate virtual environment and run whisper with output directory | |
| source "$WHISPER_VENV/bin/activate" | |
| whisper "$AUDIO_FILE" --model turbo --output_dir "$TRANSCRIPTS_DIR" | |
| deactivate | |
| echo "" | |
| echo "Transcription complete!" | |
| echo "All files saved in: $TRANSCRIPTS_DIR" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment