Commit graph

256 commits

Author SHA1 Message Date
Jan Schmidt
fae29cb3c2 qtmux: Protect against writing absurd sample durations
If the input DTS goes backward or is missing, the calculated
sample duration goes negative and wraps around to a very big
number. In that case, just write a sample with a duration of
0 and hope the problem is transient.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/914>
2021-04-13 00:18:36 +10:00
Stéphane Cerveau
2cce1247da isomp4: allow per feature registration
Split plugin into features including
dynamic types which can be indiviually
registered during a static build.

More details here:

https://gitlab.freedesktop.org/gstreamer/gst-build/-/merge_requests/199
https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/661

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/876>
2021-03-29 12:45:22 +02:00
Matthew Waters
9d74a60810 qtmux: support muxing multiple codec_data for h264/h265
Each codec_data is put into its own SampleTableEntry inside the stsd.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/787>
2020-11-02 03:32:50 +00:00
Jan Schmidt
537e7d873a qtmux: Chain up when releasing pad, and fix some locking.
Release pads by calling up into aggregator so it can do the right
things. Don't clean up the pad until after that.

 Add some missing locks around some accesses to shared pad state.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/797>
2020-10-31 02:01:10 +00:00
Thibault Saunier
6eef0967b9 isomp4: Rename GstQTMux to GstBaseQTMux to avoid breaking API
Since 52b63de19a the qtmux GType was
renamed GstQTMuxElement which breaks presets, revert that change.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/755>
2020-09-30 09:18:13 -03:00
Matthew Waters
7736a21659 qtmux: output the correct limits in error messages
Having the current bytes being less than the limit was confusing!

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/732>
2020-09-28 15:37:12 +10:00
Matthew Waters
e81ce6f2d7 qtmux: properly support initial caps nego failure
Scenario:
- gap event causes h264parse to push made up caps that may fail checks
  inside qtmux (e.g missing codec_data).
- the caps event has already been marked as received and is sticky on
  the sink pad
- gst_qt_mux_pad_can_renegotiate() will retrieve the failed caps event
  using gst_pad_get_current_caps() and reject the correct updated caps
  with codec_data.
- Failure!

Keep track of the configured caps ourselves instead of relying on the
sticky event on the pad.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/732>
2020-09-28 15:37:12 +10:00
Matthew Waters
b27dc540d0 qtmux: support non-seekable downstream mode
Write an mdat per buffer in that case.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/732>
2020-09-28 15:37:12 +10:00
Matthew Waters
e64227f585 qtmux: make documentation happy
introduce a base qtmux class that we can install documentation snippets
on instead of duplicating across alll the isomp4 elements

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/643>
2020-09-21 12:09:09 +10:00
Matthew Waters
52b63de19a isomp4/mux: add a fragment mode for initial moov with data
Used by some proprietary software for their fragmented files.

Adds some support for multi-stream fragmented files

Flow is as follows.
1. The first 'fragment' is written as a self-contained fragmented
   mdat+moov complete with an edit list and durations, tags, etc.
2. Subsequent fragments are written with a mdat+moof and each stream is
   interleaved as data arrives (currently ignoring the interleave-*
   properties).  data-offsets in both the traf and the trun ensure
   data is read from the correct place on demuxing.  Data/chunk offsets
   are also kept for writing out the final moov.
3. On finalisation, the initial moov is invalidated to a hoov and the
   size of the first mdat is extended to cover the entire file contents.
   Then a moov is written as regularly would in moov-at-end mode (the
   default).

This results in a file that is playable throughout while leaving a
finalised file on completion for players that do not understand
fragmented mp4.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/643>
2020-09-21 12:08:14 +10:00
Sebastian Dröge
54bc0157b5 qtmux: Don't lock object lock twice in prefill mode
Fixes https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/issues/762

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/663>
2020-07-07 12:36:01 +03:00
Jordan Petridis
3e2420361a Use gst_element_class_set_metadata when passing dynamic strings
gst_element_class_set_metadata is meant to only be used with
static or inlined strings, which isn't the case for the 2 elements
here resulting in use-after-free later on.

https://gstreamer.freedesktop.org/documentation/gstreamer/gstelement.html?gi-language=c#gst_element_class_set_static_metadata

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/622>
2020-06-11 20:39:33 +03:00
Mathieu Duponchelle
f63299ff2f plugins: uddate gst_type_mark_as_plugin_api() calls 2020-06-06 00:42:25 +02:00
Mathieu Duponchelle
37c619f995 plugins: Use gst_type_mark_as_plugin_api() for all non-element plugin types 2020-06-03 22:44:09 -04:00
Sebastian Dröge
cf3fbf57bf qtmux: Add property for enforcing the creation of chunks in single-stream files
This is disabled by default as it unnecessarily creates bigger headers
but it is something that is required by some applications and most
notably the Apple ProRes spec.
2020-04-06 16:25:59 +03:00
Vivia Nikolaidou
5817c659e6 qtmux: Add option to create a timecode trak in non-mov flavors
Even if timecode trak is officially unsupported in non-mov flavors,
some software still supports it, e.g. Final Cut Pro X:

https://developer.apple.com/library/archive/technotes/tn2174/_index.html

The user might still expect to see the timecode information in the
non-mov file despite it being officially unsupported , because other
software e.g. QuickTime will create a timecode trak even in mp4 files.
Furthermore, software that supports timecode trak in non-mov flavors
will also display the file duration in "timecode units" instead of real
clock time, which is not necessarily the same for 29.97 fps and friends.
This might confuse users, who see a different duration for the same
framerate and amount of frames depending on whether the container is mp4
or mov.

Fixes https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/issues/512
2020-04-03 18:19:38 +00:00
Sebastian Dröge
d427b9bddf qtmux: Error out instead of crashing if reserved-max-duration is 0 or no samples could be created in prefill mode 2020-03-27 10:35:04 +00:00
Seungha Yang
4f443c81cf qtmux: Fix build warning
gstqtmux.c(644): warning C4133: '=':
  incompatible types - from 'gboolean (__cdecl *)(GstAggregator *,GstAggregatorPad *,GstEvent *)'
  to 'GstFlowReturn (__cdecl *)(GstAggregator *,GstAggregatorPad *,GstEvent *)'
2020-03-19 19:20:05 +00:00
Mathieu Duponchelle
56e5243f03 qtmux: fix renegotiation check
By the time sink_event is called, the pad's current caps have
already been updated. To address this, implement sink_event_pre_queue,
and check if the pad can be renegotiated there.

Fixes #707
2020-03-19 23:34:52 +11:00
Jan Schmidt
54f68ff36b qtmux: Remove warning in the log for mono video
Vanilla mono video was generating a spurious warning into the debug log
that's just misleading. Handle mono caps explicitly to avoid the warning.
2020-03-04 04:14:40 +00:00
Sebastian Dröge
35a1cedb97 qtmux: Add support for 8k resolutions in prefill mode with ProRes 2020-02-25 15:46:44 +02:00
Mathieu Duponchelle
5766731bd4 qtmux: protect access to GstElement.sinkpads 2019-12-16 14:17:38 +00:00
Mathieu Duponchelle
e2462005fb qtmux: port to GstAggregator 2019-12-16 14:17:38 +00:00
Patricia Muscalu
203ad39d53 qtmux: Fix memory leak while pushing fragmented data
The memory leak occurs in the case when the buffer has been
added to the fragment_buffers array of the current pad and
never been sent because of the push failure of the previous
buffers: moof or mdat header or fragmented buffer(s).
2019-10-24 10:21:11 +00:00
Aaron Boxer
46989dca96 documentation: fix a number of typos 2019-10-05 22:38:11 +00:00
Seungha Yang
2ef74f2c81 qtmux: Fix incompatible type warning with MSVC
gstqtmux.c(5582): warning C4133: 'function':
  incompatible types - from 'GstVideoMultiviewFlags *' to 'guint *'
2019-09-02 15:07:17 +00:00
Mathieu Duponchelle
3429ddde38 docstrings: port ulinks to markdown links 2019-08-23 18:56:01 +02:00
Sebastian Dröge
2bed2687bb qtmux: Use size of first closed caption buffer in prefill mode
It must be accurate for all samples to work in Final Cut properly, so
the best we can do is to assume that all samples are the same as the
first. Bigger samples are truncated, smaller samples are padded.
2019-06-03 12:46:34 +03:00
Mathieu Duponchelle
d704790519 doc: fix element section documentations
Element sections were not rendered anymore after the hotdoc
port, fixing this revealed a few incorrect links.
2019-05-25 16:57:31 +02:00
Thibault Saunier
232e3682ea Mark some properties as DOC_SHOW_DEFAULT 2019-05-13 10:24:40 -04:00
Thibault Saunier
0a6a62aa76 docs: Port all docstring to gtk-doc markdown 2019-05-13 10:24:40 -04:00
Vivia Nikolaidou
92272b5e5c qtmux: Only write timecode trak for video
Recent changes in ccextractor were attaching timecode meta to the closed
caption track. We shouldn't write timecode information for the closed
caption trak.
2019-02-08 14:13:46 +02:00
Sebastian Dröge
4f7ef56c53 isomp4: Replace GST_VIDEO_CAPTION_TYPE_CEA608_IN_CEA708_RAW with CEA608_S334_1A
For the demuxer we have to select line offset 0 for the time being as
this information is not passed over MOV.
2018-12-15 21:31:20 +00:00
Sebastian Dröge
830e7dc14b qtmux: Set timescale of closedcaption tracks to the one of the main video track 2018-12-06 16:05:50 +00:00
Alicia Boya García
5fcb7f715a qtmux: round to nearest when computing mehd and tkhd duration
This fixes a bug where in some files mehd.fragment_duration is one unit
less than the actual duration of the fragmented movie, as explained below:

mehd.fragment_duration is computed by scaling the end timestamp of
the last frame of the movie in (in nanoseconds) by the movie timescale.

In some situations, the end timestamp is innacurate due to lossy conversion to
fixed point required by GstBuffer upstream.

Take for instance a movie with 3 frames at exactly 3 fps.

$ gst-launch-1.0 -v videotestsrc num-buffers=3 \
  ! video/x-raw, framerate="(fraction)3/1" \
  ! x264enc \
  ! fakesink silent=false

dts: 999:59:59.333333334,  pts: 1000:00:00.000000000, duration: 0:00:00.333333333
dts: 999:59:59.666666667,  pts: 1000:00:00.666666666, duration: 0:00:00.333333334
dts: 1000:00:00.000000000, pts: 1000:00:00.333333333, duration: 0:00:00.333333333

The end timestamp is calculated by qtmux in this way:

end timestamp = last frame DTS + last frame DUR - first frame DTS =
  = 1000:00:00.000000000 + 0:00:00.333333333 - 999:59:59.333333334 =
  = 0:00:00.999999999

qtmux needs to round this timestamp to the declared movie timescale, which can
ameliorate this distortion, but it's important that round-neareast is used;
otherwise it would backfire badly.

Take for example a movie with a timescale of 30 units/s.

0.999999999 s * 30 units/s = 29.999999970 units

A round-floor (as it was done before this patch) would set fragment_duration to
29 units, amplifying the original distorsion from 1 nanosecond up to 33
milliseconds less than the correct value. The greatest distortion would occur
in the case where timescale = framerate, where an entire frame duration would
be subtracted.

Also, rounding is added to tkhd duration computation too, which
potentially has the same problem.

https://bugzilla.gnome.org/show_bug.cgi?id=793959
2018-10-27 13:12:56 +01:00
Sebastian Dröge
01a2119ad0 qtmux: Add property for providing a threshold after which we create an edit list for gaps at the start
https://bugzilla.gnome.org/show_bug.cgi?id=797290
2018-10-22 12:29:23 +01:00
Vivia Nikolaidou
09904e59df qtmux: Allow up to 1% of frame rate for lateness
https://bugzilla.gnome.org/show_bug.cgi?id=797290
2018-10-16 16:05:46 +03:00
Sebastian Dröge
c6e07a6eee qtmux: Set Closed Caption track width/height to that of the first video track
Otherwise software like Premiere or Final Cut Pro won't like our files.

https://bugzilla.gnome.org/show_bug.cgi?id=797111
2018-09-20 11:35:31 +03:00
Sebastian Dröge
54a5b3f845 qtmux: Initialize caption track language code to 0 instead of "und"
Without this, Final Cut considers it "non-standard" and 0 (english) is a
good default for closed captions.

https://bugzilla.gnome.org/show_bug.cgi?id=797111
2018-09-18 17:32:46 +03:00
Vivia Nikolaidou
94f8603411 qtmux: Allow up to 1 trak timescale unit of lateness in prefill mode
For 59.94 FPS, it's common to set 60000 as timescale. For that
timescale, if the audio is late by as little as 0:00:00.000016666
(definitely less than one audio sample), lateness gets rounded to 1.
Added a safeguard that allows lateness up to 1 sample with the specific
trak's timescale, to make sure that values less than e.g. one audio
sample won't break the prefill mode. What will happen in this case is
that the audio will get squeezed back to the video's timestamp, which in
practice means that the audio will be 0.000016666 seconds early (with
the patch).

https://bugzilla.gnome.org/show_bug.cgi?id=797133
2018-09-13 13:51:18 +03:00
Sebastian Dröge
d9b52d1f5e qtmux: Use existing helper function to create "und" language code 2018-09-06 20:07:57 +03:00
Mathieu Duponchelle
bfcddb7125 mp4 robust muxing: improve documentation and logging 2018-08-16 19:43:50 +02:00
Sebastian Dröge
7a354d0507 qtmux: The sample size we have to reserve is 256+8 bytes for the header for CDP packets 2018-08-02 13:40:09 +03:00
Sebastian Dröge
8a3075fbae qtmux: Properly allocate 256 bytes per CDP packet in prefill mode
Instead of allowing 256 but only pre-allocating 100.
2018-08-02 12:27:45 +03:00
Sebastian Dröge
bbfd76e94e Revert "qtmux: Allow for CDP packets up to 320 bytes"
This reverts commit 5eed1d49bd.

255 is actually the maximum, there's a bug if more is arriving.
2018-08-02 12:27:17 +03:00
Sebastian Dröge
5eed1d49bd qtmux: Allow for CDP packets up to 320 bytes
Apparently they can be bigger than 256 bytes sometimes.
2018-08-01 16:51:11 +03:00
Sebastian Dröge
7679412b69 qtdemux: Don't assert in prefill mode if a track has no samples at all
Just write it with a duration of 0, no samples, etc.
2018-07-31 12:47:47 +03:00
Sebastian Dröge
e58dceec3a qtmux: Reserve 256 bytes for CDP packets in pre-fill mode
92 is sometimes too small and compared to the wasted space for other
codecs 256 bytes is small (and should be the maximum CDP packet size)
2018-07-30 13:35:02 +03:00
Olivier Crête
6c478453a8 qtmux: Implement muxing of AV1 into MP4 files
According to
https://aomediacodec.github.io/av1-isobmff/
2018-07-26 14:14:53 -04:00
Sebastian Dröge
6e7b0d6061 qtmux: Print expected/actual values in debug log on mismatch in prefill mode
This helps debugging a lot.
2018-05-14 21:06:55 +03:00