[FFmpeg-cvslog] mpeg12enc: add support for PANSCAN side data in sequence_display_extension

Marton Balint git at videolan.org
Sat Jun 14 19:54:51 CEST 2014


ffmpeg | branch: master | Marton Balint <cus at passwd.hu> | Sat Jun 14 17:07:27 2014 +0200| [66f4891e6422ada894dccdd63bc4464d634d9e61] | committer: Michael Niedermayer

mpeg12enc: add support for PANSCAN side data in sequence_display_extension

Signed-off-by: Marton Balint <cus at passwd.hu>
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=66f4891e6422ada894dccdd63bc4464d634d9e61
---

 libavcodec/mpeg12enc.c |   28 +++++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)

diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c
index cb7c367..4fb9c44 100644
--- a/libavcodec/mpeg12enc.c
+++ b/libavcodec/mpeg12enc.c
@@ -311,6 +311,11 @@ static void mpeg1_encode_sequence_header(MpegEncContext *s)
         ff_write_quant_matrix(&s->pb, s->avctx->inter_matrix);
 
         if (s->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
+            AVFrameSideData *side_data;
+            int width = s->width;
+            int height = s->height;
+            int use_seq_disp_ext;
+
             put_header(s, EXT_START_CODE);
             put_bits(&s->pb, 4, 1);                 // seq ext
 
@@ -330,9 +335,22 @@ static void mpeg1_encode_sequence_header(MpegEncContext *s)
             put_bits(&s->pb, 2, s->mpeg2_frame_rate_ext.num-1); // frame_rate_ext_n
             put_bits(&s->pb, 5, s->mpeg2_frame_rate_ext.den-1); // frame_rate_ext_d
 
-            if (s->avctx->color_primaries != AVCOL_PRI_UNSPECIFIED ||
-                s->avctx->color_trc != AVCOL_TRC_UNSPECIFIED ||
-                s->avctx->colorspace != AVCOL_SPC_UNSPECIFIED) {
+            side_data = av_frame_get_side_data(s->current_picture_ptr->f, AV_FRAME_DATA_PANSCAN);
+            if (side_data) {
+                AVPanScan *pan_scan = (AVPanScan *)side_data->data;
+                if (pan_scan->width && pan_scan->height) {
+                    width = pan_scan->width >> 4;
+                    height = pan_scan->height >> 4;
+                }
+            }
+
+            use_seq_disp_ext = (width != s->width ||
+                                height != s->height ||
+                                s->avctx->color_primaries != AVCOL_PRI_UNSPECIFIED ||
+                                s->avctx->color_trc != AVCOL_TRC_UNSPECIFIED ||
+                                s->avctx->colorspace != AVCOL_SPC_UNSPECIFIED);
+
+            if (use_seq_disp_ext) {
                 put_header(s, EXT_START_CODE);
                 put_bits(&s->pb, 4, 2);                         // sequence display extension
                 put_bits(&s->pb, 3, 0);                         // video_format: 0 is components
@@ -340,9 +358,9 @@ static void mpeg1_encode_sequence_header(MpegEncContext *s)
                 put_bits(&s->pb, 8, s->avctx->color_primaries); // colour_primaries
                 put_bits(&s->pb, 8, s->avctx->color_trc);       // transfer_characteristics
                 put_bits(&s->pb, 8, s->avctx->colorspace);      // matrix_coefficients
-                put_bits(&s->pb, 14, s->width);                 // display_horizontal_size
+                put_bits(&s->pb, 14, width);                    // display_horizontal_size
                 put_bits(&s->pb, 1, 1);                         // marker_bit
-                put_bits(&s->pb, 14, s->height);                // display_vertical_size
+                put_bits(&s->pb, 14, height);                   // display_vertical_size
                 put_bits(&s->pb, 3, 0);                         // remaining 3 bits are zero padding
             }
         }



More information about the ffmpeg-cvslog mailing list