[MPlayer-dev-eng] [PATCH] new TOOLS utility for timestamp adjusting in ass/ssa subtitles

Andrew Savchenko Bircoph at list.ru
Mon Dec 11 21:28:32 CET 2006


Greetings!

I've made a small script for time adjusting for ass or ssa 
subtitles. It isn't a rare case when subtitles timestamps mismatch 
video's one. This becames a problem when different parts of movie 
requires different shifts.

So, this script's goal is to help in repairing such subtitles. It 
is like subedit.pl (from TOOLS dir) but for ass/ssa and not srt 
subtitle type. 

Script actually consist of 2 files (gawk and bash program).
Patch for README with program's description is also attached.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20061211/5522bca8/attachment.pgp>
-------------- next part --------------
# This program is distributed under the terms of GPLv2 License
# It's a part of ssa_timing script

#convert time to milliseconds
function time2ms(str)
{
    split(str,arr,"[:.]");
    return ((arr[1]*60 +arr[2])*60+ arr[3])*100+ arr[4]
}

#convert milliseconds to time
function ms2time(tm)
{
    return int(tm/360000) % 60 ":" \
           int(tm/6000) % 60 ":" \
           int(tm/100) % 60 "." \
	   tm % 100
}

#init global variables
BEGIN {
    FS=","
    
    #set defaults
    if (shift=="") shift=0
    if (delay=="") delay=0
    if (from=="") from=0
    #2^31-1 msec -- we have no such long movies
    if (to=="") to=2147483647
    #show all strings flag
    if (mess=="") mess=0
    mess=!mess
    
    #start processing flag
    start=0
    events=0
    
    shift=time2ms(shift)
    delay=time2ms(delay)	
    #save some calculations
    delay=delay+shift
    from=time2ms(from)
    to=time2ms(to)
}

{   #proceed only non-empty message strings
    if (start && length())
    {
	time = time2ms($2)
	#skip messages outside the gate
	if (time<from || time > to)
	    next
	#convert time
	gsub($2, ms2time(time + shift))
	gsub($3, ms2time(time2ms($3) + delay))
	print $0
    }
    else 
    {
	if (mess)
	    print $0
	#assume message as nonempty string after Format: in [Events]
	#can't use "Dialogue:" tag, many other exist
	if (index($0,"[Events]")==1)
	    events=1
	if (index($0,"Format:")==1 && events)
	    start=1
    }
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ssa_timing
Type: application/x-shellscript
Size: 1572 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20061211/5522bca8/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: readme.patch
Type: text/x-diff
Size: 964 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20061211/5522bca8/attachment.patch>


More information about the MPlayer-dev-eng mailing list