Making Switchable Subtitles for a Black Video with FFmpeg: A Comprehensive Guide
In this article, we will explore how to create switchable subtitles for a black video using FFmpeg. This technique is useful for creating videos with subtitles in different languages that can be switched on the fly in video players like QuickTime.
What are Subtitles?
Subtitles are text overlays that display dialogue or narration in a video. They are commonly used to provide captions for the hearing impaired or to translate dialogue into different languages. Subtitles can be hard-coded into a video or they can be separate files that can be switched on or off during playback.
Creating a Black Video with FFmpeg
Before we can add subtitles to a video, we need to create a black video. We can do this using the following FFmpeg command:
ffmpeg -f lavfi -i color=c=black:s=1920x1080 -t 60 black_video.mp4This command creates a 60-second black video with a resolution of 1920x1080 pixels. We can adjust the duration and resolution to suit our needs.
Creating Subtitle Files with FFmpeg
Once we have our black video, we can create subtitle files using FFmpeg. Subtitle files are plain text files that contain the subtitle text along with timing information. We can create a subtitle file for each language we want to support.
Here is an example subtitle file for English:
1
00:00:00,000 --> 00:00:05,000
Welcome to our video.
2
00:00:05,000 --> 00:00:10,000
This is the first part of our video.
3
00:00:10,000 --> 00:00:15,000
In this part, we will cover the basics of FFmpeg.
We can create a subtitle file for another language, such as Spanish, using the same format:
1
00:00:00,000 --> 00:00:05,000
Bienvenido a nuestro video.
2
00:00:05,000 --> 00:00:10,000
Esta es la primera parte de nuestro video.
3
00:00:10,000 --> 00:00:15,000
En esta parte, cubriremos los conceptos básicos de FFmpeg.
Adding Subtitles to a Video with FFmpeg
Once we have our subtitle files, we can add them to our black video using FFmpeg. We can use the following command to add subtitles to our video:
ffmpeg -i black_video.mp4 -vf "subtitles=english.srt" -c:a copy black_video_english.mp4This command adds the English subtitle file to our black video and creates a new video file called black_video_english.mp4. We can repeat this command for each subtitle file we want to add to our video.
Switching Subtitles in QuickTime
Once we have our video files with subtitles, we can switch between them in QuickTime. To do this, we can open our video file in QuickTime and select the "Subtitles" menu. From there, we can select the subtitle track we want to display.
- We can create a black video using FFmpeg with the following command:
ffmpeg -f lavfi -i color=c=black:s=1920x1080 -t 60 black_video.mp4 - We can create subtitle files using FFmpeg in the following format:
1 00:00:00,000 --> 00:00:05,000 Welcome to our video. 2 00:00:05,000 --> 00:00:10,000 This is the first part of our video. 3 00:00:10,000 --> 00:00:15,000 In this part, we will cover the basics of FFmpeg. - We can add subtitles to our black video using FFmpeg with the following command:
ffmpeg -i black_video.mp4 -vf "subtitles=english.srt" -c:a copy black_video_english.mp4 - We can switch between subtitle tracks in QuickTime by selecting the "Subtitles" menu and selecting the desired subtitle track.
References
- FFmpeg Documentation: https://ffmpeg.org/documentation.html
- QuickTime Player User Guide: https://support.apple.com/guide/quicktime-player/welcome/mac