x264enc: Add information for mixed mode
authorVivia Nikolaidou <vivia@ahiru.eu>
Wed, 30 Nov 2016 16:11:30 +0000 (18:11 +0200)
committerSebastian Dröge <sebastian@centricular.com>
Wed, 30 Nov 2016 16:54:20 +0000 (18:54 +0200)
https://bugzilla.gnome.org/show_bug.cgi?id=775411

ext/x264/gstx264enc.c

index 0c84b41..f5d8f9f 100644 (file)
@@ -1824,6 +1824,9 @@ gst_x264_enc_init_encoder (GstX264Enc * encoder)
 
   if (GST_VIDEO_INFO_IS_INTERLACED (info)) {
     encoder->x264param.b_interlaced = TRUE;
+    if (GST_VIDEO_INFO_INTERLACE_MODE (info) == GST_VIDEO_INTERLACE_MODE_MIXED) {
+      encoder->x264param.b_pic_struct = TRUE;
+    }
     if (GST_VIDEO_INFO_FIELD_ORDER (info) ==
         GST_VIDEO_FIELD_ORDER_TOP_FIELD_FIRST) {
       encoder->x264param.b_tff = TRUE;
@@ -2361,6 +2364,24 @@ gst_x264_enc_handle_frame (GstVideoEncoder * video_enc,
   pic_in.i_pts = frame->pts;
   pic_in.opaque = GINT_TO_POINTER (frame->system_frame_number);
 
+  if (GST_VIDEO_INFO_INTERLACE_MODE (info) == GST_VIDEO_INTERLACE_MODE_MIXED) {
+    if ((fdata->vframe.flags & GST_VIDEO_FRAME_FLAG_INTERLACED) == 0) {
+      pic_in.i_pic_struct = PIC_STRUCT_PROGRESSIVE;
+    } else if ((fdata->vframe.flags & GST_VIDEO_FRAME_FLAG_RFF) != 0) {
+      if ((fdata->vframe.flags & GST_VIDEO_FRAME_FLAG_TFF) != 0) {
+        pic_in.i_pic_struct = PIC_STRUCT_TOP_BOTTOM_TOP;
+      } else {
+        pic_in.i_pic_struct = PIC_STRUCT_BOTTOM_TOP_BOTTOM;
+      }
+    } else {
+      if ((fdata->vframe.flags & GST_VIDEO_FRAME_FLAG_TFF) != 0) {
+        pic_in.i_pic_struct = PIC_STRUCT_TOP_BOTTOM;
+      } else {
+        pic_in.i_pic_struct = PIC_STRUCT_BOTTOM_TOP;
+      }
+    }
+  }
+
   ret = gst_x264_enc_encode_frame (encoder, &pic_in, frame, &i_nal, TRUE);
 
   /* input buffer is released later on */