Log in

View Full Version : DCSQT Subtitle timestamp duration (in Vobsub file)


Dark-Cracker
5th April 2005, 19:22
Hi,

i am actually working on the vobsub subtitle format and i try to find the correct duration of each subtitle.

i get a delay (SP_DCSQ_STM) value from the DCSQT (Display Control Sequence Table) when the DCC (Display Control Command) is at 2 (for the command to stop displaying the subtitle).

i was thinking the delay of the command can be converted in millisec using the formula : ((delay * 1024)/90)
and by adding this ms value at the "start" timestamp stored in the .idx file i could get the timestamp's subtitle display end.

but i get some wrong values when i made some tests :(

i also know some bad dvd authoring doesn't add the command=2 (to stop display) but it's not this problem.

does my formula is incorrect or is it my code who get the timestamp who is wrong ?

for exemple in my subtitle test the command stop have a duration = 158 and the display duration of the subtitle is in fact 2992 ms.
my second subtitle is duration = 133 for a display duration = 3949 ms.


PS : the start display subtitle (command=1) show a delay = 0 .

so here are my questions :

1) is there a tool to parse the DCSQT structure to know the duration of each command ? to check if there is an error in the value retrieved by my code.

2) does my formula to get the timestamp is incorrect or incomplete ?

any hints are welcome :)

for those who doesn't well remember dvd subtitle struct and DCQST part there is a link : http://dvd.sourceforge.net/dvdinfo/spu.html

Bye.

mpucoder
5th April 2005, 20:07
It's not bad authoring to leave out the stop command, that is legitimate. In fact it is mandatory for menus (forced start, no stop). In that case the subpicture displays until the end of the cell, or another subpicture starts.
Stm values are not cumulative, each one is the delay from pts - each must be greater than the preceeding, and the first must be zero.

Before you can calculate the duration in milliseconds you must first calculate it in frames. First you need the duration of a frame in clock ticks, which is 3003 for NTSC or 3600 for PAL.

duration_in_frames = (stm*1024 + frame_duration-1)/frame_duration

That is an integer divide, and the formula ensures rounding up to the next integer number of frames.

Dark-Cracker
5th April 2005, 22:15
thank u for the quick answer :)

unhappily my english is rather basic and i an not really sure to fully understand you.

if i have right understand the delay value (stm) is the delay from the pts until the end of the subtitle (if i get the stm only when the command=2). and : pts+stm should be < than the next pts+stm

i suppose you need to add the pts because in my subtitle test the 2 first subtitle have the value 158 and the next was 133. (and if i use the formula i don't find the real 2992 ms and 3949 ms.

once i have the pts+stm i can use you formula to get the correct number of ms to know the duration of the subtitle.

i am right ? (sorry to bother you if i have misunderstand you, and in that case if you could re-explain me).

PS : however i have some problem to get the pts when i parse the MPEG PES struct :(

++

mpucoder
5th April 2005, 22:36
STM is the delay from the start of the SPU presentation until the commands for that SP_DCSQT execute.

The SPU begins its presentation at pts, which will align exactly with a frame.*

The first SP_DCSQT must have a STM of 0.

Each SP_DCSQT after that must have a higher STM than the preceeding SP_DCSQT.

The final SP_DCSQT is the only one allowed to have a stop command, therefore the STM of the final SP_DCSQT is the duration of the sub if there are 2 or more SP_DCSQT

Since subs are synchronized to the video, their duration is always a multiple of video frame duration. But because the value for STM is divided by 1024 and rounded down (simple truncation) you must round up when converting back to frames.

* this is where most subs programs go wrong, frame 0 of a vob does not have a pts of 0. In order to convert pts to a frame number or time value you must account for the video delay. For the first vob, and simple titles, this value appears in every NAV pack as vob_v_s_ptm (offset 0x433 of the sector) which is "PTM of first video frame in first GOP of VOB". note: PTM = pts

Dark-Cracker
6th April 2005, 00:07
ok the thing are started to get more clear :)
but i still not fully understand the relation ship beetween the STM and the display duration of the subtitle. and the relation with the PTM.

i understand that when you have more than 1 SP_DCSQT the STM is the duration of the display duration. but if my subtitle is stored only on 1 SP_DCSQT the STM will be = 0.

in fact i made an OCR for the vobsub file and i need to save the final output textfile with the start and end timestamp, actually i can get the start display timestamp of the subtitle (there are listed in the .idx file) but i want to compute the display duration to add it at the start time to get the subtitle display end.

i have check in the vobsub struct and i don't think it store the NAV pack, i think (not sure) it only store the Packetized Elementary Stream Headers. i think it store the PTM in this structure because when i have read an cpp exemple where it get the PTS from this structure (http://smgl.positivism.org/mplayer-cvs/vobsub.c search the text "case 0xbd:" it's in the first half of the document) each packet (of 2048 bytes) start with this structure.

i think i should do the following to compute the subtitle's display time :

- retrieve the PTM (i convert it in ms) it's the delay before the video display the frame 0.

- to compute the display end timestamp i do :

if STM=0 then //only 1 SP_DCSQT
timestamp_end = timestamp_start + PTM_converted_in_ms
else // there is more than 1 SP_DCSQT
timestamp_end = timestamp_start + PTM_converted_in_ms + Your_Previous_Formula(STM)
end if

i am right ?

Bye.

Dark-Cracker
6th April 2005, 21:20
if i get the PTS subtitle (offset &H17 at the start of each packet) does this will help me for the calculation of the subtitle display duration ? i still don't understand how to compute them.

any hint is welcome.

++

Dark-Cracker
9th April 2005, 18:32
Hi,

i fact i have found that my code was wrong (i was doing a loop of the next SP_DCSQT offset and in my loop i was missing the last packet because i have used somethink like : loop while oldDCSQToffset < newDCQSToffset instead of <= and i was missing the last packet so some off my SPU duration were = 0 and i was thinking there were a hint to compute the duration.)

to sum up the subtitle duration is the SPU time until the last packet (who have the stop commad).

i now understand why mpucoder have stop to answer me and should have think i was crazy :)

But i still have some few questions .

to compute the subtitle duration from the SPU delay there is actually 2 formula :
- the first is using : duration_in_ms = fix((delay * 1024) / 90)
- the second is :
duration_in_frames = round((stm*1024 + frame_duration-1)/frame_duration)
duration_in_ms = fix((duration_in_frames / fps ) * 1000)

which is correct ?

---

> but if my subtitle is stored only on 1 SP_DCSQT the STM will be = 0.

i have not found some subtitle only on 1 SP_DCSQT but i am asking myself how calculate the subtitle duration if there is less than 2 SP_DCSQT ? should i use a default value (like 3000 ms in vobsub ?) or should i reuse the previous subtitle duration ? or is there another way ?

Bye.

mpucoder
9th April 2005, 23:55
I just thought maybe if you read the post again, or played with your program, you would learn more than if I repeated things.

Duration should always be a multiple of video frame durations, so the second formula is correct. You could also compute it the first way if you then round up to the next multiple of the video frame duration. Personally, I prefer using frames as the unit of time, not ms. The actual duration of PAL is very exact (40ms/frame) but NTSC is different. As far as DVD is concerned the duration of one NTSC frame is 3003 ticks of the 90KHz clock, or 33.366...ms

Subtitles with no stop command have infinite duration. What you need to do is convey that fact, and not try to compute the duration. In .sst files that is denoted with a minus sign for the stop time. In .scp files there is an entire section to describe the stop portion. For Muxman a duration of 0, or the absense of the duration statement, means infinite.

If you want to find subs with no stop look in menues.

Dark-Cracker
10th April 2005, 00:28
@mpucoder

i have found a subtitle with the first 3 subtitles with a duration = 0 i have made an ocr on these file and the end timestamp is equal at the start time of the next subtitle (i suppose it's what u mean by infinite display [until another subtitle appear]) i have use this way in my way to calculate the duration. if SPU = 0 i use the end timestamp = start time of the next subtitle, and if the last subtitle SPU = 0 , i use the same duration than the previous subtitle.


for the formula it seems vobsub and subrip use the first one, personnaly i will try to use the second but to use it i need to check if it's PAL or NTSC and in the vobsub file format i think the only solution is to check the subtitle picture height and with to detect if it's NTSC or PAL, and it's not really a clean way to detect it (i have see for exemple some subtitle with a *wrong* height for exemple 721 or 719). i will made more search.

thank u for your help, really appreciated :) sorry for the previous misunderstanding.

Bye.