This is an automatic translation generated by artificial intelligence. May contain errors.
Automatic video generation with FFmpeg
Video editing can be a long, repetitive, and error-prone process when working with large volumes of material. To make this work easier and standardize audiovisual production, at OfiLibre we have developed a series of scripts that allow the automated generation of videos from YAML configurations. These scripts are designed to be easily adaptable to different contexts: from educational videos to interviews or institutional presentations.
In this guide we present three practical approaches, depending on the type of content you need to edit.
What is FFmpeg?
FFmpeg is a free and open-source software tool that allows you to record, convert, stream, and process audio and video files. Its name comes from Fast Forward Moving Picture Experts Group, referring to the group that developed the MPEG standards.
History
The FFmpeg project was started in 2000 by Fabrice Bellard and has been maintained and improved by an active community of developers. Since its inception, it has become an essential tool for any multimedia-related task, especially in automated or non-graphical environments.
Platforms
FFmpeg is cross-platform: it works on Linux, Windows, macOS, and other UNIX-like systems. It is also used as an internal engine in many video editing applications, streaming platforms, and online services.
How to use FFmpeg?
Installation:
- Linux:
sudo apt install ffmpeg
- macOS:
brew install ffmpeg
- Windows: Download from https://ffmpeg.org/ and add to PATH during installation or use Chocolatey via
choco install ffmpeg
The tool is run from the command line. Its general syntax is:
ffmpeg -i input.ext options output.ext
For example:
ffmpeg -i video.mp4 -vf "scale=1280:720" -c:v libx264 output_720p.mp4
This command takes video.mp4, resizes it to 1280x720 pixels, and encodes it in H.264.
Basic FFmpeg concepts
Here are some key concepts for working with FFmpeg:
- Inputs and outputs (-i)
Each command requires at least one input file (-i) and, generally, an output file.
ffmpeg -i input.mp4 output.avi
- Video filters (-vf) and audio filters (-af)
You can apply transformations with filters:
# Scale resolution
-vf "scale=1280:720"
# Adjust volume
-af "volume=2.0"
- Trimming videos
# Trim the first 10 seconds
ffmpeg -ss 10 -i input.mp4 -c copy output.mp4
# Extract only a 30-second segment starting at second 60
ffmpeg -ss 60 -t 30 -i input.mp4 -c copy clip.mp4
- Concatenation
To join videos without re-encoding:
# Create a file with the list
echo "file 'part1.mp4'" > list.txt
echo "file 'part2.mp4'" >> list.txt
# Concatenate
ffmpeg -f concat -safe 0 -i list.txt -c copy output.mp4
- Transitions and effects (more advanced)
FFmpeg also allows complex effects such as transitions (xfade), audio mixes (acrossfade), overlay, etc. Example of a transition between two videos:
ffmpeg -i video1.mp4 -i video2.mp4 -filter_complex \
"[0][1]xfade=transition=fade:duration=1:offset=5" \
-c:v libx264 output.mp4
Script implementation
1. General script for concatenating images and videos
This script allows you to define in a config.yml
file a list of elements (images or videos), indicating their durations, volume adjustments, trims, etc. Each element is processed individually in a temporary directory and then concatenated precisely, keeping audio and video synchronized.
Use cases:
- Generate a video from multiple slides + clips.
- Prepare informational pills with multiple blocks.
- Stylize visual resources without the need for graphic editing software.
Advantages:
- Full control over resolution, FPS, and encoding.
- Handling of video trims (start and end).
- Individual volume management per segment.
Code
You can find the code and all the details in this repository, specifically in the folder /automatizacion/video-generator/
.
2. Simple script: cover image + main video
This script is designed for very common cases: when we want a still image (for example, with title, authorship, or institutional logos) to be displayed during the first few seconds of the video. Afterwards, the main video begins.
Use cases:
- Courses and open subjects.
- Presentations or conferences.
- Static intros before a recorded video.
Technical details:
- The image is converted into a 5-second video.
- Both files are concatenated without recompressing the content, which speeds up the process and avoids quality loss.
- Uses
mpegts
encoding to ensure correct concatenation.
Code
You can find the code and all the details in this repository, specifically in the folder /automatizacion/videos-asignaturas-abierto/
.
3. Complete script for Cafés con OfiLibre
This is the most elaborate of the three. It is designed for editing the videos belonging to our series Cafés con OfiLibre. The final edit combines several segments:
- Institutional intro (short video with music)
- Still image with the meeting details
- Main video, recorded raw
- Closing institutional (another video)
Highlighted features:
- Use of
xfade
andacrossfade
for smooth transitions between blocks. - Optional trimming of the main video (start and end).
- Volume adjustments for each segment.
- Consistent quality standard (720p, 44.1kHz audio, etc.).
The complete script is generated from a YAML configuration (config.yml
) where the path to each element and the necessary durations/adjustments are defined. Transitions are made with precision, maintaining synchronization between image and sound, resulting in a professional and cohesive final product.
Code
You can find the code and all the details in this repository, specifically in the folder /automatizacion/edicion-cafes/
.
Conclusion
Automating video editing not only saves time: it also ensures that all produced content follows the same quality and style standards. These scripts, supported by ffmpeg
and yq
, are free, adaptable, and easy to integrate into any command-line-based workflow.
If you use these resources in your projects, don’t hesitate to share your experience or propose improvements. We continue building free, accessible, and useful tools for everyone!