[FFmpeg-devel] [PATCH v6 18/22] vaapi_encode_h264: Support stereo 3D metadata

Mark Thompson sw at jkqxz.net
Mon Jul 27 19:32:33 EEST 2020


Insert frame packing arrangement messages into the stream when input
frames have associated stereo 3D side-data.
---
 doc/encoders.texi              |  3 +++
 libavcodec/vaapi_encode.h      |  1 +
 libavcodec/vaapi_encode_h264.c | 24 +++++++++++++++++++++++-
 3 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index ed8ef63784..32870f5939 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -3175,6 +3175,9 @@ Include picture timing parameters (@emph{buffering_period} and
 @emph{pic_timing} messages).
 @item recovery_point
 Include recovery points where appropriate (@emph{recovery_point} messages).
+ at item frame_packing
+Include stereo 3D metadata if the input frames have it
+(@emph{frame_packing_arrangement} messages).
 @end table
 
 @end table
diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h
index 3bb240ec68..671b21f283 100644
--- a/libavcodec/vaapi_encode.h
+++ b/libavcodec/vaapi_encode.h
@@ -483,6 +483,7 @@ enum {
     SEI_RECOVERY_POINT          = 0x04,
     SEI_MASTERING_DISPLAY       = 0x08,
     SEI_CONTENT_LIGHT_LEVEL     = 0x10,
+    SEI_FRAME_PACKING           = 0x20,
 };
 
 
diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index 62f95ea59f..f6d16b5c24 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -25,6 +25,7 @@
 #include "libavutil/common.h"
 #include "libavutil/internal.h"
 #include "libavutil/opt.h"
+#include "libavutil/stereo3d.h"
 
 #include "avcodec.h"
 #include "cbs.h"
@@ -90,6 +91,7 @@ typedef struct VAAPIEncodeH264Context {
     H264RawSEIBufferingPeriod      sei_buffering_period;
     H264RawSEIPicTiming            sei_pic_timing;
     H264RawSEIRecoveryPoint        sei_recovery_point;
+    H264RawSEIFramePackingArrangement sei_frame_packing;
     H264RawSEIUserDataUnregistered sei_identifier;
     char                          *sei_identifier_string;
 
@@ -244,6 +246,12 @@ static int vaapi_encode_h264_write_extra_header(AVCodecContext *avctx,
             sei->payload[i].payload.recovery_point = priv->sei_recovery_point;
             ++i;
         }
+        if (priv->sei_needed & SEI_FRAME_PACKING) {
+            sei->payload[i].payload_type = H264_SEI_TYPE_FRAME_PACKING;
+            sei->payload[i].payload.frame_packing_arrangement =
+                priv->sei_frame_packing;
+            ++i;
+        }
 
         sei->payload_count = i;
         av_assert0(sei->payload_count > 0);
@@ -693,6 +701,17 @@ static int vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,
         priv->sei_needed |= SEI_RECOVERY_POINT;
     }
 
+    if (priv->sei & SEI_FRAME_PACKING) {
+        AVFrameSideData *sd = av_frame_get_side_data(pic->input_image,
+                                                     AV_FRAME_DATA_STEREO3D);
+        if (sd) {
+            ff_cbs_h264_fill_sei_frame_packing_arrangement(
+                &priv->sei_frame_packing, (const AVStereo3D*)sd->data);
+
+            priv->sei_needed |= SEI_FRAME_PACKING;
+        }
+    }
+
     vpic->CurrPic = (VAPictureH264) {
         .picture_id          = pic->recon_surface,
         .frame_idx           = hpic->frame_num,
@@ -1264,7 +1283,7 @@ static const AVOption vaapi_encode_h264_options[] = {
 
     { "sei", "Set SEI to include",
       OFFSET(sei), AV_OPT_TYPE_FLAGS,
-      { .i64 = SEI_IDENTIFIER | SEI_TIMING | SEI_RECOVERY_POINT },
+      { .i64 = SEI_IDENTIFIER | SEI_TIMING | SEI_RECOVERY_POINT | SEI_FRAME_PACKING },
       0, INT_MAX, FLAGS, "sei" },
     { "identifier", "Include encoder version identifier",
       0, AV_OPT_TYPE_CONST, { .i64 = SEI_IDENTIFIER },
@@ -1275,6 +1294,9 @@ static const AVOption vaapi_encode_h264_options[] = {
     { "recovery_point", "Include recovery points where appropriate",
       0, AV_OPT_TYPE_CONST, { .i64 = SEI_RECOVERY_POINT },
       INT_MIN, INT_MAX, FLAGS, "sei" },
+    { "frame_packing", "Include frame packing arrangement for stereo 3D",
+      0, AV_OPT_TYPE_CONST, { .i64 = SEI_FRAME_PACKING },
+      INT_MIN, INT_MAX, FLAGS, "sei" },
 
     { "profile", "Set profile (profile_idc and constraint_set*_flag)",
       OFFSET(profile), AV_OPT_TYPE_INT,
-- 
2.27.0



More information about the ffmpeg-devel mailing list