]> granicus.if.org Git - handbrake/commitdiff
tx3g: make font size scale with video height
authorJohn Stebbins <jstebbins.hb@gmail.com>
Fri, 3 Nov 2017 18:10:02 +0000 (11:10 -0700)
committerGitHub <noreply@github.com>
Fri, 3 Nov 2017 18:10:02 +0000 (11:10 -0700)
Fixes https://forum.handbrake.fr/viewtopic.php?f=5&t=37034

libhb/internal.h
libhb/muxavformat.c
libhb/muxcommon.c

index 487304383c08755bd93326b00135d438f3258b93..80b5b4de2aa3b71e41883a4c6347be12ef3f8d93 100644 (file)
@@ -494,9 +494,9 @@ DECLARE_MUX( mp4 );
 DECLARE_MUX( mkv );
 DECLARE_MUX( avformat );
 
-void hb_muxmp4_process_subtitle_style( uint8_t *input,
-                                       uint8_t **output,
-                                       uint8_t **style, uint16_t *stylesize );
+void hb_muxmp4_process_subtitle_style(int        height,
+                                      uint8_t  * input, uint8_t  ** output,
+                                      uint8_t ** style, uint16_t  * stylesize);
 
 void hb_deinterlace(hb_buffer_t *dst, hb_buffer_t *src);
 void hb_avfilter_combine( hb_list_t * list );
index cad3c09deb75d9a195b1eb754bd294d7a1bbe20e..f011c0cee5b7e23e75633d9e2047609a908c18ee 100644 (file)
@@ -831,9 +831,20 @@ static int avformatInit( hb_mux_object_t * m )
                 'A','r','i','a','l'         // Font name
             };
 
-            int width, height = 60;
-            width = job->width * job->par.num / job->par.den;
-            track->st->codecpar->width = width;
+            int width, height, font_size;
+            width     = job->width * job->par.num / job->par.den;
+            font_size = 0.05 * job->height;
+            if (font_size < 12)
+            {
+                font_size = 12;
+            }
+            else if (font_size > 255)
+            {
+                font_size = 255;
+            }
+            properties[25] = font_size;
+            height = 3 * font_size;
+            track->st->codecpar->width  = width;
             track->st->codecpar->height = height;
             properties[14] = height >> 8;
             properties[15] = height & 0xff;
@@ -1258,8 +1269,9 @@ static int avformatMux(hb_mux_object_t *m, hb_mux_data_t *track, hb_buffer_t *bu
                      * Copy the subtitle into buffer stripping markup and
                      * creating style atoms for them.
                      */
-                    hb_muxmp4_process_subtitle_style(buf->data, &buffer,
-                                                     &styleatom, &stylesize );
+                    hb_muxmp4_process_subtitle_style(
+                        job->height, buf->data, &buffer,
+                        &styleatom, &stylesize );
 
                     if (buffer != NULL)
                     {
index 02f9e1dddca88f99fcf64463f39d5230bfda886e..88072edadd80e4a3ba984e8aaee33af8b723b550 100644 (file)
@@ -719,6 +719,7 @@ typedef struct style_context_s
     int                   style_atom_count;
     hb_subtitle_style_t   current_style;
     int                   style_start;
+    int                   height;
 } style_context_t;
 
 static int check_realloc_output(struct output_buf_s * output, int size)
@@ -748,6 +749,7 @@ static int update_style_atoms(style_context_t *ctx, int stop)
 {
     uint8_t * style_entry;
     uint8_t   face = 0;
+    int       font_size;
     int       pos  = 10 + (12 * ctx->style_atom_count);
     int       size = 10 + (12 * (ctx->style_atom_count + 1));
 
@@ -768,10 +770,19 @@ static int update_style_atoms(style_context_t *ctx, int stop)
     style_entry[1]  = ctx->style_start & 0xff;
     style_entry[2]  = (stop >> 8) & 0xff;               // endChar
     style_entry[3]  = stop & 0xff;
-    style_entry[4]  = 0;    // font-ID msb
-    style_entry[5]  = 1;    // font-ID lsb
-    style_entry[6]  = face; // face-style-flags
-    style_entry[7]  = 24;   // font-size
+    style_entry[4]  = 0;            // font-ID msb
+    style_entry[5]  = 1;            // font-ID lsb
+    style_entry[6]  = face;         // face-style-flags
+    font_size       = 0.05 * ctx->height;
+    if (font_size < 12)
+    {
+        font_size = 12;
+    }
+    else if (font_size > 255)
+    {
+        font_size = 255;
+    }
+    style_entry[7]  = font_size;    // font-size
     style_entry[8]  = (ctx->current_style.fg_rgb >> 16) & 0xff; // r
     style_entry[9]  = (ctx->current_style.fg_rgb >> 8)  & 0xff; // g
     style_entry[10] = (ctx->current_style.fg_rgb)       & 0xff; // b
@@ -821,10 +832,11 @@ static void style_context_init(style_context_t *ctx)
  * Copy the input to output removing markup and adding markup to the style
  * atom where appropriate.
  */
-void hb_muxmp4_process_subtitle_style(uint8_t *input,
-                                      uint8_t **out_buf,
-                                      uint8_t **out_style_atoms,
-                                      uint16_t *stylesize)
+void hb_muxmp4_process_subtitle_style(int        height,
+                                      uint8_t  * input,
+                                      uint8_t ** out_buf,
+                                      uint8_t ** out_style_atoms,
+                                      uint16_t * stylesize)
 {
     uint16_t              utf8_count = 0; // utf8 count from start of subtitle
     int                   consumed, in_pos = 0, out_pos = 0, len, ii;
@@ -841,6 +853,7 @@ void hb_muxmp4_process_subtitle_style(uint8_t *input,
     *stylesize       = 0;
 
     style_context_init(&ctx);
+    ctx.height = height;
     hb_ssa_style_init(&style);
 
     // Skip past the SSA preamble