diff --git a/gst/mpegtsdemux/Makefile.am b/gst/mpegtsdemux/Makefile.am
index 55b57d9..301aa09 100644
--- a/gst/mpegtsdemux/Makefile.am
+++ b/gst/mpegtsdemux/Makefile.am
@@ -1,4 +1,5 @@
-plugin_LTLIBRARIES = libgstmpegtsdemux.la
+plugin_LTLIBRARIES = libgstmpegtsdemux.la libgstmpegpesdepay.la \
+	libgstmpegpesparse.la
 
 libgstmpegtsdemux_la_SOURCES = \
 	gsttsdemux.c \
@@ -19,15 +20,38 @@ libgstmpegtsdemux_la_LIBADD = \
 libgstmpegtsdemux_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
 libgstmpegtsdemux_la_LIBTOOLFLAGS = --tag=disable-static
 
+libgstmpegpesdepay_la_SOURCES = \
+	mpegpesdepay.c \
+	mpegpesdepkt.c \
+	pesparse.c
+
+libgstmpegpesdepay_la_CFLAGS = $(GST_CFLAGS)
+libgstmpegpesdepay_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
+libgstmpegpesdepay_la_LIBADD = $(GST_BASE_LIBS)
+libgstmpegpesdepay_la_LIBTOOLFLAGS = --tag=disable-static
+
+libgstmpegpesparse_la_SOURCES = \
+	mpegpesparse.c \
+	mpegpescmn.c \
+	pesparse.c
+
+libgstmpegpesparse_la_CFLAGS = $(GST_CFLAGS)
+libgstmpegpesparse_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
+libgstmpegpesparse_la_LIBADD = $(GST_BASE_LIBS)
+libgstmpegpesparse_la_LIBTOOLFLAGS = --tag=disable-static
+
 noinst_HEADERS = \
 	gstmpegdefs.h   \
 	gstmpegdesc.h   \
-	mpegtsbase.h	\
+	mpegtsbase.h \
 	mpegtspacketizer.h \
 	mpegtsparse.h \
 	payload_parsers.h \
-	tsdemux.h	\
-	pesparse.h
+	tsdemux.h \
+	pesparse.h \
+	mpegpesdepay.h \
+	mpegpesparse.h \
+	mpegpescmn.h
 
 Android.mk: Makefile.am $(BUILT_SOURCES)
 	androgenizer \
diff --git a/gst/mpegtsdemux/mpegpescmn.c b/gst/mpegtsdemux/mpegpescmn.c
new file mode 100644
index 0000000..669e1a2
--- /dev/null
+++ b/gst/mpegtsdemux/mpegpescmn.c
@@ -0,0 +1,358 @@
+/*
+ * Copyright 2011 Rikor IMT, Inc
+ *  Author: Stas Sergeev <stsp@users.sourceforge.net>
+ *
+ * This library is licensed under 4 different licenses and you
+ * can choose to use it under the terms of any one of them. The
+ * four licenses are the MPL 1.1, the LGPL, the GPL and the MIT
+ * license.
+ *
+ * MPL:
+ *
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/.
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * LGPL:
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * GPL:
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * MIT:
+ *
+ * Unless otherwise indicated, Source Code is licensed under MIT license.
+ * See further explanation attached in License Statement (distributed in the file
+ * LICENSE).
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is furnished to do
+ * so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include <stdio.h>
+#include <string.h>
+#include <gst/base/gstbytereader.h>
+
+#include "pesparse.h"
+#include "mpegpesdepay.h"
+
+static gint
+add_to_queue (MpegPes * mux, GstBuffer * buf)
+{
+  gint pos;
+  if (mux->queued) {
+    pos = GST_BUFFER_SIZE (mux->queue);
+    mux->queue = gst_buffer_join (mux->queue, buf);
+  } else {
+    pos = 0;
+    mux->queue = buf;
+  }
+  mux->queued++;
+  return pos;
+}
+
+static void
+clear_queue (MpegPes * mux)
+{
+  if (mux->queued) {
+    gst_buffer_unref (mux->queue);
+    mux->queued = 0;
+  }
+}
+
+static void
+drop_queue (MpegPes * mux)
+{
+  g_assert (mux->queued);
+  mux->queued = 0;
+}
+
+static gint
+find_sync (GstBuffer * buf, guint offs)
+{
+  GstByteReader *reader = gst_byte_reader_new_from_buffer (buf);
+  gint len = GST_BUFFER_SIZE (buf) - offs;
+  guint pos;
+  g_assert (len > 0);
+  pos = gst_byte_reader_masked_scan_uint32 (reader,
+      0xffffff00, 0x00000100, offs, len);
+  gst_byte_reader_free (reader);
+  return pos;
+}
+
+static GstFlowReturn
+push_queue (MpegPes * mux, GstPad * pad)
+{
+  mux->queued = 0;
+  return mux->push (pad, mux->queue);
+}
+
+enum ParseRes
+{ PR_OK, PR_NEED_MORE, PR_ERROR, PR_CONTINUE };
+
+static enum ParseRes
+handle_delta (MpegPes * mux, GstBuffer * buf, GstPad * pad, gint * r_sync_pos)
+{
+  gint sync_pos;
+  GstFlowReturn ret;
+
+  g_assert (!mux->frame_unbound);
+  sync_pos = find_sync (buf, 0);
+  if (sync_pos == 0) {
+    if (r_sync_pos)
+      *r_sync_pos = 0;
+    return PR_CONTINUE;
+  }
+  if (sync_pos > 0) {
+    GstBuffer *dbuf = gst_buffer_create_sub (buf, 0, sync_pos);
+    GST_BUFFER_FLAG_SET (dbuf, MPEGPES_FLAG_UNBOUND);
+    GST_BUFFER_FLAG_SET (dbuf, MPEGPES_FLAG_UNBOUND_NO_START);
+    GST_BUFFER_FLAG_SET (dbuf, GST_BUFFER_FLAG_DELTA_UNIT);
+    GST_BUFFER_TIMESTAMP (dbuf) = mux->cur_pts;
+    ret = mux->push (pad, dbuf);
+    if (ret != GST_FLOW_OK)
+      return PR_ERROR;
+    if (r_sync_pos)
+      *r_sync_pos = sync_pos;
+    return PR_CONTINUE;
+  }
+  /* sync not here */
+  GST_BUFFER_FLAG_SET (buf, MPEGPES_FLAG_UNBOUND);
+  GST_BUFFER_FLAG_SET (buf, MPEGPES_FLAG_UNBOUND_NO_START);
+  GST_BUFFER_FLAG_SET (buf, MPEGPES_FLAG_UNBOUND_NO_END);
+  GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DELTA_UNIT);
+  GST_BUFFER_TIMESTAMP (buf) = mux->cur_pts;
+  ret = mux->push (pad, buf);
+  if (ret != GST_FLOW_OK)
+    return PR_ERROR;
+  return PR_OK;
+}
+
+static enum ParseRes
+parse_chunk (MpegPes * mux, GstBuffer * buf, GstPad * pad, GstBuffer ** r_buf)
+{
+  GstFlowReturn ret;
+  GstBuffer *rem;
+  gint sync_pos, buf_offs;
+  guint8 *data;
+  guint32 length;
+  PESParsingResult parseres;
+  PESHeader header;
+
+  g_assert (!mux->is_delta);
+  rem = NULL;
+  buf_offs = add_to_queue (mux, buf);
+  if (buf_offs == -1) {
+    clear_queue (mux);
+    return PR_ERROR;
+  }
+  buf = mux->queue;
+
+  g_assert (buf);
+  data = GST_BUFFER_DATA (buf);
+  length = GST_BUFFER_SIZE (buf);
+
+  parseres = mpegts_parse_pes_header (data, length, &header, 0);
+
+  switch (parseres) {
+    case PES_PARSING_BAD:
+      g_assert (buf_offs == 0);
+      if (mux->pedantic) {
+        clear_queue (mux);
+        return PR_ERROR;
+      }
+      sync_pos = find_sync (buf, 0);
+      if (sync_pos == -1) {
+        clear_queue (mux);
+        return PR_NEED_MORE;
+      }
+      if (sync_pos == 0) {
+        clear_queue (mux);
+        return PR_ERROR;
+      }
+      drop_queue (mux);
+      GST_BUFFER_DATA (buf) += sync_pos;
+      GST_BUFFER_SIZE (buf) -= sync_pos;
+      *r_buf = buf;
+      return PR_CONTINUE;
+    case PES_PARSING_NEED_MORE:
+      return PR_NEED_MORE;
+    case PES_PARSING_OK:
+      if (header.packet_length > length)
+        return PR_NEED_MORE;
+      if (!header.packet_length) {
+        GST_BUFFER_FLAG_SET (buf, MPEGPES_FLAG_UNBOUND);
+        sync_pos = find_sync (buf, buf_offs + header.header_size);
+        if (sync_pos == -1) {
+          if (mux->frame_unbound)
+            return PR_NEED_MORE;
+          g_assert (buf_offs == 0);
+          GST_BUFFER_FLAG_SET (buf, MPEGPES_FLAG_UNBOUND_NO_END);
+          GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DELTA_UNIT);
+          mux->is_delta = TRUE;
+          /* will push it anyway */
+        } else {
+          /* have both start and end, just hack the header */
+          header.packet_length = buf_offs + sync_pos;
+        }
+      }
+      break;
+  }
+
+  if (header.PTS != -1) {
+    GST_DEBUG_OBJECT (mux, "PES has pts %" G_GINT64_FORMAT, header.PTS);
+    mux->cur_pts = MPEGTIME_TO_GSTTIME (header.PTS);
+  } else {
+    mux->cur_pts = GST_CLOCK_TIME_NONE;
+  }
+  if (header.DTS != -1) {
+    GST_DEBUG_OBJECT (mux, "PES has dts %" G_GINT64_FORMAT
+        ", great, but gstreamer doesnt support those", header.DTS);
+    mux->cur_dts = MPEGTIME_TO_GSTTIME (header.DTS);
+  } else {
+    mux->cur_dts = GST_CLOCK_TIME_NONE;
+  }
+  GST_BUFFER_TIMESTAMP (buf) = mux->cur_pts;
+
+  if (header.packet_length && header.packet_length < length) {
+    guint rem_len = length - header.packet_length;
+    rem = gst_buffer_create_sub (buf, header.packet_length, rem_len);
+    GST_BUFFER_SIZE (buf) -= rem_len;
+  }
+
+  ret = push_queue (mux, pad);
+  if (ret != GST_FLOW_OK)
+    return PR_ERROR;
+
+  if (rem) {
+    *r_buf = rem;
+    return PR_CONTINUE;
+  }
+
+  return PR_OK;
+}
+
+GstFlowReturn
+mpegpes_chain (MpegPes * mux, GstBuffer * buf, GstPad * pad)
+{
+  GstFlowReturn ret;
+  enum ParseRes pr;
+  GstBuffer *rem;
+  gint sync_pos;
+
+  g_return_val_if_fail (buf != NULL, GST_FLOW_ERROR);
+
+  if (mux->is_delta) {
+    enum ParseRes hd_ret = handle_delta (mux, buf, pad, &sync_pos);
+    switch (hd_ret) {
+      case PR_CONTINUE:
+        g_assert (!mux->queued);
+        /* position to next packet */
+        GST_BUFFER_DATA (buf) += sync_pos;
+        GST_BUFFER_SIZE (buf) -= sync_pos;
+        mux->is_delta = FALSE;
+        g_assert (GST_BUFFER_SIZE (buf) > 0);
+        /* go continue parsing */
+        break;
+      case PR_OK:
+        return GST_FLOW_OK;
+      case PR_ERROR:
+        mux->is_delta = FALSE;
+        return GST_FLOW_ERROR;
+      case PR_NEED_MORE:
+        /* should not be here, frame_unbound case is handled elsewhere */
+        g_assert (0);
+        return GST_FLOW_OK;
+    }
+  }
+
+  for (;; buf = rem) {
+    pr = parse_chunk (mux, buf, pad, &rem);
+    if (pr != PR_CONTINUE)
+      break;
+    g_assert (!mux->is_delta);
+  }
+  switch (pr) {
+    case PR_OK:
+    case PR_NEED_MORE:
+      ret = GST_FLOW_OK;
+      break;
+    case PR_ERROR:
+      ret = GST_FLOW_ERROR;
+      break;
+    case PR_CONTINUE:
+      /* cannot be here */
+      g_assert (0);
+      ret = GST_FLOW_ERROR;
+      break;
+  }
+
+  return ret;
+}
+
+void
+mpegpes_init (MpegPes * mux, PushBufFunc callb)
+{
+  mux->queued = 0;
+  mux->is_delta = FALSE;
+  mux->push = callb;
+  mux->frame_unbound = FALSE;
+}
+
+void
+mpegpes_destroy (MpegPes * mux)
+{
+  clear_queue (mux);
+}
diff --git a/gst/mpegtsdemux/mpegpescmn.h b/gst/mpegtsdemux/mpegpescmn.h
new file mode 100644
index 0000000..e268a27
--- /dev/null
+++ b/gst/mpegtsdemux/mpegpescmn.h
@@ -0,0 +1,114 @@
+/*
+ * Copyright 2011 Rikor IMT, Inc
+ *  Author: Stas Sergeev <stsp@users.sourceforge.net>
+ *
+ * This library is licensed under 4 different licenses and you
+ * can choose to use it under the terms of any one of them. The
+ * four licenses are the MPL 1.1, the LGPL, the GPL and the MIT
+ * license.
+ *
+ * MPL:
+ *
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/.
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * LGPL:
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * GPL:
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * MIT:
+ *
+ * Unless otherwise indicated, Source Code is licensed under MIT license.
+ * See further explanation attached in License Statement (distributed in the file
+ * LICENSE).
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is furnished to do
+ * so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ */
+
+#ifndef __MPEGPESCMN_H__
+#define __MPEGPESCMN_H__
+
+#include <gst/gst.h>
+
+G_BEGIN_DECLS
+
+typedef GstFlowReturn (*PushBufFunc) (GstPad * pad, GstBuffer * buf);
+
+typedef struct MpegPes MpegPes;
+
+struct MpegPes
+{
+  GstClockTime cur_pts;
+  GstClockTime cur_dts;
+  gboolean is_delta;
+  gint queued;
+  GstBuffer *queue;
+  PushBufFunc push;
+
+  gboolean pedantic;
+  gboolean frame_unbound;
+};
+
+#define MPEGPES_FLAG_UNBOUND            GST_BUFFER_FLAG_MEDIA1
+#define MPEGPES_FLAG_UNBOUND_NO_START   GST_BUFFER_FLAG_MEDIA2
+#define MPEGPES_FLAG_UNBOUND_NO_END     GST_BUFFER_FLAG_MEDIA3
+
+void mpegpes_init (MpegPes * mux, PushBufFunc callb);
+void mpegpes_destroy (MpegPes * mux);
+GstFlowReturn mpegpes_chain (MpegPes * mux, GstBuffer * buf, GstPad * pad);
+
+G_END_DECLS
+#endif
diff --git a/gst/mpegtsdemux/mpegpesdepay.c b/gst/mpegtsdemux/mpegpesdepay.c
new file mode 100644
index 0000000..d717c35
--- /dev/null
+++ b/gst/mpegtsdemux/mpegpesdepay.c
@@ -0,0 +1,194 @@
+/*
+ * Copyright 2011 Rikor IMT, Inc
+ *  Author: Stas Sergeev <stsp@users.sourceforge.net>
+ *
+ * This library is licensed under 4 different licenses and you
+ * can choose to use it under the terms of any one of them. The
+ * four licenses are the MPL 1.1, the LGPL, the GPL and the MIT
+ * license.
+ *
+ * MPL:
+ *
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/.
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * LGPL:
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * GPL:
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * MIT:
+ *
+ * Unless otherwise indicated, Source Code is licensed under MIT license.
+ * See further explanation attached in License Statement (distributed in the file
+ * LICENSE).
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is furnished to do
+ * so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include <stdio.h>
+#include <string.h>
+
+#include "mpegpesdepkt.h"
+#include "mpegpesdepay.h"
+
+GST_DEBUG_CATEGORY (mpegpesdepay_debug);
+#define GST_CAT_DEFAULT mpegpesdepay_debug
+
+static void mpegpesdepay_dispose (GObject * object);
+
+static void mpegpesdepay_set_property (GObject * object, guint prop_id,
+    const GValue * value, GParamSpec * pspec);
+static void mpegpesdepay_get_property (GObject * object, guint prop_id,
+    GValue * value, GParamSpec * pspec);
+
+GST_BOILERPLATE (MpegPesDepay, mpegpesdepay, GstBin, GST_TYPE_BIN);
+
+enum
+{
+  PROP_0,
+  PROP_PEDANTIC,
+};
+
+static void
+mpegpesdepay_base_init (gpointer g_class)
+{
+  GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
+  gst_element_class_set_details_simple (element_class,
+      "MPEG PES Depayloader", "Codec/Depayloader",
+      "Extracts Elementary Stream from PES",
+      "Stas Sergeev <stsp@users.sourceforge.net>");
+  mpegpesdepkt_plugin_init ();
+}
+
+static void
+mpegpesdepay_class_init (MpegPesDepayClass * klass)
+{
+  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+  gobject_class->dispose = mpegpesdepay_dispose;
+  gobject_class->set_property = mpegpesdepay_set_property;
+  gobject_class->get_property = mpegpesdepay_get_property;
+  g_object_class_install_property (gobject_class, PROP_PEDANTIC,
+      g_param_spec_boolean ("pedantic", "Pedantic parsing",
+          "Pedantically treat garbage data in the input stream as an error",
+          FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+}
+
+static void
+mpegpesdepay_init (MpegPesDepay * mux, MpegPesDepayClass * g_class)
+{
+  GstBin *bin = GST_BIN (mux);
+  GstPad *srcpad, *sinkpad;
+  mux->depkt = gst_element_factory_make ("mpegpesdepkt", "depacketizer");
+  mux->parser = gst_element_factory_make ("mpegpesparse", "parser");
+  gst_bin_add_many (bin, mux->parser, mux->depkt, NULL);
+  srcpad = gst_ghost_pad_new_no_target ("src", GST_PAD_SRC);
+  sinkpad = gst_ghost_pad_new_no_target ("sink", GST_PAD_SINK);
+  gst_ghost_pad_set_target (GST_GHOST_PAD (srcpad),
+      gst_element_get_static_pad (mux->depkt, "src"));
+  gst_ghost_pad_set_target (GST_GHOST_PAD (sinkpad),
+      gst_element_get_static_pad (mux->parser, "sink"));
+  gst_pad_link (gst_element_get_static_pad (mux->parser, "src"),
+      gst_element_get_static_pad (mux->depkt, "sink"));
+  gst_element_add_pad (GST_ELEMENT (mux), srcpad);
+  gst_element_add_pad (GST_ELEMENT (mux), sinkpad);
+}
+
+static void
+mpegpesdepay_dispose (GObject * object)
+{
+  MpegPesDepay *mux = GST_MPEG_PES_DEPAY (object);
+  GstBin *bin = GST_BIN (object);
+  gst_bin_remove (bin, mux->parser);
+  gst_bin_remove (bin, mux->depkt);
+
+  GST_CALL_PARENT (G_OBJECT_CLASS, dispose, (object));
+}
+
+static void
+mpegpesdepay_set_property (GObject * object, guint prop_id,
+    const GValue * value, GParamSpec * pspec)
+{
+  MpegPesDepay *mux = GST_MPEG_PES_DEPAY (object);
+  g_object_set_property (G_OBJECT (mux->parser), pspec->name, value);
+}
+
+static void
+mpegpesdepay_get_property (GObject * object, guint prop_id,
+    GValue * value, GParamSpec * pspec)
+{
+  MpegPesDepay *mux = GST_MPEG_PES_DEPAY (object);
+  g_object_get_property (G_OBJECT (mux->parser), pspec->name, value);
+}
+
+static gboolean
+plugin_init (GstPlugin * plugin)
+{
+  if (!gst_element_register (plugin, "mpegpesdepay", GST_RANK_PRIMARY,
+          mpegpesdepay_get_type ()))
+    return FALSE;
+
+  GST_DEBUG_CATEGORY_INIT (mpegpesdepay_debug, "mpegpesdepay", 0,
+      "MPEG PES depayloader");
+
+  return TRUE;
+}
+
+GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, GST_VERSION_MINOR,
+    "mpegpesdepay", "MPEG PES depayloader",
+    plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
diff --git a/gst/mpegtsdemux/mpegpesdepay.h b/gst/mpegtsdemux/mpegpesdepay.h
new file mode 100644
index 0000000..b18fd8a
--- /dev/null
+++ b/gst/mpegtsdemux/mpegpesdepay.h
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2011 Rikor IMT, Inc
+ *  Author: Stas Sergeev <stsp@users.sourceforge.net>
+ *
+ * This library is licensed under 4 different licenses and you
+ * can choose to use it under the terms of any one of them. The
+ * four licenses are the MPL 1.1, the LGPL, the GPL and the MIT
+ * license.
+ *
+ * MPL:
+ *
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/.
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * LGPL:
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * GPL:
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * MIT:
+ *
+ * Unless otherwise indicated, Source Code is licensed under MIT license.
+ * See further explanation attached in License Statement (distributed in the file
+ * LICENSE).
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is furnished to do
+ * so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ */
+
+#ifndef __MPEGPESDEPAY_H__
+#define __MPEGPESDEPAY_H__
+
+#include <gst/gst.h>
+#include "mpegpescmn.h"
+
+G_BEGIN_DECLS
+#define GST_TYPE_MPEG_PES_DEPAY  (mpegpesdepay_get_type())
+#define GST_MPEG_PES_DEPAY(obj)  (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_MPEG_PES_DEPAY, MpegPesDepay))
+typedef struct MpegPesDepay MpegPesDepay;
+typedef struct MpegPesDepayClass MpegPesDepayClass;
+
+struct MpegPesDepay
+{
+  GstBin parent;
+  GstElement *parser;
+  GstElement *depkt;
+};
+
+struct MpegPesDepayClass
+{
+  GstBinClass parent_class;
+};
+
+GType mpegpesdepay_get_type (void);
+
+G_END_DECLS
+#endif
diff --git a/gst/mpegtsdemux/mpegpesdepkt.c b/gst/mpegtsdemux/mpegpesdepkt.c
new file mode 100644
index 0000000..e4415e3
--- /dev/null
+++ b/gst/mpegtsdemux/mpegpesdepkt.c
@@ -0,0 +1,198 @@
+/*
+ * Copyright 2011 Rikor IMT, Inc
+ *  Author: Stas Sergeev <stsp@users.sourceforge.net>
+ *
+ * This library is licensed under 4 different licenses and you
+ * can choose to use it under the terms of any one of them. The
+ * four licenses are the MPL 1.1, the LGPL, the GPL and the MIT
+ * license.
+ *
+ * MPL:
+ *
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/.
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * LGPL:
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * GPL:
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * MIT:
+ *
+ * Unless otherwise indicated, Source Code is licensed under MIT license.
+ * See further explanation attached in License Statement (distributed in the file
+ * LICENSE).
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is furnished to do
+ * so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include <stdio.h>
+#include <string.h>
+
+#include "pesparse.h"
+#include "mpegpesdepkt.h"
+
+GST_DEBUG_CATEGORY (mpegpesdepkt_debug);
+#define GST_CAT_DEFAULT mpegpesdepay_debug
+
+static GstStaticPadTemplate mpegpesdepkt_src_factory =
+GST_STATIC_PAD_TEMPLATE ("src",
+    GST_PAD_SRC,
+    GST_PAD_ALWAYS,
+    GST_STATIC_CAPS ("video/mpeg, "
+        "systemstream = (boolean) false, "
+        "parsed = (boolean) false, " "framed = (boolean) false"));
+
+static GstStaticPadTemplate mpegpesdepkt_sink_factory =
+GST_STATIC_PAD_TEMPLATE ("sink",
+    GST_PAD_SINK,
+    GST_PAD_ALWAYS,
+    GST_STATIC_CAPS ("video/mpegpes, framed = (boolean) true")
+    );
+
+static GstFlowReturn mpegpesdepkt_chain (GstPad * pad, GstBuffer * buf);
+
+GST_BOILERPLATE (MpegPesDepkt, mpegpesdepkt, GstElement, GST_TYPE_ELEMENT);
+
+static void
+mpegpesdepkt_base_init (gpointer g_class)
+{
+  GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
+
+  gst_element_class_add_pad_template (element_class,
+      gst_static_pad_template_get (&mpegpesdepkt_sink_factory));
+  gst_element_class_add_pad_template (element_class,
+      gst_static_pad_template_get (&mpegpesdepkt_src_factory));
+
+  gst_element_class_set_details_simple (element_class,
+      "MPEG PES Depacketizer", "Codec/Depayloader",
+      "Extracts Elementary Stream from PES",
+      "Stas Sergeev <stsp@users.sourceforge.net>");
+}
+
+static void
+mpegpesdepkt_class_init (MpegPesDepktClass * klass)
+{
+}
+
+static void
+mpegpesdepkt_init (MpegPesDepkt * mux, MpegPesDepktClass * g_class)
+{
+  mux->srcpad =
+      gst_pad_new_from_template (gst_static_pad_template_get
+      (&mpegpesdepkt_src_factory), "src");
+  gst_pad_use_fixed_caps (mux->srcpad);
+  gst_element_add_pad (GST_ELEMENT (mux), mux->srcpad);
+
+  mux->sinkpad =
+      gst_pad_new_from_template (gst_static_pad_template_get
+      (&mpegpesdepkt_sink_factory), "sink");
+  gst_pad_use_fixed_caps (mux->sinkpad);
+  gst_pad_set_chain_function (mux->sinkpad, mpegpesdepkt_chain);
+  gst_element_add_pad (GST_ELEMENT (mux), mux->sinkpad);
+}
+
+static GstFlowReturn
+push_buf (MpegPesDepkt * mux, GstBuffer * buf)
+{
+  gst_buffer_set_caps (buf, gst_pad_get_caps (mux->srcpad));
+  return gst_pad_push (mux->srcpad, buf);
+}
+
+static GstFlowReturn
+mpegpesdepkt_chain (GstPad * pad, GstBuffer * buf)
+{
+  MpegPesDepkt *mux = GST_MPEG_PES_DEPKT (GST_OBJECT_PARENT (pad));
+  guint8 *data;
+  guint32 length;
+  PESParsingResult parseres;
+  PESHeader header;
+  data = GST_BUFFER_DATA (buf);
+  length = GST_BUFFER_SIZE (buf);
+  parseres = mpegts_parse_pes_header (data, length, &header, 0);
+  if (parseres == PES_PARSING_OK) {
+    /* Remove PES headers */
+    GST_BUFFER_DATA (buf) += header.header_size;
+    GST_BUFFER_SIZE (buf) -= header.header_size;
+  }
+  /* bad parsing may mean only the unbound pes part here,
+   * as the stream is parsed */
+  return push_buf (mux, buf);
+}
+
+static gboolean
+plugin_init (GstPlugin * plugin)
+{
+  if (!gst_element_register (plugin, "mpegpesdepkt", GST_RANK_PRIMARY,
+          mpegpesdepkt_get_type ()))
+    return FALSE;
+
+  GST_DEBUG_CATEGORY_INIT (mpegpesdepkt_debug, "mpegpesdepkt", 0,
+      "MPEG PES depacketizer");
+
+  return TRUE;
+}
+
+gboolean
+mpegpesdepkt_plugin_init (void)
+{
+  return gst_plugin_register_static (GST_VERSION_MAJOR, GST_VERSION_MINOR,
+      "mpegpesdepkt", "MPEG PES depacketizer",
+      plugin_init, VERSION, "LGPL", "mpegpesdepay", GST_PACKAGE_NAME,
+      GST_PACKAGE_ORIGIN);
+}
diff --git a/gst/mpegtsdemux/mpegpesdepkt.h b/gst/mpegtsdemux/mpegpesdepkt.h
new file mode 100644
index 0000000..8fe68a9
--- /dev/null
+++ b/gst/mpegtsdemux/mpegpesdepkt.h
@@ -0,0 +1,109 @@
+/*
+ * Copyright 2011 Rikor IMT, Inc
+ *  Author: Stas Sergeev <stsp@users.sourceforge.net>
+ *
+ * This library is licensed under 4 different licenses and you
+ * can choose to use it under the terms of any one of them. The
+ * four licenses are the MPL 1.1, the LGPL, the GPL and the MIT
+ * license.
+ *
+ * MPL:
+ *
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/.
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * LGPL:
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * GPL:
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * MIT:
+ *
+ * Unless otherwise indicated, Source Code is licensed under MIT license.
+ * See further explanation attached in License Statement (distributed in the file
+ * LICENSE).
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is furnished to do
+ * so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ */
+
+#ifndef __MPEGPESDEPKT_H__
+#define __MPEGPESDEPKT_H__
+
+#include <gst/gst.h>
+
+G_BEGIN_DECLS
+#define GST_TYPE_MPEG_PES_DEPKT  (mpegpesdepkt_get_type())
+#define GST_MPEG_PES_DEPKT(obj)  (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_MPEG_PES_DEPKT, MpegPesDepkt))
+typedef struct MpegPesDepkt MpegPesDepkt;
+typedef struct MpegPesDepktClass MpegPesDepktClass;
+
+struct MpegPesDepkt
+{
+  GstElement parent;
+  GstPad *srcpad;
+  GstPad *sinkpad;
+};
+
+struct MpegPesDepktClass
+{
+  GstElementClass parent_class;
+};
+
+GType mpegpesdepkt_get_type (void);
+
+gboolean mpegpesdepkt_plugin_init (void);
+
+G_END_DECLS
+#endif
diff --git a/gst/mpegtsdemux/mpegpesparse.c b/gst/mpegtsdemux/mpegpesparse.c
new file mode 100644
index 0000000..2930f49
--- /dev/null
+++ b/gst/mpegtsdemux/mpegpesparse.c
@@ -0,0 +1,259 @@
+/*
+ * Copyright 2011 Rikor IMT, Inc
+ *  Author: Stas Sergeev <stsp@users.sourceforge.net>
+ *
+ * This library is licensed under 4 different licenses and you
+ * can choose to use it under the terms of any one of them. The
+ * four licenses are the MPL 1.1, the LGPL, the GPL and the MIT
+ * license.
+ *
+ * MPL:
+ *
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/.
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * LGPL:
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * GPL:
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * MIT:
+ *
+ * Unless otherwise indicated, Source Code is licensed under MIT license.
+ * See further explanation attached in License Statement (distributed in the file
+ * LICENSE).
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is furnished to do
+ * so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include <stdio.h>
+#include <string.h>
+#include <gst/base/gstbytereader.h>
+
+#include "pesparse.h"
+#include "mpegpesparse.h"
+
+GST_DEBUG_CATEGORY (mpegpesparse_debug);
+#define GST_CAT_DEFAULT mpegpesparse_debug
+
+static GstStaticPadTemplate mpegpesparse_src_factory =
+GST_STATIC_PAD_TEMPLATE ("src",
+    GST_PAD_SRC,
+    GST_PAD_ALWAYS,
+    GST_STATIC_CAPS ("video/mpegpes, "
+        "parsed = (boolean) true, " "framed = (boolean) true"));
+
+static GstStaticPadTemplate mpegpesparse_sink_factory =
+GST_STATIC_PAD_TEMPLATE ("sink",
+    GST_PAD_SINK,
+    GST_PAD_ALWAYS,
+    GST_STATIC_CAPS ("video/mpegpes")
+    );
+
+static void mpegpesparse_dispose (GObject * object);
+
+static GstFlowReturn mpegpesparse_chain (GstPad * pad, GstBuffer * buf);
+static void mpegpesparse_set_property (GObject * object, guint prop_id,
+    const GValue * value, GParamSpec * pspec);
+static void mpegpesparse_get_property (GObject * object, guint prop_id,
+    GValue * value, GParamSpec * pspec);
+static GstFlowReturn push_buf (GstPad * pad, GstBuffer * buf);
+
+GST_BOILERPLATE (MpegPesParse, mpegpesparse, GstElement, GST_TYPE_ELEMENT);
+
+enum
+{
+  PROP_0,
+  PROP_PEDANTIC,
+  PROP_FRAME_UNBOUND
+};
+
+static void
+mpegpesparse_base_init (gpointer g_class)
+{
+
+  GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
+
+  gst_element_class_add_pad_template (element_class,
+      gst_static_pad_template_get (&mpegpesparse_sink_factory));
+  gst_element_class_add_pad_template (element_class,
+      gst_static_pad_template_get (&mpegpesparse_src_factory));
+
+  gst_element_class_set_details_simple (element_class,
+      "MPEG PES Parser", "Codec/Parser",
+      "Parses packetized elementary stream",
+      "Stas Sergeev <stsp@users.sourceforge.net>");
+}
+
+static void
+mpegpesparse_class_init (MpegPesParseClass * klass)
+{
+  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+  gobject_class->dispose = mpegpesparse_dispose;
+
+  gobject_class->set_property = mpegpesparse_set_property;
+  gobject_class->get_property = mpegpesparse_get_property;
+  g_object_class_install_property (gobject_class, PROP_PEDANTIC,
+      g_param_spec_boolean ("pedantic", "Pedantic parsing",
+          "Pedantically treat garbage data in the input stream as an error",
+          FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+  g_object_class_install_property (gobject_class, PROP_FRAME_UNBOUND,
+      g_param_spec_boolean ("frame-unbound", "Frame unbound PES packets",
+          "Try to join parts of the unbound PES packets into a single data frame",
+          FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+}
+
+static void
+mpegpesparse_init (MpegPesParse * mux, MpegPesParseClass * g_class)
+{
+  mux->srcpad =
+      gst_pad_new_from_template (gst_static_pad_template_get
+      (&mpegpesparse_src_factory), "src");
+  gst_pad_use_fixed_caps (mux->srcpad);
+  gst_element_add_pad (GST_ELEMENT (mux), mux->srcpad);
+
+  mux->sinkpad =
+      gst_pad_new_from_template (gst_static_pad_template_get
+      (&mpegpesparse_sink_factory), "sink");
+  gst_pad_use_fixed_caps (mux->sinkpad);
+  gst_pad_set_chain_function (mux->sinkpad, mpegpesparse_chain);
+  gst_element_add_pad (GST_ELEMENT (mux), mux->sinkpad);
+
+  mpegpes_init (&mux->pes, push_buf);
+}
+
+static void
+mpegpesparse_dispose (GObject * object)
+{
+  MpegPesParse *mux = GST_MPEG_PES_PARSE (object);
+
+  mpegpes_destroy (&mux->pes);
+
+  GST_CALL_PARENT (G_OBJECT_CLASS, dispose, (object));
+}
+
+static void
+mpegpesparse_set_property (GObject * object, guint prop_id,
+    const GValue * value, GParamSpec * pspec)
+{
+  MpegPesParse *mux = GST_MPEG_PES_PARSE (object);
+
+  switch (prop_id) {
+    case PROP_PEDANTIC:
+      mux->pes.pedantic = g_value_get_boolean (value);
+      break;
+    case PROP_FRAME_UNBOUND:
+      mux->pes.frame_unbound = g_value_get_boolean (value);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
+static void
+mpegpesparse_get_property (GObject * object, guint prop_id,
+    GValue * value, GParamSpec * pspec)
+{
+  MpegPesParse *mux = GST_MPEG_PES_PARSE (object);
+
+  switch (prop_id) {
+    case PROP_PEDANTIC:
+      g_value_set_boolean (value, mux->pes.pedantic);
+      break;
+    case PROP_FRAME_UNBOUND:
+      g_value_set_boolean (value, mux->pes.frame_unbound);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
+static GstFlowReturn
+push_buf (GstPad * pad, GstBuffer * buf)
+{
+  MpegPesParse *mux = GST_MPEG_PES_PARSE (GST_OBJECT_PARENT (pad));
+  gst_buffer_set_caps (buf, gst_pad_get_caps (mux->srcpad));
+  return gst_pad_push (mux->srcpad, buf);
+}
+
+static GstFlowReturn
+mpegpesparse_chain (GstPad * pad, GstBuffer * buf)
+{
+  MpegPesParse *mux = GST_MPEG_PES_PARSE (GST_OBJECT_PARENT (pad));
+  return mpegpes_chain (&mux->pes, buf, pad);
+}
+
+static gboolean
+plugin_init (GstPlugin * plugin)
+{
+  if (!gst_element_register (plugin, "mpegpesparse", GST_RANK_PRIMARY,
+          mpegpesparse_get_type ()))
+    return FALSE;
+
+  GST_DEBUG_CATEGORY_INIT (mpegpesparse_debug, "mpegpesparse", 0,
+      "MPEG PES parser");
+
+  return TRUE;
+}
+
+GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, GST_VERSION_MINOR,
+    "mpegpesparse", "MPEG PES parser",
+    plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
diff --git a/gst/mpegtsdemux/mpegpesparse.h b/gst/mpegtsdemux/mpegpesparse.h
new file mode 100644
index 0000000..3f40855
--- /dev/null
+++ b/gst/mpegtsdemux/mpegpesparse.h
@@ -0,0 +1,109 @@
+/*
+ * Copyright 2011 Rikor IMT, Inc
+ *  Author: Stas Sergeev <stsp@users.sourceforge.net>
+ *
+ * This library is licensed under 4 different licenses and you
+ * can choose to use it under the terms of any one of them. The
+ * four licenses are the MPL 1.1, the LGPL, the GPL and the MIT
+ * license.
+ *
+ * MPL:
+ *
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/.
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * LGPL:
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * GPL:
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * MIT:
+ *
+ * Unless otherwise indicated, Source Code is licensed under MIT license.
+ * See further explanation attached in License Statement (distributed in the file
+ * LICENSE).
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is furnished to do
+ * so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ */
+
+#ifndef __MPEGPESPARSE_H__
+#define __MPEGPESPARSE_H__
+
+#include <gst/gst.h>
+#include "mpegpescmn.h"
+
+G_BEGIN_DECLS
+#define GST_TYPE_MPEG_PES_PARSE  (mpegpesparse_get_type())
+#define GST_MPEG_PES_PARSE(obj)  (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_MPEG_PES_PARSE, MpegPesParse))
+typedef struct MpegPesParse MpegPesParse;
+typedef struct MpegPesParseClass MpegPesParseClass;
+
+struct MpegPesParse
+{
+  GstElement parent;
+  GstPad *srcpad;
+  GstPad *sinkpad;
+  MpegPes pes;
+};
+
+struct MpegPesParseClass
+{
+  GstElementClass parent_class;
+};
+
+GType mpegpesparse_get_type (void);
+
+G_END_DECLS
+#endif
