Index: mpegpesenc.c
===================================================================
--- mpegpesenc.c	(revision 2130)
+++ mpegpesenc.c	(working copy)
@@ -391,6 +391,39 @@
 }
 
 /**
+*check AUD nal units for H264 stream
+*@param [in] pkt  the packet to check.
+*@return  1 when success and 0 when fail
+*/
+int check_aud_nal_units(AVPacket * pkt)
+{
+    int size = pkt->size;
+    uint8_t *buf = pkt->data;
+    int buf_index = 0;
+    int is_aud = 0;
+    uint8_t *new_buf = 0;
+    for(; buf_index + 3 < size; buf_index++){
+        if(buf[buf_index] == 0 && buf[buf_index+1] == 0 && buf[buf_index+2] == 1){
+            is_aud = 1;
+            break;
+        }
+    }
+    if(!is_aud){
+    new_buf = av_mallocz(size + 3);
+    if (!new_buf)
+        return 0;
+    new_buf[0] = 0;
+    new_buf[1] = 0;
+    new_buf[2] = 1;
+    memcpy(new_buf + 3, buf, size);
+    av_free(buf);
+    pkt->data = new_buf;
+    pkt->size = size + 3;        
+    }
+    return 1;  
+}
+
+/**
  * Write packet into PES FIFO.
  * @param [in] ctx  the AVFormatContext which contains streams.
  * @param [in] pkt  the packet to write.
@@ -406,7 +439,12 @@
     int64_t pts, dts;
     PacketDesc *pkt_desc;
     const int preload= av_rescale(ctx->preload, 90000, AV_TIME_BASE);
+    if(st->codec->codec_id == CODEC_ID_H264)
+        check_aud_nal_units(pkt);
 
+    int size= pkt->size;
+    uint8_t *buf= pkt->data;
+
     pts= pkt->pts;
     dts= pkt->dts;
 
Index: mpegtsenc.c
===================================================================
--- mpegtsenc.c	(revision 2130)
+++ mpegtsenc.c	(working copy)
@@ -288,6 +288,39 @@
                 put16(&q, 1); /* ancillary page id */
             }
             break;
+        case CODEC_TYPE_VIDEO:
+            {
+                if(st->codec->codec_id == CODEC_ID_H264){
+                    H264Context * h_st = st->codec->priv_data;
+                    //write AVC descriptor
+                    if(h_st->nal_unit_type == NAL_SPS){
+                        *q++ = 0x28;
+                        *q++ = 4;
+                        *q++ = h_st->sps->profile_idc;
+                        *q++ = 0;
+                        *q++ = h_st->sps->level_idc;
+                        *q++ = 0xc0;
+                        // write HRD descriptor
+                        if(h_st->sps->timing_info_present_flag){
+                            *q++ = 0x2a;
+                            *q++ = 8;
+                            *q++ = 0x81;
+                            *q++ = 0;//90khz_flag
+                            uint32_t ntick;
+                            ntick = h_st->sps->num_units_in_tick;
+                            *q++ = ntick >> 24;
+                            *q++ = ntick >> 16;
+                            *q++ = ntick >> 8;
+                            *q++ = ntick;
+                            int fixed_frame_rate_flag = h_st->sps->fixed_frame_rate_flag;
+                            if(fixed_frame_rate_flag)
+                                *q++ = 0xe0;
+                            else
+                                *q++ = 0x20;
+                        }
+                    }
+                }
+            }
         }
 
         val = 0xf000 | (q - desc_length_ptr - 2);
