diff --git a/ffmpeg.c b/ffmpeg.c
index 7310df492935fb99d17aa0d4d54d6bef0cfe6ef7..da084de12162557e8d7b373d7cade5ad20da5462 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -274,7 +274,7 @@ static void do_audio_out(AVFormatContext *s,
                      &ost->fifo.rptr) == 0) {
             ret = avcodec_encode_audio(enc, audio_out, sizeof(audio_out), 
                                        (short *)audio_buf);
-            s->format->write_packet(s, ost->index, audio_out, ret);
+            s->format->write_packet(s, ost->index, audio_out, ret, 0);
         }
     } else {
         /* output a pcm frame */
@@ -291,7 +291,7 @@ static void do_audio_out(AVFormatContext *s,
         }
         ret = avcodec_encode_audio(enc, audio_out, size_out, 
                                    (short *)buftmp);
-        s->format->write_packet(s, ost->index, audio_out, ret);
+        s->format->write_packet(s, ost->index, audio_out, ret, 0);
     }
 }
 
@@ -387,7 +387,7 @@ static void write_picture(AVFormatContext *s, int index, AVPicture *picture,
     default:
         return;
     }
-    s->format->write_packet(s, index, buf, size);
+    s->format->write_packet(s, index, buf, size, 0);
     free(buf);
 }
 
@@ -484,7 +484,7 @@ static void do_video_out(AVFormatContext *s,
             ret = avcodec_encode_video(enc, 
                                        video_buffer, sizeof(video_buffer), 
                                        picture);
-            s->format->write_packet(s, ost->index, video_buffer, ret);
+            s->format->write_packet(s, ost->index, video_buffer, ret, 0);
             *frame_size = ret;
         } else {
             write_picture(s, ost->index, picture, enc->pix_fmt, enc->width, enc->height);
@@ -728,6 +728,11 @@ static int av_encode(AVFormatContext **output_files,
                 codec->sample_rate == icodec->sample_rate &&
                 codec->channels == icodec->channels) {
                 /* no reencoding */
+                /* use the same frame size */
+                codec->frame_size = icodec->frame_size;
+                //codec->frame_size = 8*icodec->sample_rate*icodec->frame_size/
+                //                    icodec->bit_rate;
+                //fprintf(stderr,"\nFrame size: %d", codec->frame_size);
             } else {
                 if (fifo_init(&ost->fifo, 2 * MAX_AUDIO_PACKET_SIZE))
                     goto fail;
@@ -999,7 +1004,8 @@ static int av_encode(AVFormatContext **output_files,
                         }
                     } else {
                         /* no reencoding needed : output the packet directly */
-                        os->format->write_packet(os, ost->index, data_buf, data_size);
+                        /* force the input stream PTS */
+                        os->format->write_packet(os, ost->index, data_buf, data_size, pkt.pts);
                     }
                 }
             }
diff --git a/ffserver.c b/ffserver.c
index 2f1b0b5459e16864b36ef1db877bc8e7ab7ad3c7..4704c51c7575b15c63d7dfa230f8a394b7d35af2 100644
--- a/ffserver.c
+++ b/ffserver.c
@@ -882,7 +882,7 @@ static int http_prepare_data(HTTPContext *c)
                     }
                 } else {
 		send_it:
-                    if (av_write_packet(&c->fmt_ctx, &pkt))
+                    if (av_write_packet(&c->fmt_ctx, &pkt, 0))
 			c->state = HTTPSTATE_SEND_DATA_TRAILER;
                 }
                 
diff --git a/libav/asf.c b/libav/asf.c
index 60960db2b9a17bd9dcc17998970223124a872dc7..0dc4fca2d75c6a2ef0b33f14bba2aa3fabd11150 100644
--- a/libav/asf.c
+++ b/libav/asf.c
@@ -524,7 +524,7 @@ static void put_frame(AVFormatContext *s, ASFStream *stream, int timestamp,
 
 
 static int asf_write_packet(AVFormatContext *s, int stream_index,
-                            UINT8 *buf, int size)
+                            UINT8 *buf, int size, int force_pts)
 {
     ASFContext *asf = s->priv_data;
     int timestamp;
diff --git a/libav/audio.c b/libav/audio.c
index 2f4ef759b600d58f7ff2484777a0c19d4f16d2e3..330310c29230a71db888ad7af728a3400bfb1ce8 100644
--- a/libav/audio.c
+++ b/libav/audio.c
@@ -161,7 +161,7 @@ static int audio_write_header(AVFormatContext *s1)
 }
 
 static int audio_write_packet(AVFormatContext *s1, int stream_index,
-                              UINT8 *buf, int size)
+                              UINT8 *buf, int size, int force_pts)
 {
     AudioData *s = s1->priv_data;
     int len, ret;
diff --git a/libav/avformat.h b/libav/avformat.h
index 630c5af95bc3bed0e12d7cbe340db635d6b54945..2f5025c1686abecb9343cae4e0c83fc82c115d84 100644
--- a/libav/avformat.h
+++ b/libav/avformat.h
@@ -44,7 +44,7 @@ typedef struct AVFormat {
     int (*write_header)(struct AVFormatContext *);
     int (*write_packet)(struct AVFormatContext *, 
                         int stream_index,
-                        unsigned char *buf, int size);
+                        unsigned char *buf, int size, int force_pts);
     int (*write_trailer)(struct AVFormatContext *);
 
     /* optional input support */
@@ -187,7 +187,7 @@ AVFormatContext *av_open_input_file(const char *filename,
 int av_read_packet(AVFormatContext *s, AVPacket *pkt);
 void av_close_input_file(AVFormatContext *s);
 
-int av_write_packet(AVFormatContext *s, AVPacket *pkt);
+int av_write_packet(AVFormatContext *s, AVPacket *pkt, int force_pts);
 
 void dump_format(AVFormatContext *ic,
                  int index, 
diff --git a/libav/avienc.c b/libav/avienc.c
index 1be5da424cca4e5689b2eded187d50ff8cfae6a9..b21a2527a2a2a476b5178531cf484f8221f5933d 100644
--- a/libav/avienc.c
+++ b/libav/avienc.c
@@ -277,7 +277,7 @@ static int avi_write_header(AVFormatContext *s)
 }
 
 static int avi_write_packet(AVFormatContext *s, int stream_index,
-                            UINT8 *buf, int size)
+                            UINT8 *buf, int size, int force_pts)
 {
     AVIContext *avi = s->priv_data;
     ByteIOContext *pb = &s->pb;
diff --git a/libav/ffm.c b/libav/ffm.c
index 80f41ff0f0379f6e2d429096ef9684b3839cb252..b5d28333e19ffdefb1ffdb4809e7dc8b1456ff79 100644
--- a/libav/ffm.c
+++ b/libav/ffm.c
@@ -195,7 +195,7 @@ static int ffm_write_header(AVFormatContext *s)
 }
 
 static int ffm_write_packet(AVFormatContext *s, int stream_index,
-                            UINT8 *buf, int size)
+                            UINT8 *buf, int size, int force_pts)
 {
     AVStream *st = s->streams[stream_index];
     FFMStream *fst = st->priv_data;
diff --git a/libav/img.c b/libav/img.c
index e793d43d09f2a84d47da2c39fb8f9ccb1a59f229..57cc0c303aeaef4c475048912730553f446b4b79 100644
--- a/libav/img.c
+++ b/libav/img.c
@@ -515,7 +515,7 @@ static int img_write_header(AVFormatContext *s)
 }
 
 static int img_write_packet(AVFormatContext *s, int stream_index,
-                            UINT8 *buf, int size)
+                            UINT8 *buf, int size, int force_pts)
 {
     VideoData *img = s->priv_data;
     AVStream *st = s->streams[stream_index];
diff --git a/libav/jpeg.c b/libav/jpeg.c
index 531e79792c714aa4980bf8e13278726990b01a30..94971d9f8fefb22fd2a245ed01f4618097e0a104 100644
--- a/libav/jpeg.c
+++ b/libav/jpeg.c
@@ -32,8 +32,8 @@ static int mpjpeg_write_header(AVFormatContext *s)
     return 0;
 }
 
-static int mpjpeg_write_packet(AVFormatContext *s, 
-                               int stream_index, UINT8 *buf, int size)
+static int mpjpeg_write_packet(AVFormatContext *s, int stream_index, 
+                               UINT8 *buf, int size, int force_pts)
 {
     UINT8 buf1[256];
 
@@ -74,7 +74,7 @@ static int single_jpeg_write_header(AVFormatContext *s)
 }
 
 static int single_jpeg_write_packet(AVFormatContext *s, int stream_index,
-                            UINT8 *buf, int size)
+                            UINT8 *buf, int size, int force_pts)
 {
     put_buffer(&s->pb, buf, size);
     put_flush_packet(&s->pb);
@@ -120,7 +120,7 @@ static int jpeg_write_header(AVFormatContext *s1)
 }
 
 static int jpeg_write_packet(AVFormatContext *s1, int stream_index,
-                            UINT8 *buf, int size)
+                            UINT8 *buf, int size, int force_pts)
 {
     JpegContext *s = s1->priv_data;
     char filename[1024];
diff --git a/libav/mpeg.c b/libav/mpeg.c
index 2871278778d3efb6f724721bcdd47909b533b24c..637972471c8c4470a4562b32ddc2954ff2a0c7e8 100644
--- a/libav/mpeg.c
+++ b/libav/mpeg.c
@@ -321,18 +321,21 @@ static void flush_packet(AVFormatContext *ctx, int stream_index)
     stream->start_pts = -1;
 }
 
-static int mpeg_mux_write_packet(AVFormatContext *ctx, 
-                                 int stream_index, UINT8 *buf, int size)
+static int mpeg_mux_write_packet(AVFormatContext *ctx, int stream_index,
+                                 UINT8 *buf, int size, int force_pts)
 {
     MpegMuxContext *s = ctx->priv_data;
     AVStream *st = ctx->streams[stream_index];
     StreamInfo *stream = st->priv_data;
     int len;
-
+    
     while (size > 0) {
         /* set pts */
-        if (stream->start_pts == -1)
+        if (stream->start_pts == -1) {
+            if (force_pts)
+                stream->pts = force_pts;
             stream->start_pts = stream->pts;
+        }
         len = s->packet_data_max_size - stream->buffer_ptr;
         if (len > size)
             len = size;
@@ -714,6 +717,8 @@ static int mpeg_mux_read_packet(AVFormatContext *s,
     goto redo;
  found:
     av_new_packet(pkt, len);
+    //printf("\nRead Packet ID: %x PTS: %f Size: %d", startcode,
+    //       (float)pts/90000, len);
     get_buffer(&s->pb, pkt->data, pkt->size);
     pkt->pts = pts;
     pkt->stream_index = i;
diff --git a/libav/raw.c b/libav/raw.c
index 02b56b48eec4a258fcdc6687f6237e85247ebf4b..d2c2c3486a524c0ec856489a66c06318db0af7ef 100644
--- a/libav/raw.c
+++ b/libav/raw.c
@@ -26,7 +26,7 @@ int raw_write_header(struct AVFormatContext *s)
 
 int raw_write_packet(struct AVFormatContext *s, 
                      int stream_index,
-                     unsigned char *buf, int size)
+                     unsigned char *buf, int size, int force_pts)
 {
     put_buffer(&s->pb, buf, size);
     put_flush_packet(&s->pb);
diff --git a/libav/rm.c b/libav/rm.c
index d987ba30ca35bb6f159cc6322f05f558d3a56e6e..be2f064badaec8afd80ffd4470704cbfd91762db 100644
--- a/libav/rm.c
+++ b/libav/rm.c
@@ -389,7 +389,7 @@ static int rm_write_video(AVFormatContext *s, UINT8 *buf, int size)
 }
 
 static int rm_write_packet(AVFormatContext *s, int stream_index, 
-                           UINT8 *buf, int size)
+                           UINT8 *buf, int size, int force_pts)
 {
     if (s->streams[stream_index]->codec.codec_type == 
         CODEC_TYPE_AUDIO)
diff --git a/libav/swf.c b/libav/swf.c
index ebd4ada886320fb1a1a28309c4bcbdac8578920f..27755a39694aacfba66eb379bbf26ae6063cb6d9 100644
--- a/libav/swf.c
+++ b/libav/swf.c
@@ -378,7 +378,7 @@ static int swf_write_audio(AVFormatContext *s, UINT8 *buf, int size)
 }
 
 static int swf_write_packet(AVFormatContext *s, int stream_index, 
-                           UINT8 *buf, int size)
+                           UINT8 *buf, int size, int force_pts)
 {
     AVCodecContext *codec = &s->streams[stream_index]->codec;
     if (codec->codec_type == CODEC_TYPE_AUDIO)
diff --git a/libav/utils.c b/libav/utils.c
index 7315ebdc925dd716a824e74509ce6ab25e90db8b..8570be2055bb49191aae284c97117f532fa456eb 100644
--- a/libav/utils.c
+++ b/libav/utils.c
@@ -375,10 +375,10 @@ void av_close_input_file(AVFormatContext *s)
 }
 
 
-int av_write_packet(AVFormatContext *s, AVPacket *pkt)
+int av_write_packet(AVFormatContext *s, AVPacket *pkt, int force_pts)
 {
     /* XXX: currently, an emulation because internal API must change */
-    return s->format->write_packet(s, pkt->stream_index, pkt->data, pkt->size);
+    return s->format->write_packet(s, pkt->stream_index, pkt->data, pkt->size, force_pts);
 }
 
 /* "user interface" functions */
diff --git a/libav/wav.c b/libav/wav.c
index df18a64ec76a67bbc48f2e1acb9e0fb985b18eb4..0023ac608aa6d8ff5c70a6294fb449d5e3fc4a98 100644
--- a/libav/wav.c
+++ b/libav/wav.c
@@ -127,7 +127,7 @@ static int wav_write_header(AVFormatContext *s)
 }
 
 static int wav_write_packet(AVFormatContext *s, int stream_index_ptr,
-                           UINT8 *buf, int size)
+                           UINT8 *buf, int size, int force_pts)
 {
     ByteIOContext *pb = &s->pb;
     put_buffer(pb, buf, size);
diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c
index d983690119e96a34047261a1155e08de8a6708a3..fbe177ccfd050eaf5bd7e9a3e9a3e185993439f9 100644
--- a/libavcodec/mpeg12.c
+++ b/libavcodec/mpeg12.c
@@ -1403,6 +1403,7 @@ static int mpeg_decode_slice(AVCodecContext *avctx,
 
     for(;;) {
         clear_blocks(s->block[0]);
+        emms_c();
         ret = mpeg_decode_mb(s, s->block);
         dprintf("ret=%d\n", ret);
         if (ret < 0)
diff --git a/libavcodec/mpegaudiodec.c b/libavcodec/mpegaudiodec.c
index bb86bd0ca49a2a02bf9698d56d273778c7eb8d77..b423788ca890f7cec30c38097ac3f3ff1b6d825c 100644
--- a/libavcodec/mpegaudiodec.c
+++ b/libavcodec/mpegaudiodec.c
@@ -2314,6 +2314,7 @@ static int decode_frame(AVCodecContext * avctx,
                         avctx->sample_rate = s->sample_rate;
                         avctx->channels = s->nb_channels;
 			avctx->bit_rate = s->bit_rate;
+			avctx->frame_size = s->frame_size;
                     }
 		}
 	    }