2005年3月22日

讓 MPlayer 使用 TrueType 字型顯示字幕

為了一個 MPlayer 播放字幕不正常的問題,導至我整個重新安裝了一遍系統… orz

經過一次次的測試後,終於又可以開始顯示正確的字幕了。現在這台 Server 的資訊如下:

  1. based on Gentoo 2004.3 在 Gentoo 2006.0 上作法大原則不變。
  2. glibc 不使用 userlocales 設定,也就是讓 glibc 支援全部的編碼字集 新版的 glibc 不再使用 userlocales 方式設定系統所支援的編碼字集了,而且原本這一句的重點只是為了確保 MPLAYER 可在處理所指定的任何編碼字集。換句話說其實可以依個人需要支援部份編碼字集即可。
  3. 所有套件都不特別加上 USE="unicode" 設定
  4. 有使用 GOT 所提供的中文特別版 Xorg-x11 及相關套件 用不用其實已無所謂了。
  5. 有使用 xtt 及 firefly 開發的 xttmgr 套件進行字形管理 在 Gentoo 2006.0 時已全部使用系統預設管理方式。
  6. 有使用 firefly 先前釋出的字形設定檔 locale.conf
  7. 安裝 MPlayer 1.0-pre5-r5 版,相關設定參數如后
www root # emerge -pv mplayer

These are the packages that I would merge, in order:

Calculating dependencies ...done! [ebuild R ] media-video/mplayer-1.0_pre5-r5 -3dfx +3dnow +3dnowex +X +aalib +alsa (-altivec) +arts +avi +bidi -cdparanoia -debug +dga +directfb +divx4linux -doc -dvb +dvd +dvdread -edl +encode +esd -fbcon +ggi +gif +gtk -i8x0 -ipv6 -jack -joystick +jpeg +libcaca -lirc +live -lzo +mad +matroska -matrox +mmx -mmxext +mpeg -mythtv +nas +network +nls -nvidia +oggvorbis +opengl +oss +png +real +rtc -samba +sdl +sse -sse2 +svga +tga -theora +truetype +v4l +v4l2 -xanim +xinerama +xmms +xv +xvid -xvmc 0 kB

Total size of downloads: 0 kB

※2007-03-18 補充:MPlayer 1.0_rc1_r2 設定參數,這個參數會啟用 amd64codecs 套件且會啟用正體中文支援。

www ~ # emerge -pv mplayer

These are the packages that would be merged, in order:

[ebuild R ] media-video/mplayer-1.0_rc1-r2 USE="3dnow X aac aalib alsa dga directfb dts dvb dvd dvdread enca encode fbcon ggi gif gtk iconv joystick jpeg libcaca lzo mad mmx musepack nas openal opengl png real rtc sdl sse sse2 theora truetype unicode v4l v4l2 vorbis x264 xanim xinerama xv xvid xvmc (-3dfx) -3dnowext (-altivec) -amr -arts -bidi -bindist -bl -cdparanoia -cpudetection -custom-cflags -debug -doc -dv -esd -ipv6 -jack -lirc -live -livecd -matrox -mmxext -oss -samba -speex (-svga) -tga (-win32codecs)" LINGUAS="zh_TW -bg -cs -da -de -el -en -es -fr -hu -ja -ko -mk -nl -no -pl -pt_BR -ro -ru -sk -tr -uk -zh_CN" 0 kB

Total: 1 package (1 reinstall), Size of downloads: 0 kB

在其他網站上通常會告訴我們只要將 .ttf 字形檔放到 ~/.mplayer 目錄下並改名為 subfont.ttf 檔後即可讓 mplayer 正常顯示字幕,通常會使用 link 方式將系統上的字形連結過來:

ada@www ada $ ln -s /usr/share/fonts/arphicfonts/bkai00mp.ttf \
> ~/.mplayer/subfont.ttf

ada@www Shrek2-WS $ ls -al ~/.mplayer/ 總計 5 drwxr-xr-x 2 ada users 104 3月 22 11:11 . drwxr-xr-x 30 ada users 1432 3月 22 11:11 .. -rw-r--r-- 1 ada users 202 3月 22 11:11 config lrwxrwxrwx 1 ada users 41 3月 22 11:08 subfont.ttf -> /usr/share/fonts/arphicfonts/bkai00mp.ttf

另一種方式則是在執行 mplayer 時一併設定 -font 參數:

mplayer -font /usr/share/fonts/arphicfonts/bkai00mp.ttf -sub movie.srt movie.avi

不過很可惜,在我的環境上因為不明原因他不會動,錯誤訊息如下:

…
/usr/share/fonts/arphicfonts/bkai00mp.ttf doesn't look like a font description, ignoring
Cannot load font: /usr/share/fonts/arphicfonts/bkai00mp.ttf
...

從錯誤訊息中很容易讓人懷疑:是否是因為未將 truetype/freetype 支援編入 mplayer 中呢?從先前的 mplayer USES 參數中可以確定真的有將 truetype/freetype 支援編入,那麼是網站的資料有誤囉?以下是 mplayer 的 man pages 片段,看來似乎是這樣設定沒錯啊?那倒底是那邊有問題,因為今年犯太歲嗎?

man mplayer
-font <path to font.desc file> (OSD only)
 Search for the OSD/SUB fonts in an alternative directory (default for  normal
 fonts: ~/.mplayer/font/font.desc, default for FreeType fonts: ~/.mplayer/sub-
 font.ttf).
 NOTE: With FreeType, this option determines path to the text font file.
 With fontconfig, this option determines the fontconfig font name.

EXAMPLE: -font ~/.mplayer/arial-14/font.desc -font ~/.mplayer/arialuni.ttf -font 'Bitstream Vera Sans'

同樣從 mplayer 的 man pages 中看到的,似乎可以透過 fontconfig 來處理字形?

man mplayer
-fontconfig (fontconfig only)
 Enables the usage of fontconfig managed fonts.

最後死馬當活馬醫,將 -fontconfig 支援打開,改用字體名稱餵給 mplayer 試試:

mplayer -fontconfig -font 'AR PL KaitiM Big5' -sub movie.srt movie.avi

喲,可以顯示字幕了!雖然編碼似乎有點問題,不過只要額外設定一下即可正確輸出中文字:

mplayer -unicode -subcp cp950 -fontconfig \
> -font 'AR PL KaitiM Big5' -sub movie.srt movie.avi

趕快將設定寫到 ~/.mplayer/config 檔中:

# Write your default config options here!

# 開啟 fontconfig 支援 (大概吧,忘了試不設定會不會出錯) fontconfig = yes # 可以自行替換字體名稱 (我是從 gedit 中看來的) # 這是 吳聰敏 老師提供的 圓體 #font = 'cwTeXYen' # 這是大家都知道的 文鼎 楷書 #font = 'AR PL KaitiM Big5' # 簡體字形 #font = 'AR PL SungtiL GB' # 微軟字型可以這樣下 #font = 'Microsoft JhengHei' font = '微軟正黑體' # 字幕檔編碼 subcp = cp950 # 字形體編碼 subfont-encoding = unicode unicode = yes # 開啟選單支援,可是還不知道怎麼用中… menu = yes # 字幕放大方式, 見 man mplayer subfont-autoscale=3 subfont-osd-scale=3 subfont-text-scale=5

# 使用 ALSA 聲效輸出 ao = alsa # 六聲道支援 channels = 6

# 選擇 video out 順序 vo = x11,gl2,xv

# 螢幕規格 monitoraspect = 1920:1200

# 全螢幕播放 fs=true zoom=true # ass 字幕支援 ass = yes ass-font-scale = 2

nocache = true

沒有留言:

張貼留言