static int mov_text_decode_frame(AVCodecContext *avctx,

                            void *data, int *got_sub_ptr, AVPacket *avpkt)

{

    AVSubtitle *sub = data;

    int ret, ts_start, ts_end;

    AVBPrint buf;

    char *ptr = avpkt->data;

    char *end;

    //char *ptr_temp;

    int text_length, tsmb_type, style_entries, tsmb_size;

    int **style_start = {0,};

    int **style_end = {0,};

    int **style_flags = {0,};

    const uint8_t *tsmb;

    int index, i;

    int *flag;

    int *style_pos;



    if (!ptr || avpkt->size < 2)

        return AVERROR_INVALIDDATA;



    /*

     * A packet of size two with value zero is an empty subtitle

     * used to mark the end of the previous non-empty subtitle.

     * We can just drop them here as we have duration information

     * already. If the value is non-zero, then it's technically a

     * bad packet.

     */

    if (avpkt->size == 2)

        return AV_RB16(ptr) == 0 ? 0 : AVERROR_INVALIDDATA;



    /*

     * The first two bytes of the packet are the length of the text string

     * In complex cases, there are style descriptors appended to the string

     * so we can't just assume the packet size is the string size.

     */

    text_length = AV_RB16(ptr);

    end = ptr + FFMIN(2 + text_length, avpkt->size);

    ptr += 2;



    ts_start = av_rescale_q(avpkt->pts,

                            avctx->time_base,

                            (AVRational){1,100});

    ts_end   = av_rescale_q(avpkt->pts + avpkt->duration,

                            avctx->time_base,

                            (AVRational){1,100});



    tsmb_size = 0;

    // Note that the spec recommends lines be no longer than 2048 characters.

    av_bprint_init(&buf, 0, AV_BPRINT_SIZE_UNLIMITED);

    if (text_length + 2 != avpkt->size) {

        while (text_length + 2 + tsmb_size < avpkt->size)  {

            tsmb = ptr + text_length + tsmb_size;

            tsmb_size = AV_RB32(tsmb);

            tsmb += 4;

            tsmb_type = AV_RB32(tsmb);

            tsmb += 4;



            if (tsmb_type == MKBETAG('s','t','y','l')) {

                style_entries = AV_RB16(tsmb);

                tsmb += 2;



                for(i = 0; i < style_entries; i++) {

                    style_pos = av_malloc(4);

                    *style_pos = AV_RB16(tsmb);

                    index = i;

                    av_dynarray_add(&style_start, &index, style_pos);

                    tsmb += 2;

                    style_pos = av_malloc(4);

                    *style_pos = AV_RB16(tsmb);

                    index = i;

                    av_dynarray_add(&style_end, &index, style_pos);

                    tsmb += 2;

                    // fontID = AV_RB16(tsmb);

                    tsmb += 2;

                    flag = av_malloc(4);

                    *flag = AV_RB8(tsmb);

                    index = i;

                    av_dynarray_add(&style_flags, &index, flag);

                    //fontsize=AV_RB8(tsmb);

                    tsmb += 2;

                    // text-color-rgba

                    tsmb += 4;

                }

                text_to_ass(&buf, ptr, end, style_start, style_end, style_flags, style_entries);

                av_freep(&style_start);

                av_freep(&style_end);

                av_freep(&style_flags);

            }

        }

    } else

        text_to_ass(&buf, ptr, end, NULL, NULL, 0, 0);



    ret = ff_ass_add_rect_bprint(sub, &buf, ts_start, ts_end - ts_start);

    av_bprint_finalize(&buf, NULL);

    if (ret < 0)

        return ret;

    *got_sub_ptr = sub->num_rects > 0;

    return avpkt->size;

}

static int mov_text_decode_frame(AVCodecContext *avctx,

                            void *data, int *got_sub_ptr, AVPacket *avpkt)

{

    AVSubtitle *sub = data;

    int ret, ts_start, ts_end;

    AVBPrint buf;

    char *ptr = avpkt->data;

    char *end;

    

    int text_length, tsmb_type, style_entries, tsmb_size;

    int **style_start = {0,};

    int **style_end = {0,};

    int **style_flags = {0,};

    const uint8_t *tsmb;

    int index, i;

    int *flag;

    int *style_pos;



    if (!ptr || avpkt->size < 2)

        return AVERROR_INVALIDDATA;



    













    if (avpkt->size == 2)

        return AV_RB16(ptr) == 0 ? 0 : AVERROR_INVALIDDATA;



    









    text_length = AV_RB16(ptr);

    end = ptr + FFMIN(2 + text_length, avpkt->size);

    ptr += 2;



    ts_start = av_rescale_q(avpkt->pts,

                            avctx->time_base,

                            (AVRational){1,100});

    ts_end   = av_rescale_q(avpkt->pts + avpkt->duration,

                            avctx->time_base,

                            (AVRational){1,100});



    tsmb_size = 0;

    

    av_bprint_init(&buf, 0, AV_BPRINT_SIZE_UNLIMITED);

    if (text_length + 2 != avpkt->size) {

        while (text_length + 2 + tsmb_size < avpkt->size)  {

            tsmb = ptr + text_length + tsmb_size;

            tsmb_size = AV_RB32(tsmb);

            tsmb += 4;

            tsmb_type = AV_RB32(tsmb);

            tsmb += 4;



            if (tsmb_type == MKBETAG('s','t','y','l')) {

                style_entries = AV_RB16(tsmb);

                tsmb += 2;



                for(i = 0; i < style_entries; i++) {

                    style_pos = av_malloc(4);

                    *style_pos = AV_RB16(tsmb);

                    index = i;

                    av_dynarray_add(&style_start, &index, style_pos);

                    tsmb += 2;

                    style_pos = av_malloc(4);

                    *style_pos = AV_RB16(tsmb);

                    index = i;

                    av_dynarray_add(&style_end, &index, style_pos);

                    tsmb += 2;

                    

                    tsmb += 2;

                    flag = av_malloc(4);

                    *flag = AV_RB8(tsmb);

                    index = i;

                    av_dynarray_add(&style_flags, &index, flag);

                    

                    tsmb += 2;

                    

                    tsmb += 4;

                }

                text_to_ass(&buf, ptr, end, style_start, style_end, style_flags, style_entries);

                av_freep(&style_start);

                av_freep(&style_end);

                av_freep(&style_flags);

            }

        }

    } else

        text_to_ass(&buf, ptr, end, NULL, NULL, 0, 0);



    ret = ff_ass_add_rect_bprint(sub, &buf, ts_start, ts_end - ts_start);

    av_bprint_finalize(&buf, NULL);

    if (ret < 0)

        return ret;

    *got_sub_ptr = sub->num_rects > 0;

    return avpkt->size;

}

    int text_length, tsmb_type, style_entries, tsmb_size;         while (text_length + 2 + tsmb_size < avpkt->size)  {             tsmb = ptr + text_length + tsmb_size;
static int FUNC_0(AVCodecContext *VAR_0,

                            void *VAR_1, int *VAR_2, AVPacket *VAR_3)

{

    AVSubtitle *sub = VAR_1;

    int VAR_4, VAR_5, VAR_6;

    AVBPrint buf;

    char *VAR_7 = VAR_3->VAR_1;

    char *VAR_8;

    

    int VAR_9, VAR_10, VAR_11, VAR_12;

    int **VAR_13 = {0,};

    int **VAR_14 = {0,};

    int **VAR_15 = {0,};

    const uint8_t *VAR_16;

    int VAR_17, VAR_18;

    int *VAR_19;

    int *VAR_20;



    if (!VAR_7 || VAR_3->size < 2)

        return AVERROR_INVALIDDATA;



    













    if (VAR_3->size == 2)

        return AV_RB16(VAR_7) == 0 ? 0 : AVERROR_INVALIDDATA;



    









    VAR_9 = AV_RB16(VAR_7);

    VAR_8 = VAR_7 + FFMIN(2 + VAR_9, VAR_3->size);

    VAR_7 += 2;



    VAR_5 = av_rescale_q(VAR_3->pts,

                            VAR_0->time_base,

                            (AVRational){1,100});

    VAR_6   = av_rescale_q(VAR_3->pts + VAR_3->duration,

                            VAR_0->time_base,

                            (AVRational){1,100});



    VAR_12 = 0;

    

    av_bprint_init(&buf, 0, AV_BPRINT_SIZE_UNLIMITED);

    if (VAR_9 + 2 != VAR_3->size) {

        while (VAR_9 + 2 + VAR_12 < VAR_3->size)  {

            VAR_16 = VAR_7 + VAR_9 + VAR_12;

            VAR_12 = AV_RB32(VAR_16);

            VAR_16 += 4;

            VAR_10 = AV_RB32(VAR_16);

            VAR_16 += 4;



            if (VAR_10 == MKBETAG('s','t','y','l')) {

                VAR_11 = AV_RB16(VAR_16);

                VAR_16 += 2;



                for(VAR_18 = 0; VAR_18 < VAR_11; VAR_18++) {

                    VAR_20 = av_malloc(4);

                    *VAR_20 = AV_RB16(VAR_16);

                    VAR_17 = VAR_18;

                    av_dynarray_add(&VAR_13, &VAR_17, VAR_20);

                    VAR_16 += 2;

                    VAR_20 = av_malloc(4);

                    *VAR_20 = AV_RB16(VAR_16);

                    VAR_17 = VAR_18;

                    av_dynarray_add(&VAR_14, &VAR_17, VAR_20);

                    VAR_16 += 2;

                    

                    VAR_16 += 2;

                    VAR_19 = av_malloc(4);

                    *VAR_19 = AV_RB8(VAR_16);

                    VAR_17 = VAR_18;

                    av_dynarray_add(&VAR_15, &VAR_17, VAR_19);

                    

                    VAR_16 += 2;

                    

                    VAR_16 += 4;

                }

                text_to_ass(&buf, VAR_7, VAR_8, VAR_13, VAR_14, VAR_15, VAR_11);

                av_freep(&VAR_13);

                av_freep(&VAR_14);

                av_freep(&VAR_15);

            }

        }

    } else

        text_to_ass(&buf, VAR_7, VAR_8, NULL, NULL, 0, 0);



    VAR_4 = ff_ass_add_rect_bprint(sub, &buf, VAR_5, VAR_6 - VAR_5);

    av_bprint_finalize(&buf, NULL);

    if (VAR_4 < 0)

        return VAR_4;

    *VAR_2 = sub->num_rects > 0;

    return VAR_3->size;

}

static int FUNC_0(AVCodecContext *VAR_0,
void *VAR_1, int *VAR_2, AVPacket *VAR_3)
{ AVSubtitle *sub = VAR_1; int VAR_4, VAR_5, VAR_6; AVBPrint buf; char *VAR_7 = VAR_3->VAR_1; char *VAR_8; int VAR_9, VAR_10, VAR_11, VAR_12; int **VAR_13 = {0,}; int **VAR_14 = {0,}; int **VAR_15 = {0,}; const uint8_t *VAR_16; int VAR_17, VAR_18; int *VAR_19; int *VAR_20; if (!VAR_7 || VAR_3->size < 2)
return AVERROR_INVALIDDATA; if (VAR_3->size == 2)
return AV_RB16(VAR_7) == 0 ? 0 : AVERROR_INVALIDDATA; VAR_9 = AV_RB16(VAR_7); VAR_8 = VAR_7 + FFMIN(2 + VAR_9, VAR_3->size); VAR_7 += 2; VAR_5 = av_rescale_q(VAR_3->pts,
VAR_0->time_base,
(AVRational){1,100}); VAR_6   = av_rescale_q(VAR_3->pts + VAR_3->duration,
VAR_0->time_base,
(AVRational){1,100}); VAR_12 = 0; av_bprint_init(&buf, 0, AV_BPRINT_SIZE_UNLIMITED); if (VAR_9 + 2 != VAR_3->size) { while (VAR_9 + 2 + VAR_12 < VAR_3->size)  { VAR_16 = VAR_7 + VAR_9 + VAR_12; VAR_12 = AV_RB32(VAR_16); VAR_16 += 4; VAR_10 = AV_RB32(VAR_16); VAR_16 += 4; if (VAR_10 == MKBETAG('s','t','y','l')) { VAR_11 = AV_RB16(VAR_16); VAR_16 += 2; for(VAR_18 = 0; VAR_18 < VAR_11; VAR_18++) { VAR_20 = av_malloc(4); *VAR_20 = AV_RB16(VAR_16); VAR_17 = VAR_18; av_dynarray_add(&VAR_13, &VAR_17, VAR_20); VAR_16 += 2; VAR_20 = av_malloc(4); *VAR_20 = AV_RB16(VAR_16); VAR_17 = VAR_18; av_dynarray_add(&VAR_14, &VAR_17, VAR_20); VAR_16 += 2; VAR_16 += 2; VAR_19 = av_malloc(4); *VAR_19 = AV_RB8(VAR_16); VAR_17 = VAR_18; av_dynarray_add(&VAR_15, &VAR_17, VAR_19); VAR_16 += 2; VAR_16 += 4; } text_to_ass(&buf, VAR_7, VAR_8, VAR_13, VAR_14, VAR_15, VAR_11); av_freep(&VAR_13); av_freep(&VAR_14); av_freep(&VAR_15); } } } else text_to_ass(&buf, VAR_7, VAR_8, NULL, NULL, 0, 0); VAR_4 = ff_ass_add_rect_bprint(sub, &buf, VAR_5, VAR_6 - VAR_5); av_bprint_finalize(&buf, NULL); if (VAR_4 < 0)
return VAR_4; *VAR_2 = sub->num_rects > 0; return VAR_3->size; }