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 751103 - qtdemux: Segment seeks broken with CTTS version 1 .mov files
qtdemux: Segment seeks broken with CTTS version 1 .mov files
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-good
git master
Other Linux
: Normal blocker
: git master
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2015-06-17 13:13 UTC by Vivia Nikolaidou
Modified: 2015-06-22 23:04 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
ctts_dump: Fix signess issues (1.37 KB, patch)
2015-06-17 19:21 UTC, Nicolas Dufresne (ndufresne)
committed Details | Review
cslg: Add Composition Shift Least Greatest Atom (3.43 KB, patch)
2015-06-17 19:21 UTC, Nicolas Dufresne (ndufresne)
committed Details | Review
qtdemux: Add cslg support (4.61 KB, patch)
2015-06-18 21:17 UTC, Nicolas Dufresne (ndufresne)
reviewed Details | Review
qtdemux: Add cslg support (4.56 KB, patch)
2015-06-19 23:21 UTC, Nicolas Dufresne (ndufresne)
none Details | Review
qtmux: Set edit list to compensate DTS shift (2.93 KB, patch)
2015-06-19 23:21 UTC, Nicolas Dufresne (ndufresne)
none Details | Review
qtmux: Use PTS to figure-out presence of gaps (1.25 KB, patch)
2015-06-19 23:21 UTC, Nicolas Dufresne (ndufresne)
none Details | Review
qtmux: Test gaps at start of stream (5.40 KB, patch)
2015-06-19 23:21 UTC, Nicolas Dufresne (ndufresne)
none Details | Review

Description Vivia Nikolaidou 2015-06-17 13:13:29 UTC
Since commit 135e5167304ced786d48f2187b3f0322edf7f0c0 in gst-plugins-good (with the fix from 717265ebfbbb4ef477d7a0922f3322cb5ac21600 backported), segment seeks do not work with some .mov files.

Test file: http://ahiru.eu/~vivia/claudia.mov
Tried with gst-plugins-good/tests/icles/test-segment-seeks claudia.mov and I only get a frozen image. Another random file works.
Comment 1 Vivia Nikolaidou 2015-06-17 13:18:09 UTC
^ To enable the URL catcher above: commit 717265ebfbbb4ef477d7a0922f3322cb5ac21600 is the fix to be backported.
Comment 2 Nicolas Dufresne (ndufresne) 2015-06-17 13:33:54 UTC
> 717265ebfbbb4ef477d7a0922f3322cb5ac21600:
> flvmux: Make sure best_time is initialized

Not sure why you refer to this patch if you are having issue with MOV. Have you tried reverting, to make sure it's a regression ?
Comment 3 Vivia Nikolaidou 2015-06-17 13:46:10 UTC
I was just unable to compile -good without that patch, that's all :)
Comment 4 Nicolas Dufresne (ndufresne) 2015-06-17 14:03:10 UTC
So here we go. The first CTTS is always 0, hence CTTS goes negative. This is totally not what the code expects. It also an exploit of spec ambiguity. Thanks for the same, I was looking for one.

The problem we'll have is that I implemented CTTS version 0, as the new version contradict itself. In version 1, CTTS can be negative, but that invalidate a bunch of other paragraph that where not updated as the DTS stored in the file is no longer a DTS. It's the DTS + a certain offset so the first CTTS is 0.

Also, some file (possibly generated from GST) lies about implementing CTTS 1, while actually implementing CTTS 0. That's going to be fun mess to fix. We'll probably need some quirk. If some more sample with B-Frames could be provided. I expect that one implementing CTTS 0 to work.
Comment 5 Nicolas Dufresne (ndufresne) 2015-06-17 14:04:24 UTC
(In reply to Vivia Nikolaidou from comment #3)
> I was just unable to compile -good without that patch, that's all :)

You'll have to clarify, I really don't follow why you refer to patches against FLV muxer, in a bug about qtdemuxer.
Comment 6 Vivia Nikolaidou 2015-06-17 14:14:46 UTC
vivia@kleio /u/l/s/g/h/gst-plugins-good ((37e3ca1...))> 
git checkout 135e5167304ced786d48f2187b3f0322edf7f0c0
Previous HEAD position was 37e3ca1... rtpbin: Rename some variables and debug output to make more sense
HEAD is now at 135e516... qtdemux: Adjust segment according to ctts offset
vivia@kleio /u/l/s/g/h/gst-plugins-good ((135e516...))> ./autogen.sh 
[...]
Now type 'make' to compile gst-plugins-good.
vivia@kleio /u/l/s/g/h/gst-plugins-good ((135e516...))> make -j10
[...]
gstflvmux.c: In function ‘gst_flv_mux_handle_buffer’:
gstflvmux.c:1543:7: error: ‘best_time’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
       && best_time / GST_MSECOND > G_MAXINT32) {
       ^
  CCLD     libgsticydemux.la
  CC       tvtime/libgstdeinterlace_la-scalerbob.lo
cc1: all warnings being treated as errors
Makefile:678: recipe for target 'libgstflv_la-gstflvmux.lo' failed
make[3]: *** [libgstflv_la-gstflvmux.lo] Error 1
make[3]: Leaving directory '/usr/local/src/gstreamer/head/gst-plugins-good/gst/flv'
Makefile:850: recipe for target 'flv' failed
make[2]: *** [flv] Error 2


That's why I backported that patch. Otherwise I wasn't able to compile -good at all, and therefore I wasn't able to properly bisect.
Comment 7 Nicolas Dufresne (ndufresne) 2015-06-17 14:20:43 UTC
Ok, here's a video (picked from an Olympus camera) that implements CTTS version 0. Which works as expected (did I mention I implemented CTTS 0 ? ;-P).

https://people.collabora.com/~nicolas/dance.mov
Comment 8 Nicolas Dufresne (ndufresne) 2015-06-17 14:23:20 UTC
Ok, so you have a custom branch of GStreamer for testing, I'd recommend to keep going forward with top of the tree for the following work on this bug.
Comment 9 Nicolas Dufresne (ndufresne) 2015-06-17 18:52:37 UTC
So, the version cannot be trusted, also I realize that the spec didn't bump the Atom version even though they have change the semantic by making this field signed.
Comment 10 Nicolas Dufresne (ndufresne) 2015-06-17 19:21:19 UTC
Created attachment 305500 [details] [review]
ctts_dump: Fix signess issues

It didn't bug, but use correct signess in traces. The number of
entries is unsigned while the offset can be signed according to
recent spec.
Comment 11 Nicolas Dufresne (ndufresne) 2015-06-17 19:21:24 UTC
Created attachment 305501 [details] [review]
cslg: Add Composition Shift Least Greatest Atom

This simply add fourcc and dump function for the cslg Atom.
Comment 12 Nicolas Dufresne (ndufresne) 2015-06-17 19:22:06 UTC
These two patches are just utilities that can help implementing negative CTTS support.
Comment 13 Nicolas Dufresne (ndufresne) 2015-06-17 19:32:03 UTC
Attachment 305500 [details] pushed as 8a406c9 - ctts_dump: Fix signess issues
Attachment 305501 [details] pushed as d6e1e74 - cslg: Add Composition Shift Least Greatest Atom
Comment 14 Nicolas Dufresne (ndufresne) 2015-06-18 21:17:25 UTC
Created attachment 305629 [details] [review]
qtdemux: Add cslg support

The cslg atom provide information about the DTS shift. This is
needed in recent version of ctts atom where the offset can be
negative.
Comment 15 Nicolas Dufresne (ndufresne) 2015-06-18 21:28:57 UTC
Thiago, please have a look, but this fixes both videos for me. I'm missing a patch to comment about reading signed CTTS as a workaround to some muxers not complying to ISO.
Comment 16 Nicolas Dufresne (ndufresne) 2015-06-18 21:31:25 UTC
I just notice, but the CTTS offset was already read as signed since it was introduce in 2009 by Robert Swain.
Comment 17 Thiago Sousa Santos 2015-06-19 13:42:12 UTC
Review of attachment 305629 [details] [review]:

This is very close to a solution but there are still some things to solve.

::: gst/isomp4/qtdemux.c
@@ +7185,3 @@
+
+    stream->cslg_shift = ABS (least_soffset);
+  }

Also, keep in mind that parse_samples will be called incrementally, parsing only the first N samples so the observation of least_offset might not be correct at the beginning, this means that the initial segment.start could be wrong and we could end up with some desync if we find a smaller cslg_shift at some point.

Also, we should reset this value when a new fragment starts as it is only valid for the movie it is present and not for subsequent ones in a fragmented stream.
Comment 18 Nicolas Dufresne (ndufresne) 2015-06-19 14:46:30 UTC
(In reply to Thiago Sousa Santos from comment #17)
> Review of attachment 305629 [details] [review] [review]:
> 
> This is very close to a solution but there are still some things to solve.
> 
> ::: gst/isomp4/qtdemux.c
> @@ +7185,3 @@
> +
> +    stream->cslg_shift = ABS (least_soffset);
> +  }
> 
> Also, keep in mind that parse_samples will be called incrementally, parsing
> only the first N samples so the observation of least_offset might not be
> correct at the beginning, this means that the initial segment.start could be
> wrong and we could end up with some desync if we find a smaller cslg_shift
> at some point.

We can try and improve the fallback, what do you propose ? Do we parse incrementally to distribute the load, or will the data be found later in the stream ?

> 
> Also, we should reset this value when a new fragment starts as it is only
> valid for the movie it is present and not for subsequent ones in a
> fragmented stream.

This is not a new bug, the CTTS has never been reset on streams since day one of CTTS support.
Comment 19 Nicolas Dufresne (ndufresne) 2015-06-19 23:21:02 UTC
Created attachment 305723 [details] [review]
qtdemux: Add cslg support

The cslg atom provide information about the DTS shift. This is
needed in recent version of ctts atom where the offset can be
negative. When cslg is missing, we parse the CTTS table as proposed
in the spec to calculate these values.

In this implementation, we only need to know the shift. As GStreamer
cannot transport negative timestamps, we shift the timestamps forward
using that value and adapt the segment to compensate. This patch also
removes bogus offset of ctts_soffset, this offset shall be included
in the edit list.
Comment 20 Nicolas Dufresne (ndufresne) 2015-06-19 23:21:06 UTC
Created attachment 305724 [details] [review]
qtmux: Set edit list to compensate DTS shift

We shift DTS forward to avoid negative timestamps which cannot be
represented with version 0 of the CTTS table. To stick with that
version (backward compatibility), the spec recommend using an
edit list entry to move back the presentation time to where it
should be.
Comment 21 Nicolas Dufresne (ndufresne) 2015-06-19 23:21:11 UTC
Created attachment 305725 [details] [review]
qtmux: Use PTS to figure-out presence of gaps

We need to look at the presentation timestamp in order to conclude if
there is a gap at the start of a stream.
Comment 22 Nicolas Dufresne (ndufresne) 2015-06-19 23:21:14 UTC
Created attachment 305726 [details] [review]
qtmux: Test gaps at start of stream
Comment 23 Nicolas Dufresne (ndufresne) 2015-06-19 23:26:59 UTC
Oops, the other patches should be in another bug, sorry.
Comment 24 Nicolas Dufresne (ndufresne) 2015-06-22 23:04:44 UTC
Attachment 305723 [details] pushed as dd72267 - qtdemux: Add cslg support