Mercurial > mplayer.hg
annotate TOOLS/vobshift.py @ 35823:b4ec8c8ee5b6
configure: Refactor listing libav* subparts into a function
author | diego |
---|---|
date | Mon, 18 Feb 2013 02:58:32 +0000 |
parents | 0f1b5b68af32 |
children |
rev | line source |
---|---|
15829
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
1 #!/usr/bin/env python |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
2 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
15829
diff
changeset
|
3 #usage: |
15829
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
4 # |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
5 # vobshift.py in.idx out.idx -8.45 |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
6 # |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
7 # this will read in in.idx,shift it by 8.45 seconds back, |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
8 # and save it as out.idx |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
9 # |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
10 # license: i don't care ;) |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
11 # |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
12 |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
13 import datetime |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
14 import sys |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
15 |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
16 def tripletize(line): |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
17 begin = line[:11] |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
18 middle = line[11:23] |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
19 end = line[23:] |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
20 return (begin,middle,end) |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
21 |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
22 def text2delta(t): |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
23 h = int( t[0:2] ) |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
24 m = int( t[3:5] ) |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
25 s = int( t[6:8] ) |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
26 milli = int( t[9:12] ) |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
27 return datetime.timedelta(hours=h,minutes=m,seconds=s,milliseconds=milli) |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
28 |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
29 def delta2text(d): |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
30 t = str(d) |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
31 milli = t[8:11] |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
32 if len(milli) == 0: #fix for .000 seconds |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
33 milli = '000' |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
34 return '0'+t[:7]+':'+milli |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
35 |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
36 def shift(line,seconds): |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
37 triplet = tripletize(line) |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
15829
diff
changeset
|
38 |
15829
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
39 base = text2delta(triplet[1]) |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
40 base = base + datetime.timedelta(seconds=seconds) |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
41 base = delta2text(base) |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
42 |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
43 return triplet[0]+base+triplet[2] |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
44 |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
45 INFILE =sys.argv[1] |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
46 OUTFILE =sys.argv[2] |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
47 DIFF =float(sys.argv[3]) |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
48 |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
49 o = open(OUTFILE,'wt') |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
50 |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
51 |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
52 for line in open(INFILE): |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
53 if line.startswith('timestamp'): |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
54 line = shift(line,DIFF) |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
15829
diff
changeset
|
55 |
15829
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
56 o.write(line) |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
57 |
96b84e3a0d96
vobsub time-adjust tool by Gbor Farkas < gabor AH nekomancer POUM net >
gpoirier
parents:
diff
changeset
|
58 o.close() |