A powerful Python web application that automatically translates English video subtitles to Persian (Farsi) and burns them directly into your videos with precise timing and formatting. Perfect for content creators, educators, and video enthusiasts who want Persian subtitles in a snap.
- Automatic Speech Recognition: Uses OpenAI's Whisper model (medium) for high-accuracy transcription.
- English β Persian Translation: Powered by Google Translate API.
- SRT Subtitle Generation: Proper timing and formatting guaranteed.
- Subtitle Burning: Embed subtitles into videos via FFmpeg.
- User-Friendly Web Interface: Upload, manage, and track your videos easily.
- Queue System: Handle multiple video translations efficiently.
- Real-Time Status Updates: Monitor processing status live.
- Automatic Cleanup: Temporary files removed to save storage.
- Formal-to-Casual Persian Conversion: Natural and fluent translations.
- Custom Persian Text Normalization: Improves readability and accuracy.
Component | Technology |
---|---|
Backend | Flask (Python) |
Speech-to-Text | OpenAI Whisper (medium) |
Translation | Google Translator API |
Video Processing | FFmpeg |
Text Processing | Custom Persian text normalizer |
Concurrency | Python Threading |
- Python 3.8+
- FFmpeg (must be in system PATH)
- Whisper dependencies (
openai/whisper
)
# Clone the repository
git clone https://github.com/yourusername/persian-video-translator.git
cd persian-video-translator
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Create necessary directories
mkdir -p Videos output process_status config Converted_Videos logs SRT black_list fonts
# Create config file
echo '{}' > config/config.json
# Start the application
python app.py
- Access the web interface at http://localhost:5000
- Upload your video files (MP4 recommended)
- Click Start Processing
- Download processed videos when ready
persian-video-translator/
βββ app.py # Main Flask application
βββ main.py # Core processing pipeline
βββ extract_from_video.py # Audio extraction and transcription
βββ Translator.py # Translation module
βββ Generate_srt.py # SRT file generation
βββ burn_srt.py # Subtitle burning with FFmpeg
βββ Regex.py # Persian text normalization
βββ config/ # Configuration files
βββ Videos/ # Uploaded videos storage
βββ output/ # Processed videos output
βββ process_status/ # Processing status files
βββ templates/ # Flask templates
βββ requirements.txt # Python dependencies
Edit config/config.json
to customize paths and behavior:
{
"video_path": "path/to/input/video",
"converted_audio_dir": "Converted_Videos",
"logs_dir": "logs",
"logs_filename": "logs.json",
"translated_segments_filename": "translated_segments.json",
"blacklist_dir": "black_list",
"blacklist_filename": "black_list.json",
"srt_output_dir": "SRT",
"srt_suffix": "_translated.srt",
"srt_path": "SRT/output_translated.srt",
"output_video_path": "output/output_translated.mp4",
"formal_2_casual": "formal2casual_dataset/formal_to_casual_dict.json"
}
- Video Upload: User uploads video via web interface
- Audio Extraction: Extract audio track using MoviePy
- Speech Recognition: Transcribe audio using Whisper
- Translation: Translate English text to Persian
- Text Normalization: Apply Persian formatting rules
- SRT Generation: Create subtitle file with proper timing
- Subtitle Burning: Burn subtitles into video with FFmpeg
- Cleanup: Remove temporary files
- Download: Processed video available for download
Method | Endpoint | Description |
---|---|---|
POST | / |
Upload video files |
POST | /start_processing |
Start processing queue |
GET | /status |
Get processing status |
GET | /check_file/<filename> |
Check if file is ready |
GET | /download/<filename> |
Download processed video |
POST | /delete/<filename> |
Delete uploaded file |
- Processing time depends on video length and hardware
- Medium Whisper model balances accuracy & speed
- Recommended max video length: 30 minutes
- Queue system prevents resource overutilization
- Long videos may timeout during processing
- Some special characters may not render perfectly
- Complex English sentences may not translate ideally
MIT License Β© 2025
- OpenAI for Whisper model
- Google for translation services
- FFmpeg for video processing
- Persian NLP community for text normalization rules