TCAX 字幕特效制作工具官方论坛 | ASS | TCAS | Python | Aegisub | Lua

 找回密码
 新人加入
查看: 4794|回复: 0
打印 上一主题 下一主题

TCAX 时间计算及文字定位 (英文) [复制链接]

Administrator

TCAX Dev.

Rank: 7Rank: 7Rank: 7

跳转到指定楼层
楼主
发表于 2011-8-12 19:47:29 |显示全部楼层 |倒序浏览
Introduction

To a subtitle effect, the positioning and timing are the most two fundamental yet important aspects. The basic function of TCAX is to provide the required information for the user to deal with these two problems.


Time Calculation

The basic time calculation is somewhat easier than the basic position calculation, because the information, or say, predefined global values concerning the timing is less and less complicated than the positioning information. There are mainly five global values available to calculate the timing. They are:

    1. val_FXFPS, defines a global constant that indicates the frame rate of the target FX. Usually we use it in the following way, _FD = 1000 / GetVal(val_FXFPS), _FD is another variable that stores the frame duration, in milliseconds. If we are going to make an FX with all its frames defined by ourselves (meaning that we are not going to use ASS animation tags, such as \move, \t, etc.), we will need this variable, definitely.

    2. val_BegTime, it is a one dimensional array that contains the beginning time of each line.

    3. val_EndTime, it is a one dimensional array that contains the ending time of each line.

    4. val_KarTime, it is a two dimensional array that contains the duration of each syllable.

    5. val_KarTimeDiff, it is a two dimensional array that contains the elapsed time from the very first syllable in a line to the target syllable in the same line. It is derived by summing up the karaoke timings.

With the help of these variables, we can calculate the existing time of a syllable easily, by the two formulas below:
Start Time of a Syllable = GetVal(val_BegTime)[line_index] + GetVal(val_KarTimeDiff)[line_index][syl_index]
End Time of a Syllable = (Start Time of a Syllable) + GetVal(val_KarTime)[line_index][syl_index]

In the tcaxPy_Main function, GetVal(val_BegTime)[line_index] is just the same with _start, GetVal(val_EndTime)[line_index] is the same with _end, GetVal(val_KarTimeDiff)[line_index][syl_index] is the same with _elapk and GetVal(val_KarTime)[line_index][syl_index] is the same with _k.

Although it seems easy to calculate the basic timing, it is not the case to do the advanced, on which the making of an awesome FX greatly relies. However, the sense of timing can be gained by trial and error.


Position Calculation

Comparing to the basic time calculation, position calculation is more complicated. The predefined global values concerning the positioning are much more than timing. And I will not cover all aspects of text layout here, but only to show some basic usage of it. You can refer to the FreeType documentation for more sophisticated information on text layout.

There are two layout styles in TCAX, horizontal and vertical. If you can understand one of them, you can understand both. So, let us first deal with the horizontal layout, which is more commonly used. Recalling the alignments of ASS before we start, there are in total nine alignments, from an1 to an9. Assuming that we have a text placed at position (x, y) using an1, and the advance of the text is a, the font size used is fs, how can we change it to the other alignments yet still put it at the same position visually? The answer is simple, and the transformation formulas are listed below:

    1. an1, at (x, y)
    2. an2, at (x + a / 2, y)
    3. an3, at (x + a, y)
    4. an4, at (x, y - fs / 2)
    5. an5, at (x + a / 2, y - fs / 2)
    6. an6, at (x + a, y - fs / 2)
    7. an7, at (x, y - fs)
    8. an8, at (x + a / 2, y - fs)
    9. an9, at (x + a, y - fs)

Note that, the alignment you can set in the TCC file has a different meaning from the one we mentioned in the above, it just indicates where we will put our texts on the screen, and the actual ASS alignment we use is an5 by default (in the ASS style). So, how can we do the positioning? The most important thing is to find at where we should put our first text. Suppose that we are using horizontal layout and ASS alignment is an7, the formulas below can be a hint to you.

    1. alignment 1, x = GetVal(val_OffsetX), y = GetVal(val_ResolutionY) - GetVal(val_FontSize) - GetVal(val_OffsetY)
    2. alignment 2, x = GetVal(val_OffsetX) + (GetVal(val_ResolutionX) - GetVal(val_TextLength)[line_index]) / 2, y = GetVal(val_ResolutionY) - GetVal(val_FontSize) - GetVal(val_OffsetY)
    3. alignment 3, x = GetVal(val_ResolutionX) - GetVal(val_TextLength)[line_index] - GetVal(val_OffsetX), y = GetVal(val_ResolutionY) - GetVal(val_FontSize) - GetVal(val_OffsetY)
    4. alignment 4, x = GetVal(val_OffsetX), y = GetVal(val_ResolutionY) / 2 - GetVal(val_OffsetY)
    5. alignment 5, x = GetVal(val_OffsetX) + (GetVal(val_ResolutionX) - GetVal(val_TextLength)[line_index]) / 2, y = GetVal(val_ResolutionY) / 2 - GetVal(val_OffsetY)
    6. alignment 6, x = GetVal(val_ResolutionX) - GetVal(val_TextLength)[line_index] - GetVal(val_OffsetX), y = GetVal(val_ResolutionY) / 2 - GetVal(val_OffsetY)
    7. alignment 7, x = GetVal(val_OffsetX), y = GetVal(val_OffsetY)
    8. alignment 8, x = GetVal(val_OffsetX) + (GetVal(val_ResolutionX) - GetVal(val_TextLength)[line_index]) / 2, y = GetVal(val_OffsetY)
    9. alignment 9, x = GetVal(val_ResolutionX) - GetVal(val_TextLength)[line_index] - GetVal(val_OffsetX), y = GetVal(val_OffsetY)

After knowing the first text position, we can easily derive the left ones using the formula, (x + GetVal(val_TextAdvanceDiff)[line_index][syl_index], y), val_TextAdvanceDiff is the sum of advances of texts, derived in a similar way with val_KarTimeDiff.

In the tcaxPy_Main function _a indicates the advance of the current text being processed, while _x and _y indicate its position, they are calculated by _x = x + _a / 2, _y = y + GetVal(val_FontSize) / 2, in which x and y are derived by the formulas 1 to 9 listed in the above.

In TCAS or the pixel-level effects of ASS, there is only one alignment, that is an7, you can either calculate it directly from the predefined global values using the formulas listed in the above, or use the intermediate approach, x = _x - a / 2, y = _y - GetVal(val_FontSize) / 2.





您需要登录后才可以回帖 登录 | 新人加入

GitHub|TCAX 主页

GMT+8, 2024-5-3 06:57

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部
RealH