From e4f6e2d48b25d63e9e9471aa4136359383db2775 Mon Sep 17 00:00:00 2001
From: Haiwei Sun <haiwei.sun@sg.panasonic.com>
Date: Wed, 17 Jun 2020 01:09:36 +0200
Subject: [PATCH] Fixed slice type decision, POC calculation, and picture
 buffer selection for field coding

---
 .../VTM_encoder_lowdelay_field_GOP16.cfg      | 39 +++++------
 cfg/field/VTM_encoder_lowdelay_field_GOP8.cfg | 23 +++---
 .../VTM_encoder_randomaccess_field_GOP16.cfg  | 38 +++++-----
 .../VTM_encoder_randomaccess_field_GOP32.cfg  | 70 +++++++++----------
 source/Lib/EncoderLib/EncGOP.cpp              |  4 +-
 source/Lib/EncoderLib/EncLib.cpp              |  3 +-
 source/Lib/EncoderLib/EncSlice.cpp            | 18 ++---
 7 files changed, 92 insertions(+), 103 deletions(-)

diff --git a/cfg/field/VTM_encoder_lowdelay_field_GOP16.cfg b/cfg/field/VTM_encoder_lowdelay_field_GOP16.cfg
index 596ee9fd0a..b72c90675b 100644
--- a/cfg/field/VTM_encoder_lowdelay_field_GOP16.cfg
+++ b/cfg/field/VTM_encoder_lowdelay_field_GOP16.cfg
@@ -1,26 +1,23 @@
 FieldCoding                   : 1           # (0: Frame based coding, 1: Field based coding)
 TopFieldFirst                 : 1           # Field parity order (1: Top field first, 0: Bottom field first)
 ConformanceMode               : 1
-VuiParametersPresent          : 1
-SEIPictureTiming              : 1
 SEIFrameFieldInfo             : 1
-IntraPeriod                   : -1          # Period of I-Frame ( -1 = only first)
-DecodingRefreshType           : 0           # Random Accesss 0:none, 1:CRA, 2:IDR, 3:Recovery Point SEI
 GOPSize                       : 16          # GOP Size (number of B slice = GOPSize-1)
-#        Type POC QPoffset QPOffsetModelOff QPOffsetModelScale CbQPoffset CrQPoffset QPfactor tcOffsetDiv2 betaOffsetDiv2 temporal_id #ref_pics_active_L0 #ref_pics_L0   reference_pictures_L0     #ref_pics_active_L1 #ref_pics_L1   reference_pictures_L1
-Frame1:    B    2   5       -6.5                      0.2590         0          0          1.0      0            0               0             8                8         1 2 9 10 17 18 25 26            8                   8         1 2 9 10 17 18 25 26
-Frame2:    B    3   5       -6.5                      0.2590         0          0          1.0      0            0               0             8                9         1 2 3 10 11 18 19 26 27         8                   9         1 2 3 10 11 18 19 26 27
-Frame3:    B    4   4       -6.5                      0.2590         0          0          1.0      0            0               0             8                8         1 2 3 4 11 12 19 20             8                   8         1 2 3 4 11 12 19 20
-Frame4:    B    5   4       -6.5                      0.2590         0          0          1.0      0            0               0             8                9         1 2 3 4 5 12 13 20 21           8                   9         1 2 3 4 5 12 13 20 21
-Frame5:    B    6   5       -6.5                      0.2590         0          0          1.0      0            0               0             8                8         1 2 5 6 13 14 21 22             8                   8         1 2 5 6 13 14 21 22
-Frame6:    B    7   5       -6.5                      0.2590         0          0          1.0      0            0               0             8                9         1 2 3 6 7 14 15 22 23           8                   9         1 2 3 6 7 14 15 22 23
-Frame7:    B    8   4       -6.5                      0.2590         0          0          1.0      0            0               0             8                8         1 2 7 8 15 16 23 24             8                   8         1 2 7 8 15 16 23 24
-Frame8:    B    9   4       -6.5                      0.2590         0          0          1.0      0            0               0             8                9         1 2 3 8 9 16 17 24 25           8                   9         1 2 3 8 9 16 17 24 25
-Frame9:    B   10   5       -6.5                      0.2590         0          0          1.0      0            0               0             8                8         1 2 9 10 17 18 25 26            8                   8         1 2 9 10 17 18 25 26
-Frame10:   B   11   5       -6.5                      0.2590         0          0          1.0      0            0               0             8                9         1 2 3 10 11 18 19 26 27         8                   9         1 2 3 10 11 18 19 26 27
-Frame11:   B   12   4       -6.5                      0.2590         0          0          1.0      0            0               0             8                8         1 2 3 4 11 12 19 20             8                   8         1 2 3 4 11 12 19 20
-Frame12:   B   13   4       -6.5                      0.2590         0          0          1.0      0            0               0             8                9         1 2 3 4 5 12 13 20 21           8                   9         1 2 3 4 5 12 13 20 21
-Frame13:   B   14   5       -6.5                      0.2590         0          0          1.0      0            0               0             8                8         1 2 5 6 13 14 21 22             8                   8         1 2 5 6 13 14 21 22
-Frame14:   B   15   5       -6.5                      0.2590         0          0          1.0      0            0               0             8                9         1 2 3 6 7 14 15 22 23           8                   9         1 2 3 6 7 14 15 22 23
-Frame15:   B   16   1        0.0                      0.0            0          0          1.0      0            0               0             8                8         1 2 7 8 15 16 23 24             8                   8         1 2 7 8 15 16 23 24
-Frame16:   B   17   1        0.0                      0.0            0          0          1.0      0            0               0             8                9         1 2 3 8 9 16 17 24 25           8                   9         1 2 3 8 9 16 17 24 25
+
+#        Type POC QPoffset QPOffsetModelOff QPOffsetModelScale CbQPoffset CrQPoffset QPfactor tcOffsetDiv2 betaOffsetDiv2 CbTcOffsetDiv2 CbBetaOffsetDiv2 CrTcOffsetDiv2 CrBetaOffsetDiv2 temporal_id #ref_pics_active_L0 #ref_pics_L0   reference_pictures_L0   #ref_pics_active_L1    #ref_pics_L1   reference_pictures_L1
+Frame1:    B    2   5       -6.5                      0.2590         0          0          1.0      0            0               0              0               0               0               0             8                8         1 2 9 10 17 18 25 26            8                   8         1 2 9 10 17 18 25 26
+Frame2:    B    3   5       -6.5                      0.2590         0          0          1.0      0            0               0              0               0               0               0             8                9         1 2 3 10 11 18 19 26 27         8                   9         1 2 3 10 11 18 19 26 27
+Frame3:    B    4   4       -6.5                      0.2590         0          0          1.0      0            0               0              0               0               0               0             8                8         1 2 3 4 11 12 19 20             8                   8         1 2 3 4 11 12 19 20
+Frame4:    B    5   4       -6.5                      0.2590         0          0          1.0      0            0               0              0               0               0               0             8                9         1 2 3 4 5 12 13 20 21           8                   9         1 2 3 4 5 12 13 20 21
+Frame5:    B    6   5       -6.5                      0.2590         0          0          1.0      0            0               0              0               0               0               0             8                8         1 2 5 6 13 14 21 22             8                   8         1 2 5 6 13 14 21 22
+Frame6:    B    7   5       -6.5                      0.2590         0          0          1.0      0            0               0              0               0               0               0             8                9         1 2 3 6 7 14 15 22 23           8                   9         1 2 3 6 7 14 15 22 23
+Frame7:    B    8   4       -6.5                      0.2590         0          0          1.0      0            0               0              0               0               0               0             8                8         1 2 7 8 15 16 23 24             8                   8         1 2 7 8 15 16 23 24
+Frame8:    B    9   4       -6.5                      0.2590         0          0          1.0      0            0               0              0               0               0               0             8                9         1 2 3 8 9 16 17 24 25           8                   9         1 2 3 8 9 16 17 24 25
+Frame9:    B   10   5       -6.5                      0.2590         0          0          1.0      0            0               0              0               0               0               0             8                8         1 2 9 10 17 18 25 26            8                   8         1 2 9 10 17 18 25 26
+Frame10:   B   11   5       -6.5                      0.2590         0          0          1.0      0            0               0              0               0               0               0             8                9         1 2 3 10 11 18 19 26 27         8                   9         1 2 3 10 11 18 19 26 27
+Frame11:   B   12   4       -6.5                      0.2590         0          0          1.0      0            0               0              0               0               0               0             8                8         1 2 3 4 11 12 19 20             8                   8         1 2 3 4 11 12 19 20
+Frame12:   B   13   4       -6.5                      0.2590         0          0          1.0      0            0               0              0               0               0               0             8                9         1 2 3 4 5 12 13 20 21           8                   9         1 2 3 4 5 12 13 20 21
+Frame13:   B   14   5       -6.5                      0.2590         0          0          1.0      0            0               0              0               0               0               0             8                8         1 2 5 6 13 14 21 22             8                   8         1 2 5 6 13 14 21 22
+Frame14:   B   15   5       -6.5                      0.2590         0          0          1.0      0            0               0              0               0               0               0             8                9         1 2 3 6 7 14 15 22 23           8                   9         1 2 3 6 7 14 15 22 23
+Frame15:   B   16   1        0.0                      0.0            0          0          1.0      0            0               0              0               0               0               0             8                8         1 2 7 8 15 16 23 24             8                   8         1 2 7 8 15 16 23 24
+Frame16:   B   17   1        0.0                      0.0            0          0          1.0      0            0               0              0               0               0               0             8                9         1 2 3 8 9 16 17 24 25           8                   9         1 2 3 8 9 16 17 24 25
diff --git a/cfg/field/VTM_encoder_lowdelay_field_GOP8.cfg b/cfg/field/VTM_encoder_lowdelay_field_GOP8.cfg
index dc23e0a35a..9f43989178 100644
--- a/cfg/field/VTM_encoder_lowdelay_field_GOP8.cfg
+++ b/cfg/field/VTM_encoder_lowdelay_field_GOP8.cfg
@@ -1,18 +1,15 @@
 FieldCoding                   : 1           # (0: Frame based coding, 1: Field based coding)
 TopFieldFirst                 : 1           # Field parity order (1: Top field first, 0: Bottom field first)
 ConformanceMode               : 1
-VuiParametersPresent          : 1
-SEIPictureTiming              : 1
 SEIFrameFieldInfo             : 1
-IntraPeriod                   : -1          # Period of I-Frame ( -1 = only first)
-DecodingRefreshType           : 0           # Random Accesss 0:none, 1:CRA, 2:IDR, 3:Recovery Point SEI
 GOPSize                       : 8          # GOP Size (number of B slice = GOPSize-1)
-#        Type POC QPoffset QPOffsetModelOff QPOffsetModelScale CbQPoffset CrQPoffset QPfactor tcOffsetDiv2 betaOffsetDiv2 temporal_id #ref_pics_active_L0 #ref_pics_L0   reference_pictures_L0     #ref_pics_active_L1 #ref_pics_L1   reference_pictures_L1
-Frame1:    B    2   5        -6.5                      0.2590         0          0          1.0      0            0               0             5                5         1 2 9 10 17                  5                   5         1 2 9 10 17
-Frame2:    B    3   5        -6.5                      0.2590         0          0          1.0      0            0               0             6                6         1 2 3 10 11 18               6                   6         1 2 3 10 11 18
-Frame3:    B    4   4        -6.5                      0.2590         0          0          1.0      0            0               0             7                7         1 2 3 4 11 12 19             7                   7         1 2 3 4 11 12 19
-Frame4:    B    5   4        -6.5                      0.2590         0          0          1.0      0            0               0             8                8         1 2 3 4 5 12 13 20           8                   8         1 2 3 4 5 12 13 20
-Frame5:    B    6   5        -6.5                      0.2590         0          0          1.0      0            0               0             7                7         1 2 5 6 13 14 21             7                   7         1 2 5 6 13 14 21
-Frame6:    B    7   5        -6.5                      0.2590         0          0          1.0      0            0               0             8                8         1 2 3 6 7 14 15 22           8                   8         1 2 3 6 7 14 15 22
-Frame7:    B    8   1         0.0                      0.0            0          0          1.0      0            0               0             7                7         1 2 7 8 15 16 23             7                   7         1 2 7 8 15 16 23
-Frame8:    B    9   1         0.0                      0.0            0          0          1.0      0            0               0             8                8         1 2 3 8 9 16 17 24           8                   8         1 2 3 8 9 16 17 24
+
+#        Type POC QPoffset QPOffsetModelOff QPOffsetModelScale CbQPoffset CrQPoffset QPfactor tcOffsetDiv2 betaOffsetDiv2 CbTcOffsetDiv2 CbBetaOffsetDiv2 CrTcOffsetDiv2 CrBetaOffsetDiv2    temporal_id #ref_pics_active_L0 #ref_pics_L0  reference_pictures_L0  #ref_pics_active_L1   #ref_pics_L1   reference_pictures_L1
+Frame1:    B    2   5        -6.5                      0.2590         0          0          1.0      0            0              0               0                0               0                0             5                5         1 2 9 10 17                  5                   5         1 2 9 10 17
+Frame2:    B    3   5        -6.5                      0.2590         0          0          1.0      0            0              0               0                0               0                0             6                6         1 2 3 10 11 18               6                   6         1 2 3 10 11 18
+Frame3:    B    4   4        -6.5                      0.2590         0          0          1.0      0            0              0               0                0               0                0             7                7         1 2 3 4 11 12 19             7                   7         1 2 3 4 11 12 19
+Frame4:    B    5   4        -6.5                      0.2590         0          0          1.0      0            0              0               0                0               0                0             8                8         1 2 3 4 5 12 13 20           8                   8         1 2 3 4 5 12 13 20
+Frame5:    B    6   5        -6.5                      0.2590         0          0          1.0      0            0              0               0                0               0                0             7                7         1 2 5 6 13 14 21             7                   7         1 2 5 6 13 14 21
+Frame6:    B    7   5        -6.5                      0.2590         0          0          1.0      0            0              0               0                0               0                0             8                8         1 2 3 6 7 14 15 22           8                   8         1 2 3 6 7 14 15 22
+Frame7:    B    8   1         0.0                      0.0            0          0          1.0      0            0              0               0                0               0                0             7                7         1 2 7 8 15 16 23             7                   7         1 2 7 8 15 16 23
+Frame8:    B    9   1         0.0                      0.0            0          0          1.0      0            0              0               0                0               0                0             8                8         1 2 3 8 9 16 17 24           8                   8         1 2 3 8 9 16 17 24
diff --git a/cfg/field/VTM_encoder_randomaccess_field_GOP16.cfg b/cfg/field/VTM_encoder_randomaccess_field_GOP16.cfg
index 040922b186..638988b6fc 100644
--- a/cfg/field/VTM_encoder_randomaccess_field_GOP16.cfg
+++ b/cfg/field/VTM_encoder_randomaccess_field_GOP16.cfg
@@ -1,26 +1,24 @@
 FieldCoding                   : 1           # (0: Frame based coding, 1: Field based coding)
 TopFieldFirst                 : 1           # Field parity order (1: Top field first, 0: Bottom field first)
 ConformanceMode               : 1
-VuiParametersPresent          : 1
-SEIPictureTiming              : 1
 SEIFrameFieldInfo             : 1
 IntraPeriod                   : 32          # Period of I-Frame ( -1 = only first)
-DecodingRefreshType           : 1           # Random Accesss 0:none, 1:CRA, 2:IDR, 3:Recovery Point SEI
 GOPSize                       : 16          # GOP Size (number of B slice = GOPSize-1)
-#        Type POC QPoffset QPOffsetModelOff QPOffsetModelScale CbQPoffset CrQPoffset QPfactor tcOffsetDiv2 betaOffsetDiv2 temporal_id #ref_pics_active_L0 #ref_pics_L0   reference_pictures_L0 #ref_pics_active_L1 #ref_pics_L1   reference_pictures_L1
-Frame1:  B    17  1        0.0                      0.0        0          0          0.442    0            0              0             4                4          16 17 20 21                 4                4           16 17 20 21
-Frame2:  B    16  1        0.0                      0.0        0          0          0.442    0            0              0             3                3          15 16 -1                    3                3           -1 15 16
-Frame3:  B    8   2        0.0                      0.0        0          0          0.3536   0            0              1             2                4          7 8 -8 -9                   2                4           -8 -9 7 8
-Frame4:  B    9   2        0.0                      0.0        0          0          0.3536   0            0              1             2                5          1 8 9 -7 -8                 2                5           -7 -8 1 8 9
-Frame5:  B    4   3        0.0                      0.0        0          0          0.3536   0            0              2             2                4          3 4 -4 -5                   2                4           -4 -5 -12 -13
-Frame6:  B    5   3        0.0                      0.0        0          0          0.3536   0            0              2             2                5          1 4 5 -3 -4                 2                4           -3 -4 -11 -12
-Frame7:  B    2   4        0.0                      0.0        0          0          0.68     0            0              3             2                4          1 2 -2 -3                   2                6           -2 -3 -6 -7 -14 -15
-Frame8:  B    3   4        0.0                      0.0        0          0          0.68     0            0              3             2                4          1 2 -1 -2                   2                6           -1 -2 -5 -6 -13 -14
-Frame9:  B    6   4        0.0                      0.0        0          0          0.68     0            0              3             2                4          1 2 -2 -3                   2                4           -2 -3 -10 -11
-Frame10: B    7   4        0.0                      0.0        0          0          0.68     0            0              3             2                5          1 2 3 -1 -2                 2                4           -1 -2 -9 -10
-Frame11: B    12  3        0.0                      0.0        0          0          0.3536   0            0              2             2                4          3 4 -4 -5                   2                4           -4 -5 3 4
-Frame12: B    13  3        0.0                      0.0        0          0          0.3536   0            0              2             2                5          1 4 5 -3 -4                 2                5           -3 -4 1 4 5
-Frame13: B    10  4        0.0                      0.0        0          0          0.68     0            0              3             2                4          1 2 -2 -3                   2                4           -2 -3 -6 -7
-Frame14: B    11  4        0.0                      0.0        0          0          0.68     0            0              3             2                5          1 2 3 -1 -2                 2                4           -1 -2 -5 -6
-Frame15: B    14  4        0.0                      0.0        0          0          0.68     0            0              3             2                5          1 2 5 -2 -3                 2                4           -2 -3 1 2
-Frame16: B    15  4        0.0                      0.0        0          0          0.68     0            0              3             2                4          1 2 3 6                     2                4           -1 -2 1 2
+
+#        Type POC QPoffset QPOffsetModelOff QPOffsetModelScale CbQPoffset CrQPoffset QPfactor tcOffsetDiv2 betaOffsetDiv2 CbTcOffsetDiv2 CbBetaOffsetDiv2 CrTcOffsetDiv2 CrBetaOffsetDiv2 temporal_id #ref_pics_active_L0 #ref_pics_L0   reference_pictures_L0 #ref_pics_active_L1 #ref_pics_L1   reference_pictures_L1
+Frame1:  B    17  1        0.0                      0.0        0          0          0.442    0            0                    0               0               0               0              0             4                4          16 17 20 21                 4                4           16 17 20 21
+Frame2:  B    16  1        0.0                      0.0        0          0          0.442    0            0                    0               0               0               0              0             3                3          15 16 -1                    3                3           -1 15 16
+Frame3:  B    8   2        0.0                      0.0        0          0          0.3536   0            0                    0               0               0               0              1             2                4          7 8 -8 -9                   2                4           -8 -9 7 8
+Frame4:  B    9   2        0.0                      0.0        0          0          0.3536   0            0                    0               0               0               0              1             2                5          1 8 9 -7 -8                 2                5           -7 -8 1 8 9
+Frame5:  B    4   3        0.0                      0.0        0          0          0.3536   0            0                    0               0               0               0              2             2                4          3 4 -4 -5                   2                4           -4 -5 -12 -13
+Frame6:  B    5   3        0.0                      0.0        0          0          0.3536   0            0                    0               0               0               0              2             2                5          1 4 5 -3 -4                 2                4           -3 -4 -11 -12
+Frame7:  B    2   4        0.0                      0.0        0          0          0.68     0            0                    0               0               0               0              3             2                4          1 2 -2 -3                   2                6           -2 -3 -6 -7 -14 -15
+Frame8:  B    3   4        0.0                      0.0        0          0          0.68     0            0                    0               0               0               0              3             2                4          1 2 -1 -2                   2                6           -1 -2 -5 -6 -13 -14
+Frame9:  B    6   4        0.0                      0.0        0          0          0.68     0            0                    0               0               0               0              3             2                4          1 2 -2 -3                   2                4           -2 -3 -10 -11
+Frame10: B    7   4        0.0                      0.0        0          0          0.68     0            0                    0               0               0               0              3             2                5          1 2 3 -1 -2                 2                4           -1 -2 -9 -10
+Frame11: B    12  3        0.0                      0.0        0          0          0.3536   0            0                    0               0               0               0              2             2                4          3 4 -4 -5                   2                4           -4 -5 3 4
+Frame12: B    13  3        0.0                      0.0        0          0          0.3536   0            0                    0               0               0               0              2             2                5          1 4 5 -3 -4                 2                5           -3 -4 1 4 5
+Frame13: B    10  4        0.0                      0.0        0          0          0.68     0            0                    0               0               0               0              3             2                4          1 2 -2 -3                   2                4           -2 -3 -6 -7
+Frame14: B    11  4        0.0                      0.0        0          0          0.68     0            0                    0               0               0               0              3             2                5          1 2 3 -1 -2                 2                4           -1 -2 -5 -6
+Frame15: B    14  4        0.0                      0.0        0          0          0.68     0            0                    0               0               0               0              3             2                5          1 2 5 -2 -3                 2                4           -2 -3 1 2
+Frame16: B    15  4        0.0                      0.0        0          0          0.68     0            0                    0               0               0               0              3             2                4          1 2 3 6                     2                4           -1 -2 1 2
diff --git a/cfg/field/VTM_encoder_randomaccess_field_GOP32.cfg b/cfg/field/VTM_encoder_randomaccess_field_GOP32.cfg
index 3443595248..2d759ab949 100644
--- a/cfg/field/VTM_encoder_randomaccess_field_GOP32.cfg
+++ b/cfg/field/VTM_encoder_randomaccess_field_GOP32.cfg
@@ -1,42 +1,40 @@
 FieldCoding                   : 1           # (0: Frame based coding, 1: Field based coding)
 TopFieldFirst                 : 1           # Field parity order (1: Top field first, 0: Bottom field first)
 ConformanceMode               : 1
-VuiParametersPresent          : 1
-SEIPictureTiming              : 1
 SEIFrameFieldInfo             : 1
 IntraPeriod                   : 64          # Period of I-Frame ( -1 = only first)
-DecodingRefreshType           : 1           # Random Accesss 0:none, 1:CRA, 2:IDR, 3:Recovery Point SEI
 GOPSize                       : 32          # GOP Size (number of B slice = GOPSize-1)
-#        Type POC QPoffset QPOffsetModelOff QPOffsetModelScale CbQPoffset CrQPoffset QPfactor tcOffsetDiv2 betaOffsetDiv2 temporal_id #ref_pics_active_L0 #ref_pics_L0   reference_pictures_L0 #ref_pics_active_L1 #ref_pics_L1   reference_pictures_L1
-Frame1:   B   33   1        0.0                   0.0            0          0          1.0      0            0              0             4                4          32 33 48 49                 4                4           32 33 48 49
-Frame2:   B   32   1        0.0                   0.0            0          0          1.0      0            0              0             4                5          31 32 47 48 -1              4                5           -1 31 32 47 48
-Frame3:   B   16   1       -4.8848                0.2061         0          0          1.0      0            0              1             4                4          15 16 31 32                 4                4           -16 -17 15 16
-Frame4:   B   17   1       -4.8848                0.2061         0          0          1.0      0            0              1             4                5          1 16 17 32 33               4                4           -15 -16 16 17
-Frame5:   B    8   4       -5.7476                0.2286         0          0          1.0      0            0              2             4                4          7 8 23 24                   4                4           -8 -9 -24 -25
-Frame6:   B    9   4       -5.7476                0.2286         0          0          1.0      0            0              2             4                5          1 8 9 24 25                 4                4           -7 -8 -23 -24
-Frame7:   B    4   5       -5.90                  0.2333         0          0          1.0      0            0              3             4                4          3 4 19 20                   4                6           -4 -5 -12 -13 -28 -29
-Frame8:   B    5   5       -5.90                  0.2333         0          0          1.0      0            0              3             4                5          1 4 5 20 21                 4                6           -3 -4 -11 -12 -27 -28
-Frame9:   B    2   6       -7.1444                0.3            0          0          1.0      0            0              4             4                4          1 2 -2 -3                   4                8           -2 -3 -6 -7 -14 -15 -30 -31
-Frame10:  B    3   6       -7.1444                0.3            0          0          1.0      0            0              4             4                5          1 2 3 -1 -2                 4                8           -1 -2 -5 -6 -13 -14 -29 -30
-Frame11:  B    6   6       -7.1444                0.3            0          0          1.0      0            0              4             4                4          1 2 5 6                     4                6           -2 -3 -10 -11 -26 -27
-Frame12:  B    7   6       -7.1444                0.3            0          0          1.0      0            0              4             4                5          1 2 3 6 7                   4                6           -1 -2 -9 -10 -25 -26
-Frame13:  B   12   5       -5.90                  0.2333         0          0          1.0      0            0              3             4                4          3 4 11 12                   4                4           -4 -5 -20 -21
-Frame14:  B   13   5       -5.90                  0.2333         0          0          1.0      0            0              3             4                5          1 4 5 12 13                 4                4           -3 -4 -19 -20
-Frame15:  B   10   6       -7.1444                0.3            0          0          1.0      0            0              4             4                4          1 2 9 10                    4                6           -2 -3 -6 -7 -22 -23
-Frame16:  B   11   6       -7.1444                0.3            0          0          1.0      0            0              4             4                5          1 2 3 10 11                 4                6           -1 -2 -5 -6 -21 -22
-Frame17:  B   14   6       -7.1444                0.3            0          0          1.0      0            0              4             4                6          1 2 5 6 13 14               4                4           -2 -3 -18 -19
-Frame18:  B   15   6       -7.1444                0.3            0          0          1.0      0            0              4             4                7          1 2 3 6 7 14 15             4                4           -1 -2 -17 -18
-Frame19:  B   24   4       -5.7476                0.2286         0          0          1.0      0            0              2             4                4          7 8 23 24                   4                4           -8 -9 7 8
-Frame20:  B   25   4       -5.7476                0.2286         0          0          1.0      0            0              2             4                5          1 8 9 24 25                 4                4           -7 -8 8 9
-Frame21:  B   20   5       -5.90                  0.2333         0          0          1.0      0            0              3             4                4          3 4 19 20                   4                4           -4 -5 -12 -13
-Frame22:  B   21   5       -5.90                  0.2333         0          0          1.0      0            0              3             4                5          1 4 5 20 21                 4                4           -3 -4 -11 -12
-Frame23:  B   18   6       -7.1444                0.3            0          0          1.0      0            0              4             4                4          1 2 17 18                   4                6           -2 -3 -6 -7 -14 -15
-Frame24:  B   19   6       -7.1444                0.3            0          0          1.0      0            0              4             4                5          1 2 3 18 19                 4                6           -1 -2 -5 -6 -13 -14
-Frame25:  B   22   6       -7.1444                0.3            0          0          1.0      0            0              4             4                6          1 2 5 6 21 22               4                4           -2 -3 -10 -11
-Frame26:  B   23   6       -7.1444                0.3            0          0          1.0      0            0              4             4                7          1 2 3 6 7 22 23             4                4           -1 -2 -9 -10
-Frame27:  B   28   5       -5.90                  0.2333         0          0          1.0      0            0              3             4                6          3 4 11 12 27 28             4                4           -4 -5 3 4
-Frame28:  B   29   5       -5.90                  0.2333         0          0          1.0      0            0              3             4                7          1 4 5 12 13 28 29           4                4           -3 -4 4 5
-Frame29:  B   26   6       -7.1444                0.3            0          0          1.0      0            0              4             4                6          1 2 9 10 25 26              4                4           -2 -3 -6 -7
-Frame30:  B   27   6       -7.1444                0.3            0          0          1.0      0            0              4             4                7          1 2 3 10 11 26 27           4                4           -1 -2 -5 -6
-Frame31:  B   30   6       -7.1444                0.3            0          0          1.0      0            0              4             4                8          1 2 5 6 13 14 29 30         4                4           -2 -3 1 2
-Frame32:  B   31   6       -7.1444                0.3            0          0          1.0      0            0              4             4                9          1 2 3 6 7 14 15 30 31       4                4           -1 -2 2 3
+
+#        Type POC QPoffset QPOffsetModelOff QPOffsetModelScale CbQPoffset CrQPoffset QPfactor tcOffsetDiv2 betaOffsetDiv2 CbTcOffsetDiv2 CbBetaOffsetDiv2 CrTcOffsetDiv2 CrBetaOffsetDiv2 temporal_id #ref_pics_active_L0 #ref_pics_L0   reference_pictures_L0 #ref_pics_active_L1 #ref_pics_L1   reference_pictures_L1
+Frame1:   B   33   1        0.0                   0.0            0          0          1.0      0            0                   0               0               0               0               0             4                4          32 33 48 49                 4                4           32 33 48 49
+Frame2:   B   32   1        0.0                   0.0            0          0          1.0      0            0                   0               0               0               0               0             4                5          31 32 47 48 -1              4                5           -1 31 32 47 48
+Frame3:   B   16   1       -4.8848                0.2061         0          0          1.0      0            0                   0               0               0               0               1             4                4          15 16 31 32                 4                4           -16 -17 15 16
+Frame4:   B   17   1       -4.8848                0.2061         0          0          1.0      0            0                   0               0               0               0               1             4                5          1 16 17 32 33               4                4           -15 -16 16 17
+Frame5:   B    8   4       -5.7476                0.2286         0          0          1.0      0            0                   0               0               0               0               2             4                4          7 8 23 24                   4                4           -8 -9 -24 -25
+Frame6:   B    9   4       -5.7476                0.2286         0          0          1.0      0            0                   0               0               0               0               2             4                5          1 8 9 24 25                 4                4           -7 -8 -23 -24
+Frame7:   B    4   5       -5.90                  0.2333         0          0          1.0      0            0                   0               0               0               0               3             4                4          3 4 19 20                   4                6           -4 -5 -12 -13 -28 -29
+Frame8:   B    5   5       -5.90                  0.2333         0          0          1.0      0            0                   0               0               0               0               3             4                5          1 4 5 20 21                 4                6           -3 -4 -11 -12 -27 -28
+Frame9:   B    2   6       -7.1444                0.3            0          0          1.0      0            0                   0               0               0               0               4             4                4          1 2 -2 -3                   4                8           -2 -3 -6 -7 -14 -15 -30 -31
+Frame10:  B    3   6       -7.1444                0.3            0          0          1.0      0            0                   0               0               0               0               4             4                5          1 2 3 -1 -2                 4                8           -1 -2 -5 -6 -13 -14 -29 -30
+Frame11:  B    6   6       -7.1444                0.3            0          0          1.0      0            0                   0               0               0               0               4             4                4          1 2 5 6                     4                6           -2 -3 -10 -11 -26 -27
+Frame12:  B    7   6       -7.1444                0.3            0          0          1.0      0            0                   0               0               0               0               4             4                5          1 2 3 6 7                   4                6           -1 -2 -9 -10 -25 -26
+Frame13:  B   12   5       -5.90                  0.2333         0          0          1.0      0            0                   0               0               0               0               3             4                4          3 4 11 12                   4                4           -4 -5 -20 -21
+Frame14:  B   13   5       -5.90                  0.2333         0          0          1.0      0            0                   0               0               0               0               3             4                5          1 4 5 12 13                 4                4           -3 -4 -19 -20
+Frame15:  B   10   6       -7.1444                0.3            0          0          1.0      0            0                   0               0               0               0               4             4                4          1 2 9 10                    4                6           -2 -3 -6 -7 -22 -23
+Frame16:  B   11   6       -7.1444                0.3            0          0          1.0      0            0                   0               0               0               0               4             4                5          1 2 3 10 11                 4                6           -1 -2 -5 -6 -21 -22
+Frame17:  B   14   6       -7.1444                0.3            0          0          1.0      0            0                   0               0               0               0               4             4                6          1 2 5 6 13 14               4                4           -2 -3 -18 -19
+Frame18:  B   15   6       -7.1444                0.3            0          0          1.0      0            0                   0               0               0               0               4             4                7          1 2 3 6 7 14 15             4                4           -1 -2 -17 -18
+Frame19:  B   24   4       -5.7476                0.2286         0          0          1.0      0            0                   0               0               0               0               2             4                4          7 8 23 24                   4                4           -8 -9 7 8
+Frame20:  B   25   4       -5.7476                0.2286         0          0          1.0      0            0                   0               0               0               0               2             4                5          1 8 9 24 25                 4                4           -7 -8 8 9
+Frame21:  B   20   5       -5.90                  0.2333         0          0          1.0      0            0                   0               0               0               0               3             4                4          3 4 19 20                   4                4           -4 -5 -12 -13
+Frame22:  B   21   5       -5.90                  0.2333         0          0          1.0      0            0                   0               0               0               0               3             4                5          1 4 5 20 21                 4                4           -3 -4 -11 -12
+Frame23:  B   18   6       -7.1444                0.3            0          0          1.0      0            0                   0               0               0               0               4             4                4          1 2 17 18                   4                6           -2 -3 -6 -7 -14 -15
+Frame24:  B   19   6       -7.1444                0.3            0          0          1.0      0            0                   0               0               0               0               4             4                5          1 2 3 18 19                 4                6           -1 -2 -5 -6 -13 -14
+Frame25:  B   22   6       -7.1444                0.3            0          0          1.0      0            0                   0               0               0               0               4             4                6          1 2 5 6 21 22               4                4           -2 -3 -10 -11
+Frame26:  B   23   6       -7.1444                0.3            0          0          1.0      0            0                   0               0               0               0               4             4                7          1 2 3 6 7 22 23             4                4           -1 -2 -9 -10
+Frame27:  B   28   5       -5.90                  0.2333         0          0          1.0      0            0                   0               0               0               0               3             4                6          3 4 11 12 27 28             4                4           -4 -5 3 4
+Frame28:  B   29   5       -5.90                  0.2333         0          0          1.0      0            0                   0               0               0               0               3             4                7          1 4 5 12 13 28 29           4                4           -3 -4 4 5
+Frame29:  B   26   6       -7.1444                0.3            0          0          1.0      0            0                   0               0               0               0               4             4                6          1 2 9 10 25 26              4                4           -2 -3 -6 -7
+Frame30:  B   27   6       -7.1444                0.3            0          0          1.0      0            0                   0               0               0               0               4             4                7          1 2 3 10 11 26 27           4                4           -1 -2 -5 -6
+Frame31:  B   30   6       -7.1444                0.3            0          0          1.0      0            0                   0               0               0               0               4             4                8          1 2 5 6 13 14 29 30         4                4           -2 -3 1 2
+Frame32:  B   31   6       -7.1444                0.3            0          0          1.0      0            0                   0               0               0               0               4             4                9          1 2 3 6 7 14 15 30 31       4                4           -1 -2 2 3
diff --git a/source/Lib/EncoderLib/EncGOP.cpp b/source/Lib/EncoderLib/EncGOP.cpp
index e8b53be40e..c25609ba03 100644
--- a/source/Lib/EncoderLib/EncGOP.cpp
+++ b/source/Lib/EncoderLib/EncGOP.cpp
@@ -1970,12 +1970,12 @@ void EncGOP::compressGOP( int iPOCLast, int iNumPicRcvd, PicList& rcListPic,
     if(iPOCLast == 0) //case first frame or first top field
     {
       pocCurr=0;
-      iTimeOffset = multipleFactor;
+      iTimeOffset = isField ? (1 - multipleFactor) : multipleFactor;
     }
     else if(iPOCLast == 1 && isField) //case first bottom field, just like the first frame, the poc computation is not right anymore, we set the right value
     {
       pocCurr = 1;
-      iTimeOffset = 1;
+      iTimeOffset = multipleFactor + 1;
     }
     else
     {
diff --git a/source/Lib/EncoderLib/EncLib.cpp b/source/Lib/EncoderLib/EncLib.cpp
index 7157048148..5352ee1c3c 100644
--- a/source/Lib/EncoderLib/EncLib.cpp
+++ b/source/Lib/EncoderLib/EncLib.cpp
@@ -876,7 +876,6 @@ bool EncLib::encodePrep( bool flush, PelStorage* pcPicYuvOrg, PelStorage* pcPicY
   if( m_iNumPicRcvd && ( flush || m_iPOCLast == 1 || m_iNumPicRcvd == m_iGOPSize ) )
   {
     m_picIdInGOP = 0;
-    m_iPOCLast -= 2;
     keepDoing = false;
   }
 
@@ -889,7 +888,7 @@ bool EncLib::encode( const InputColourSpaceConversion snrCSC, std::list<PelUnitB
 
   for( int fieldNum = 0; fieldNum < 2; fieldNum++ )
   {
-    m_iPOCLast = ( m_iNumPicRcvd == m_iGOPSize ) ? m_uiNumAllPicCoded + m_iNumPicRcvd - 1 : m_iPOCLast + 1;
+    m_iPOCLast = m_iPOCLast < 2 ? fieldNum : m_iPOCLast;
 
     // compress GOP
     m_cGOPEncoder.compressGOP( m_iPOCLast, m_iPOCLast < 2 ? m_iPOCLast + 1 : m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, true, isTff, snrCSC, m_printFrameMSE, false, m_picIdInGOP );
diff --git a/source/Lib/EncoderLib/EncSlice.cpp b/source/Lib/EncoderLib/EncSlice.cpp
index a3cabec379..f5a22f9f30 100644
--- a/source/Lib/EncoderLib/EncSlice.cpp
+++ b/source/Lib/EncoderLib/EncSlice.cpp
@@ -448,7 +448,7 @@ void EncSlice::initEncSlice(Picture* pcPic, const int pocLast, const int pocCurr
   }
   else
   {
-    eSliceType = (pocLast == 0 || pocCurr - (isField ? 1 : 0) == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
+    eSliceType = (pocLast == 0 || pocCurr == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
   }
 
   rpcSlice->setDepth        ( depth );
@@ -599,23 +599,23 @@ void EncSlice::initEncSlice(Picture* pcPic, const int pocLast, const int pocCurr
   {
     // restore original slice type
 
-    if (m_pcCfg->getIntraPeriod() > 0 )
+    if (m_pcCfg->getIntraPeriod() > 0)
     {
-      if(!(isField && pocLast == 1) || !m_pcCfg->getEfficientFieldIRAPEnabled())
+      if (!(isField && pocLast == 1) || !m_pcCfg->getEfficientFieldIRAPEnabled())
       {
-        if(m_pcCfg->getDecodingRefreshType() == 3)
+        if (m_pcCfg->getDecodingRefreshType() == 3)
         {
-          eSliceType = (pocLast == 0 || (pocCurr) % (m_pcCfg->getIntraPeriod() * multipleFactor) == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
+          eSliceType = (pocLast == 0 || pocCurr % (m_pcCfg->getIntraPeriod() * multipleFactor) == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
         }
         else
         {
           eSliceType = (pocLast == 0 || (pocCurr - (isField ? 1 : 0)) % (m_pcCfg->getIntraPeriod() * multipleFactor) == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
         }
       }
-      else
-      {
-        eSliceType = (pocLast == 0 || pocCurr - (isField ? 1 : 0) == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
-      }
+    }
+    else
+    {
+      eSliceType = (pocLast == 0 || pocCurr == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
     }
     rpcSlice->setSliceType        ( eSliceType );
   }
-- 
GitLab