A Python tool that generates videos of Quranic verses with accurate timing and syncs it with audio recitations.
- Rendering: We use
html2image(headless Chrome) to render the Arabic text. This handles complex ligatures and diacritics much better than standard Python libraries like Pillow. - Sync: The script uses word-level timing data to perfectly sync the text pagination with the audio. If timing data is missing for a verse, it falls back to a proportional time distribution.
- Video Engine: Instead of relying on
MoviePyfor the final composition (which is slow and sometimes drops audio sync), the project uses nativeFFmpegto concatenate frames and audio streams. This makes the generation process extremely fast. - Backgrounds: The tool supports applying a slow Ken Burns zoom effect to static background images, or you can pass a looping video background.
gen/
├── src/
│ ├── config.py # Handles loading the config.json file
│ ├── renderer.py # Responsible for rendering HTML to transparent PNGs
│ ├── utils.py # Helper functions for downloading audio and formatting text
│ └── video_engine.py # Handles FFmpeg and background video logic
├── assets/
│ ├── backgrounds/ # Put your background images here
│ ├── data/ # Quran text and timing JSON files
│ └── fonts/
├── main.py # The main entry point
└── config.json # Your configuration settings
This is the easiest way to generate a video without installing anything on your machine.
- Fork this repository to your own GitHub account.
- Go to the Actions tab in your fork.
- Click on "Quran Video Generator" in the left sidebar.
- Click "Run workflow" and fill in the inputs:
- Surah number (e.g.
108) - Start Ayah and End Ayah (e.g.
1and3) - Background filename — just the filename of an image in
assets/backgrounds/(e.g.background4.png)
- Surah number (e.g.
- Click the green "Run workflow" button.
- Once the workflow finishes, click on the completed run and download the video from the Artifacts section at the bottom.
- Python 3.11 or higher
- FFmpeg installed and added to your system PATH
- Google Chrome or Chromium (needed for
html2image)
-
Clone this repository:
git clone https://github.com/your-username/quran-video-generator.git cd quran-video-generator -
Create a virtual environment and activate it:
python -m venv venv # On Windows: venv\Scripts\activate # On Linux/macOS: source venv/bin/activate
-
Install the dependencies:
pip install -r requirements.txt
Option 1 — Edit config.json and run:
python main.pyOption 2 — Pass arguments directly on the command line:
python main.py --surah 1 --start 1 --end 7 --background background4.pngCLI arguments always override config.json values. The --background flag accepts either a bare filename (looks inside assets/backgrounds/ automatically) or a full path.
The output will be saved in the output/ folder.
- Word Timing Data: Sourced from the quran-align repository by @cpfair, licensed under the MIT License.