sub_header->end_display_time = date * 10;
sub_header->end_display_time = (date << 10) / 90;
static int decode_dvd_subtitles(AVSubtitle *sub_header,                                 const uint8_t *buf, int buf_size){    int cmd_pos, pos, cmd, x1, y1, x2, y2, offset1, offset2, next_cmd_pos;    uint8_t palette[4], alpha[4];    int date;    int i;        if (buf_size < 4)        return -1;    sub_header->rects = NULL;    sub_header->num_rects = 0;    sub_header->start_display_time = 0;    sub_header->end_display_time = 0;    cmd_pos = getbe16(buf + 2);    while ((cmd_pos + 4) < buf_size) {        date = getbe16(buf + cmd_pos);        next_cmd_pos = getbe16(buf + cmd_pos + 2);#ifdef DEBUG        av_log(NULL, AV_LOG_INFO, "cmd_pos=0x%04x next=0x%04x date=%d\n",                cmd_pos, next_cmd_pos, date);#endif        pos = cmd_pos + 4;        offset1 = -1;        offset2 = -1;        x1 = y1 = x2 = y2 = 0;        while (pos < buf_size) {            cmd = buf[pos++];#ifdef DEBUG            av_log(NULL, AV_LOG_INFO, "cmd=%02x\n", cmd);#endif            switch(cmd) {            case 0x00:                /* force display */                break;            case 0x01:                /* set start date */                sub_header->start_display_time = date * 10;                break;            case 0x02:                /* set end date */                sub_header->end_display_time = date * 10;                break;            case 0x03:                /* set palette */                if ((buf_size - pos) < 2)                    goto fail;                palette[0] = buf[pos] >> 4;                palette[1] = buf[pos] & 0x0f;                palette[2] = buf[pos + 1] >> 4;                palette[3] = buf[pos + 1] & 0x0f;                pos += 2;                break;            case 0x04:                /* set alpha */                if ((buf_size - pos) < 2)                    goto fail;                alpha[0] = buf[pos] >> 4;                alpha[1] = buf[pos] & 0x0f;                alpha[2] = buf[pos + 1] >> 4;                alpha[3] = buf[pos + 1] & 0x0f;                pos += 2;                break;            case 0x05:                if ((buf_size - pos) < 6)                    goto fail;                x1 = (buf[pos] << 4) | (buf[pos + 1] >> 4);                x2 = ((buf[pos + 1] & 0x0f) << 8) | buf[pos + 2];                y1 = (buf[pos + 3] << 4) | (buf[pos + 4] >> 4);                y2 = ((buf[pos + 4] & 0x0f) << 8) | buf[pos + 5];#ifdef DEBUG                av_log(NULL, AV_LOG_INFO, "x1=%d x2=%d y1=%d y2=%d\n",                       x1, x2, y1, y2);#endif                pos += 6;                break;            case 0x06:                if ((buf_size - pos) < 4)                    goto fail;                offset1 = getbe16(buf + pos);                offset2 = getbe16(buf + pos + 2);#ifdef DEBUG                av_log(NULL, AV_LOG_INFO, "offset1=0x%04x offset2=0x%04x\n", offset1, offset2);#endif                pos += 4;                break;            case 0xff:            default:                goto the_end;            }        }    the_end:        if (offset1 >= 0) {            int w, h;            uint8_t *bitmap;                        /* decode the bitmap */            w = x2 - x1 + 1;            if (w < 0)                w = 0;            h = y2 - y1;            if (h < 0)                h = 0;            if (w > 0 && h > 0) {                if (sub_header->rects != NULL) {                    for (i = 0; i < sub_header->num_rects; i++) {                        av_free(sub_header->rects[i].bitmap);                        av_free(sub_header->rects[i].rgba_palette);                    }                    av_freep(&sub_header->rects);                    sub_header->num_rects = 0;                }                bitmap = av_malloc(w * h);                sub_header->rects = av_mallocz(sizeof(AVSubtitleRect));                sub_header->num_rects = 1;                sub_header->rects[0].rgba_palette = av_malloc(4 * 4);                decode_rle(bitmap, w * 2, w, h / 2,                           buf, offset1 * 2, buf_size);                decode_rle(bitmap + w, w * 2, w, h / 2,                           buf, offset2 * 2, buf_size);                guess_palette(sub_header->rects[0].rgba_palette,                              palette, alpha, 0xffff00);                sub_header->rects[0].x = x1;                sub_header->rects[0].y = y1;                sub_header->rects[0].w = w;                sub_header->rects[0].h = h;                sub_header->rects[0].nb_colors = 4;                sub_header->rects[0].linesize = w;                sub_header->rects[0].bitmap = bitmap;            }        }        if (next_cmd_pos == cmd_pos)            break;        cmd_pos = next_cmd_pos;    }    if (sub_header->num_rects > 0)        return 0; fail:    return -1;}