使用 .ass 字幕和嵌入字体的 MKV 文件硬字幕

使用 .ass 字幕和嵌入字体的 MKV 文件硬字幕

该问题仅涉及 Linux 和 FreeBSD。

我有几个需要进行硬字幕处理的软字幕动漫 mkv 文件。它们都使用带有嵌入字体的 .ass 字幕。例如,其中一个文件上的 mkvinfo 显示:

+ EBML head
|+ EBML version: 1
|+ EBML read version: 1
|+ EBML maximum ID length: 4
|+ (Unknown element: EBMLMaxSizeLength; ID: 0x42f3 size: 4)
|+ Doc type: matroska
|+ Doc type version: 2
|+ Doc type read version: 2
+ Segment, size 622344259
|+ Seek head (subentries will be skipped)
|+ EbmlVoid (size: 4013)
|+ Segment information
| + Timecode scale: 1000000
| + Muxing application: libebml v1.0.0 + libmatroska v1.0.0
| + Writing application: mkvmerge v4.4.0 ('Die Wiederkehr') built on Oct 31 2010 21:52:48
| + Duration: 1384.853s (00:23:04.853)
| + Date: Sat Jun 18 05:53:42 2011 UTC
| + Segment UID: 0xb4 0x1e 0xa7 0x16 0x2e 0xe2 0x35 0x46 0x9b 0xb6 0x7c 0x35 0x18 0x69 0x84 0xc6
|+ Segment tracks
| + A track
|  + Track number: 1
|  + Track UID: 1
|  + Track type: video
|  + Lacing flag: 0
|  + MinCache: 1
|  + Codec ID: V_MPEG4/ISO/AVC
|  + CodecPrivate, length 42
|  + Default duration: 41.708ms (23.976 fps for a video track)
|  + Language: jpn
|  + Name: Cee - 10
|  + Video track
|   + Pixel width: 1280
|   + Pixel height: 720
|   + Display width: 1280
|   + Display height: 720
| + A track
|  + Track number: 2
|  + Track UID: 952275621
|  + Track type: audio
|  + Codec ID: A_AAC
|  + CodecPrivate, length 2
|  + Default duration: 21.333ms (46.875 fps for a video track)
|  + Language: jpn
|  + Name: AAC 2.0
|  + Audio track
|   + Sampling frequency: 48000
|   + Channels: 2
| + A track
|  + Track number: 3
|  + Track UID: 608595611
|  + Track type: subtitles
|  + Lacing flag: 0
|  + Codec ID: S_TEXT/ASS
|  + CodecPrivate, length 2214
|  + Name: ass
|+ EbmlVoid (size: 1120)
|+ Attachments
| + Attached
|  + File name: Helvetica CE Regular.ttf
|  + Mime type: application/x-truetype-font
|  + File data, size: 52412
|  + File UID: 3055405240
| + Attached
|  + File name: l_10646.ttf
|  + Mime type: application/x-truetype-font
|  + File data, size: 325400
|  + File UID: 1366813323
| + Attached
|  + File name: PURIB10.TTF
|  + Mime type: application/x-truetype-font
|  + File data, size: 23232
|  + File UID: 1837754524
| + Attached
|  + File name: TIMESS_.ttf
|  + Mime type: application/x-truetype-font
|  + File data, size: 253852
|  + File UID: 1030865051
| + Attached
|  + File name: aeaswfte.ttf
|  + Mime type: application/x-truetype-font
|  + File data, size: 46900
|  + File UID: 3926331521
| + Attached
|  + File name: arialbd.ttf
|  + Mime type: application/x-truetype-font
|  + File data, size: 751104
|  + File UID: 2840438428
| + Attached
|  + File name: GaramondPremrPro.otf
|  + Mime type: application/x-truetype-font
|  + File data, size: 359040
|  + File UID: 2335914165
| + Attached
|  + File name: l_10646.ttf
|  + Mime type: application/x-truetype-font
|  + File data, size: 325400
|  + File UID: 3148854668
| + Attached
|  + File name: arial.ttf
|  + Mime type: application/x-truetype-font
|  + File data, size: 772192
|  + File UID: 488371860
| + Attached
|  + File name: PURIB10.TTF
|  + Mime type: application/x-truetype-font
|  + File data, size: 23232
|  + File UID: 1014572700
| + Attached
|  + File name: PURIBI10.TTF
|  + Mime type: application/x-truetype-font
|  + File data, size: 24696
|  + File UID: 400339132
| + Attached
|  + File name: subpear.ttf
|  + Mime type: application/x-truetype-font
|  + File data, size: 75704
|  + File UID: 3123006086
| + Attached
|  + File name: Syntax.otf
|  + Mime type: application/x-truetype-font
|  + File data, size: 21700
|  + File UID: 3519688351
| + Attached
|  + File name: TIMESS__.ttf
|  + Mime type: application/x-truetype-font
|  + File data, size: 253852
|  + File UID: 2672448677
| + Attached
|  + File name: aeaswfte.ttf
|  + Mime type: application/x-truetype-font
|  + File data, size: 46900
|  + File UID: 3495655056
| + Attached
|  + File name: curswfte.ttf
|  + Mime type: application/x-truetype-font
|  + File data, size: 50696
|  + File UID: 2317778051
| + Attached
|  + File name: PURI10.TTF
|  + Mime type: application/x-truetype-font
|  + File data, size: 23492
|  + File UID: 239740086
|+ Chapters
| + EditionEntry
|  + EditionFlagHidden: 0
|  + EditionFlagDefault: 0
|  + EditionUID: 721729707
|  + ChapterAtom
|   + ChapterUID: 3979152268
|   + ChapterTimeStart: 00:00:00.000000000
|   + ChapterFlagHidden: 0
|   + ChapterFlagEnabled: 1
|   + ChapterDisplay
|    + ChapterString: EVERYONE IS GETTING HACKED
|    + ChapterLanguage: eng
|  + ChapterAtom
|   + ChapterUID: 540927916
|   + ChapterTimeStart: 00:01:11.071000000
|   + ChapterFlagHidden: 0
|   + ChapterFlagEnabled: 1
|   + ChapterDisplay
|    + ChapterString: then again
|    + ChapterLanguage: eng
|  + ChapterAtom
|   + ChapterUID: 68503466
|   + ChapterTimeStart: 00:02:40.994000000
|   + ChapterFlagHidden: 0
|   + ChapterFlagEnabled: 1
|   + ChapterDisplay
|    + ChapterString: it can't be helped.
|    + ChapterLanguage: eng
|  + ChapterAtom
|   + ChapterUID: 1400111522
|   + ChapterTimeStart: 00:14:31.954000000
|   + ChapterFlagHidden: 0
|   + ChapterFlagEnabled: 1
|   + ChapterDisplay
|    + ChapterString: ICE CREAM
|    + ChapterLanguage: eng
|  + ChapterAtom
|   + ChapterUID: 1320654241
|   + ChapterTimeStart: 00:14:46.969000000
|   + ChapterFlagHidden: 0
|   + ChapterFlagEnabled: 1
|   + ChapterDisplay
|    + ChapterString: animu
|    + ChapterLanguage: eng
|  + ChapterAtom
|   + ChapterUID: 1532255160
|   + ChapterTimeStart: 00:21:35.502000000
|   + ChapterFlagHidden: 0
|   + ChapterFlagEnabled: 1
|   + ChapterDisplay
|    + ChapterString: money never sleeps, kid!
|    + ChapterLanguage: eng
|+ EbmlVoid (size: 101)
|+ Cluster

如您所见,此 mkv 中使用了许多嵌入字体。到目前为止,我已经花了 8 个小时尝试找出如何让 mencoder 将此文件正确编码为包含视频流中使用的嵌入字体的 avi。尽管我已经使用 mkvextract 提取了字体,将它们复制到我的 ~/.fonts 目录,并使用 fc-cache -v ~/.fonts 进行字体配置,但我能得到的最好结果是让 mencoder 使用 mencoder 的默认子字体创建一个文件。

我知道一定有办法可以做到这一点。

我更希望答案只使用 cli 工具。此外,我更希望尽量避免使用 avidemux,因为它在处理 .ass subs 时容易崩溃(尽管欢迎提出任何建议)。

答案1

我很惊讶你没有尝试过 VirtualDub,它是最强大的替代方案。它在 WINE 下运行良好。

答案2

您可以使用ffmpeg将文件附加到 mkv 文件。ffmpeg 手册中的一个示例:

ffmpeg -i INPUT -attach DejaVuSans.ttf -metadata:s:2 mimetype=application/x-truetype-font out.mkv

在我看来,ffmpeg(我目前在 FreeBSD 上使用的 2.0.1 版本/usr/ports/multimedia/ffmpeg2/)是 mencoder 的一个很好的替代品。

相关内容