From 3e396ca8eda473d619ce5ffc1e01950c978194e8 Mon Sep 17 00:00:00 2001 From: Marton Balint Date: Sat, 23 Nov 2013 17:25:46 +0100 Subject: [PATCH 1/3] ffmpeg: do not pass possibly undefined subtitles to sub2video_update It should not matter for real-life usage, it is just cleaner this way. Signed-off-by: Marton Balint Reviewed-by: Nicolas George --- ffmpeg.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ffmpeg.c b/ffmpeg.c index 62a548761c..bbd30190cb 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -1822,9 +1822,12 @@ static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output) FFSWAP(AVSubtitle, subtitle, ist->prev_sub.subtitle); } + if (!*got_output) + return ret; + sub2video_update(ist, &subtitle); - if (!*got_output || !subtitle.num_rects) + if (!subtitle.num_rects) return ret; for (i = 0; i < nb_output_streams; i++) { From 4d6f2ff524afc01f2af30677ca271a6387cf8657 Mon Sep 17 00:00:00 2001 From: Marton Balint Date: Sat, 23 Nov 2013 17:27:22 +0100 Subject: [PATCH 2/3] ffmpeg: free empty subtitles as well in transcode_subtitles Even if it does not matter at the moment, because subtitles with num_rect == 0 have no memory allocated, this is how we expect the users to use the API, a returned AVSubtitle should be freed with avsubtitle_free. Signed-off-by: Marton Balint Reviewed-by: Nicolas George --- ffmpeg.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ffmpeg.c b/ffmpeg.c index bbd30190cb..105efbcb22 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -1828,7 +1828,7 @@ static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output) sub2video_update(ist, &subtitle); if (!subtitle.num_rects) - return ret; + goto out; for (i = 0; i < nb_output_streams; i++) { OutputStream *ost = output_streams[i]; @@ -1839,6 +1839,7 @@ static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output) do_subtitle_out(output_files[ost->file_index]->ctx, ost, ist, &subtitle); } +out: avsubtitle_free(&subtitle); return ret; } From 31bb172be26aa7531a0917994d79ea5dc3709a0b Mon Sep 17 00:00:00 2001 From: Marton Balint Date: Sat, 23 Nov 2013 17:48:49 +0100 Subject: [PATCH 3/3] ffmpeg: ensure that -fix_sub_duration doesnt create subtitles with zero duration When fix_sub_duration is used, and the duration fixing code is generating 0 duration, that is definitely zero, and not undefined or infinite (which may be the case for decoded AVSubtitles depending on the codec), so it is safe to drop it. It fixes teletext subtitle sources, when the subtitles are transmitted twice after each other for some reason. Signed-off-by: Marton Balint Reviewed-by: Nicolas George --- ffmpeg.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ffmpeg.c b/ffmpeg.c index 105efbcb22..6411ce3039 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -1807,19 +1807,23 @@ static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output) } if (ist->fix_sub_duration) { + int end = 1; if (ist->prev_sub.got_output) { - int end = av_rescale(subtitle.pts - ist->prev_sub.subtitle.pts, - 1000, AV_TIME_BASE); + end = av_rescale(subtitle.pts - ist->prev_sub.subtitle.pts, + 1000, AV_TIME_BASE); if (end < ist->prev_sub.subtitle.end_display_time) { av_log(ist->st->codec, AV_LOG_DEBUG, - "Subtitle duration reduced from %d to %d\n", - ist->prev_sub.subtitle.end_display_time, end); + "Subtitle duration reduced from %d to %d%s\n", + ist->prev_sub.subtitle.end_display_time, end, + end <= 0 ? ", dropping it" : ""); ist->prev_sub.subtitle.end_display_time = end; } } FFSWAP(int, *got_output, ist->prev_sub.got_output); FFSWAP(int, ret, ist->prev_sub.ret); FFSWAP(AVSubtitle, subtitle, ist->prev_sub.subtitle); + if (end <= 0) + goto out; } if (!*got_output)