Extract PGS Subtitles from MKV to PNG with FFmpeg
This article provides a straightforward, step-by-step guide on how to extract PGS (Presentation Graphic Stream) subtitles from an MKV video file and save them as individual, sequential PNG images using the powerful command-line tool FFmpeg. Since PGS subtitles are already image-based, FFmpeg allows you to easily demux and decode them directly into standard image files for editing, OCR (Optical Character Recognition), or archiving.
Step 1: Identify the Subtitle Stream Index
Before extracting, you need to find which stream inside your MKV file contains the PGS subtitles. Run the following command in your terminal:
ffmpeg -i input.mkvLook through the output for the “Subtitle” streams. You will see a line that looks similar to this:
Stream #0:2: Subtitle: hdmv_pgs_subtitle (default)
In this example, the subtitle stream is indexed as 0:2
(the third stream of the first input file) or subtitle index
0:s:0 (the first subtitle stream).
Step 2: Extract the PGS Subtitles as PNG Images
Once you know the stream index, use the following FFmpeg command to extract the subtitle frames into PNG images:
ffmpeg -i input.mkv -map 0:s:0 output_%04d.pngCommand Breakdown:
-i input.mkv: Specifies the input MKV video file.-map 0:s:0: Tells FFmpeg to select only the first subtitle stream. If your PGS subtitle was the second subtitle stream, you would use-map 0:s:1.output_%04d.png: Specifies the output format and naming convention. The%04dplaceholder creates sequentially numbered files padded with zeros (e.g.,output_0001.png,output_0002.png).
FFmpeg will process the file and save every individual PGS subtitle frame as a transparent PNG image in your current directory.