static int ass_get_duration(AVFormatContext *s, const uint8_t *p)
{
    int sh, sm, ss, sc, eh, em, es, ec;
    uint64_t start, end;

    if (sscanf(p, "%*[^,],%d:%d:%d%*c%d,%d:%d:%d%*c%d",
               &sh, &sm, &ss, &sc, &eh, &em, &es, &ec) != 8)
        return 0;

    if (sh > 9 || sm > 59 || ss > 59 || sc > 99 ||
        eh > 9 || em > 59 || es > 59 || ec > 99) {
        av_log(s, AV_LOG_WARNING,
               "Non-standard time reference %d:%d:%d.%d,%d:%d:%d.%d\n",
               sh, sm, ss, sc, eh, em, es, ec);
        return 0;
    }

    start = 3600000 * sh + 60000 * sm + 1000 * ss + 10 * sc;
    end   = 3600000 * eh + 60000 * em + 1000 * es + 10 * ec;

    if (start > end) {
        av_log(s, AV_LOG_WARNING,
               "Unexpected time reference %d:%d:%d.%d,%d:%d:%d.%d\n",
               sh, sm, ss, sc, eh, em, es, ec);
        return 0;
    }

    return end - start;
}