diff mbox

[FFmpeg-devel] libavformat/utils: ignore outlier subtitle and data stream end times as well

Message ID 20161004011018.7577-1-rodger.combs@gmail.com
State Accepted
Headers show

Commit Message

Rodger Combs Oct. 4, 2016, 1:10 a.m. UTC
---
 libavformat/utils.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

Comments

Michael Niedermayer Oct. 5, 2016, 11:16 a.m. UTC | #1
On Mon, Oct 03, 2016 at 08:10:18PM -0500, Rodger Combs wrote:
> ---
>  libavformat/utils.c | 15 ++++++++++++---
>  1 file changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/libavformat/utils.c b/libavformat/utils.c
> index 3acb260..ce68408 100644
> --- a/libavformat/utils.c
> +++ b/libavformat/utils.c
> @@ -2524,7 +2524,7 @@ static int has_duration(AVFormatContext *ic)
>   */
>  static void update_stream_timings(AVFormatContext *ic)
>  {
> -    int64_t start_time, start_time1, start_time_text, end_time, end_time1;
> +    int64_t start_time, start_time1, start_time_text, end_time, end_time1, end_time_text;
>      int64_t duration, duration1, filesize;
>      int i;
>      AVStream *st;
> @@ -2533,6 +2533,7 @@ static void update_stream_timings(AVFormatContext *ic)
>      start_time = INT64_MAX;
>      start_time_text = INT64_MAX;
>      end_time   = INT64_MIN;
> +    end_time_text   = INT64_MIN;
>      duration   = INT64_MIN;
>      for (i = 0; i < ic->nb_streams; i++) {
>          st = ic->streams[i];
> @@ -2549,7 +2550,10 @@ static void update_stream_timings(AVFormatContext *ic)
>                                           AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
>              if (end_time1 != AV_NOPTS_VALUE && (end_time1 > 0 ? start_time1 <= INT64_MAX - end_time1 : start_time1 >= INT64_MIN - end_time1)) {
>                  end_time1 += start_time1;
> -                end_time = FFMAX(end_time, end_time1);
> +                if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE || st->codecpar->codec_type == AVMEDIA_TYPE_DATA)
> +                    end_time_text = FFMAX(end_time_text, end_time1);
> +                else
> +                    end_time = FFMAX(end_time, end_time1);
>              }
>              for (p = NULL; (p = av_find_program_from_stream(ic, p, i)); ) {
>                  if (p->start_time == AV_NOPTS_VALUE || p->start_time > start_time1)
> @@ -2569,10 +2573,15 @@ static void update_stream_timings(AVFormatContext *ic)
>      else if (start_time > start_time_text)
>          av_log(ic, AV_LOG_VERBOSE, "Ignoring outlier non primary stream starttime %f\n", start_time_text / (float)AV_TIME_BASE);
>  
> +    if (end_time == INT64_MIN || (end_time < end_time_text && end_time_text - end_time < AV_TIME_BASE))
> +        end_time = end_time_text;
> +    else if (end_time < end_time_text)

please add {} between if /else  this simplifies any possible future
diffs as adding a line in the future would otherwise need more lines
changed (to add  {})



> +        av_log(ic, AV_LOG_VERBOSE, "Ignoring outlier non primary stream endtime %f\n", end_time_text / (float)AV_TIME_BASE);
> +

>      if (start_time != INT64_MAX) {
>          ic->start_time = start_time;
>          if (end_time != INT64_MIN) {
> -            if (ic->nb_programs) {
> +            if (ic->nb_programs > 1) {

should be a seperate commit

LGTM otherwise

thanks

[...]
diff mbox

Patch

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 3acb260..ce68408 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -2524,7 +2524,7 @@  static int has_duration(AVFormatContext *ic)
  */
 static void update_stream_timings(AVFormatContext *ic)
 {
-    int64_t start_time, start_time1, start_time_text, end_time, end_time1;
+    int64_t start_time, start_time1, start_time_text, end_time, end_time1, end_time_text;
     int64_t duration, duration1, filesize;
     int i;
     AVStream *st;
@@ -2533,6 +2533,7 @@  static void update_stream_timings(AVFormatContext *ic)
     start_time = INT64_MAX;
     start_time_text = INT64_MAX;
     end_time   = INT64_MIN;
+    end_time_text   = INT64_MIN;
     duration   = INT64_MIN;
     for (i = 0; i < ic->nb_streams; i++) {
         st = ic->streams[i];
@@ -2549,7 +2550,10 @@  static void update_stream_timings(AVFormatContext *ic)
                                          AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
             if (end_time1 != AV_NOPTS_VALUE && (end_time1 > 0 ? start_time1 <= INT64_MAX - end_time1 : start_time1 >= INT64_MIN - end_time1)) {
                 end_time1 += start_time1;
-                end_time = FFMAX(end_time, end_time1);
+                if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE || st->codecpar->codec_type == AVMEDIA_TYPE_DATA)
+                    end_time_text = FFMAX(end_time_text, end_time1);
+                else
+                    end_time = FFMAX(end_time, end_time1);
             }
             for (p = NULL; (p = av_find_program_from_stream(ic, p, i)); ) {
                 if (p->start_time == AV_NOPTS_VALUE || p->start_time > start_time1)
@@ -2569,10 +2573,15 @@  static void update_stream_timings(AVFormatContext *ic)
     else if (start_time > start_time_text)
         av_log(ic, AV_LOG_VERBOSE, "Ignoring outlier non primary stream starttime %f\n", start_time_text / (float)AV_TIME_BASE);
 
+    if (end_time == INT64_MIN || (end_time < end_time_text && end_time_text - end_time < AV_TIME_BASE))
+        end_time = end_time_text;
+    else if (end_time < end_time_text)
+        av_log(ic, AV_LOG_VERBOSE, "Ignoring outlier non primary stream endtime %f\n", end_time_text / (float)AV_TIME_BASE);
+
     if (start_time != INT64_MAX) {
         ic->start_time = start_time;
         if (end_time != INT64_MIN) {
-            if (ic->nb_programs) {
+            if (ic->nb_programs > 1) {
                 for (i = 0; i < ic->nb_programs; i++) {
                     p = ic->programs[i];
                     if (p->start_time != AV_NOPTS_VALUE && p->end_time > p->start_time)