]> granicus.if.org Git - libx264/commitdiff
Support writing the alternative transfer SEI message
authorVittorio Giovara <vittorio.giovara@gmail.com>
Tue, 8 Aug 2017 13:40:45 +0000 (15:40 +0200)
committerAnton Mitrofanov <BugMaster@narod.ru>
Sun, 24 Dec 2017 20:47:24 +0000 (23:47 +0300)
common/base.c
common/base.h
encoder/encoder.c
encoder/set.c
encoder/set.h
x264.c
x264.h

index 294c8d52b21eae53e1b6f3fee8f949b506759300..66bf6227920fa271cfddc1a81a60336f6ff24318 100644 (file)
@@ -409,6 +409,7 @@ void x264_param_default( x264_param_t *param )
     param->b_pic_struct = 0;
     param->b_fake_interlaced = 0;
     param->i_frame_packing = -1;
+    param->i_alternative_transfer = 2; /* undef */
     param->b_opencl = 0;
     param->i_opencl_device = 0;
     param->opencl_device_id = NULL;
@@ -936,6 +937,8 @@ int x264_param_parse( x264_param_t *p, const char *name, const char *value )
         p->vui.i_chroma_loc = atoi(value);
         b_error = ( p->vui.i_chroma_loc < 0 || p->vui.i_chroma_loc > 5 );
     }
+    OPT("alternative-transfer")
+        b_error |= parse_enum( value, x264_transfer_names, &p->i_alternative_transfer );
     OPT("fps")
     {
         if( sscanf( value, "%u/%u", &p->i_fps_num, &p->i_fps_den ) != 2 )
index 1903b909bd5834f92ef6bcde5f7598f483a2b352..ab33cb8d782cb9cb5a2be735ae7a4986277d7283 100644 (file)
@@ -119,6 +119,7 @@ enum sei_payload_type_e
     SEI_RECOVERY_POINT         = 6,
     SEI_DEC_REF_PIC_MARKING    = 7,
     SEI_FRAME_PACKING          = 45,
+    SEI_ALTERNATIVE_TRANSFER   = 147,
 };
 
 #define X264_BFRAME_MAX 16
index b1be6359acf551abafcd90f3b951ddcc571dba3e..088f5411501949aa56fb08b5dadb14526aeb87e1 100644 (file)
@@ -3636,6 +3636,15 @@ int     x264_encoder_encode( x264_t *h,
         overhead += h->out.nal[h->out.i_nal-1].i_payload + SEI_OVERHEAD;
     }
 
+    if( h->param.i_alternative_transfer != 2 )
+    {
+        nal_start( h, NAL_SEI, NAL_PRIORITY_DISPOSABLE );
+        x264_sei_alternative_transfer_write( h, &h->out.bs );
+        if( nal_end( h ) )
+            return -1;
+        overhead += h->out.nal[h->out.i_nal-1].i_payload + SEI_OVERHEAD;
+    }
+
     /* generate sei pic timing */
     if( h->sps->vui.b_pic_struct_present || h->sps->vui.b_nal_hrd_parameters_present )
     {
index 79014e686931da450aefa0c1e462398f09a1be28..a19fd4e5fffb744388fcad09e94b6e72e7bb1466 100644 (file)
@@ -690,6 +690,23 @@ void x264_sei_frame_packing_write( x264_t *h, bs_t *s )
     x264_sei_write( s, tmp_buf, bs_pos( &q ) / 8, SEI_FRAME_PACKING );
 }
 
+void x264_sei_alternative_transfer_write( x264_t *h, bs_t *s )
+{
+    bs_t q;
+    ALIGNED_4( uint8_t tmp_buf[100] );
+    M32( tmp_buf ) = 0; // shut up gcc
+    bs_init( &q, tmp_buf, 100 );
+
+    bs_realign( &q );
+
+    bs_write ( &q, 8, h->param.i_alternative_transfer ); // preferred_transfer_characteristics
+
+    bs_align_10( &q );
+    bs_flush( &q );
+
+    x264_sei_write( s, tmp_buf, bs_pos( &q ) / 8, SEI_ALTERNATIVE_TRANSFER );
+}
+
 void x264_filler_write( x264_t *h, bs_t *s, int filler )
 {
     bs_realign( s );
index 20b7481336d72baeeb4d8e5c18a3a284539de2e4..19312785c8c49c2d2c2aad7ee60ad3d1359587e5 100644 (file)
@@ -51,6 +51,8 @@ void x264_sei_pic_timing_write( x264_t *h, bs_t *s );
 void x264_sei_dec_ref_pic_marking_write( x264_t *h, bs_t *s );
 #define x264_sei_frame_packing_write x264_template(sei_frame_packing_write)
 void x264_sei_frame_packing_write( x264_t *h, bs_t *s );
+#define x264_sei_alternative_transfer_write x264_template(sei_alternative_transfer_write)
+void x264_sei_alternative_transfer_write( x264_t *h, bs_t *s );
 #define x264_sei_avcintra_umid_write x264_template(sei_avcintra_umid_write)
 int  x264_sei_avcintra_umid_write( x264_t *h, bs_t *s );
 #define x264_sei_avcintra_vanc_write x264_template(sei_avcintra_vanc_write)
diff --git a/x264.c b/x264.c
index b9669ddce880d6e62084ec65e1a6cc144f16ec69..daea0f30624a46231a2db648c76d8073dcc5b0c4 100644 (file)
--- a/x264.c
+++ b/x264.c
@@ -868,7 +868,10 @@ static void help( x264_param_t *defaults, int longhelp )
                                        strtable_lookup( x264_colmatrix_names, defaults->vui.i_colmatrix ) );
     H2( "      --chromaloc <integer>   Specify chroma sample location (0 to 5) [%d]\n",
                                        defaults->vui.i_chroma_loc );
-
+    H2( "      --alternative-transfer <string> Specify an alternative transfer\n"
+        "                              characteristics [\"%s\"]\n"
+        "                                  - same values as --transfer\n",
+                                       strtable_lookup( x264_transfer_names, defaults->i_alternative_transfer ) );
     H2( "      --nal-hrd <string>      Signal HRD information (requires vbv-bufsize)\n"
         "                                  - none, vbr, cbr (cbr not allowed in .mp4)\n" );
     H2( "      --filler                Force hard-CBR and generate filler (implied by\n"
@@ -1142,6 +1145,7 @@ static struct option long_options[] =
     { "pulldown",    required_argument, NULL, OPT_PULLDOWN },
     { "fake-interlaced",   no_argument, NULL, 0 },
     { "frame-packing",     required_argument, NULL, 0 },
+    { "alternative-transfer", required_argument, NULL, 0 },
     { "vf",          required_argument, NULL, OPT_VIDEO_FILTER },
     { "video-filter", required_argument, NULL, OPT_VIDEO_FILTER },
     { "input-fmt",   required_argument, NULL, OPT_INPUT_FMT },
diff --git a/x264.h b/x264.h
index a9775400fbafc7de0af1c238efa4fbae6eaee7fb..88cc9229334e27ff5d66314cb42b6e5062c24dca 100644 (file)
--- a/x264.h
+++ b/x264.h
@@ -45,7 +45,7 @@ extern "C" {
 
 #include "x264_config.h"
 
-#define X264_BUILD 154
+#define X264_BUILD 155
 
 /* Application developers planning to link against a shared library version of
  * libx264 from a Microsoft Visual Studio or similar development environment
@@ -460,6 +460,9 @@ typedef struct x264_param_t
     /* frame packing arrangement flag */
     int i_frame_packing;
 
+    /* alternative transfer SEI */
+    int i_alternative_transfer;
+
     /* Muxing parameters */
     int b_aud;                  /* generate access unit delimiters */
     int b_repeat_headers;       /* put SPS/PPS before each keyframe */