diff --git a/libavformat/Makefile b/libavformat/Makefile
index 5bf2fda..20dc6d0 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -239,6 +239,7 @@ OBJS-$(CONFIG_PCM_U32LE_DEMUXER)         += pcmdec.o pcm.o rawdec.o
 OBJS-$(CONFIG_PCM_U32LE_MUXER)           += pcmenc.o rawenc.o
 OBJS-$(CONFIG_PCM_U8_DEMUXER)            += pcmdec.o pcm.o rawdec.o
 OBJS-$(CONFIG_PCM_U8_MUXER)              += pcmenc.o rawenc.o
+OBJS-$(CONFIG_PGS_DEMUXER)               += pgsdec.o
 OBJS-$(CONFIG_PMP_DEMUXER)               += pmpdec.o
 OBJS-$(CONFIG_PVA_DEMUXER)               += pva.o
 OBJS-$(CONFIG_QCP_DEMUXER)               += qcp.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 614b341..0b06089 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -190,6 +190,7 @@ void av_register_all(void)
     REGISTER_MUXDEMUX (PCM_U16BE, pcm_u16be);
     REGISTER_MUXDEMUX (PCM_U16LE, pcm_u16le);
     REGISTER_MUXDEMUX (PCM_U8,    pcm_u8);
+    REGISTER_DEMUXER  (PGS, pgs);
     REGISTER_DEMUXER  (PMP, pmp);
     REGISTER_MUXER    (PSP, psp);
     REGISTER_DEMUXER  (PVA, pva);
diff --git a/libavformat/pgsdec.c b/libavformat/pgsdec.c
index e69de29..7dbc8fa 100644
--- a/libavformat/pgsdec.c
+++ b/libavformat/pgsdec.c
@@ -0,0 +1,61 @@
+/*
+ * probe function for PGS subtitles 
+ * Copyright (c) 2008 Michael Niedermayer <michaelni@gmx.at>
+ * Copyright (c) 2011, 2012 Carl Eugen Hoyos
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/intreadwrite.h"
+#include "avformat.h"
+
+static int pgs_subtitle_probe(AVProbeData *p)
+{
+    int frames, max_frames = 0, first_frames = 0;
+    uint8_t *buf0 = p->buf;
+    uint8_t *buf, *buf2;
+    uint8_t *end = buf0 + p->buf_size - 3;
+
+    buf = buf0;
+
+    for(; buf < end; buf= buf2+1) {
+        buf2 = buf;
+
+        for(frames = 0; buf2 < end; frames++) {
+            uint16_t size = AV_RB16(buf2 + 1) + 3;
+            if (*buf2 != 0x80 && (*buf2 | 3) != 0x17 ||
+                buf2 + size > end ||
+                buf2[size] != 0x80 && (buf2[size] | 3) != 0x17)
+                break;
+            buf2 += size;
+        }
+        max_frames = FFMAX(max_frames, frames);
+        if(buf == buf0)
+            first_frames= frames;
+    }
+    if   (first_frames>=10) return AVPROBE_SCORE_MAX/2+1;
+    else if(max_frames> 10) return AVPROBE_SCORE_MAX/2;
+    else if(max_frames>=5)  return AVPROBE_SCORE_MAX/4;
+    else if(max_frames>=3)  return 1;
+    else                   return 0;
+}
+
+AVInputFormat ff_pgs_demuxer = {
+    .name           = "pgs",
+    .long_name      = NULL_IF_CONFIG_SMALL("raw PGS subtitles"),
+    .read_probe     = pgs_subtitle_probe,
+};
diff --git a/libavformat/utils.c b/libavformat/utils.c
index dce3444..e30d0ed 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -401,6 +401,7 @@ static int set_codec_from_probe_data(AVFormatContext *s, AVStream *st, AVProbeDa
         { "m4v"      , CODEC_ID_MPEG4     , AVMEDIA_TYPE_VIDEO },
         { "mp3"      , CODEC_ID_MP3       , AVMEDIA_TYPE_AUDIO },
         { "mpegvideo", CODEC_ID_MPEG2VIDEO, AVMEDIA_TYPE_VIDEO },
+        { "pgs"      , CODEC_ID_HDMV_PGS_SUBTITLE, AVMEDIA_TYPE_SUBTITLE },
         { 0 }
     };
     int score;
