When adding subtitles and setting their language with ffmpeg, follow these steps:
Step 1: Prepare the Subtitle File
First, ensure you have a subtitle file, typically in .srt format or another format supported by ffmpeg. For example, consider a subtitle file named subtitle.srt.
Step 2: Add Subtitles Using ffmpeg
To embed subtitles into the video using ffmpeg, use the following command:
bashffmpeg -i input_video.mp4 -vf subtitles=subtitle.srt output_video.mp4
Here, -i input_video.mp4 specifies the input video file, subtitles=subtitle.srt specifies the subtitle file, and output_video.mp4 is the output video name.
Step 3: Set Subtitle Language
To set the subtitle language, use the -metadata:s:s:0 language=eng parameter (English is used as an example here). The full command is:
bashffmpeg -i input_video.mp4 -vf subtitles=subtitle.srt -metadata:s:s:0 language=eng output_video.mp4
Here, -metadata:s:s:0 language=eng specifies the language of the first subtitle stream as English (eng). If you have multiple subtitle streams, you can specify different streams by changing the number in :s:0.
Example
Suppose we have a video file example.mp4 and a French subtitle file french_subs.srt. We want to add this subtitle to the video and set the subtitle language to French. The command is:
bashffmpeg -i example.mp4 -vf subtitles=french_subs.srt -metadata:s:s:0 language=fra output_with_subs.mp4
This command adds french_subs.srt subtitles to example.mp4 and sets the subtitle language to French (fra), with the output file named output_with_subs.mp4.
By following this method, you can easily add and configure subtitle languages for videos using ffmpeg. This is highly beneficial for creating multilingual video content, as it enhances accessibility and viewer understanding.