Skip to content

Instantly share code, notes, and snippets.

@victorespigares
Created January 18, 2026 22:43
Show Gist options
  • Select an option

  • Save victorespigares/cf8d3f099ac90f8dd295a9d2858a400d to your computer and use it in GitHub Desktop.

Select an option

Save victorespigares/cf8d3f099ac90f8dd295a9d2858a400d to your computer and use it in GitHub Desktop.
Transcript video shell script. Use chunks for longer videos and local faster-wisper. Co-authored with Claude.
#!/usr/bin/env bash
set -euo pipefail
if [ $# -lt 1 ]; then
echo "Uso: $0 ruta/al/video.mp4"
exit 1
fi
VIDEO_PATH="$1"
if [ ! -f "$VIDEO_PATH" ]; then
echo "Archivo no encontrado: $VIDEO_PATH"
exit 1
fi
BASENAME="$(basename "$VIDEO_PATH" .mp4)"
OUT_DIR="$(pwd)/salida_${BASENAME}"
mkdir -p "$OUT_DIR"
AUDIO_PATH="${OUT_DIR}/${BASENAME}.wav"
FINAL_OUTPUT="${OUT_DIR}/${BASENAME}_transcripcion_completa.txt"
echo "=== 1) Extrayendo audio con ffmpeg ==="
ffmpeg -y -i "$VIDEO_PATH" -ac 1 -ar 16000 "$AUDIO_PATH"
echo "=== 2) Dividiendo audio en chunks de 10 minutos ==="
CHUNK_DURATION=600 # 10 minutos en segundos
ffmpeg -i "$AUDIO_PATH" -f segment -segment_time $CHUNK_DURATION -c copy "${OUT_DIR}/chunk_%03d.wav"
echo "=== 3) Transcribiendo cada chunk ==="
rm -f "$FINAL_OUTPUT" # Limpia output anterior
for chunk in "${OUT_DIR}"/chunk_*.wav; do
chunk_name=$(basename "$chunk" .wav)
echo "Procesando $chunk_name..."
faster-whisper "$chunk" \
--model_size_or_path large-v2 \
--language es \
--device cpu \
--compute_type int8 \
--cpu_threads 4 \
-o "${OUT_DIR}/${chunk_name}.txt"
# Añadir al archivo final
if [ -f "${OUT_DIR}/${chunk_name}.txt" ]; then
cat "${OUT_DIR}/${chunk_name}.txt" >> "$FINAL_OUTPUT"
echo "" >> "$FINAL_OUTPUT" # Salto de línea entre chunks
fi
done
echo "=== 4) Limpiando archivos temporales ==="
rm -f "${OUT_DIR}"/chunk_*.wav
echo "=== 5) Listo ==="
echo "Transcripción completa en: $FINAL_OUTPUT"
ls -lh "$FINAL_OUTPUT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment