Commit graph

69 commits

Author SHA1 Message Date
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
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
47c43b29eb gst: Update for gst_video_transfer_function_*() function renaming
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/715>
2020-09-07 12:13:18 +03:00
Jan Schmidt
e2d75939bb qtdemux: Factor out svmi parsing. Fix bounds checking.
Move the SVMI stereoscopic atom parsing out to a helper
function to shrink qtdemux_parse_trak a bit.

Add a bounds check that the received atom is large enough
before parsing it.

Add a note to the atom parser that svmi comes from the
MPEG-A spec 23000-11.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/634>
2020-06-18 14:41:27 +00: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
Edward Hervey
8e1c224fbc good: Avoid usage of deprecated API
GTimeval and related functions are now deprecated in glib.
Replacement APIs have been present since 2.26
2019-10-16 07:46:58 +00:00
Sebastian Dröge
d7738da285 qtmux: Use the new helper functions for mapping the colr atom values to colorimetry 2019-09-18 18:32:02 +03: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
324f8c7f3c qtmux: Correctly set tkhd width/height to the display size
It was previously set to the display aspect ratio, e.g. 4x3, 16x9, etc.
but should be set to the display size.

This is a regression from e655d47dfc
(1.5.1) and was correct before that.

https://bugzilla.gnome.org/show_bug.cgi?id=797318
2018-10-22 12:23:05 +01:00
Sebastian Dröge
d9b52d1f5e qtmux: Use existing helper function to create "und" language code 2018-09-06 20:07:57 +03:00
Edward Hervey
7378f1b4fd isomp4: qtmux: Add Closed Caption support
Supports CEA 608 and CEA 708 CC streams

Also supports usage in "Robust Prefill" mode if the incoming caption
stream is constant (i.e. there is one incoming CC buffer for each
video frame).

https://bugzilla.gnome.org/show_bug.cgi?id=606643
2018-04-23 15:58:10 +02:00
Edward Hervey
76e32ef414 isomp4: Make 'gmhd' atom usage more generic
Only the 'gmin' atom is required. Any other entry within it are
optional.

https://bugzilla.gnome.org/show_bug.cgi?id=606643
2018-04-23 15:58:10 +02:00
Sebastian Dröge
e7177059e9 qtmux: Add support for muxing svmi atom for stereoscopic video information
https://bugzilla.gnome.org/show_bug.cgi?id=793120
2018-02-09 11:05:02 +02:00
Vivia Nikolaidou
379059b1c7 qtmux: Make sure timecode uses the same timescale as video
Don't blindly derive it from the frame rate, but try to get the per-pad
configured timescale first (if it exists)

https://bugzilla.gnome.org/show_bug.cgi?id=792680
2018-01-23 16:40:36 +02:00
Mark Nauwelaerts
dbcb99ac1d qtmux: initialize mdhd language code as undefined 2017-06-28 20:00:44 +02:00
Sebastian Dröge
deb9c62cd9 qtmux: Un-merge the last two stsc entries after serializing
The last entry will most likely get new samples added to it in "robust"
muxing mode, changing the samples_per_chunk and thus making it wrong to
keep the last two entries merged. It will run into an assertion later
when adding a new sample to the chunk.

Thanks to gdiener@cardinalpeak.com for the analysis of the bug and
proposal for a solution.
2017-06-15 11:50:44 +03:00
Sebastian Dröge
55f949676e qtmux: Add new prefill recording mode
This sets up a moov with the correct sample positions beforehand and
only works with constant framerate, I-frame only streams.

Currently only support for ProRes and raw audio is implemented but
adding new codecs is just a matter of defining appropriate maximum frame
sizes.

https://bugzilla.gnome.org/show_bug.cgi?id=781447
2017-05-09 14:17:04 +02:00
Sebastian Dröge
e51c08b0a2 qtmux: Fix timescale of timecode tracks
They should have ideally the same timescale of the video track, which we
can't guarantee here as in theory timecode configuration and video
framerate could be different. However we should set a correct timescale
based on the framerate given in the timecode configuration, and not just
use the framerate numerator.
2017-04-14 13:38:53 +03:00
Sebastian Dröge
98583dc944 qtmux: Free EDTS instead of just clearing it and setting it to NULL 2017-03-08 16:01:02 +02:00
Sebastian Dröge
0e62a0603d qtmux: Fix some memory leaks related to timecode tracks 2017-03-08 15:27:32 +02:00
Sebastian Dröge
7709920ca3 qtmux: Update modification times when sending the moov
https://bugzilla.gnome.org/show_bug.cgi?id=779422
2017-03-02 20:33:30 +02:00
Sebastian Dröge
1426a55a83 qtmux: Clear edit lists every time we recalculate them
We recalculate them, so any old information has to be forgotten.
Otherwise we write invalid edit lists when writing headers multiple
times.

https://bugzilla.gnome.org/show_bug.cgi?id=778330
2017-02-08 17:26:21 +02:00
Vivia Nikolaidou
af47e93b97 qtmux: Timecode track fixes for STSD entry
The n_frames field (frames per second) should follow the nominal frame
rate for drop-frame timecodes.

Also, the trak's timescale (and duration, accordingly) should follow the
STSD entry's timescale and frame duration (fps_n and fps_d accordingly),
not the other way around.

https://bugzilla.gnome.org/show_bug.cgi?id=777832
2017-01-27 16:41:34 +02:00
Sebastian Dröge
d1ce68e840 qtmux: Only write 4 byte zero padding to the Video Sample Description in MOV
For MP4 this is not defined, and it actually breaks things for MSE in
Chrome if we do this. For MOV this is required by some broken software
but the official specification says it's optional:
https://developer.apple.com/library/content/documentation/QuickTime/QTFF/QTFFChap3/qtff3.html

https://bugzilla.gnome.org/show_bug.cgi?id=777540
2017-01-24 17:59:59 +02:00
Sebastian Dröge
e12c94065d qtmux: Write tapt atom for MOV files if PAR not 1/1
Needed for QuickTime 7 to properly play files.

Also write the clap atom for MOV files always, not only when ProRes is
used as a video codec. It's mandatory for MOV.

https://bugzilla.gnome.org/show_bug.cgi?id=777100
2017-01-12 19:09:22 +02:00
Jan Schmidt
12ad37fdb3 qtmux: Write tfdt atom into fragmented files.
The DASH spec requires that tfdt atoms be present, so
write one out. ISO/IEC 23009-1:2014 6.3.4.2

https://bugzilla.gnome.org/show_bug.cgi?id=708221
2017-01-08 01:23:52 +11:00
Jan Schmidt
db0eddb10f qtmux: Remove bogus check in atom_stsc_add_new_entry()
Remove an old check from atom_stsc_add_new_entry() that
extends the last entry in the STSC if the samples per chunk
matches, as the new interleave merging logic requires that
the final entry by updateable. There's already code
below which simply merges the final entry into the previous
one when needed, so rely on that instead.

Fixes asserts like:

ERROR:atoms.c:2940:atom_stsc_update_entry: assertion failed:
(atom_array_index (&stsc->entries, len - 1).first_chunk == first_chunk)
2017-01-03 01:34:02 +11:00
Sebastian Dröge
c2225781bb qtmux: Allow configuring the interleave size in bytes/time
Previously we were switching from one chunk to another on every single
buffer. This wastes some space in the headers and, depending on the
software, might depend in more reads (e.g. if the software is reading
multiple samples in one go if they're in the same chunk).

The ProRes guidelines suggest an interleave of 0.5s is common, but
specifies that for ProRes at most 2MB (for SD) and 4MB (for HD) should
be used per chunk. This will be handled in a follow-up commit.

https://bugzilla.gnome.org/show_bug.cgi?id=773217
2016-11-01 20:41:22 +02:00
Sebastian Dröge
a2c6921482 qtmux: Write 'clap' atom for ProRes
It's required for ProRes to work with other software.

It is also in the MP4 standard, but inventing values here seems a bit
tricky for the general case and it does not really give any extra
information.

https://bugzilla.gnome.org/show_bug.cgi?id=769048
2016-11-01 20:41:22 +02:00
Sebastian Dröge
53e436883a qtmux: Always write colr atom with the colorimetry information
https://bugzilla.gnome.org/show_bug.cgi?id=772181
2016-11-01 20:41:22 +02:00
Sebastian Dröge
0584a71123 qtmux: Fix writing of the 'fiel' extension atom
This was also wrong for JPEG2000. Also write it for all MOV files and
JPEG2000, not only for ProRes.

https://bugzilla.gnome.org/show_bug.cgi?id=769048
2016-11-01 20:41:22 +02:00
Sebastian Dröge
b815c41b7e qtmux: Write 4 bytes of zeroes at the end of the sample description extensions
This is working around some broken software.

https://bugzilla.gnome.org/show_bug.cgi?id=769048
2016-11-01 20:41:22 +02:00
Sebastian Dröge
4cff5093ee atoms: 'pasp' atom is also part of MP4, write it always
https://bugzilla.gnome.org/show_bug.cgi?id=769048
2016-11-01 20:41:22 +02:00
Vivia Nikolaidou
fe38414412 qtmux: Write additional atoms for prores video
These required atoms are: colorimetry, field information, spatial/temporal
quality, and vendor.

https://bugzilla.gnome.org/show_bug.cgi?id=769048
2016-11-01 20:41:22 +02:00
Vivia Nikolaidou
64fd099a3a isomp4: Fix coverity warning
If atom_copy_data fails to write anything, return 0

CID #1371458
2016-08-19 17:53:25 +03:00
Vivia Nikolaidou
cdb7649909 qtmux: Added support for writing timecode track
https://bugzilla.gnome.org/show_bug.cgi?id=767950
2016-08-17 09:03:52 +03:00
Luis de Bethencourt
e731fe4af5 isomp4: remove unused parameters in build_*_extension
AtomTRAK parameter is not used by build_mov_alac_extension(),
build_jp2h_extension(), or build_mov_alac_extension()  and can be
removed.
2015-12-10 18:39:04 +00:00
Luis de Bethencourt
0fffb8f2e2 atoms: remove unused argument of build_mov_wave_extension()
AtomTrak * trak argument of build_move_wave_extension() isn't used.
Removing it.
2015-11-19 19:48:09 +00:00
Luis de Bethencourt
ca46897bf7 isomp4: centralize all FourCC
10 FourCCs generated with GST_MAKE_FOURCC() in gstqtmux.c and atoms.c
already exist in fourcc.h. Don't duplicate these and use them directly.
Plus moving 6 to fourcc.h, to centralize them all.
2015-11-19 18:41:39 +00:00
Luis de Bethencourt
5ed8cba024 isomp4: add support for Opus in mp4mpux
Add support for muxing MP4 files containing Opus. Based on the spec
detailed here:
https://www.opus-codec.org/docs/opus_in_isobmff.html

https://bugzilla.gnome.org/show_bug.cgi?id=742643
2015-11-19 17:08:25 +00:00
Reynaldo H. Verdejo Pinochet
48c4362cdc isomp4/atoms: remove unnecessary NULL checks before g_free() 2015-11-15 01:43:08 -08:00
Stefan Sauer
12930c2f8c docs: fix "Symbol name not found at the start of the comment block"
Add symbols or change comment into a regular comment.
2015-07-07 17:12:02 +02:00
Thiago Santos
03f1a2ea67 atoms: remove custom gst_buffer_new function in favor of core version
Remove a custom specialized version of gst_buffer_new_wrapped by
using gst_buffer_new_wrapped_full inside a macro to simplify
parameters and give it a more meaningful name.
It is only used to create temporary buffers to have its data copied.
2015-06-11 01:11:31 -03:00
Thiago Santos
1596972674 atoms: simplify free form data atoms creation
Avoid creating an intermediary buffer or memory area just
to copy into an atom's data area.
2015-06-11 01:11:31 -03:00
Thiago Santos
ab18f5035c qtmux: add AC-3 muxing support
Adds AC-3 muxing support. It is defined for mp4 and 3gp formats.

One extra feature that was added was the ability to add extension
atoms after set_caps as the AC-3 extension atom needs some data
that has to be extracted from the stream itself and is not
present on caps.
2015-06-11 01:11:31 -03:00
Thiago Santos
674e0cc2df qtmux: remove unused type MP4S 2015-06-11 01:11:31 -03:00
Jan Schmidt
1d058c7d8a isomp4: Implement robust muxing using ping-pong strategy
Implement a robust recording mode, where the output
file is always in a playable state, seeking and rewriting
the moov header at a configurable interval. Rewriting
moov is done using reserved space at the start of
the file, and a ping-pong strategy where the moov
is replaced atomically so it's never invalid.

Track when tags have actually changed, and don't write them into
the moov unless they've changed. Clear any existing tags when
re-writing them, so we can do progressive moov updating in robust
recording mode.

Write placeholder mdat as a free atom plus a 32-bit mdat
with '0' size, which means "rest of the file" in the spec.

Re-write it later to a full 64-bit extended size atom if needed.
2015-06-08 14:49:11 +10:00
Jan Schmidt
3d7b343525 isomp4: Update edit list when re-writing moov
Correctly update any edit lists each time the moov is recalculated,
updating existing table entries if they already exist instead of just
adding new ones.
2015-06-08 14:16:36 +10:00
Thiago Santos
6321cdedb3 qtmux: refactor tags functions to accomodata UDTA at trak level
Refactor the functions that were bound to the 'moov' atom to
directly pass the desired 'udta' that should receive the tags.
This allows the tags to be written to 'udta' at the 'moov' or
the 'trak' level, creating tags that are for the container or
for a stream only.

https://bugzilla.gnome.org/show_bug.cgi?id=692473
2015-01-31 17:22:57 -03:00
Sebastian Dröge
d5aab81a77 Constify some static arrays everywhere 2015-01-21 09:55:53 +01:00