Commit d51e08bb authored by Clément Bœsch's avatar Clément Bœsch

lavc: switch from ts_end to duration in ff_ass_add_rect.

Make possible a end-to-presentation duration.
parent e7cb1615
...@@ -70,15 +70,18 @@ static int ts_to_string(char *str, int strlen, int ts) ...@@ -70,15 +70,18 @@ static int ts_to_string(char *str, int strlen, int ts)
} }
int ff_ass_add_rect(AVSubtitle *sub, const char *dialog, int ff_ass_add_rect(AVSubtitle *sub, const char *dialog,
int ts_start, int ts_end, int raw) int ts_start, int duration, int raw)
{ {
int len = 0, dlen, duration = ts_end - ts_start; int len = 0, dlen;
char s_start[16], s_end[16], header[48] = {0}; char s_start[16], s_end[16], header[48] = {0};
AVSubtitleRect **rects; AVSubtitleRect **rects;
if (!raw) { if (!raw) {
ts_to_string(s_start, sizeof(s_start), ts_start); ts_to_string(s_start, sizeof(s_start), ts_start);
ts_to_string(s_end, sizeof(s_end), ts_end ); if (duration == -1)
snprintf(s_end, sizeof(s_end), "9:59:59.99");
else
ts_to_string(s_end, sizeof(s_end), ts_start + duration);
len = snprintf(header, sizeof(header), "Dialogue: 0,%s,%s,", len = snprintf(header, sizeof(header), "Dialogue: 0,%s,%s,",
s_start, s_end); s_start, s_end);
} }
......
...@@ -74,7 +74,8 @@ int ff_ass_subtitle_header_default(AVCodecContext *avctx); ...@@ -74,7 +74,8 @@ int ff_ass_subtitle_header_default(AVCodecContext *avctx);
* @param sub pointer to the AVSubtitle * @param sub pointer to the AVSubtitle
* @param dialog ASS dialog to add to sub * @param dialog ASS dialog to add to sub
* @param ts_start start timestamp for this dialog (in 1/100 second unit) * @param ts_start start timestamp for this dialog (in 1/100 second unit)
* @param ts_end end timestamp for this dialog (in 1/100 second unit) * @param duration duration for this dialog (in 1/100 second unit), can be -1
* to last until the end of the presentation
* @param raw when set to 1, it indicates that dialog contains a whole ASS * @param raw when set to 1, it indicates that dialog contains a whole ASS
* dialog line which should be copied as is. * dialog line which should be copied as is.
* when set to 0, it indicates that dialog contains only the Text * when set to 0, it indicates that dialog contains only the Text
...@@ -85,6 +86,6 @@ int ff_ass_subtitle_header_default(AVCodecContext *avctx); ...@@ -85,6 +86,6 @@ int ff_ass_subtitle_header_default(AVCodecContext *avctx);
* A negative value indicates an error. * A negative value indicates an error.
*/ */
int ff_ass_add_rect(AVSubtitle *sub, const char *dialog, int ff_ass_add_rect(AVSubtitle *sub, const char *dialog,
int ts_start, int ts_end, int raw); int ts_start, int duration, int raw);
#endif /* AVCODEC_ASS_H */ #endif /* AVCODEC_ASS_H */
...@@ -175,8 +175,6 @@ static int jacosub_decode_frame(AVCodecContext *avctx, ...@@ -175,8 +175,6 @@ static int jacosub_decode_frame(AVCodecContext *avctx,
goto end; goto end;
if (*ptr) { if (*ptr) {
int ts_start = avpkt->pts;
int ts_end = avpkt->pts + avpkt->duration;
AVBPrint buffer; AVBPrint buffer;
char *dec_sub; char *dec_sub;
...@@ -188,7 +186,7 @@ static int jacosub_decode_frame(AVCodecContext *avctx, ...@@ -188,7 +186,7 @@ static int jacosub_decode_frame(AVCodecContext *avctx,
av_bprint_init(&buffer, JSS_MAX_LINESIZE, JSS_MAX_LINESIZE); av_bprint_init(&buffer, JSS_MAX_LINESIZE, JSS_MAX_LINESIZE);
jacosub_to_ass(avctx, &buffer, ptr); jacosub_to_ass(avctx, &buffer, ptr);
av_bprint_finalize(&buffer, &dec_sub); av_bprint_finalize(&buffer, &dec_sub);
ff_ass_add_rect(sub, dec_sub, ts_start, ts_end, 0); ff_ass_add_rect(sub, dec_sub, avpkt->pts, avpkt->duration, 0);
av_free(dec_sub); av_free(dec_sub);
} }
......
...@@ -261,10 +261,6 @@ static int microdvd_decode_frame(AVCodecContext *avctx, ...@@ -261,10 +261,6 @@ static int microdvd_decode_frame(AVCodecContext *avctx,
char *decoded_sub; char *decoded_sub;
char *line = avpkt->data; char *line = avpkt->data;
char *end = avpkt->data + avpkt->size; char *end = avpkt->data + avpkt->size;
int64_t frame_start = avpkt->pts;
int64_t frame_end = avpkt->pts + avpkt->duration;
int ts_start = av_rescale_q(frame_start, avctx->time_base, (AVRational){1,100});
int ts_end = av_rescale_q(frame_end, avctx->time_base, (AVRational){1,100});
struct microdvd_tag tags[sizeof(MICRODVD_TAGS) - 1] = {{0}}; struct microdvd_tag tags[sizeof(MICRODVD_TAGS) - 1] = {{0}};
if (avpkt->size <= 0) if (avpkt->size <= 0)
...@@ -299,8 +295,14 @@ static int microdvd_decode_frame(AVCodecContext *avctx, ...@@ -299,8 +295,14 @@ static int microdvd_decode_frame(AVCodecContext *avctx,
end: end:
av_bprint_finalize(&new_line, &decoded_sub); av_bprint_finalize(&new_line, &decoded_sub);
if (*decoded_sub) if (*decoded_sub) {
ff_ass_add_rect(sub, decoded_sub, ts_start, ts_end, 0); 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); av_free(decoded_sub);
*got_sub_ptr = sub->num_rects > 0; *got_sub_ptr = sub->num_rects > 0;
......
...@@ -222,7 +222,7 @@ static int srt_decode_frame(AVCodecContext *avctx, ...@@ -222,7 +222,7 @@ static int srt_decode_frame(AVCodecContext *avctx,
break; break;
ptr = srt_to_ass(avctx, buffer, buffer+sizeof(buffer), ptr, ptr = srt_to_ass(avctx, buffer, buffer+sizeof(buffer), ptr,
x1, y1, x2, y2); x1, y1, x2, y2);
ff_ass_add_rect(sub, buffer, ts_start, ts_end, 0); ff_ass_add_rect(sub, buffer, ts_start, ts_end-ts_start, 0);
} }
*got_sub_ptr = sub->num_rects > 0; *got_sub_ptr = sub->num_rects > 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment