使用 FFmpeg 從藍光碟 M2TS 影片中提取 SUP 字幕

jinzesudawei發表於2024-04-21

1. 在 Windows 中安裝 FFmpeg 解碼器

https://www.gyan.dev/ffmpeg/builds/

winget install "FFmpeg (Essentials Build)"

2. 檢視影片資訊詳情

ffmpeg -i Werckmeister.Harmonies.2000.CC.1080p.BluRay.x265.10bit.FLAC.1.0-SONYHD.m2ts

例如本影片有5條字幕(簡中英 / 繁中英 / 簡中 / 繁中 / 英)

  Stream #0:0: Video: hevc (Main 10), yuv420p10le(tv), 1780x1080, SAR 1:1 DAR 89:54, 23.98 fps, 23.98 tbr, 1k tbn (default)
      Metadata:
        BPS             : 10351521
        DURATION        : 02:26:46.465000000
        NUMBER_OF_FRAMES: 211144
        NUMBER_OF_BYTES : 11395038795
        _STATISTICS_WRITING_APP: mkvmerge v73.0.0 ('25 or 6 to 4') 64-bit
        _STATISTICS_WRITING_DATE_UTC: 2024-04-15 05:28:34
        _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
  Stream #0:1(hun): Audio: flac, 48000 Hz, mono, s16 (default)
      Metadata:
        title           : Hungarian
        BPS             : 280047
        DURATION        : 02:26:46.464000000
        NUMBER_OF_FRAMES: 103201
        NUMBER_OF_BYTES : 308278018
        _STATISTICS_WRITING_APP: mkvmerge v73.0.0 ('25 or 6 to 4') 64-bit
        _STATISTICS_WRITING_DATE_UTC: 2024-04-15 05:28:34
        _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
  Stream #0:2(chi): Subtitle: hdmv_pgs_subtitle (pgssub), 1920x1080 (default)
      Metadata:
        title           : chs&eng
        BPS             : 21668
        DURATION        : 02:16:48.075000000
        NUMBER_OF_FRAMES: 1622
        NUMBER_OF_BYTES : 22232545
        SOURCE_ID       : 001201
        _STATISTICS_WRITING_APP: mkvmerge v73.0.0 ('25 or 6 to 4') 64-bit
        _STATISTICS_WRITING_DATE_UTC: 2024-04-15 05:28:34
        _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES SOURCE_ID
  Stream #0:3(chi): Subtitle: hdmv_pgs_subtitle (pgssub), 1920x1080
      Metadata:
        title           : cht&eng
        BPS             : 21760
        DURATION        : 02:16:48.075000000
        NUMBER_OF_FRAMES: 1622
        NUMBER_OF_BYTES : 22326274
        SOURCE_ID       : 001202
        _STATISTICS_WRITING_APP: mkvmerge v73.0.0 ('25 or 6 to 4') 64-bit
        _STATISTICS_WRITING_DATE_UTC: 2024-04-15 05:28:34
        _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES SOURCE_ID
  Stream #0:4(chi): Subtitle: hdmv_pgs_subtitle (pgssub), 1920x1080
      Metadata:
        title           : chs
        BPS             : 12173
        DURATION        : 02:16:48.075000000
        NUMBER_OF_FRAMES: 1622
        NUMBER_OF_BYTES : 12490564
        SOURCE_ID       : 001203
        _STATISTICS_WRITING_APP: mkvmerge v73.0.0 ('25 or 6 to 4') 64-bit
        _STATISTICS_WRITING_DATE_UTC: 2024-04-15 05:28:34
        _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES SOURCE_ID
  Stream #0:5(chi): Subtitle: hdmv_pgs_subtitle (pgssub), 1920x1080
      Metadata:
        title           : cht
        BPS             : 12265
        DURATION        : 02:16:48.075000000
        NUMBER_OF_FRAMES: 1622
        NUMBER_OF_BYTES : 12584392
        SOURCE_ID       : 001204
        _STATISTICS_WRITING_APP: mkvmerge v73.0.0 ('25 or 6 to 4') 64-bit
        _STATISTICS_WRITING_DATE_UTC: 2024-04-15 05:28:34
        _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES SOURCE_ID
  Stream #0:6(eng): Subtitle: hdmv_pgs_subtitle (pgssub)
      Metadata:
        title           : eng
        BPS             : 15036
        DURATION        : 02:24:17.191000000
        NUMBER_OF_FRAMES: 1564
        NUMBER_OF_BYTES : 16271639
        SOURCE_ID       : 001200
        _STATISTICS_WRITING_APP: mkvmerge v73.0.0 ('25 or 6 to 4') 64-bit
        _STATISTICS_WRITING_DATE_UTC: 2024-04-15 05:28:34
        _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES SOURCE_ID
  Stream #0:7: Video: mjpeg (Baseline), yuvj444p(pc, bt470bg/unknown/unknown), 640x360 [SAR 100:100 DAR 16:9], 90k tbr, 90k tbn (attached pic)
      Metadata:
        filename        : cover.jpg
        mimetype        : image/jpeg

3. 進行字幕提取

ffmpeg -i Werckmeister.Harmonies.2000.CC.1080p.BluRay.x265.10bit.FLAC.1.0-SONYHD.m2ts -map 0:s:0 -c copy Subtitle_chs_eng.sup
ffmpeg -i Werckmeister.Harmonies.2000.CC.1080p.BluRay.x265.10bit.FLAC.1.0-SONYHD.m2ts -map 0:s:1 -c copy Subtitle_cht_eng.sup
ffmpeg -i Werckmeister.Harmonies.2000.CC.1080p.BluRay.x265.10bit.FLAC.1.0-SONYHD.m2ts -map 0:s:2 -c copy Subtitle_chs.sup
ffmpeg -i Werckmeister.Harmonies.2000.CC.1080p.BluRay.x265.10bit.FLAC.1.0-SONYHD.m2ts -map 0:s:3 -c copy Subtitle_cht.sup
ffmpeg -i Werckmeister.Harmonies.2000.CC.1080p.BluRay.x265.10bit.FLAC.1.0-SONYHD.m2ts -map 0:s:4 -c copy Subtitle_eng.sup

參考資料

https://ffmpeg.org/
https://stackoverflow.com/a/72415890

相關文章