Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

More PGS improvements

Add patch to fix timestamp handling in libav pgs decoder and add
"forced" subtitle flag support.

Add support for foreign audio search and forced subtitles to decpgs.c

Move processing of interjob foreign audio search to before
initialization of filters.  The subtitle found needs to exist in
list_subtitle in order for the rendersub filter to initialize properly.

Add capability to initialize filters in a different order than they are
executed in the pipeline.  rendersub needs to be initialized after we
know cropping (cropscale), but must be executed before cropping.

Fix a problem in rendersub.c blend function that caused subtitles that
have the same resolution as the video frame to be dropped.
  • Loading branch information...
commit 3fdd1eb8ffd5c6a4a02a665ea2e045ef97228528 1 parent 0f29d8b
John Stebbins authored April 22, 2012
82  contrib/ffmpeg/A09-pgs-pts.patch
... ...
@@ -0,0 +1,82 @@
  1
+diff -Naur ffmpeg-v0.7-1696-gcae4f4b.orig/libavcodec/avcodec.h ffmpeg-v0.7-1696-gcae4f4b/libavcodec/avcodec.h
  2
+--- ffmpeg-v0.7-1696-gcae4f4b.orig/libavcodec/avcodec.h	2011-11-03 12:29:48.000000000 +0100
  3
++++ ffmpeg-v0.7-1696-gcae4f4b/libavcodec/avcodec.h	2012-04-22 10:59:41.122351884 +0200
  4
+@@ -3193,6 +3193,7 @@
  5
+     unsigned num_rects;
  6
+     AVSubtitleRect **rects;
  7
+     int64_t pts;    ///< Same as packet pts, in AV_TIME_BASE
  8
++    uint8_t forced;
  9
+ } AVSubtitle;
  10
+ 
  11
+ /* packet functions */
  12
+diff -Naur ffmpeg-v0.7-1696-gcae4f4b.orig/libavcodec/pgssubdec.c ffmpeg-v0.7-1696-gcae4f4b/libavcodec/pgssubdec.c
  13
+--- ffmpeg-v0.7-1696-gcae4f4b.orig/libavcodec/pgssubdec.c	2011-11-03 12:29:48.000000000 +0100
  14
++++ ffmpeg-v0.7-1696-gcae4f4b/libavcodec/pgssubdec.c	2012-04-22 13:09:29.499671541 +0200
  15
+@@ -45,6 +45,8 @@
  16
+     int y;
  17
+     int id_number;
  18
+     int object_number;
  19
++    uint8_t composition_flag;
  20
++    int64_t pts;
  21
+ } PGSSubPresentation;
  22
+ 
  23
+ typedef struct PGSSubPicture {
  24
+@@ -271,7 +273,8 @@
  25
+  * @todo TODO: Implement forcing of subtitles
  26
+  */
  27
+ static void parse_presentation_segment(AVCodecContext *avctx,
  28
+-                                       const uint8_t *buf, int buf_size)
  29
++                                       const uint8_t *buf, int buf_size,
  30
++                                       int64_t pts)
  31
+ {
  32
+     PGSSubContext *ctx = avctx->priv_data;
  33
+ 
  34
+@@ -280,6 +283,8 @@
  35
+     int w = bytestream_get_be16(&buf);
  36
+     int h = bytestream_get_be16(&buf);
  37
+ 
  38
++    ctx->presentation.pts = pts;
  39
++
  40
+     av_dlog(avctx, "Video Dimensions %dx%d\n",
  41
+             w, h);
  42
+     if (av_image_check_size(w, h, 0, avctx) >= 0)
  43
+@@ -299,16 +304,17 @@
  44
+     buf += 3;
  45
+ 
  46
+     ctx->presentation.object_number = bytestream_get_byte(&buf);
  47
++    ctx->presentation.composition_flag = 0;
  48
+     if (!ctx->presentation.object_number)
  49
+         return;
  50
+ 
  51
+     /*
  52
+-     * Skip 4 bytes of unknown:
  53
++     * Skip 3 bytes of unknown:
  54
+      *     object_id_ref (2 bytes),
  55
+      *     window_id_ref,
  56
+-     *     composition_flag (0x80 - object cropped, 0x40 - object forced)
  57
+      */
  58
+-    buf += 4;
  59
++    buf += 3;
  60
++    ctx->presentation.composition_flag = bytestream_get_byte(&buf);
  61
+ 
  62
+     x = bytestream_get_be16(&buf);
  63
+     y = bytestream_get_be16(&buf);
  64
+@@ -356,6 +362,9 @@
  65
+      */
  66
+ 
  67
+     memset(sub, 0, sizeof(*sub));
  68
++    sub->pts = ctx->presentation.pts;
  69
++    sub->forced = (ctx->presentation.composition_flag & 0x40) != 0;
  70
++
  71
+     // Blank if last object_number was 0.
  72
+     // Note that this may be wrong for more complex subtitles.
  73
+     if (!ctx->presentation.object_number)
  74
+@@ -441,7 +450,7 @@
  75
+             parse_picture_segment(avctx, buf, segment_length);
  76
+             break;
  77
+         case PRESENTATION_SEGMENT:
  78
+-            parse_presentation_segment(avctx, buf, segment_length);
  79
++            parse_presentation_segment(avctx, buf, segment_length, avpkt->pts);
  80
+             break;
  81
+         case WINDOW_SEGMENT:
  82
+             /*
1  libhb/common.h
@@ -928,6 +928,7 @@ struct hb_filter_object_s
928 928
 {
929 929
     int                     id;
930 930
     int                     enforce_order;
  931
+    int                     init_index;
931 932
     char                  * name;
932 933
     char                  * settings;
933 934
 
1  libhb/cropscale.c
@@ -30,6 +30,7 @@ hb_filter_object_t hb_filter_crop_scale =
30 30
 {
31 31
     .id            = HB_FILTER_CROP_SCALE,
32 32
     .enforce_order = 1,
  33
+    .init_index    = 0,
33 34
     .name          = "Crop and Scale",
34 35
     .settings      = NULL,
35 36
     .init          = hb_crop_scale_init,
1  libhb/deblock.c
@@ -63,6 +63,7 @@ hb_filter_object_t hb_filter_deblock =
63 63
 {
64 64
     .id            = HB_FILTER_DEBLOCK,
65 65
     .enforce_order = 1,
  66
+    .init_index    = 0,
66 67
     .name          = "Deblock (pp7)",
67 68
     .settings      = NULL,
68 69
     .init          = hb_deblock_init,
1  libhb/decomb.c
@@ -233,6 +233,7 @@ hb_filter_object_t hb_filter_decomb =
233 233
 {
234 234
     .id            = HB_FILTER_DECOMB,
235 235
     .enforce_order = 1,
  236
+    .init_index    = 0,
236 237
     .name          = "Decomb",
237 238
     .settings      = NULL,
238 239
     .init          = hb_decomb_init,
192  libhb/decpgssub.c
@@ -4,8 +4,7 @@
4 4
 struct hb_work_private_s
5 5
 {
6 6
     AVCodecContext * context;
7  
-    hb_buffer_t * subtitle;
8  
-    uint32_t frame;
  7
+    hb_job_t * job;
9 8
 };
10 9
 
11 10
 static int decsubInit( hb_work_object_t * w, hb_job_t * job )
@@ -14,13 +13,12 @@ static int decsubInit( hb_work_object_t * w, hb_job_t * job )
14 13
     AVCodecContext *context = avcodec_alloc_context3( codec );
15 14
     context->codec = codec;
16 15
 
17  
-    hb_work_private_t * private_data;
18  
-    private_data = calloc( 1, sizeof( hb_work_private_t ) );
19  
-    w->private_data = private_data;
  16
+    hb_work_private_t * pv;
  17
+    pv = calloc( 1, sizeof( hb_work_private_t ) );
  18
+    w->private_data = pv;
20 19
 
21  
-    private_data->context = context;
22  
-    private_data->subtitle = NULL;
23  
-    private_data->frame = 0;
  20
+    pv->context = context;
  21
+    pv->job = job;
24 22
 
25 23
     return 0;
26 24
 }
@@ -28,15 +26,14 @@ static int decsubInit( hb_work_object_t * w, hb_job_t * job )
28 26
 static int decsubWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
29 27
                 hb_buffer_t ** buf_out )
30 28
 {
31  
-    hb_work_private_t * private_data = w->private_data;
  29
+    hb_work_private_t * pv = w->private_data;
32 30
     hb_buffer_t * in = *buf_in;
33 31
 
34 32
     if ( in->size <= 0 )
35 33
     {
36 34
         /* EOF on input stream - send it downstream & say that we're done */
37 35
         *buf_out = in;
38  
-        *buf_in = private_data->subtitle;
39  
-        private_data->subtitle = NULL;
  36
+        *buf_in = NULL;
40 37
 
41 38
         return HB_WORK_DONE;
42 39
     }
@@ -44,122 +41,145 @@ static int decsubWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
44 41
     AVSubtitle subtitle;
45 42
     memset( &subtitle, 0, sizeof(subtitle) );
46 43
 
47  
-    AVPacket packet;
48  
-    av_init_packet( &packet );
49  
-    packet.data = in->data;
50  
-    packet.size = in->size;
  44
+    AVPacket avp;
  45
+    av_init_packet( &avp );
  46
+    avp.data = in->data;
  47
+    avp.size = in->size;
  48
+    // libav wants pkt pts in AV_TIME_BASE units
  49
+    avp.pts = av_rescale(in->s.start, AV_TIME_BASE, 90000);
51 50
 
52 51
     int has_subtitle = 0;
53 52
 
54 53
     do
55 54
     {
56  
-        int usedBytes = avcodec_decode_subtitle2( private_data->context, &subtitle, &has_subtitle, &packet );
  55
+        int usedBytes = avcodec_decode_subtitle2( pv->context, &subtitle, &has_subtitle, &avp );
57 56
         if (usedBytes < 0)
58 57
         {
59  
-            hb_log("unable to decode subtitle with %d bytes.", packet.size);
  58
+            hb_log("unable to decode subtitle with %d bytes.", avp.size);
60 59
             return HB_WORK_OK;
61 60
         }
62 61
 
63  
-        if (usedBytes <= packet.size)
  62
+        if (usedBytes <= avp.size)
64 63
         {
65  
-            packet.data += usedBytes;
66  
-            packet.size -= usedBytes;
  64
+            avp.data += usedBytes;
  65
+            avp.size -= usedBytes;
67 66
         }
68 67
         else
69 68
         {
70  
-            packet.size = 0;
  69
+            avp.size = 0;
71 70
         }
72 71
 
73  
-        if (has_subtitle)
  72
+        // The sub is "usable" if:
  73
+        // 1. libav returned a sub AND
  74
+        // 2. we are scanning for foreign audio subs OR
  75
+        // 3. we want all subs (e.g. not forced) OR
  76
+        // 4. the sub is forced and we only want forced OR
  77
+        // 5. subtitle clears the previous sub (these are never forced)
  78
+        //    subtitle.num_rects == 0
  79
+        uint8_t useable_sub = (has_subtitle && 
  80
+                ( pv->job->indepth_scan ||
  81
+                  subtitle.num_rects == 0 ||
  82
+                  !w->subtitle->config.force ||
  83
+                  ( w->subtitle->config.force && subtitle.forced ) ) );
  84
+
  85
+        if (useable_sub)
74 86
         {
  87
+            int64_t pts = av_rescale(subtitle.pts, 90000, AV_TIME_BASE);
75 88
             hb_buffer_t * out = NULL;
76  
-            if (subtitle.num_rects != 0)
  89
+
  90
+            if( pv->job->indepth_scan )
  91
+            {
  92
+                if (subtitle.forced)
  93
+                {
  94
+                    w->subtitle->forced_hits++;
  95
+                }
  96
+            }
  97
+            else
77 98
             {
78  
-                unsigned rectIndex;
79  
-                for (rectIndex = 0; rectIndex < subtitle.num_rects; rectIndex++)
  99
+                if (subtitle.num_rects != 0)
80 100
                 {
81  
-                    AVSubtitleRect *rect = subtitle.rects[rectIndex];
  101
+                    unsigned ii;
  102
+                    for (ii = 0; ii < subtitle.num_rects; ii++)
  103
+                    {
  104
+                        AVSubtitleRect *rect = subtitle.rects[ii];
82 105
 
83  
-                    hb_buffer_t * image = hb_frame_buffer_init(
84  
-                            PIX_FMT_YUVA420P, rect->w, rect->h );
  106
+                        hb_buffer_t * image = hb_frame_buffer_init(
  107
+                                PIX_FMT_YUVA420P, rect->w, rect->h );
85 108
 
86  
-                    image->s.id     = in->s.id;
87  
-                    image->sequence = in->sequence;
88  
-                    image->s.start  = in->s.start;
89  
-                    image->s.stop   = 0;
90  
-                    image->f.x      = rect->x;
91  
-                    image->f.y      = rect->y;
  109
+                        image->s.id     = in->s.id;
  110
+                        image->sequence = in->sequence;
  111
+                        image->s.start  = pts;
  112
+                        image->s.stop   = 0;
  113
+                        image->f.x      = rect->x;
  114
+                        image->f.y      = rect->y;
92 115
 
93  
-                    uint8_t *lum     = image->plane[0].data;
94  
-                    uint8_t *chromaU = image->plane[1].data;
95  
-                    uint8_t *chromaV = image->plane[2].data;
96  
-                    uint8_t *alpha   = image->plane[3].data;
  116
+                        uint8_t *lum     = image->plane[0].data;
  117
+                        uint8_t *chromaU = image->plane[1].data;
  118
+                        uint8_t *chromaV = image->plane[2].data;
  119
+                        uint8_t *alpha   = image->plane[3].data;
97 120
 
98  
-                    int xx, yy;
99  
-                    for (yy = 0; yy < rect->h; yy++)
100  
-                    {
101  
-                        for (xx = 0; xx < rect->w; xx++)
  121
+                        int xx, yy;
  122
+                        for (yy = 0; yy < rect->h; yy++)
102 123
                         {
103  
-                            unsigned pixel = yy * rect->w + xx;
104  
-                            uint8_t color = rect->pict.data[0][pixel];
105  
-                            uint32_t argb;
106  
-                            memcpy( &argb, &rect->pict.data[1][4 * color], 4);
107  
-                            uint32_t yuv = hb_rgb2yuv(argb);
108  
-
109  
-                            lum[xx] = (yuv >> 16) & 0xff;
110  
-                            alpha[xx] = (argb >> 24) & 0xff;
111  
-                            if ((xx & 1) == 0 && (yy & 1) == 0)
  124
+                            for (xx = 0; xx < rect->w; xx++)
112 125
                             {
113  
-                                chromaU[xx>>1] = (yuv >> 8) & 0xff;
114  
-                                chromaV[xx>>1] = yuv & 0xff;
  126
+                                uint32_t argb, yuv;
  127
+                                int pixel;
  128
+                                uint8_t color;
  129
+
  130
+                                pixel = yy * rect->w + xx;
  131
+                                color = rect->pict.data[0][pixel];
  132
+                                argb = ((uint32_t*)rect->pict.data[1])[color];
  133
+                                yuv = hb_rgb2yuv(argb);
  134
+
  135
+                                lum[xx] = (yuv >> 16) & 0xff;
  136
+                                alpha[xx] = (argb >> 24) & 0xff;
  137
+                                if ((xx & 1) == 0 && (yy & 1) == 0)
  138
+                                {
  139
+                                    chromaU[xx>>1] = (yuv >> 8) & 0xff;
  140
+                                    chromaV[xx>>1] = yuv & 0xff;
  141
+                                }
115 142
                             }
  143
+                            lum += image->plane[0].stride;
  144
+                            if ((yy & 1) == 0)
  145
+                            {
  146
+                                chromaU += image->plane[1].stride;
  147
+                                chromaV += image->plane[2].stride;
  148
+                            }
  149
+                            alpha += image->plane[3].stride;
116 150
                         }
117  
-                        lum += image->plane[0].stride;
118  
-                        if ((yy & 1) == 0)
119  
-                        {
120  
-                            chromaU += image->plane[1].stride;
121  
-                            chromaV += image->plane[2].stride;
122  
-                        }
123  
-                        alpha += image->plane[3].stride;
124  
-                    }
125 151
 
126  
-                    image->sub = NULL;
127  
-                    out = image;
  152
+                        image->sub = NULL;
  153
+                        out = image;
  154
+                    }
  155
+                }
  156
+                else
  157
+                {
  158
+                    out = hb_buffer_init( 1 );
  159
+
  160
+                    out->s.id     = in->s.id;
  161
+                    out->s.start  = pts;
  162
+                    out->s.stop   = 0;
  163
+                    out->f.x      = 0;
  164
+                    out->f.y      = 0;
  165
+                    out->f.width  = 0;
  166
+                    out->f.height = 0;
128 167
                 }
129  
-            }
130  
-            else
131  
-            {
132  
-                out = hb_buffer_init( 0 );
133  
-
134  
-                out->s.id     = in->s.id;
135  
-                out->s.start  = in->s.start;
136  
-                out->s.stop   = in->s.start;
137  
-                out->f.x      = 0;
138  
-                out->f.y      = 0;
139  
-                out->f.width  = 0;
140  
-                out->f.height = 0;
141 168
             }
142 169
 
143 170
             *buf_out = out;
144 171
         }
145  
-        else
146  
-        {
147  
-            hb_log("no subtitle.");
148  
-        }
149 172
 
150  
-    } while (packet.size > 0);
  173
+    } while (avp.size > 0);
151 174
 
152 175
     return HB_WORK_OK;
153 176
 }
154 177
 
155 178
 static void decsubClose( hb_work_object_t * w )
156 179
 {
157  
-    hb_work_private_t * private_data = w->private_data;
158  
-    avcodec_flush_buffers( private_data->context );
159  
-    avcodec_close( private_data->context );
160  
-
161  
-    if (private_data->subtitle != NULL)
162  
-        hb_buffer_close( &private_data->subtitle );
  180
+    hb_work_private_t * pv = w->private_data;
  181
+    avcodec_flush_buffers( pv->context );
  182
+    avcodec_close( pv->context );
163 183
 }
164 184
 
165 185
 hb_work_object_t hb_decpgssub =
1  libhb/deinterlace.c
@@ -77,6 +77,7 @@ hb_filter_object_t hb_filter_deinterlace =
77 77
 {
78 78
     .id            = HB_FILTER_DEINTERLACE,
79 79
     .enforce_order = 1,
  80
+    .init_index    = 0,
80 81
     .name          = "Deinterlace (ffmpeg or yadif/mcdeint)",
81 82
     .settings      = NULL,
82 83
     .init          = hb_deinterlace_init,
1  libhb/denoise.c
@@ -46,6 +46,7 @@ hb_filter_object_t hb_filter_denoise =
46 46
 {
47 47
     .id            = HB_FILTER_DENOISE,
48 48
     .enforce_order = 1,
  49
+    .init_index    = 0,
49 50
     .name          = "Denoise (hqdn3d)",
50 51
     .settings      = NULL,
51 52
     .init          = hb_denoise_init,
1  libhb/detelecine.c
@@ -98,6 +98,7 @@ hb_filter_object_t hb_filter_detelecine =
98 98
 {
99 99
     .id            = HB_FILTER_DETELECINE,
100 100
     .enforce_order = 1,
  101
+    .init_index    = 0,
101 102
     .name          = "Detelecine (pullup)",
102 103
     .settings      = NULL,
103 104
     .init          = hb_detelecine_init,
2  libhb/hb.c
@@ -1570,7 +1570,7 @@ void hb_add( hb_handle_t * h, hb_job_t * job )
1570 1570
         {
1571 1571
             subtitle = hb_list_item( title->list_subtitle, i );
1572 1572
             if( strcmp( subtitle->iso639_2, audio_lang ) == 0 &&
1573  
-                subtitle->source == VOBSUB )
  1573
+                hb_subtitle_can_force( subtitle->source ) )
1574 1574
             {
1575 1575
                 /*
1576 1576
                  * Matched subtitle language with audio language, so
10  libhb/rendersub.c
@@ -62,6 +62,7 @@ hb_filter_object_t hb_filter_render_sub =
62 62
 {
63 63
     .id            = HB_FILTER_RENDER_SUB,
64 64
     .enforce_order = 1,
  65
+    .init_index    = 1,
65 66
     .name          = "Subtitle renderer",
66 67
     .settings      = NULL,
67 68
     .init          = hb_rendersub_init,
@@ -90,16 +91,15 @@ static void blend( hb_buffer_t *dst, hb_buffer_t *src, int left, int top )
90 91
     }
91 92
 
92 93
     ww = src->f.width;
93  
-    if( left + src->f.width > dst->f.width )
  94
+    if( src->f.width - x0 > dst->f.width - left )
94 95
     {
95  
-        ww = dst->f.width - ( left + src->f.width );
  96
+        ww = dst->f.width - left + x0;
96 97
     }
97 98
     hh = src->f.height;
98  
-    if( top + src->f.height > dst->f.height )
  99
+    if( src->f.height - y0 > dst->f.height - top )
99 100
     {
100  
-        hh = dst->f.height - ( top + src->f.height );
  101
+        hh = dst->f.height - top + y0;
101 102
     }
102  
-
103 103
     // Blend luma
104 104
     for( yy = y0; yy < hh; yy++ )
105 105
     {
1  libhb/rotate.c
@@ -46,6 +46,7 @@ hb_filter_object_t hb_filter_rotate =
46 46
 {
47 47
     .id            = HB_FILTER_ROTATE,
48 48
     .enforce_order = 0,
  49
+    .init_index    = 2,
49 50
     .name          = "Rotate (rotate & flip image axes)",
50 51
     .settings      = NULL,
51 52
     .init          = hb_rotate_init,
1  libhb/vfr.c
@@ -46,6 +46,7 @@ hb_filter_object_t hb_filter_vfr =
46 46
 {
47 47
     .id            = HB_FILTER_VFR,
48 48
     .enforce_order = 1,
  49
+    .init_index    = 0,
49 50
     .name          = "Framerate Shaper",
50 51
     .settings      = NULL,
51 52
     .init          = hb_vfr_init,
164  libhb/work.c
@@ -489,6 +489,46 @@ void correct_framerate( hb_job_t * job )
489 489
     interjob->vrate_base = job->vrate_base;
490 490
 }
491 491
 
  492
+void hb_filter_init_next( hb_list_t * list, int *score, int *ret_pos )
  493
+{
  494
+    int count = hb_list_count( list );
  495
+    int pos = *ret_pos + 1;
  496
+    int ii = 0;
  497
+    if ( pos == 0 )
  498
+    {
  499
+        hb_filter_object_t * filter = hb_list_item( list, pos );
  500
+        if ( filter->init_index == *score )
  501
+        {
  502
+            *ret_pos = pos;
  503
+            return;
  504
+        }
  505
+        pos++;
  506
+    }
  507
+    while (1)
  508
+    {
  509
+        if ( pos == count )
  510
+        {
  511
+            pos = 0;
  512
+            (*score)++;
  513
+        }
  514
+        hb_filter_object_t * filter = hb_list_item( list, pos );
  515
+        if ( filter->init_index == *score )
  516
+        {
  517
+            *ret_pos = pos;
  518
+            return;
  519
+        }
  520
+        pos++;
  521
+        ii++;
  522
+        if (ii > count)
  523
+        {
  524
+            // This is an error that should never happen
  525
+            hb_error("internal error during filter initialization");
  526
+            *ret_pos = -1;
  527
+            return;
  528
+        }
  529
+    }
  530
+}
  531
+
492 532
 /**
493 533
  * Job initialization rountine.
494 534
  * Initializes fifos.
@@ -529,11 +569,67 @@ static void do_job( hb_job_t * job )
529 569
 
530 570
     hb_log( "starting job" );
531 571
 
  572
+    /*
  573
+     * Look for the scanned subtitle in the existing subtitle list
  574
+     * select_subtitle implies that we did a scan.
  575
+     */
  576
+    if ( !job->indepth_scan && interjob->select_subtitle &&
  577
+         ( job->pass == 0 || job->pass == 2 ) )
  578
+    {
  579
+        /*
  580
+         * Disable forced subtitles if we didn't find any in the scan
  581
+         * so that we display normal subtitles instead.
  582
+         */
  583
+        if( interjob->select_subtitle->config.force && 
  584
+            interjob->select_subtitle->forced_hits == 0 )
  585
+        {
  586
+            interjob->select_subtitle->config.force = 0;
  587
+        }
  588
+        for( i=0; i < hb_list_count(title->list_subtitle); i++ )
  589
+        {
  590
+            subtitle =  hb_list_item( title->list_subtitle, i );
  591
+
  592
+            if( subtitle )
  593
+            {
  594
+                /*
  595
+                * Remove the scanned subtitle from the subtitle list if
  596
+                * it would result in an identical duplicate subtitle track
  597
+                * or an emty track (forced and no forced hits).
  598
+                */
  599
+                if( ( interjob->select_subtitle->id == subtitle->id ) &&
  600
+                    ( ( interjob->select_subtitle->forced_hits == 0 &&
  601
+                        subtitle->config.force ) ||
  602
+                    ( subtitle->config.force == interjob->select_subtitle->config.force ) ) )
  603
+                {
  604
+                    *subtitle = *(interjob->select_subtitle);
  605
+                    free( interjob->select_subtitle );
  606
+                    interjob->select_subtitle = NULL;
  607
+                    break;
  608
+                }
  609
+            }
  610
+        }
  611
+
  612
+        if( interjob->select_subtitle )
  613
+        {
  614
+            /*
  615
+             * Its not in the existing list
  616
+             *
  617
+             * Must be second pass of a two pass with subtitle scan enabled, so
  618
+             * add the subtitle that we found on the first pass for use in this
  619
+             * pass.
  620
+             */
  621
+            hb_list_add( title->list_subtitle, interjob->select_subtitle );
  622
+            interjob->select_subtitle = NULL;
  623
+        }
  624
+    }
  625
+
  626
+
532 627
     // Filters have an effect on settings.
533 628
     // So initialize the filters and update the job.
534 629
     if( job->list_filter && hb_list_count( job->list_filter ) )
535 630
     {
536 631
         hb_filter_init_t init;
  632
+        int pos = -1, score = 0;
537 633
 
538 634
         init.job = job;
539 635
         init.pix_fmt = PIX_FMT_YUV420P;
@@ -547,7 +643,19 @@ static void do_job( hb_job_t * job )
547 643
         init.cfr = 0;
548 644
         for( i = 0; i < hb_list_count( job->list_filter ); i++ )
549 645
         {
550  
-            hb_filter_object_t * filter = hb_list_item( job->list_filter, i );
  646
+            // Some filters need to be initialized in a different order
  647
+            // than they are executed in the pipeline.  e.g. rendersub
  648
+            // needs to be initialized after cropscale so that it knows
  649
+            // the crop settings, but it needs to be executed before
  650
+            // cropscale. so hb_filter_init_next() finds returns the
  651
+            // position of filters in initialization order.
  652
+            hb_filter_init_next( job->list_filter, &score, &pos );
  653
+            if( pos == -1)
  654
+            {
  655
+                // This is an error that should never happen!
  656
+                break;
  657
+            }
  658
+            hb_filter_object_t * filter = hb_list_item( job->list_filter, pos );
551 659
             if( filter->init( filter, &init ) )
552 660
             {
553 661
                 hb_log( "Failure to initialise filter '%s', disabling",
@@ -847,60 +955,6 @@ static void do_job( hb_job_t * job )
847 955
     w->fifo_in  = job->fifo_mpeg2;
848 956
     w->fifo_out = job->fifo_raw;
849 957
 
850  
-    /*
851  
-     * Look for the scanned subtitle in the existing subtitle list
852  
-     * select_subtitle implies that we did a scan.
853  
-     */
854  
-    if ( !job->indepth_scan && interjob->select_subtitle &&
855  
-         ( job->pass == 0 || job->pass == 2 ) )
856  
-    {
857  
-        /*
858  
-         * Disable forced subtitles if we didn't find any in the scan
859  
-         * so that we display normal subtitles instead.
860  
-         */
861  
-        if( interjob->select_subtitle->config.force && 
862  
-            interjob->select_subtitle->forced_hits == 0 )
863  
-        {
864  
-            interjob->select_subtitle->config.force = 0;
865  
-        }
866  
-        for( i=0; i < hb_list_count(title->list_subtitle); i++ )
867  
-        {
868  
-            subtitle =  hb_list_item( title->list_subtitle, i );
869  
-
870  
-            if( subtitle )
871  
-            {
872  
-                /*
873  
-                * Remove the scanned subtitle from the subtitle list if
874  
-                * it would result in an identical duplicate subtitle track
875  
-                * or an emty track (forced and no forced hits).
876  
-                */
877  
-                if( ( interjob->select_subtitle->id == subtitle->id ) &&
878  
-                    ( ( interjob->select_subtitle->forced_hits == 0 &&
879  
-                        subtitle->config.force ) ||
880  
-                    ( subtitle->config.force == interjob->select_subtitle->config.force ) ) )
881  
-                {
882  
-                    *subtitle = *(interjob->select_subtitle);
883  
-                    free( interjob->select_subtitle );
884  
-                    interjob->select_subtitle = NULL;
885  
-                    break;
886  
-                }
887  
-            }
888  
-        }
889  
-
890  
-        if( interjob->select_subtitle )
891  
-        {
892  
-            /*
893  
-             * Its not in the existing list
894  
-             *
895  
-             * Must be second pass of a two pass with subtitle scan enabled, so
896  
-             * add the subtitle that we found on the first pass for use in this
897  
-             * pass.
898  
-             */
899  
-            hb_list_add( title->list_subtitle, interjob->select_subtitle );
900  
-            interjob->select_subtitle = NULL;
901  
-        }
902  
-    }
903  
-
904 958
     for( i=0; i < hb_list_count(title->list_subtitle); i++ )
905 959
     {
906 960
         subtitle =  hb_list_item( title->list_subtitle, i );

0 notes on commit 3fdd1eb

Please sign in to comment.
Something went wrong with that request. Please try again.