Skip to content

Instantly share code, notes, and snippets.

@panchicore
Last active March 8, 2025 18:14
Show Gist options
  • Save panchicore/2491da0b4f43e0fbb048d14023616b9f to your computer and use it in GitHub Desktop.
Save panchicore/2491da0b4f43e0fbb048d14023616b9f to your computer and use it in GitHub Desktop.
very basic veed.io on my mac

Video Creator Script

A simple bash script to convert audio files to videos with subtitles and a static image.

Requirements

  • ffmpeg
  • whisper (OpenAI's Whisper speech recognition system)

Quick Start

  1. Place your files in the working directory:

    • audio.wav - Your audio file
    • image.png - Background image
  2. Make the script executable:

    chmod +x create_video.sh
  3. Run the script:

    ./create_video.sh --transcribe

Parameters

Parameter Description Default
--test Create a 20-second preview false
--opacity N Background opacity (0-100) 50
--fontsize N Subtitle font size 24
--lang CODE Language code (en, es, fr, etc.) en
--hd Generate 1080p video instead of 720p false
--transcribe Generate subtitles from audio false
--model SIZE Whisper model (tiny, base, small, medium, large) base
--help Show help -

Examples

Basic Usage

Transcribe audio and create a test video:

./create_video.sh --transcribe --test

Standard Video

Create a complete video with Spanish subtitles and 70% opacity:

./create_video.sh --transcribe --lang es --opacity 70

Advanced Configuration

Create a high-definition video with large, accurate subtitles:

./create_video.sh --transcribe --model large --hd --fontsize 32 --lang es --opacity 80

Output Files

  • subtitle_[lang].srt - Generated subtitles
  • output_video.mp4 - Standard video (720p)
  • output_video_hd.mp4 - HD video (1080p)
  • output_video_test.mp4 - Test video (first 20 seconds)

Notes

  • Transcription may take time, especially with larger models
  • For better results with non-English audio, specify the language with --lang
  • Use --test first to check subtitle appearance
#!/bin/bash
# create_video.sh - Script para crear video con subtítulos desde audio e imagen
# Uso: ./create_video.sh [opciones]
#
# Opciones:
# --test Crear video de prueba (solo 20 segundos)
# --opacity N Opacidad del fondo (0-100, default: 50)
# --fontsize N Tamaño de fuente (default: 24)
# --lang CODE Código de idioma (default: en)
# --hd Generar video HD (1080p)
# --transcribe Transcribir audio usando Whisper
# --model SIZE Tamaño del modelo Whisper (tiny, base, small, medium, large; default: base)
# --help Muestra esta ayuda
# Valores por defecto
TEST_MODE=false
OPACITY=50
FONT_SIZE=24
LANGUAGE="en"
HD_MODE=false
TRANSCRIBE=false
MODEL_SIZE="base"
OUTPUT_FILE="output_video.mp4"
# Manejo de argumentos
while [[ $# -gt 0 ]]; do
case $1 in
--test)
TEST_MODE=true
shift
;;
--opacity)
OPACITY=$2
shift 2
;;
--fontsize)
FONT_SIZE=$2
shift 2
;;
--lang)
LANGUAGE=$2
shift 2
;;
--hd)
HD_MODE=true
shift
;;
--transcribe)
TRANSCRIBE=true
shift
;;
--model)
MODEL_SIZE=$2
shift 2
;;
--help)
echo "Uso: ./create_video.sh [opciones]"
echo ""
echo "Opciones:"
echo " --test Crear video de prueba (solo 20 segundos)"
echo " --opacity N Opacidad del fondo (0-100, default: 50)"
echo " --fontsize N Tamaño de fuente (default: 24)"
echo " --lang CODE Código de idioma (default: en)"
echo " --hd Generar video HD (1080p)"
echo " --transcribe Transcribir audio usando Whisper"
echo " --model SIZE Tamaño del modelo Whisper (tiny, base, small, medium, large; default: base)"
echo " --help Muestra esta ayuda"
exit 0
;;
*)
echo "Opción desconocida: $1"
echo "Usa --help para ver las opciones disponibles"
exit 1
;;
esac
done
# Verificar archivos necesarios
if [ ! -f "audio.wav" ]; then
echo "Error: No se encuentra el archivo audio.wav"
exit 1
fi
if [ ! -f "image.png" ]; then
echo "Error: No se encuentra el archivo image.png"
exit 1
fi
SUBTITLE_FILE="subtitle_${LANGUAGE}.srt"
# Transcribir audio si se solicita
if [ "$TRANSCRIBE" = true ]; then
echo "Transcribiendo audio con Whisper (modelo: $MODEL_SIZE, idioma: $LANGUAGE)..."
# Verificar si Whisper está instalado
if ! command -v whisper &> /dev/null; then
echo "Error: Whisper no está instalado. Instálalo con: pip install openai-whisper"
exit 1
fi
# Comando para transcribir con Whisper
WHISPER_CMD="whisper audio.wav --model $MODEL_SIZE --output_dir . --output_format srt"
# Añadir opción de idioma si no es "en" (inglés)
if [ "$LANGUAGE" != "en" ]; then
WHISPER_CMD="$WHISPER_CMD --language $LANGUAGE"
fi
echo "Ejecutando: $WHISPER_CMD"
eval $WHISPER_CMD
# Renombrar el archivo generado al formato esperado
if [ -f "audio.srt" ]; then
mv audio.srt $SUBTITLE_FILE
echo "Subtítulos creados y renombrados a $SUBTITLE_FILE"
else
echo "Error: No se generó el archivo de subtítulos"
exit 1
fi
fi
# Verificar si existe el archivo de subtítulos
if [ ! -f "$SUBTITLE_FILE" ]; then
echo "Error: No se encuentra el archivo $SUBTITLE_FILE"
echo "Usa la opción --transcribe para generarlo automáticamente"
exit 1
fi
# Convertir opacidad de porcentaje (0-100) a formato hexadecimal (00-FF)
HEX_OPACITY=$(printf '%02X' $(( 255 * OPACITY / 100 )))
BACK_COLOR="&H${HEX_OPACITY}000000"
# Configuración de resolución según modo HD
if [ "$HD_MODE" = true ]; then
RESOLUTION="1920:1080"
CRF="18"
PRESET="slow"
AUDIO_BITRATE="192k"
OUTPUT_FILE="output_video_hd.mp4"
else
RESOLUTION="1280:720"
CRF="23"
PRESET="medium"
AUDIO_BITRATE="128k"
fi
# Añadir sufijo al archivo si es modo test
if [ "$TEST_MODE" = true ]; then
OUTPUT_FILE="${OUTPUT_FILE%.*}_test.mp4"
fi
# Comando base de ffmpeg
FFMPEG_CMD="ffmpeg -y -loop 1 -i image.png -i audio.wav"
# Añadir opción de tiempo limitado para modo test
if [ "$TEST_MODE" = true ]; then
FFMPEG_CMD="$FFMPEG_CMD -t 20"
fi
# Completar el comando con filtros y opciones de codificación
FFMPEG_CMD="$FFMPEG_CMD -vf \"scale=$RESOLUTION,subtitles=$SUBTITLE_FILE:force_style='FontName=Arial,FontSize=$FONT_SIZE,PrimaryColour=&HFFFFFF,OutlineColour=&H000000,BackColour=$BACK_COLOR,BorderStyle=4,Outline=2,Shadow=0,Alignment=10,MarginV=0'\" -c:v libx264 -tune stillimage -crf $CRF -preset $PRESET -c:a aac -b:a $AUDIO_BITRATE -shortest $OUTPUT_FILE"
echo "Creando video con los siguientes parámetros:"
echo "- Modo prueba: $TEST_MODE"
echo "- Opacidad del fondo: $OPACITY%"
echo "- Tamaño de fuente: $FONT_SIZE"
echo "- Idioma de subtítulos: $LANGUAGE"
echo "- Modo HD: $HD_MODE"
echo "- Archivo de salida: $OUTPUT_FILE"
echo ""
echo "Ejecutando comando:"
echo $FFMPEG_CMD
echo ""
# Ejecutar el comando (usando eval debido a las comillas dentro del comando)
eval $FFMPEG_CMD
# Verificar resultado
if [ $? -eq 0 ]; then
echo "¡Video creado exitosamente!"
echo "Archivo: $OUTPUT_FILE"
else
echo "Error al crear el video. Verifica que ffmpeg esté instalado correctamente."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment