<div dir="ltr">From 0f879605935b5548391d9a3eb675d376c7afd863 Mon Sep 17 00:00:00 2001<br>From: Niranjan <<a href="mailto:niranjan@multicorewareinc.com">niranjan@multicorewareinc.com</a>><br>Date: Thu, 8 Apr 2021 00:37:54 +0530<br>Subject: [PATCH 1/1] Add: End of Sequence and End of Stream NAL units<br><br>---<br> common/base.c     |  6 ++++++<br> encoder/encoder.c | 31 +++++++++++++++++++++++++++++++<br> x264.c            |  4 ++++<br> x264.h            | 10 ++++++++++<br> 4 files changed, 51 insertions(+)<br><br>diff --git a/common/base.c b/common/base.c<br>index ee893b1..f3a347a 100644<br>--- a/common/base.c<br>+++ b/common/base.c<br>@@ -469,6 +469,8 @@ REALIGN_STACK void x264_param_default( x264_param_t *param )<br>     param->b_repeat_headers = 1;<br>     param->b_annexb = 1;<br>     param->b_aud = 0;<br>+    param->b_eob = 0;<br>+    param->b_eos = 0;<br>     param->b_vfr_input = 1;<br>     param->i_nal_hrd = X264_NAL_HRD_NONE;<br>     param->b_tff = 1;<br>@@ -1338,6 +1340,10 @@ REALIGN_STACK int x264_param_parse( x264_param_t *p, const char *name, const cha<br>         p->analyse.b_ssim = atobool(value);<br>     OPT("aud")<br>         p->b_aud = atobool(value);<br>+    OPT("eob")<br>+        p->b_eob = atobool(value);<br>+    OPT("eos")<br>+        p->b_eos = atobool(value);<br>     OPT("sps-id")<br>         p->i_sps_id = atoi(value);<br>     OPT("global-header")<br>diff --git a/encoder/encoder.c b/encoder/encoder.c<br>index bd1ff7c..04784e2 100644<br>--- a/encoder/encoder.c<br>+++ b/encoder/encoder.c<br>@@ -1322,6 +1322,8 @@ static int validate_parameters( x264_t *h, int b_open )<br>     BOOLIFY( b_interlaced );<br>     BOOLIFY( b_intra_refresh );<br>     BOOLIFY( b_aud );<br>+    BOOLIFY( b_eob );<br>+    BOOLIFY( b_eos );<br>     BOOLIFY( b_repeat_headers );<br>     BOOLIFY( b_annexb );<br>     BOOLIFY( b_vfr_input );<br>@@ -3541,6 +3543,14 @@ int     x264_encoder_encode( x264_t *h,<br>         h->out.i_nal = 0;<br>     }<br> <br>+    if (h->param.b_eos && h->fenc->i_type == X264_TYPE_IDR && h->fenc->i_frame)<br>+    {<br>+        nal_start(h, NAL_EOS, NAL_PRIORITY_DISPOSABLE);<br>+        if (nal_end(h))<br>+            return -1;<br>+        overhead += h->out.nal[h->out.i_nal - 1].i_payload + NALU_OVERHEAD;<br>+    }<br>+<br>     if( h->param.b_aud )<br>     {<br>         int pic_type;<br>@@ -3959,6 +3969,27 @@ static int encoder_frame_end( x264_t *h, x264_t *thread_current,<br>         }<br>     }<br> <br>+    if (!x264_encoder_delayed_frames(h))<br>+    {<br>+        int endNalUnit[2];<br>+        endNalUnit[0] = h->param.b_eos;<br>+        endNalUnit[1] = h->param.b_eob;<br>+        for (int i = 0; i < 2; i++)<br>+        {<br>+            int nalType = i == 0 ? NAL_EOS : NAL_EOB;<br>+            if (endNalUnit[i])<br>+            {<br>+                nal_start(h, nalType, NAL_PRIORITY_DISPOSABLE);<br>+                if (nal_end(h))<br>+                    return -1;<br>+                int total_size = encoder_encapsulate_nals(h, h->out.i_nal - 1);<br>+                if (total_size < 0)<br>+                    return -1;<br>+                frame_size += total_size;<br>+            }<br>+        }<br>+    }<br>+<br>     /* End bitstream, set output  */<br>     *pi_nal = h->out.i_nal;<br>     *pp_nal = h->out.nal;<br>diff --git a/x264.c b/x264.c<br>index 5ead60b..3fc49ee 100644<br>--- a/x264.c<br>+++ b/x264.c<br>@@ -947,6 +947,8 @@ static void help( x264_param_t *defaults, int longhelp )<br>     H2( "      --dump-yuv <string>     Save reconstructed frames\n" );<br>     H2( "      --sps-id <integer>      Set SPS and PPS id numbers [%d]\n", defaults->i_sps_id );<br>     H2( "      --aud                   Use access unit delimiters\n" );<br>+    H2( "      --eob                   Use end of stream\n" );<br>+    H2( "      --eos                   Use end of sequence\n" );<br>     H2( "      --force-cfr             Force constant framerate timestamp generation\n" );<br>     H2( "      --tcfile-in <string>    Force timestamp generation with timecode file\n" );<br>     H2( "      --tcfile-out <string>   Output timecode v2 file from input timestamps\n" );<br>@@ -1129,6 +1131,8 @@ static struct option long_options[] =<br>     { "dump-yuv",    required_argument, NULL, 0 },<br>     { "sps-id",      required_argument, NULL, 0 },<br>     { "aud",               no_argument, NULL, 0 },<br>+    { "eob",               no_argument, NULL, 0 },<br>+    { "eos",               no_argument, NULL, 0 },<br>     { "nr",          required_argument, NULL, 0 },<br>     { "cqm",         required_argument, NULL, 0 },<br>     { "cqmfile",     required_argument, NULL, 0 },<br>diff --git a/x264.h b/x264.h<br>index 29f5315..a754abf 100644<br>--- a/x264.h<br>+++ b/x264.h<br>@@ -95,6 +95,8 @@ enum nal_unit_type_e<br>     NAL_SPS         = 7,<br>     NAL_PPS         = 8,<br>     NAL_AUD         = 9,<br>+    NAL_EOS         = 10,<br>+    NAL_EOB         = 11,<br>     NAL_FILLER      = 12,<br>     /* ref_idc == 0 for 6,9,10,11,12 */<br> };<br>@@ -586,6 +588,14 @@ typedef struct x264_param_t<br> <br>     /* For internal use only */<br>     void *opaque;<br>+<br>+    /* Flag indicating whether the encoder should emit an End of Bitstream<br>+    * NAL at the end of bitstream. Default disabled */<br>+    int      b_eob;<br>+<br>+    /* Flag indicating whether the encoder should emit an End of Sequence<br>+     * NAL at the end of every Coded Video Sequence. Default disabled */<br>+    int      b_eos;<br> } x264_param_t;<br> <br> X264_API void x264_nal_encode( x264_t *h, uint8_t *dst, x264_nal_t *nal );<br>-- <br>1.8.3.1<br><br><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><font color="#0c343d" face="verdana, sans-serif"><br></font></div><div dir="ltr"><font color="#0c343d" face="verdana, sans-serif">Thanks & Regards</font><div><font color="#0c343d" face="verdana, sans-serif"><b>Niranjan Kumar B</b></font></div><div><font size="1" color="#0c343d" face="verdana, sans-serif">Video Codec Engineer </font></div><div><font size="1" color="#0c343d" face="verdana, sans-serif">Media & AI Analytics</font></div><div><font face="trebuchet ms, sans-serif" color="#0c343d">+91 958 511 1449</font></div><div><a href="https://multicorewareinc.com/" style="color:rgb(17,85,204)" target="_blank"><img src="https://docs.google.com/uc?export=download&id=1kc3RJu9M8bnIf6Xa5rUw2d-eEVUsPBE5&revid=0B7tw9XJBmynaemR1VUpQUi9DVytRVW5SVkRwVTFjb1hBMUcwPQ"></a></div></div></div></div></div></div></div></div>