--- libavcodec/mpeg12enc.org	2015-09-02 10:16:30.063910853 +0200
+++ libavcodec/mpeg12enc.c	2015-09-02 10:16:13.036243005 +0200
@@ -254,7 +254,7 @@
 
         put_sbits(&s->pb, 12, s->width  & 0xFFF);
         put_sbits(&s->pb, 12, s->height & 0xFFF);
-
+#if 0 // MEANX
         for (i = 1; i < 15; i++) {
             int64_t error = aspect_ratio.num * (1LL<<32) / aspect_ratio.den;
             if (s->codec_id == AV_CODEC_ID_MPEG1VIDEO || i <= 1)
@@ -269,12 +269,41 @@
                 s->aspect_ratio_info = i;
             }
         }
+#endif // MEANX
+            // MEANX put_bits(&s->pb, 4, s->aspect_ratio_info);
+            // MEANX put_bits(&s->pb, 4, s->frame_rate_index);
+ // MEANX 4:3
+   if(s->avctx->sample_aspect_ratio.num==16 && s->avctx->sample_aspect_ratio.den==9)
+             {
+                 //printf("FFmpeg : Wide\n");
+                 put_bits(&s->pb,4,3); //16:9
+             }
+             else        //4:3
+             {
+               if(s->codec_id == CODEC_ID_MPEG2VIDEO)
+                 put_bits(&s->pb, 4, 2);
+               else
+                 put_bits(&s->pb, 4, 12); // MPEG1
+             }
+ // /MEANX
+// MEANX : Pulldown
+            if((s->avctx->flags2 & CODEC_FLAG2_32_PULLDOWN) && (s->codec_id == CODEC_ID_MPEG2VIDEO))
+             {           
+                 put_bits(&s->pb, 4,4);
+             }
+             else
+             {                                  
+                 put_bits(&s->pb, 4, s->frame_rate_index);
+             } //MEANX pulldown
+
+            // MEANX if(s->avctx->rc_max_rate){
+                // MEANX v = (s->avctx->rc_max_rate + 399) / 400;
+           // MEANX  if(s->avctx->rc_max_rate_header){ //MEANX we use header
+           // MEANX      v = (s->avctx->rc_max_rate_header + 399) / 400;
+            if(s->avctx->rc_buffer_size_header) // MEANX we use header
+            {
+                vbv_buffer_size = s->avctx->rc_buffer_size_header;
 
-        put_bits(&s->pb, 4, s->aspect_ratio_info);
-        put_bits(&s->pb, 4, s->frame_rate_index);
-
-        if (s->avctx->rc_max_rate) {
-            v = (s->avctx->rc_max_rate + 399) / 400;
             if (v > 0x3ffff && s->codec_id == AV_CODEC_ID_MPEG1VIDEO)
                 v = 0x3ffff;
         } else {
@@ -324,7 +353,19 @@
             put_bits(&s->pb, 3, s->avctx->profile); // profile
             put_bits(&s->pb, 4, s->avctx->level);   // level
 
-            put_bits(&s->pb, 1, s->progressive_sequence);
+   // MEANX pulldown put_bits(&s->pb, 1, s->progressive_sequence);
+  // MEANX Pulldown
+ if(s->avctx->flags2 & CODEC_FLAG2_32_PULLDOWN) //MEANX
+                        put_bits(&s->pb, 1, 0);
+                else
+                        put_bits(&s->pb, 1, s->progressive_sequence);
+
+
+// /MEANX
+
+
+
+// MEANX                 put_bits(&s->pb, 1, s->progressive_sequence);
             put_bits(&s->pb, 2, s->chroma_format);
             put_bits(&s->pb, 2, s->width  >> 12);
             put_bits(&s->pb, 2, s->height >> 12);
@@ -425,6 +466,7 @@
 
 void ff_mpeg1_encode_picture_header(MpegEncContext *s, int picture_number)
 {
+    int tff, rff; //MEANX
     AVFrameSideData *side_data;
     mpeg1_encode_sequence_header(s);
 
@@ -463,6 +505,46 @@
 
     s->frame_pred_frame_dct = 1;
     if (s->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
+// MEANX
+        if(s->avctx->flags2 & CODEC_FLAG2_32_PULLDOWN)
+        {
+        
+                switch((s->picture_number - 
+                          s->gop_picture_number)&3)
+                {
+                        case 0:
+                        default:
+                                rff=1;
+                                tff=1;
+                                break;
+                        case 1:
+                                rff=0;
+                                tff=0;
+                                break;
+                        case 2:
+                                rff=1;
+                                tff=0;
+                                break;
+                        case 3:
+                                rff=0;
+                                tff=1;
+                                break;
+                }               
+           }
+        else
+        {
+                if (s->progressive_sequence) 
+                {
+                        tff=0; /* no repeat */
+                } else 
+                {
+                        tff=s->current_picture_ptr->f->top_field_first;
+                }
+                rff=s->repeat_first_field;
+        
+        }
+
+// /MEANX
         put_header(s, EXT_START_CODE);
         put_bits(&s->pb, 4, 8);                 /* pic ext */
         if (s->pict_type == AV_PICTURE_TYPE_P ||
@@ -482,10 +564,14 @@
 
         av_assert0(s->picture_structure == PICT_FRAME);
         put_bits(&s->pb, 2, s->picture_structure);
+#if 0 // MEANX
         if (s->progressive_sequence)
             put_bits(&s->pb, 1, 0);             /* no repeat */
         else
             put_bits(&s->pb, 1, s->current_picture_ptr->f->top_field_first);
+#endif // MEANX
+        put_bits(&s->pb, 1, tff);  //MEANX PULLDOWN
+
         /* XXX: optimize the generation of this flag with entropy measures */
         s->frame_pred_frame_dct = s->progressive_sequence;
 
@@ -494,7 +580,8 @@
         put_bits(&s->pb, 1, s->q_scale_type);
         put_bits(&s->pb, 1, s->intra_vlc_format);
         put_bits(&s->pb, 1, s->alternate_scan);
-        put_bits(&s->pb, 1, s->repeat_first_field);
+        // MEANX put_bits(&s->pb, 1, s->top_field_first);
+        put_bits(&s->pb, 1, rff); // MEANX
         s->progressive_frame = s->progressive_sequence;
         /* chroma_420_type */
         put_bits(&s->pb, 1, s->chroma_format ==
