Extract Subtitles from Video File using FFmpeg

Extract Subtitles from Video File using FFmpeg

FFmpeg provides utilities for working with multimedia streams, including extracting embedded subtitles from video files. Saving subtitles as a separate file can be helpful when subtitles need to be edited, reused, converted, or processed independently from the original video. This tutorial explains how to extract subtitles from video file using FFmpeg.

The ffmpeg command can copy a subtitle stream from a multimedia container into an external subtitle file without re-encoding the video or audio streams.

Download a sample video containing subtitles for testing:

curl -sSo test.mp4 https://raw.githubusercontent.com/chromium/chromium/main/media/test/data/bear-1280x720-avt_subt_frag.mp4

The subtitle stream can be extracted with the following command:

ffmpeg -v error -i test.mp4 -map 0:s:0 subtitles.srt

Command breakdown:

  • ffmpeg - the command used to process multimedia files.
  • -v error - configures FFmpeg to display only error messages, hiding informational and other non-error output.
  • -i test.mp4 - specifies the input video containing the subtitle stream.
  • -map 0:s:0 - selects the first subtitle stream from the input file.
  • subtitles.srt - defines the name of the output subtitle file.

Leave a Comment

Cancel reply

Your email address will not be published.