乐闻世界logo
搜索文章和话题

How to Set a subtitle language using ffmpeg

2个答案

1
2

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:

bash
ffmpeg -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:

bash
ffmpeg -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:

bash
ffmpeg -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.

2024年6月29日 12:07 回复

When using ffmpeg to process video files, setting subtitle language is a common requirement. This can be achieved by adding or modifying the metadata of the subtitle stream. Below are the specific steps and examples:

Step 1: Identify the subtitle streams in the video

First, determine which subtitle streams are present in the video and their indices. This can be viewed using the following command:

bash
ffmpeg -i input_video.mkv

The output displays information about all streams, including video, audio, and subtitle streams. Note down the index of the subtitle stream you wish to set the language for.

Step 2: Set the subtitle language

By using the -metadata option, you can set the language for a specific stream. Assume the subtitle stream index is 0:s:0, and we want to set it to Chinese (language code chi). The following command achieves this:

bash
ffmpeg -i input_video.mkv -map 0 -c copy -metadata:s:s:0 language=chi output_video.mkv

The command is explained as follows:

  • -i input_video.mkv:Specify the input file.
  • -map 0:Select all streams.
  • -c copy:Use copy mode to avoid re-encoding, preserving the original quality.
  • -metadata:s:s:0 language=chi:Set the language to Chinese for the first subtitle stream (s:s:0).
  • output_video.mkv:Specify the output filename.

Example

Assume you have a video file movie.mkv containing an English subtitle stream. To change the subtitle language to French (fre), use the following command:

bash
ffmpeg -i movie.mkv -map 0 -c copy -metadata:s:s:0 language=fre movie_french_sub.mkv

This command creates a new file movie_french_sub.mkv with the subtitle language set to French.

Summary

Setting subtitle language with ffmpeg is a straightforward process. You only need to identify the subtitle stream index and apply the appropriate -metadata option. This method preserves video and audio quality, as it does not involve re-encoding.

2024年6月29日 12:07 回复

你的答案