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

 找回密码
 新人加入
查看: 5910|回复: 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.





Rank: 4

沙发
发表于 2021-7-26 14:19:08 |只看该作者
本帖最后由 Seekladoom 于 2021-12-20 11:24 编辑

【如上内容的谷歌机翻】
简介

对于字幕效果来说,定位和时机是最基础也是最重要的两个方面。TCAX 的基本功能就是为用户提供处理这两个问题所需的信息。


时间计算

基本时间计算比基本位置计算稍微容易一些,因为信息,或者说,关于时间的预定义全局值比定位信息越来越简单。主要有五个全局值可用于计算时序。它们是:

    1。val_FXFPS,定义了一个全局常量,表示目标 FX 的帧速率。通常我们是这样使用的,_FD = 1000 / GetVal(val_FXFPS),_FD是另一个存储帧时长的变量,单位为毫秒。如果我们要使用我们自己定义的所有帧制作 FX(这意味着我们不打算使用 ASS 动画标签,例如 \move、\t 等),我们肯定需要这个变量。

    2. val_BegTime,它是一个一维数组,包含每一行的开始时间。

    3. val_EndTime,是一个一维数组,包含每一行的结束时间。

    4. val_KarTime,它是一个二维数组,包含每个音节的持续时间。

    5.val_KarTimeDiff,它是一个二维数组,包含从一行中的第一个音节到同一行中的目标音节所经过的时间。它是通过总结卡拉 OK 时间得出的。

借助这些变量,我们可以通过以下两个公式轻松计算音节的存在时间: 音节的
开始时间 = GetVal(val_BegTime)[line_index] + GetVal(val_KarTimeDiff)[line_index][syl_index]
结束时间音节的=(音节的开始时间)+ GetVal(val_KarTime)[line_index][syl_index]

在tcaxPy_Main函数中,GetVal(val_BegTime)[line_index]与_start相同,GetVal(val_EndTime)[line_index]与_end相同,GetVal(val_KarTimeDiff)[line_index][syl_index]与_elapk和GetVal( val_KarTime)[line_index][syl_index] 与 _k 相同。

虽然计算基本时序看起来很容易,但做高级就不是这样了,制作一个很棒的FX非常依赖。然而,时间感可以通过反复试验获得。


位置计算

与基本时间计算相比,位置计算更为复杂。与定位相关的预定义全局值远不止时序。我不会在这里涵盖文本布局的所有方面,而只是展示它的一些基本用法。你可以参考有关文本布局的更复杂信息的FreeType 文档。

TCAX中有两种布局样式,水平和垂直。如果你能理解其中之一,你就可以理解两者。那么,让我们先来处理一下比较常用的水平布局。回顾一下开始之前ASS的对齐方式,一共有九个对齐方式,从an1到an9。假设我们使用 an1 将文本放置在 (x, y) 位置,并且文本的前进为a,使用的字体大小为fs,我们如何将其更改为其他对齐方式但仍将其放置在同一位置视觉上?答案很简单,变换公式如下:

    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)

注意,你可以在TCC文件中设置的对齐方式与我们上面提到的意义不同,它只是表示我们将文本放在屏幕上的位置,而我们实际使用的ASS对齐方式是an5 by默认(在 ASS 样式中)。那么,我们如何进行定位呢?最重要的是找到我们应该把第一个文本放在哪里。假设我们使用的是水平布局,ASS对齐方式是an7,下面的公式可以给你一个提示。

    1.对齐
方式 1,x = GetVal(val_OffsetX),y = GetVal(val_ResolutionY) - GetVal(val_FontSize) - GetVal(val_OffsetY)
    2.对齐
方式 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.对齐方式 3, x = GetVal(val_ResolutionX) - GetVal(val_TextLength)[line_index] - GetVal(val_OffsetX), y = GetVal(val_ResolutionY) - GetVal(val_FontSize) - GetVal(val_OffsetY)
    4.对齐方式 4, x = GetVal(val_OffsetX), y = GetVal(val_ResolutionY) / 2 - GetVal(val_OffsetY)
    5.对齐方式 5, x = GetVal(val_OffsetX) + (GetVal(val_ResolutionX) - GetVal(val_TextLength)[line_index]) / 2, y = GetVal(val_ResolutionY) / 2 - GetVal(val_OffsetY)
    6.对齐
方式 6, x = GetVal(val_ResolutionX) - GetVal(val_TextLength)[line_index] - GetVal(val_OffsetX), y = GetVal(val_ResolutionY) / 2 - GetVal(val_OffsetY)
    7.对齐
方式 7, x = GetVal(val_OffsetX), y = GetVal(val_OffsetY)
    8.对齐
方式 8, x = GetVal(val_OffsetX) + (GetVal(val_ResolutionX) - GetVal(val_TextLength)[line_index]) / 2, y = GetVal(val_OffsetY)
    9.对齐
方式 9, x = GetVal( val_ResolutionX) - GetVal(val_TextLength)[line_index] - GetVal(val_OffsetX), y = GetVal(val_OffsetY)

知道第一个文本位置后,我们可以使用公式轻松推导出左边的位置, (x + GetVal(val_TextAdvanceDiff)[line_index] [syl_index], y), val_TextAdvanceDiff 是文本前进的总和,以与 val_KarTimeDiff 类似的方式导出。

在tcaxPy_Main函数中_a表示当前正在处理的文本的前进,而_x和_y表示其位置,它们的计算公式为_x = x + _a / 2,_y = y + GetVal(val_FontSize) / 2,其中x和y由上述公式1至9导出。

在TCAS或ASS的像素级效果中,只有一种对齐方式,即an7,你可以直接使用上面列出的公式从预定义的全局值中计算出来,也可以使用中间方法,x = _x - a / 2, y = _y - GetVal(val_FontSize) / 2。
您需要登录后才可以回帖 登录 | 新人加入

GitHub|TCAX 主页

GMT+8, 2024-12-4 01:32

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部
RealH