On Thu, Dec 15, 2016 at 10:43:15PM +0000, Erik Bråthen Solem wrote: > According to the format specification (3GPP TS 26.245, section 5.2) "storage > lengths are specified as byte-counts, wheras highlighting is specified using > character offsets." This patch replaces byte counting with character counting > for highlighting. See the following page for a link to the specification: > https://gpac.wp.mines-telecom.fr/mp4box/ttxt-format-documentation/ > --- > libavcodec/movtextenc.c | 24 +++++++++++++++--------- > 1 file changed, 15 insertions(+), 9 deletions(-) > > diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c > index 20e01e2..3ae015a 100644 > --- a/libavcodec/movtextenc.c > +++ b/libavcodec/movtextenc.c > @@ -70,6 +70,7 @@ typedef struct { > uint8_t style_fontsize; > uint32_t style_color; > uint16_t text_pos; > + uint16_t text_pos_chars; > } MovTextContext; [...] > @@ -302,7 +303,10 @@ static void mov_text_text_cb(void *priv, const char > *text, int len) > { > MovTextContext *s = priv; > av_bprint_append_data(&s->buffer, text, len); > - s->text_pos += len; > + s->text_pos += len; // length of text in bytes > + for (int i = 0; i < len; i++) // length of text in UTF-8 characters > + if ((text[i] & 0xC0) != 0x80) > + s->text_pos_chars++; > } > > static void mov_text_new_line_cb(void *priv, int forced) > @@ -310,6 +314,7 @@ static void mov_text_new_line_cb(void *priv, int forced) > MovTextContext *s = priv; > av_bprint_append_data(&s->buffer, "\n", 1); > s->text_pos += 1; > + s->text_pos_chars += 1; > }
The code isnt really my area but is there a check to prevent text_pos and text_pos_chars from overflowing the 16bit range ? [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB it is not once nor twice but times without number that the same ideas make their appearance in the world. -- Aristotle
signature.asc
Description: Digital signature
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel