summaryrefslogtreecommitdiff
path: root/libavformat/movenc.c
Commit message (Collapse)AuthorAge
* movenc: Write 'loci' geotag metadata for 3gp and mp4Martin Storsjö2016-05-19
| | | | Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Factorize a function for finding a metadata entry and the associated ↵Martin Storsjö2016-05-19
| | | | | | language Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Write ?xyz geotag metadata for mov filesMichael Niedermayer2016-05-19
| | | | Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Add a missed constMartin Storsjö2016-05-18
| | | | | | | This was missed in e1eb0fc9601, when ff_interleaved_peek was changed to include const during the evolution of the patch. Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Use packets in interleaving queues for the duration at the end of ↵Martin Storsjö2016-05-18
| | | | | | | | | | | | | | fragments As long as caller only writes packets using av_interleaved_write_frame with no manual flushing, this should allow us to always have accurate durations at the end of fragments, since there should be at least one queued packet in each stream (except for the stream where the current packet is being written, but if the muxer itself does the cutting of fragments, it also has info about the next packet for that stream). Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Provide output bytestream markers for fragmented contentMartin Storsjö2016-05-18
| | | | Signed-off-by: Martin Storsjö <martin@martin.st>
* Mark read-only tables as staticDiego Biurrun2016-05-05
|
* cosmetics: Fix spelling mistakesVittorio Giovara2016-05-04
| | | | Signed-off-by: Diego Biurrun <diego@biurrun.de>
* Drop pointless assert.h #includesDiego Biurrun2016-05-03
|
* movenc: Handle pts == NOPTS when autoflushingMartin Storsjö2016-04-21
| | | | | | | This muxer generally handles pts == NOPTS by using dts instead; do this for consistency here as well. Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Update a comment to reflect how the code actually behavesMartin Storsjö2016-04-19
| | | | | | | This codepath isn't quite as bad as it used to sound, if fragments are cut automatically at video packets. Signed-off-by: Martin Storsjö <martin@martin.st>
* lavf: replace AVStream.codec with AVStream.codecparAnton Khirnov2016-02-23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, AVStream contains an embedded AVCodecContext instance, which is used by demuxers to export stream parameters to the caller and by muxers to receive stream parameters from the caller. It is also used internally as the codec context that is passed to parsers. In addition, it is also widely used by the callers as the decoding (when demuxer) or encoding (when muxing) context, though this has been officially discouraged since Libav 11. There are multiple important problems with this approach: - the fields in AVCodecContext are in general one of * stream parameters * codec options * codec state However, it's not clear which ones are which. It is consequently unclear which fields are a demuxer allowed to set or a muxer allowed to read. This leads to erratic behaviour depending on whether decoding or encoding is being performed or not (and whether it uses the AVStream embedded codec context). - various synchronization issues arising from the fact that the same context is used by several different APIs (muxers/demuxers, parsers, bitstream filters and encoders/decoders) simultaneously, with there being no clear rules for who can modify what and the different processes being typically delayed with respect to each other. - avformat_find_stream_info() making it necessary to support opening and closing a single codec context multiple times, thus complicating the semantics of freeing various allocated objects in the codec context. Those problems are resolved by replacing the AVStream embedded codec context with a newly added AVCodecParameters instance, which stores only the stream parameters exported by the demuxers or read by the muxers.
* lavf: allow custom IO for all filesAnton Khirnov2016-01-24
| | | | | | | | | | | | | | Some (de)muxers open additional files beyond the main IO context. Currently, they call avio_open() directly, which prevents the caller from using custom IO for such streams. This commit adds callbacks to AVFormatContext that default to avio_open2()/avio_close(), but can be overridden by the caller. All muxers and demuxers using AVIO are switched to using those callbacks instead of calling avio_open()/avio_close() directly. (de)muxers that use the URLProtocol layer directly instead of AVIO remain unconverted for now. This should be fixed in later commits.
* movenc: use the CPB props side dataAnton Khirnov2015-12-06
| | | | | Do not access the encoder options, since it makes no sense when the AVStream codec context is not the encoding context.
* movenc: add fallback audio track tref supportJohn Stebbins2015-11-18
| | | | | | | | | | | | | This feature allows making associations between audio tracks that apple players recognize. E.g. when an ac3 track has a tref that points to an aac track, devices that don't support ac3 will automatically fall back to the aac track. Apple used to *guess* these associations, but new products (AppleTV 4) no longer guess and this association can only be made explicitly now using the "fall" tref. Signed-off-by: Anton Khirnov <anton@khirnov.net>
* movenc: Allow setting start_dts/start_cts before writing actual packetsMartin Storsjö2015-11-11
| | | | | | | | | | | | | | | | | By writing a zero-sized packet, the caller can communicate the start_dts/start_cts for the stream without actually writing the first packet. This allows doing random-access writing of fragments when the start dts of the stream isn't zero, so that the edit list in the moov is written based on timestamps from the nominal start time signaled via the zero-sized packet, while the first proper packet written corresponds to a later fragment. To avoid potential unexpected behaviour, empty packets only set start_dts if the frag_discont flag is set. Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Assume streams starting at pts=0 for discontinuous fragments with ↵Martin Storsjö2015-11-11
| | | | | | | | | | editlists This allows producing fragments discontinously where the video stream has b-frames (but starts at pts=0), but doesn't work for the cases with audio with preroll. Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Automatically flush after writing the initial moovMartin Storsjö2015-11-10
| | | | | | | | In most other cases when writing fragmented mp4 files, the output IO context is flushed after each fragment. Also flush it after writing the initial moov, to have it behave in the same way. Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Honor flush requests with delay_moov, when some tracks lack samplesMartin Storsjö2015-10-23
| | | | | | | | This also makes sure that a fragmented file without the empty_moov flag (i.e. with a non-empty initial moov fragment) actually gets written, if some of the tracks turn out to not have any samples. Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Add a new flag for writing global sidx indexes for dashMartin Storsjö2015-08-12
| | | | | | | | | | | | | | | | | | | | The double meaning of the faststart flag (moving a moov atom to the start of files, making them streamable, for non-fragmented files, vs inserting a global sidx index at the start of files for fragmented files) is confusing - see 40ed1cbf1 for explanation of its origins. Since the second meaning of the flag hasn't been part of any libav release yet, just rename it to get rid of the confusion without any extra deprecation (which wouldn't get rid of the potential confusion, of users adding -movflags faststart even for fragmented files, where it isn't needed for making them "streamable"). This gets back the old behaviour, where -movflags faststart doesn't have any effect for fragmented files. Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Place the sidx index after the initial moov/mdat pairMartin Storsjö2015-08-10
| | | | | | | | | | For fragmented files with non-empty moov, with a fragment index (sidx), place the index after the initial moov/mdat pair. Previously, for this pathological case, the index was written at the start of the file. Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Rename reserved_moov_pos to reserved_header_posMartin Storsjö2015-08-10
| | | | | | | The same field is also used for writing the sidx index header, for fragmented files, when the faststart flag is used. Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Check that frag_info entries exist in mov_write_sidx_tagMartin Storsjö2015-08-10
| | | | | | | | | | | | | This fixes crashes with pathological cases when trying to write a sidx index (via the -movflags faststart option, in combination with fragmenting options), when no fragments actually have been written. (This is possible if the empty_moov flag isn't used, so that all actual packet data is written in the moov/mdat pair, and no moof/mdat pairs have been written.) In these pathological cases, no sidx should be written at all. Signed-off-by: Martin Storsjö <martin@martin.st>
* lavc: Consistently prefix input buffer definesVittorio Giovara2015-07-27
| | | | Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
* mov: Preserve the metadata even when bit-exactness is requestedLuca Barbato2015-06-30
| | | | | | | Make sure to not write the custom `encoder` string in that case. Bug-Id: 845 CC: libav-stable@libav.org
* movenc: fixes a questionable valgrind uninitialized value warningJanne Grunau2015-06-10
| | | | | | | display_matrix_size is only initialized when av_stream_get_side_data() returns a side data pointer. The code is safe since the only effect this has is setting the display_matrix pointer to NULL which it was already anyway.
* movenc: Write the make and model metadata keys for mov style filesMartin Storsjö2015-03-23
| | | | | | | These are essential allowing QuickTime to keep detecting content as slow-motion - this allows preserving them on stream copy. Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: write the display transform matrixAnton Khirnov2015-03-19
|
* movenc: Don't assume that fragment durations in pts is equal to duration in dtsMartin Storsjö2015-03-19
| | | | | | | | | | | | | For strict CFR, they should be pretty much equal, but if the stream is VFR, there can be a sometimes significant difference. Calculate the pts duration separately, used in sidx atoms and for tfrf/tfxd boxes in smooth streaming ismv files. Also make sure to reduce the duration of sidx entries according to edit lists. Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Move sidx edit list timestamp adjustment into a blockMartin Storsjö2015-03-19
| | | | | | | When reading these values from track->frag_info, the same adjustment has already been done. Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Only adjust the cts offset at the start of fragments if necessaryMartin Storsjö2015-03-19
| | | | | | | | | Adjusting it is only necessary when a sidx/tfrf/tfxd atom already has been written for the previous fragment (since the sidx/tfrf/tfxd atoms include the duration between the first pts of the previous fragment, to the first pts of the new fragment). Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Write pts timestamps in tfxd, instead of dts timestampsMartin Storsjö2015-03-19
| | | | | | This matches what we write in tfra and tfrf since 9cbf70fa0e. Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Set the last packet duration based on the next packet when autoflushingMartin Storsjö2015-03-19
| | | | | | | | | | | | | | | | | | When automatically flushing fragments based on set conditions (fragmentation on keyframes, after some interval or byte size), we already have the next packet for one stream - use this for setting the duration of the last packet in the flushed fragment correctly. This avoids having to adjust the timestamp of the first packet in the new fragment since the last duration was unknown. Unfortunately, this only works for automatic flushing (not for caller-triggered flushing, like in the dash muxer), and only for the one single track that triggered the flushing. The duration of the last sample in all other tracks still is dependent on AVPacket duration (or heuristics). Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Heuristically set the duration of the last sample in a fragment if ↵Martin Storsjö2015-03-19
| | | | | | | | | | | | | | | not set Even if this is a guess, it is way better than writing a zero duration of the last sample in a fragment (because if the duration is zero, the first sample of the next fragment will have the same timestamp as the last sample in the previous one). Since we normally don't require libavformat muxer users to set the duration field in AVPacket, we probably can't strictly require it here either, so don't log this as a strict warning, only as info. Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Allow interleaving samples when writing fragmented filesMartin Storsjö2015-03-16
| | | | | | | | | | | This is incompatible with the omit_tfhd_offset flag (writing position independent fragments with interleaving requires the default_base_moof flag). This makes the moof atoms slightly bigger, but can be better for playback (improving locality of sample data in the mdat). Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Support writing multiple trun atomsMartin Storsjö2015-03-16
| | | | | | | | | This is needed if all the data for one track isn't continuous within the mdat. Normally we make sure all the data for one track is continuous, but in new cases we will need to have the samples interleaved. Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Support setting fragment_index before the moov atom is writtenMartin Storsjö2015-03-10
| | | | | | | | | | This way, the caller doesn't need to coordinate setting the option after the moov atom has been written. The downside is that it is no longer possible to use the option for checking whether the moov atom already has been written, but a caller is able to keep track of that by other means anyway. Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Don't rely on the fragment index for vc1 info gatheringMartin Storsjö2015-03-10
| | | | | | | | The previous use of the mov->fragments field, for determining whether written packets were part of the first fragment or not, didn't work as intended when using the empty_moov flag. Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Avoid writing separate flags for the first sample if not necessaryMartin Storsjö2015-03-09
| | | | Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Set tfhd default sample flags based on actual samples, if possibleMartin Storsjö2015-03-09
| | | | | | | | | | This avoids assuming that e.g. audio samples are marked as sync samples. This allows omitting the sample flags from trun, if the default flags happen to be right for all the samples. Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Keep writing zero-entry stts atoms as intendedMartin Storsjö2015-03-06
| | | | | | | | a876585215 had the unintended side effect of returning AVERROR(ENOMEM) when track->entry is zero, while the code intentionally wants to continue in that case. Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Check memory allocationsHugo Beauzée-Luyssen2015-02-17
| | | | Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
* movenc: Fix a typo in a commentMartin Storsjö2015-01-06
| | | | Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Readd an accidentally removed conditionMartin Storsjö2015-01-06
| | | | | | | This was removed accidentally as part of 847bf598. This could cause groundless warning logging. Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Enable editlists by default if delay_moov is enabledMartin Storsjö2015-01-04
| | | | | | | Being able to write editlists properly is one of the main points in the delay_moov flag. Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Get rid of a hack for updating the dvc1 atomMartin Storsjö2015-01-03
| | | | | | | Use the more generic approach with the delay_moov flag, instead of having a update mechanism specific to this one single atom. Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Add an option for delaying writing the moov with empty_moovMartin Storsjö2015-01-03
| | | | | | | | | | | | | | | | | | | | | | | | | This delays writing the moov until the first fragment is written, or can be flushed by the caller explicitly when wanted. If the first sample in all streams is available at this point, we can write a proper editlist at this point, allowing streams to start at something else than dts=0. For AC3 and DNXHD, a packet is needed in order to write the moov header properly. This isn't added to the normal behaviour for empty_moov, since the behaviour that ftyp+moov is written during avformat_write_header would be changed. Callers that split the output stream into header+segments (either by flushing manually, with the custom_frag flag set, or by just differentiating between data written during avformat_write_header and the rest) will need to be adjusted to take this option into use. For handling streams that start at something else than dts=0, an alternative would be to use different kinds of heuristics for guessing the start dts (using AVCodecContext delay or has_b_frames together with the frame rate), but this is not reliable and doesn't necessarily work well with stream copy, and wouldn't work for getting the right initialization data for AC3 or DNXHD either. Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Use start_dts/cts instead of cluster[0] for writing edit listsMartin Storsjö2015-01-03
| | | | | | | This allows writing edit lists even when track->entry == 0, if the start times have been set. Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Remove an unnecessary condition when flushing fragmentsMartin Storsjö2015-01-03
| | | | | | | | | | | If fragments == 0 it means we haven't written any moov atom yet. If the empty_moov flag is set, we already have written an empty moov atom at startup. Thus, the check for empty_moov is redundant. This is in preparation for allowing writing the moov atom later, even when using the empty moov flag. Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Factorize writing ftyp and other identification tags to a separate ↵Martin Storsjö2015-01-03
| | | | | | function Signed-off-by: Martin Storsjö <martin@martin.st>