X-Git-Url: https://git.piment-noir.org/?p=deb_ffmpeg.git;a=blobdiff_plain;f=ffmpeg%2Flibavcodec%2Fmicrodvddec.c;fp=ffmpeg%2Flibavcodec%2Fmicrodvddec.c;h=96034a042aef0e59c543b4bf3f501fbae0436764;hp=f3c640f93240ab12623bf6b91aca63e6525f8d84;hb=f6fa7814ccfe3e76514b36cf04f5cd3cb657c8cf;hpb=2ba45a602cbfa7b771effba9b11bb4245c21bc00 diff --git a/ffmpeg/libavcodec/microdvddec.c b/ffmpeg/libavcodec/microdvddec.c index f3c640f..96034a0 100644 --- a/ffmpeg/libavcodec/microdvddec.c +++ b/ffmpeg/libavcodec/microdvddec.c @@ -66,8 +66,24 @@ static void microdvd_set_tag(struct microdvd_tag *tags, struct microdvd_tag tag) // italic, bold, underline, strike-through #define MICRODVD_STYLES "ibus" +/* some samples have lines that start with a / indicating non persistent italic + * marker */ +static char *check_for_italic_slash_marker(struct microdvd_tag *tags, char *s) +{ + if (*s == '/') { + struct microdvd_tag tag = tags[indexof(MICRODVD_TAGS, 'y')]; + tag.key = 'y'; + tag.data1 |= 1 << 0 /* 'i' position in MICRODVD_STYLES */; + microdvd_set_tag(tags, tag); + s++; + } + return s; +} + static char *microdvd_load_tags(struct microdvd_tag *tags, char *s) { + s = check_for_italic_slash_marker(tags, s); + while (*s == '{') { char *start = s; char tag_char = *(s + 1); @@ -101,7 +117,7 @@ static char *microdvd_load_tags(struct microdvd_tag *tags, char *s) case 'C': tag.persistent = MICRODVD_PERSISTENT_ON; case 'c': - if (*s == '$') + while (*s == '$' || *s == '#') s++; tag.data1 = strtol(s, &s, 16) & 0x00ffffff; if (*s != '}') @@ -178,7 +194,7 @@ static char *microdvd_load_tags(struct microdvd_tag *tags, char *s) microdvd_set_tag(tags, tag); s++; } - return s; + return check_for_italic_slash_marker(tags, s); } static void microdvd_open_tags(AVBPrint *new_line, struct microdvd_tag *tags) @@ -260,8 +276,6 @@ static int microdvd_decode_frame(AVCodecContext *avctx, { AVSubtitle *sub = data; AVBPrint new_line; - char c; - char *decoded_sub; char *line = avpkt->data; char *end = avpkt->data + avpkt->size; struct microdvd_tag tags[sizeof(MICRODVD_TAGS) - 1] = {{0}}; @@ -269,15 +283,6 @@ static int microdvd_decode_frame(AVCodecContext *avctx, if (avpkt->size <= 0) return avpkt->size; - /* To be removed later */ - if (sscanf(line, "{%*d}{%*[0123456789]}%c", &c) == 1 && - line[avpkt->size - 1] == '\n') { - av_log(avctx, AV_LOG_ERROR, "AVPacket is not clean (contains timing " - "information and a trailing line break). You need to upgrade " - "your libavformat or sanitize your packet.\n"); - return AVERROR_INVALIDDATA; - } - av_bprint_init(&new_line, 0, 2048); // subtitle content @@ -301,18 +306,17 @@ static int microdvd_decode_frame(AVCodecContext *avctx, } } if (new_line.len) { - av_bprintf(&new_line, "\r\n"); - - av_bprint_finalize(&new_line, &decoded_sub); - if (*decoded_sub) { - int64_t start = avpkt->pts; - int64_t duration = avpkt->duration; - int ts_start = av_rescale_q(start, avctx->time_base, (AVRational){1,100}); - int ts_duration = duration != -1 ? - av_rescale_q(duration, avctx->time_base, (AVRational){1,100}) : -1; - ff_ass_add_rect(sub, decoded_sub, ts_start, ts_duration, 0); - } - av_free(decoded_sub); + int ret; + int64_t start = avpkt->pts; + int64_t duration = avpkt->duration; + int ts_start = av_rescale_q(start, avctx->time_base, (AVRational){1,100}); + int ts_duration = duration != -1 ? + av_rescale_q(duration, avctx->time_base, (AVRational){1,100}) : -1; + + ret = ff_ass_add_rect_bprint(sub, &new_line, ts_start, ts_duration); + av_bprint_finalize(&new_line, NULL); + if (ret < 0) + return ret; } *got_sub_ptr = sub->num_rects > 0;