diff --git a/libavformat/mpegenc.c b/libavformat/mpegenc.c
index 852b3f13c97f434c14d62af0692e8c111a2e8aed..bda8d8324b8b45ac813614f516216c5e92400ce4 100644
--- a/libavformat/mpegenc.c
+++ b/libavformat/mpegenc.c
@@ -318,6 +318,8 @@ static int mpeg_mux_init(AVFormatContext *ctx)
         s->packet_size = ctx->packet_size;
     } else
         s->packet_size = 2048;
+    if (ctx->max_delay < 0) /* Not set by the caller */
+        ctx->max_delay = 0;
 
     s->vcd_padding_bytes_written = 0;
     s->vcd_padding_bitrate=0;
diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 493ae2eb6f5dd54e051f87b062c82bf0b926f01f..a594ca257f2da15df68e3a991a27f938aa65bde4 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -460,6 +460,9 @@ static int mpegts_write_header(AVFormatContext *s)
     const char *provider_name;
     int *pids;
 
+    if (s->max_delay < 0) /* Not set by the caller */
+        s->max_delay = 0;
+
     // round up to a whole number of TS packets
     ts->pes_payload_size = (ts->pes_payload_size + 14 + 183) / 184 * 184 - 14;
 
diff --git a/libavformat/options_table.h b/libavformat/options_table.h
index 7aee448c0f8d1ecaef0e9c2b428df8bd054ce410..683596c2061430de6dc5dbf2a96441c9a3f59395 100644
--- a/libavformat/options_table.h
+++ b/libavformat/options_table.h
@@ -41,7 +41,7 @@ static const AVOption options[]={
 {"rtbufsize", "max memory used for buffering real-time frames", OFFSET(max_picture_buffer), AV_OPT_TYPE_INT, {.dbl = 3041280 }, 0, INT_MAX, D}, /* defaults to 1s of 15fps 352x288 YUYV422 video */
 {"fdebug", "print specific debug info", OFFSET(debug), AV_OPT_TYPE_FLAGS, {.dbl = DEFAULT }, 0, INT_MAX, E|D, "fdebug"},
 {"ts", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_FDEBUG_TS }, INT_MIN, INT_MAX, E|D, "fdebug"},
-{"max_delay", "maximum muxing or demuxing delay in microseconds", OFFSET(max_delay), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, INT_MAX, E|D},
+{"max_delay", "maximum muxing or demuxing delay in microseconds", OFFSET(max_delay), AV_OPT_TYPE_INT, {.dbl = -1 }, -1, INT_MAX, E|D},
 {"fpsprobesize", "number of frames used to probe fps", OFFSET(fps_probe_size), AV_OPT_TYPE_INT, {.dbl = -1}, -1, INT_MAX-1, D},
 /* this is a crutch for avconv, since it cannot deal with identically named options in different contexts.
  * to be removed when avconv is fixed */
diff --git a/libavformat/rtpenc.c b/libavformat/rtpenc.c
index 6a1be499e2fa54cb58479bf8062f4e707dc9872e..78121ed3c5abaf4fbab1e265320f63d30214536f 100644
--- a/libavformat/rtpenc.c
+++ b/libavformat/rtpenc.c
@@ -126,7 +126,7 @@ static int rtp_write_header(AVFormatContext *s1)
     s->max_payload_size = s1->packet_size - 12;
 
     s->max_frames_per_packet = 0;
-    if (s1->max_delay) {
+    if (s1->max_delay > 0) {
         if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
             int frame_size = av_get_audio_frame_duration(st->codec, 0);
             if (!frame_size)
diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index 56deed3b3acd0ca6115122f506c1ca464a32d9ac..7afd106cfb231b823fab8dc5da2ea5f4491506a9 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -1426,6 +1426,9 @@ int ff_rtsp_connect(AVFormatContext *s)
     if (!ff_network_init())
         return AVERROR(EIO);
 
+    if (s->max_delay < 0) /* Not set by the caller */
+        s->max_delay = 0;
+
     rt->control_transport = RTSP_MODE_PLAIN;
     if (rt->lower_transport_mask & (1 << RTSP_LOWER_TRANSPORT_HTTP)) {
         rt->lower_transport_mask = 1 << RTSP_LOWER_TRANSPORT_TCP;
@@ -1866,6 +1869,9 @@ static int sdp_read_header(AVFormatContext *s)
     if (!ff_network_init())
         return AVERROR(EIO);
 
+    if (s->max_delay < 0) /* Not set by the caller */
+        s->max_delay = 0;
+
     /* read the whole sdp file */
     /* XXX: better loading */
     content = av_malloc(SDP_MAX_SIZE);