[x264-devel] Support writing the alternative transfer SEI message

Vittorio Giovara git at videolan.org
Mon Dec 25 20:39:47 CET 2017


x264 | branch: master | Vittorio Giovara <vittorio.giovara at gmail.com> | Tue Aug  8 15:40:45 2017 +0200| [95cdb743463f723cea58c8ae01d7762f7ae9965c] | committer: Anton Mitrofanov

Support writing the alternative transfer SEI message

> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=95cdb743463f723cea58c8ae01d7762f7ae9965c
---

 common/base.c     |  3 +++
 common/base.h     |  1 +
 encoder/encoder.c |  9 +++++++++
 encoder/set.c     | 17 +++++++++++++++++
 encoder/set.h     |  2 ++
 x264.c            |  6 +++++-
 x264.h            |  5 ++++-
 7 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/common/base.c b/common/base.c
index 294c8d52..66bf6227 100644
--- a/common/base.c
+++ b/common/base.c
@@ -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 )
diff --git a/common/base.h b/common/base.h
index 1903b909..ab33cb8d 100644
--- a/common/base.h
+++ b/common/base.h
@@ -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
diff --git a/encoder/encoder.c b/encoder/encoder.c
index b1be6359..088f5411 100644
--- a/encoder/encoder.c
+++ b/encoder/encoder.c
@@ -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 )
     {
diff --git a/encoder/set.c b/encoder/set.c
index 79014e68..a19fd4e5 100644
--- a/encoder/set.c
+++ b/encoder/set.c
@@ -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 );
diff --git a/encoder/set.h b/encoder/set.h
index 20b74813..19312785 100644
--- a/encoder/set.h
+++ b/encoder/set.h
@@ -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 b9669ddc..daea0f30 100644
--- 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 a9775400..88cc9229 100644
--- 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 */



More information about the x264-devel mailing list