8

I've been trying to figure out how to extract hdmv pgs subtitles from an mkv file for a few days now. I must be doing something wrong. I'm a noob at this. Can someone please help? I think i need to set an encoder or set a codec parameter to fix the issue.

this is the subtitle I'm trying to rip

Stream #0:4(eng): Subtitle: hdmv_pgs_subtitle (default)
    Metadata:
      title           : Signs / Songs
      BPS-eng         : 7215
      DURATION-eng    : 00:22:43.946000000
      NUMBER_OF_FRAMES-eng: 96
      NUMBER_OF_BYTES-eng: 1230263
      _STATISTICS_WRITING_APP-eng: mkvmerge v28.0.0 ('Voice In My Head') 64-bit
      _STATISTICS_WRITING_DATE_UTC-eng: 2018-10-22 23:45:00
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES

and the ffmpeg command i'm using is

ffmpeg -i "FILE PATH".mvk -map 0:4 "FILE PATH".srt

I've also tried

ffmpeg -i "FILE PATH".mkv -map 0:4 pgssub "FILE PATH".srt

ffmpeg -i "FILE PATH".mkv -map 0:4 hdmv_pgs_Subtitles "FILE PATH".srt

along with a few other variations and always get an error.

  • Subtitle encoding currently only possible from text to text or bitmap to bitmap
  • Unable to find a suitable output format for 'hdmv_pgs_subtitle'
  • Unsupported subtitles codec: dvd_subtitle
  • Could not find codec parameters for stream 4 (Subtitle: hdmv_pgs_subtitle (pgssub)): unspecified size Consider increasing the value for the 'analyzeduration' and 'probesize' options
  • Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
  • or the srt file it creates is 0kb.

Can someone please tell me what i'm doing wrong and show me the correct code to use. I'm on a mac and i've also tried using MKVToolNix and get a weird binary file that doesn't work cause it's probably in the wrong format.

breezybrea
  • 81
  • 1
  • 1
  • 2
  • Try posting it on [Super User](https://superuser.com/) – Rohit Gupta Apr 03 '23 at 01:55
  • Or maybe [Video Production](https://video.stackexchange.com/). You will find plenty of [ffmpeg related questions](https://video.stackexchange.com/questions/tagged/ffmpeg) there. – Marcuse7 Jul 17 '23 at 16:42

2 Answers2

11

My understanding is that PGS is bitmap subtitles. In other words, it’s a bunch of pictures showing the subtitles that are simply placed on top of the video upon display.

Meanwhile, SRT is text subtitles: it is a plain text file that contains the text of each subtitle line and the times when the line is to be displayed.

To convert images to text, you need some sort of OCR (optical character recognition) software. FFmpeg does not support OCR, as far as I’m aware.

A brief search on the Web tells me that Subtitle Edit can extract PGS from MKV, run it through OCR and save the result as SRT. There are some guides for this on the Web, but if you have further questions, they are probably better suited for Super User.

Chortos-2
  • 995
  • 7
  • 20
5

To extract just the subtitle stream to a file using ffmpeg, this command seems to do the trick:

ffmpeg -i video.mkv -map 0:s -c copy subtitles.sup

The .sup extension is accepted by my ffmpeg (v5.0) to extract these subtitles without error.

Then you can use Chortos-2's answer, with a compatible OCR program to convert it to text subtitles.

Totor
  • 1,148
  • 1
  • 10
  • 21