After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 550634 - [mpeg ts demuxer] Doesn't support seeking and duration reporting
[mpeg ts demuxer] Doesn't support seeking and duration reporting
Status: RESOLVED OBSOLETE
Product: GStreamer
Classification: Platform
Component: gst-plugins-bad
git master
Other Linux
: Normal normal
: git master
Assigned To: GStreamer Maintainers
GStreamer Maintainers
: 347342 574074 585077 (view as bug list)
Depends on:
Blocks: 609601
 
 
Reported: 2008-09-03 09:41 UTC by Edward Hervey
Modified: 2012-05-22 16:04 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch to make seeking from RTSP with use of mpegtsdemux work. (3.20 KB, patch)
2010-07-15 14:22 UTC, Vitaly "_Vi" Shukela
none Details | Review
Patch to make seeking from RTSP with use of mpegtsdemux work. (1.96 KB, patch)
2010-07-15 14:48 UTC, Vitaly "_Vi" Shukela
none Details | Review

Description Edward Hervey 2008-09-03 09:41:36 UTC
The new mpeg ts demuxer doesn't support either seeking or duration reporting.

Considering virtually all contents from modern cameras (whether tape/disk/dvd/flash based) are stored in mpeg-ts ... I guess it's somewhat essential to be able to have that feature :)
Comment 1 Edward Hervey 2009-03-06 09:30:50 UTC
*** Bug 347342 has been marked as a duplicate of this bug. ***
Comment 2 Aleksey Yulin 2009-03-16 07:57:27 UTC
*** Bug 574074 has been marked as a duplicate of this bug. ***
Comment 3 Aleksey Yulin 2009-03-16 08:01:41 UTC
We get the same seek issue while trying to stream a TS file over the rtsp or http.

As we've currently investigated the main cause of the issue is the absence of the valid NEWSEGMENT event after seek.

More detailed investigation results are described here:

http://www.nabble.com/RTSP-stream-and-seeking-operations-td22178411.html
Comment 4 Edward Hervey 2009-03-16 08:21:32 UTC
So there's two different scenarios here for seeking/duration support:

* push-based (current behaviour).
** Duration reporting
  This can only be done in two different ways:
  * Upstream elements knows about duration in time (rtp source?) and pushes out newsegments in time, in that case we should just forward it.
  * Upstream elements doesn't know about duration in time, and pushes out a newsegment in bytes. If there's a specified stop position from which we can figure out the size in bytes, we could estimate the duration and constantly update it based on the current bitrate. Not perfect, but better than nothing. If the newsegment doesn't contain a stop position... we can't seek and report duration.

** Seeking
  Two different ways again:
  * mpegtsdemux sees an incoming seek in time, it pushes it upstream first. If upstream can handle it, we *should* be fine (haven't tested it). We then just forward the newsegment in time that we receive.
  * If upstream didn't accept the time seek, we need to interpolate based on the know bitrate the position in bytes, send the seek upstream, and return whatever upstream says (True/False). When the newsegment in bytes comes through, figure out duration as above and once we have enough information regarding bitrate and initial timestamp, push out the newsegment

* pull-based (not implemented).
  This is for local content (any source able to handle pull-based requests in bytes). This will require quite a few modifications in the source code to handle this. One obvious thing that seems missing for example, is that the upstream offset in bytes of every handled packet is discarded right from the start, whereas it should be remembered and passed along so that we can store that information in an index.

** Duration reporting
  We can can seek upstream for the first/last PES and figure out the duration from the difference in time between the two. This supposes it's one continuous stream (identical PAT/PMT). If it's a concatenation of several streams it will requires seeking upstream to find more PES values to figure out the proper layout.

** Seeking
  Two ways to do this:
  * Without an index/GstIndex : We need to estimate the upstream byte position from current bitrate, and then gradually seek upstream to find the correct position (many ways to do that : bisection, 3 way interpolation, ...) and once we have it, start pushing out data.
  * With an index/GstIndex : As we push out buffers, we store the position in time and bytes of *key* locations (keyframes in the various streams for ex). We then use that information to seek quickly in past positions, and use the technique above for positions in the future (except storing the information we learn along the way, and maybe also using the information in the index to extrapolate the upstream bytes seek position faster).
Comment 5 Aleksey Yulin 2009-03-16 09:26:12 UTC
(In reply to comment #4)

> ** Seeking
>   Two different ways again:
>   * mpegtsdemux sees an incoming seek in time, it pushes it upstream first. If
> upstream can handle it, we *should* be fine (haven't tested it). We then just
> forward the newsegment in time that we receive.

This is the scanario we have: seek event reaches the rtspsrc which performs the seek. Then the newsegment event is generated by rtp depayload and is passed through the demuxer downstream. But as i described before it looks like this newsegment is started from 0, but demuxer continues to set real TS packets timestamps for the outgoing buffers (like 7:26:30). Shouldn't the demuxer patch the received newsegment event before sending it downstream?
Comment 6 Edward Hervey 2009-03-16 10:02:52 UTC
The demuxer shouldn't 'patch' the newsegment in that scenario, but imho modify the timestamps of the outgoing buffers accordingly.
Comment 7 Aleksey Yulin 2009-03-16 10:31:32 UTC
(In reply to comment #6)
> The demuxer shouldn't 'patch' the newsegment in that scenario, but imho modify
> the timestamps of the outgoing buffers accordingly.

I see. Maybe it's better then to initially substract the first PTS from the initial segment start and buffers timestamps?
Comment 8 Javier Gálvez 2009-03-31 14:50:11 UTC
Hi,

Can the 576739 bug be related with the one is being discussed here? It's about A/V sync problems when seeking RTSP/RTP content.

Regards
Comment 9 kxra 2010-01-31 03:22:30 UTC
I believe this bug may be covered by Bug 585077 or vice-versa?
Comment 10 Edward Hervey 2010-02-20 08:25:04 UTC
The bugs mentionned in the two comments above are NOT duplicates of this one.
Comment 11 Vitaly Shukela 2010-05-26 09:52:45 UTC
By hacking gstmpegtsdemux to 
1. Not flush stream (ignore GST_EVENT_FLUSH_{START,STOP})
2. Provide fake times after seeking (make continuity) in gst_mpegts_demux_data_cb

it now seeks to any position (although it looks weird for user because it plays the remaining buffer content first).
Comment 12 Vitaly "_Vi" Shukela 2010-07-15 14:17:32 UTC
After making gstmpegtsdemux to override start time from 0 to the new position seeking from RTSP started working better.
Comment 13 Vitaly "_Vi" Shukela 2010-07-15 14:22:15 UTC
Created attachment 165964 [details] [review]
Patch to make seeking from RTSP with use of mpegtsdemux work.
Comment 14 Vitaly "_Vi" Shukela 2010-07-15 14:45:39 UTC
Comment on attachment 165964 [details] [review]
Patch to make seeking from RTSP with use of mpegtsdemux work.

>From da27049537a5aa5e18f8919515e31cc714707eab Mon Sep 17 00:00:00 2001
>From: Vitaly _Vi Shukela <public_vi@tut.by>
>Date: Mon, 12 Jul 2010 22:21:28 +0300
>Subject: [PATCH] mpegdemux: Hack for seeking from RTSP streams.
>
>It makes the newsegment to start not from 0, but from seek time, also fixing the stop time.
>---
> gst/mpegdemux/gstmpegtsdemux.c |   21 +++++++++++++++------
> 1 files changed, 15 insertions(+), 6 deletions(-)
>
>diff --git a/gst/mpegdemux/gstmpegtsdemux.c b/gst/mpegdemux/gstmpegtsdemux.c
>index 507cfdd..79aaa0f 100644
>--- a/gst/mpegdemux/gstmpegtsdemux.c
>+++ b/gst/mpegdemux/gstmpegtsdemux.c
>@@ -2685,7 +2685,6 @@ gst_mpegts_demux_sink_event (GstPad * pad, GstEvent * event)
>       gst_event_parse_new_segment (event, &update, &rate, &format,
>           &start, &stop, &time);
> 
>-      gst_event_unref (event);
>       GST_INFO_OBJECT (demux, "received new segment: rate %g "
>           "format %d, start: %" G_GINT64_FORMAT ", stop: %" G_GINT64_FORMAT
>           ", time: %" G_GINT64_FORMAT, rate, format, start, stop, time);
>@@ -2699,14 +2698,24 @@ gst_mpegts_demux_sink_event (GstPad * pad, GstEvent * event)
>         tstop += BYTES_TO_GSTTIME (stop);
>         pos = BYTES_TO_GSTTIME (time);
> 
>+        gst_event_unref (event);
>+        tstart = pos;
>+        tstop += tstart;
>         event = gst_event_new_new_segment (update, rate,
>             GST_FORMAT_TIME, tstart, tstop, pos);
>         GST_DEBUG_OBJECT (demux, "pushing time newsegment from %"
>             GST_TIME_FORMAT " to %" GST_TIME_FORMAT " pos %" GST_TIME_FORMAT,
>             GST_TIME_ARGS (tstart), GST_TIME_ARGS (tstop), GST_TIME_ARGS (pos));
> 
>-        res = gst_mpegts_demux_send_event (demux, event);
>+      } else {
>+        gst_event_unref (event);
>+        start = time;
>+        stop += start;
>+        event = gst_event_new_new_segment (update, rate,
>+            GST_FORMAT_TIME, start, stop, time);
>+
>       }
>+      res = gst_mpegts_demux_send_event (demux, event);
>       break;
>     }
>     default:
>-- 
>1.7.1
>
Comment 15 Vitaly "_Vi" Shukela 2010-07-15 14:48:22 UTC
Created attachment 165969 [details] [review]
Patch to make seeking from RTSP with use of mpegtsdemux work.
Comment 16 David Schleef 2010-12-08 08:36:16 UTC
*** Bug 585077 has been marked as a duplicate of this bug. ***
Comment 17 Pascal de Bruijn 2010-12-31 15:32:14 UTC
While obviously not a solution, this maybe provide a temporary workaround for end users:

for MTS in *.MTS; do ffmpeg -i ${MTS} -vcodec copy -acodec copy -scodec none `echo ${MTS} | sed 's/MTS/mkv/g'`; done
Comment 18 Pascal de Bruijn 2010-12-31 15:42:02 UTC
OK, the above actually fails if a fails has subs embedded, since the none "codec" isn't recognized. ffmpeg has a different parameter to strip out subtitles (-sn):

for MTS in *.MTS; do ffmpeg -i ${MTS} -vcodec copy -acodec copy -sn `echo ${MTS} | sed 's/MTS/mkv/g'`; done
Comment 19 kxra 2012-03-10 21:57:21 UTC
How is this bug? Ubuntu users seemed to think all was well now: https://bugs.launchpad.net/ubuntu/+source/gstreamer0.10/+bug/327872
Comment 20 Jean-François Fortin Tam 2012-03-11 03:41:09 UTC
I have absolutely no idea at all why downstream just marked it as "Fix released" out of the blue. My guess is that they don't want to have it on their bug list.
Comment 21 Sebastian Dröge (slomo) 2012-03-12 08:13:59 UTC
Could someone check if this is working correctly now with tsdemux (not mpegtsdemux) from GIT? There were lots of bugfixes related to timestamp handling and seeking recently.
Comment 22 Akhil Laddha 2012-04-28 04:07:36 UTC
Was anybody able to reproduce the problem in recent GStreamer ?
Comment 23 Akhil Laddha 2012-04-28 04:08:50 UTC
sorry, closed it by mistake.
Comment 24 Edward Hervey 2012-05-22 16:04:38 UTC
I am closing this bug due to lack of response. Please test with new tsdemux from GIT. If the issue persists, please re-open.