[FFmpeg-devel] h264_sei: handle stereoscopy frame sequential flags

Submitted by Steve Lhomme on Sept. 21, 2017, 1:57 p.m.

Details

Message ID 20170921135700.9168-1-robux4@gmail.com
State New
Headers show

Commit Message

Steve Lhomme Sept. 21, 2017, 1:57 p.m.
From: "Mohammed (Shaan) Huzaifa Danish" <shaan3@gmail.com>

---
 libavcodec/h264_sei.c   | 6 ++++--
 libavcodec/h264_sei.h   | 1 +
 libavcodec/h264_slice.c | 2 ++
 libavutil/stereo3d.h    | 4 ++++
 4 files changed, 11 insertions(+), 2 deletions(-)

Comments

wm4 Sept. 22, 2017, 2:33 a.m.
On Thu, 21 Sep 2017 15:57:00 +0200
Steve Lhomme <robux4@gmail.com> wrote:

> From: "Mohammed (Shaan) Huzaifa Danish" <shaan3@gmail.com>
> 
> ---
>  libavcodec/h264_sei.c   | 6 ++++--
>  libavcodec/h264_sei.h   | 1 +
>  libavcodec/h264_slice.c | 2 ++
>  libavutil/stereo3d.h    | 4 ++++
>  4 files changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/libavcodec/h264_sei.c b/libavcodec/h264_sei.c
> index 332ae50860..d28a9b61f6 100644
> --- a/libavcodec/h264_sei.c
> +++ b/libavcodec/h264_sei.c
> @@ -326,9 +326,11 @@ static int decode_frame_packing_arrangement(H264SEIFramePacking *h,
>          h->content_interpretation_type    = get_bits(gb, 6);
>  
>          // the following skips: spatial_flipping_flag, frame0_flipped_flag,
> -        // field_views_flag, current_frame_is_frame0_flag,
> +        // field_views_flag
> +        skip_bits(gb, 3);
> +        h->current_frame_is_frame0_flag         = get_bits1(gb);
>          // frame0_self_contained_flag, frame1_self_contained_flag
> -        skip_bits(gb, 6);
> +        skip_bits(gb, 2);
>  
>          if (!h->quincunx_sampling_flag && h->frame_packing_arrangement_type != 5)
>              skip_bits(gb, 16);      // frame[01]_grid_position_[xy]
> diff --git a/libavcodec/h264_sei.h b/libavcodec/h264_sei.h
> index a53f1899fa..817b4eaae9 100644
> --- a/libavcodec/h264_sei.h
> +++ b/libavcodec/h264_sei.h
> @@ -125,6 +125,7 @@ typedef struct H264SEIFramePacking {
>      int frame_packing_arrangement_repetition_period;
>      int content_interpretation_type;
>      int quincunx_sampling_flag;
> +    int current_frame_is_frame0_flag;
>  } H264SEIFramePacking;
>  
>  typedef struct H264SEIDisplayOrientation {
> diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
> index 2577edd8a6..2de9abe650 100644
> --- a/libavcodec/h264_slice.c
> +++ b/libavcodec/h264_slice.c
> @@ -1246,6 +1246,8 @@ static int h264_export_frame_props(H264Context *h)
>  
>          if (fp->content_interpretation_type == 2)
>              stereo->flags = AV_STEREO3D_FLAG_INVERT;
> +        if (fp->current_frame_is_frame0_flag)
> +            stereo->flags |= AV_STEREO3D_FLAG_FRAME0;
>          }
>      }
>  
> diff --git a/libavutil/stereo3d.h b/libavutil/stereo3d.h
> index 54f4c4c5c7..190918c3c6 100644
> --- a/libavutil/stereo3d.h
> +++ b/libavutil/stereo3d.h
> @@ -146,6 +146,10 @@ enum AVStereo3DType {
>   * Inverted views, Right/Bottom represents the left view.
>   */
>  #define AV_STEREO3D_FLAG_INVERT     (1 << 0)
> +/**
> + * This frame is frame0 (left view), otherwise it's the right view.
> + */
> +#define AV_STEREO3D_FLAG_FRAME0     (1 << 1)

I think it would be good to mark the other frame too?

>  
>  /**
>   * Stereo 3D type: this structure describes how two videos are packed

Out of curiosity, do files like this exist outside of sample
collections?

Patch hide | download patch | download mbox

diff --git a/libavcodec/h264_sei.c b/libavcodec/h264_sei.c
index 332ae50860..d28a9b61f6 100644
--- a/libavcodec/h264_sei.c
+++ b/libavcodec/h264_sei.c
@@ -326,9 +326,11 @@  static int decode_frame_packing_arrangement(H264SEIFramePacking *h,
         h->content_interpretation_type    = get_bits(gb, 6);
 
         // the following skips: spatial_flipping_flag, frame0_flipped_flag,
-        // field_views_flag, current_frame_is_frame0_flag,
+        // field_views_flag
+        skip_bits(gb, 3);
+        h->current_frame_is_frame0_flag         = get_bits1(gb);
         // frame0_self_contained_flag, frame1_self_contained_flag
-        skip_bits(gb, 6);
+        skip_bits(gb, 2);
 
         if (!h->quincunx_sampling_flag && h->frame_packing_arrangement_type != 5)
             skip_bits(gb, 16);      // frame[01]_grid_position_[xy]
diff --git a/libavcodec/h264_sei.h b/libavcodec/h264_sei.h
index a53f1899fa..817b4eaae9 100644
--- a/libavcodec/h264_sei.h
+++ b/libavcodec/h264_sei.h
@@ -125,6 +125,7 @@  typedef struct H264SEIFramePacking {
     int frame_packing_arrangement_repetition_period;
     int content_interpretation_type;
     int quincunx_sampling_flag;
+    int current_frame_is_frame0_flag;
 } H264SEIFramePacking;
 
 typedef struct H264SEIDisplayOrientation {
diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index 2577edd8a6..2de9abe650 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -1246,6 +1246,8 @@  static int h264_export_frame_props(H264Context *h)
 
         if (fp->content_interpretation_type == 2)
             stereo->flags = AV_STEREO3D_FLAG_INVERT;
+        if (fp->current_frame_is_frame0_flag)
+            stereo->flags |= AV_STEREO3D_FLAG_FRAME0;
         }
     }
 
diff --git a/libavutil/stereo3d.h b/libavutil/stereo3d.h
index 54f4c4c5c7..190918c3c6 100644
--- a/libavutil/stereo3d.h
+++ b/libavutil/stereo3d.h
@@ -146,6 +146,10 @@  enum AVStereo3DType {
  * Inverted views, Right/Bottom represents the left view.
  */
 #define AV_STEREO3D_FLAG_INVERT     (1 << 0)
+/**
+ * This frame is frame0 (left view), otherwise it's the right view.
+ */
+#define AV_STEREO3D_FLAG_FRAME0     (1 << 1)
 
 /**
  * Stereo 3D type: this structure describes how two videos are packed