[MPlayer-dev-eng] [PATCH] support for overlapping subtitles

Salvatore Falco sfalco at studenti.ing.uniroma1.it
Tue Oct 29 19:28:50 CET 2002


This patch is to add support for overlapping subtitles, that is
subtitles whose start or end happens during another subtitle.

After reading the subtitles from the file in `subtitle* sub_read_file
(char *, float)' this patch looks for overlapping subtitles and split
them into more non-overlapping subtitles.
For example, given two subtitles, A and B, with in time order:
    1- A's beginning,
    2- B's beginning,
    3- A's ending,
    4- B's ending,
this patch creates three subtitles:
    1- a subtitle from A's to B's beginning, with A's lines and a number
	of blank lines equal to B's lines;
    2- a subtitle from B's beginning to A's ending, with all the lines from
	both subtitles;
    3- a subtitle form A's to B's ending, with only B's lines.
This patch slightly changes also `void adjust_subs_time(subtitle*,float,float)'
to avoid its working on overlapping subtitles.

Bye all,
    Salvatore Falco
-------------- next part --------------
LS0tIHN1YnJlYWRlci5jLm9yaWcJMjAwMi0xMC0xNyAwMjo1MzoxNC4wMDAwMDAwMDAgKzAyMDAK
KysrIHN1YnJlYWRlci5jCTIwMDItMTAtMjkgMDI6MDk6MTMuMDAwMDAwMDAwICswMTAwCkBAIC03
MjgsNyArNzI4LDcgQEAKIAogI2VuZGlmCiAKLXN0YXRpYyB2b2lkIGFkanVzdF9zdWJzX3RpbWUo
c3VidGl0bGUqIHN1YiwgZmxvYXQgc3VidGltZSwgZmxvYXQgZnBzKXsKK3N0YXRpYyB2b2lkIGFk
anVzdF9zdWJzX3RpbWUoc3VidGl0bGUqIHN1YiwgZmxvYXQgc3VidGltZSwgZmxvYXQgZnBzLCB1
bnNpZ25lZCBzaG9ydCBibG9jayl7CiAJaW50IG4sbTsKIAlzdWJ0aXRsZSogbmV4dHN1YjsKIAlp
bnQgaSA9IHN1Yl9udW07CkBAIC03MzYsNiArNzM2LDcgQEAKIAkKIAluPW09MDsKIAlpZiAoaSkJ
Zm9yICg7Oyl7CisJICAgIGlmICghYmxvY2spCiAJCWlmIChzdWItPmVuZCA8PSBzdWItPnN0YXJ0
KXsKIAkJC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