From d896643576f4f03f0f2f4bc2b653895bb4c07df3 Mon Sep 17 00:00:00 2001
From: Nongji Chen <nchen@aminocom.com>
Date: Thu, 26 Jul 2018 16:25:19 +0300
Subject: [PATCH 2/2] ffmpeg_filter: keep sub2video size configuration if
likely a re-init
This way the filter chain does not accidentally mis-configure itself
in case a filter chain re-initialization happens during run-time.
---
fftools/ffmpeg_filter.c | 23 ++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)
@@ -698,11 +698,17 @@ void check_filter_outputs(void)
static int sub2video_prepare(InputStream *ist, InputFilter *ifilter)
{
AVFormatContext *avf = input_files[ist->file_index]->ctx;
- int i, w, h;
+ int i, w, h, keep_existing = 0;
/* Compute the size of the canvas for the subtitles stream.
- If the subtitles codecpar has set a size, use it. Otherwise use the
- maximum dimensions of the video streams in the same file. */
+
+ If the ifilter->width|height are nonzero and match the sub2video.w|h,
+ keep the configuration as this is likely a re-initialization
+ of the filter chain.
+
+ Otherwise if the subtitles codecpar has set a size, use it, and
+ utilize either the input filter's width|height or the maximum
+ dimensions of the video streams in the same file. */
w = ifilter->width;
h = ifilter->height;
if (!(w && h)) {
@@ -717,12 +723,19 @@ static int sub2video_prepare(InputStream *ist, InputFilter *ifilter)
h = FFMAX(h, 576);
}
av_log(avf, AV_LOG_INFO, "sub2video: using %dx%d canvas\n", w, h);
+ } else if (w == ist->sub2video.w && h == ist->sub2video.h) {
+ // This is most likely a re-configuration, so keep the currently
+ // configured values for width and height.
+ keep_existing = 1;
}
+
ist->sub2video.w = ifilter->width = w;
ist->sub2video.h = ifilter->height = h;
- ifilter->width = ist->dec_ctx->width ? ist->dec_ctx->width : ist->sub2video.w;
- ifilter->height = ist->dec_ctx->height ? ist->dec_ctx->height : ist->sub2video.h;
+ if (!keep_existing) {
+ ifilter->width = ist->dec_ctx->width ? ist->dec_ctx->width : ist->sub2video.w;
+ ifilter->height = ist->dec_ctx->height ? ist->dec_ctx->height : ist->sub2video.h;
+ }
/* rectangles are AV_PIX_FMT_PAL8, but we have no guarantee that the
palettes for all rectangles are identical or compatible */
--
2.17.1