ffmpeg-post-generator is a powerful and flexible video generation tool that automates the creation of videos from text. It combines text overlays, images, background videos, and audio to produce engaging video content. With its template-driven approach, you can easily define the structure and style of your videos. The integrated Text-to-Speech (TTS) engine brings your text to life with high-quality narration.
The video generation process is orchestrated by the script.php file and can be broken down into the following steps:
input/input.txt and shuffles the lines to create a varied order for video generation. It also reads taglines from input/tagline.txt.template.json file is loaded to get the video settings and layer definitions.generate_and_split_narration.py to generate a single audio file containing the narration for all text layers.whisper to transcribe the generated audio and find the precise start and end times for each text segment.slide_mode is enabled, the script adjusts the timeline of the layers to accommodate the duration of the narration.background and audio directories.imagemagick is used to create PNG images with the specified text, color, and alignment.ffmpeg command is built based on the template, including:
ffmpeg command is executed to generate the final MP4 video.This project is designed to run in a Docker container, which encapsulates all the necessary dependencies. To run the generator, you will need:
The Dockerfile handles the installation of all other dependencies, including:
PHPffmpegImageMagickPython 3PyTorch with CUDA supportCoqui TTSWhisperthefuzzThe project uses a specific directory structure to organize input files, assets, and output videos.
input/: This directory contains the text files that serve as the primary input for the video generation.input/taglines/: This directory is used to store pre-generated audio files for taglines. The audio files should be in .wav format and named according to the sanitized tagline text.background/: Place your background video files in this directory. The script will randomly select a video from this folder for each generated video.audio/: This directory should contain your background audio tracks. The script will choose a random audio file for each video.logo/: Store your logo images and other static image assets in this directory.output/: The final generated videos will be saved in this directory.input/input.txtThis is the main input file for the video generator. Each line in this file will be used to generate a separate video. The script will process the lines in a random order.
Example:
This is the first video.
This is the second video.
This is the third video.
input/tagline.txtThis file contains a list of taglines that can be used in the videos. Each line represents a single tagline. The script will cycle through the taglines for each generated video.
Example:
My Awesome Channel
Subscribe for more!
You can also pre-generate audio for your taglines to save time during the video creation process. See the generate_taglines.py script for more details.
template.json FileThe template.json file is the heart of the video generator, defining the structure, styling, and behavior of the output videos.
| Setting | Description |
|---|---|
fps | The frame rate of the video (e.g., "30"). |
duration | The base duration of the video in seconds. This can be extended by the slide_mode. |
vcodec | The video codec to use (e.g., "libx265", "libx264"). |
acodec | The audio codec to use (e.g., "aac"). |
audio_bitrate | The bitrate for the audio stream (e.g., "192k"). |
slide_mode | If true, the timeline will be automatically adjusted to fit the narration length. |
audio | An object containing audio processing settings. |
meta | An object for video metadata (author, description, etc.). |
tts_translations | An object for replacing text before sending it to the TTS engine (e.g., {"-": ". "}). |
The layers array defines the visual elements of the video. Each layer is an object with the following properties:
| Setting | Description |
|---|---|
file | The source file for the layer. Can be a path to an image in the logo directory, or one of the special values: [background], [text], [tagline]. |
loop | Whether to loop the layer (for images). |
inTime | The time in seconds when the layer starts to appear. |
inDuration | The duration in seconds of the fade-in effect. |
outTime | The time in seconds when the layer starts to disappear. |
outDuration | The duration in seconds of the fade-out effect. |
narration_enable | If true, narration will be generated for this layer's text content. |
text_color | The color of the text (e.g., "white", "yellow"). |
align | The horizontal alignment of the text ("left", "center", "right"). |
x, y | The coordinates for the top-left corner of the text block. |
width, height | The maximum width and height of the text block. |
narration_voice | The TTS model to use for narration. |
narration_language | The language for the TTS model. |
narration_speaker | The speaker to use for multi-speaker TTS models. |
narration_speed | The desired speed of the narration (1.0 is normal speed). |
narration_delay | A delay in seconds before the narration starts. |
The project is designed to be run as a Docker container.
First, build the Docker image using the provided Dockerfile:
docker build -t ffmpeg-post-generator .
Once the image is built, you can run the generator using the following command. This command mounts the project directories into the container, allowing the script to access your input files and save the output to your local machine.
docker run --rm --gpus all \
-v $(pwd)/input:/app/input \
-v $(pwd)/background:/app/background \
-v $(pwd)/audio:/app/audio \
-v $(pwd)/logo:/app/logo \
-v $(pwd)/output:/app/output \
ffmpeg-post-generator
Note on the --gpus all flag: This flag enables the container to use all available NVIDIA GPUs. If you do not have an NVIDIA GPU, you can remove this flag. However, TTS generation will be significantly slower.
The project uses several Python scripts to handle specific tasks.
generate_narration.py: A script to generate a single audio file from a given text using Coqui TTS.generate_and_split_narration.py: The main script for handling narration. It takes a JSON object of narration "jobs", generates a single combined audio file, and then uses whisper to analyze the audio and determine the start and end times of each job. This is crucial for synchronizing the narration with the video layers.generate_taglines.py: A utility script to pre-generate audio files for all taglines listed in input/tagline.txt. This can save time during the main video generation process.check_speech.py: A helper script that uses whisper to detect if an audio file contains speech. This is used to ensure that background audio tracks without narration do not contain speech.test_tts.py: A simple script for testing the TTS setup and generating a sample audio file.You can customize the voice used for narration by changing the narration_voice, narration_language, and narration_speaker properties in the template.json file.
narration_voice: This should be the name of a Coqui TTS model. You can find a list of available models on the Coqui TTS website.
narration_language: This is required for some models, especially multilingual ones like xtts_v2.
narration_speaker: For multi-speaker models, you can specify the speaker ID here. To get a list of available speakers for a model, you can run the following command inside the Docker container:
tts --model_name "tts_models/en/vctk/vits" --list_speaker_idxs
The slide_mode is a powerful feature that automatically adjusts the video timeline to fit the generated narration. When slide_mode is set to true in template.json:
outTime of the current layer and shifting the inTime and outTime of all subsequent layers.This is particularly useful for creating presentation-style videos where the timing of the visuals should follow the narration.
This project is licensed under the GNU General Public License v3.0. See the LICENSE file for details.
Content type
Image
Digest
sha256:9d6aa0066…
Size
8.5 GB
Last updated
about 1 year ago
docker pull gpocali/ffmpeg-post-generator