summaryrefslogtreecommitdiff
path: root/libavformat/movenc.c
Commit message (Collapse)AuthorAge
* 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>
* movenc: Adjust the pts of new fragments similarly to what is done for dtsMartin Storsjö2014-12-18
| | | | | | | The pts and the corresponding duration is written in sidx atoms, thus make sure these match up correctly. Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Expose the fragment index as an avoptionMartin Storsjö2014-11-26
| | | | | | | | This allows setting the right fragment number if doing random-access writing of fragments, and also allows reading the current sequence number. Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Add a flag for indicating a discontinuous fragmentMartin Storsjö2014-11-26
| | | | | | | | | | | | | | | | | | | | | | | This allows creating a later mp4 fragment without sequentially writing the earlier ones before (when called from a segmenter). Normally when writing a fragmented mp4 file sequentially, the first timestamps of a fragment are adjusted to match the end of the previous fragment, to make sure the timestamp is the same, even if it is calculated as the sum of previous fragment durations. (And for the first packet in a file, the offset of the first packet is written using an edit list.) When writing an individual mp4 fragment discontinuously like this (with potentially writing the earlier fragments separately later), there's a risk of getting a gap in the timeline if the duration field of the last packet in the previous fragment doesn't match up with the start time of the next fragment. Using this requires setting -avoid_negative_ts make_non_negative (or -avoid_negative_ts 0). Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Allow writing a DASH sidx atom at the start of filesMartin Storsjö2014-11-17
| | | | | | | | | | | | | | | | | This is mapped to the faststart flag (which in this case perhaps should be called "shift and write index at the start of the file"), which for fragmented files will write a sidx index at the start. When segmenting DASH into files, there's usually one sidx at the start of each segment (although it's not clear to me whether that actually is necessary). When storing all of it in one file, the MPD doesn't necessarily need to describe the individual segments, but the offsets of the fragments can be fetched from one large sidx atom at the start of the file. This allows creating files for the DASH ISO BMFF on-demand profile. Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Add tfra entries for all tracks in a moofMartin Storsjö2014-11-17
| | | | | | | | | | | | | | Previously only tfra entries were added for the first track in each moof. The frag_info array used for tfra can also be used for writing other kinds of fragment indexes, where it's more important to include all tracks. When the separate_moof option is enabled (as in ismv), we write a separate moof for each track, so this doesn't make any difference in that case. Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Add support for writing sidx atoms for DASH segmentsMartin Storsjö2014-11-17
| | | | | | | | | | A flag "dash" is added, which enables the necessary flags for creating DASH compatible fragments. When this is enabled, one sidx atom is written for each track before every moof atom. Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Factorize adding fragment info into a separate functionMartin Storsjö2014-11-17
| | | | | | | | By calling this after writing the moof the first time (for calculating the moof size), we can avoid intermediate storage of tfrf_offset in MOVTrack. Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Include empty tracks in iods when writing fragmented mp4Martin Storsjö2014-11-17
| | | | | | | | | When writing fragmented streams with an empty initial moov, we won't have any samples in any tracks when writing the moov atom, thus trust that any tracks that are added actually will be present. Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Require samples before trying to write edtsMartin Storsjö2014-11-08
| | | | | | | This avoids a potential crash if writing a fragmented psp mp4 (which probably is only a hypothetical scenario). Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Avoid leaking locally allocated data when returning on errorsMartin Storsjö2014-11-08
| | | | Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Remove an outdated commentMartin Storsjö2014-11-08
| | | | | | | QuickTime does support files with an empty initial movie these days. Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Write correct presentation timestamps in tfraMartin Storsjö2014-11-07
| | | | | | | Previously we wrote decoding timestamps here, while the specs say it should be presentation timestamps. Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Remove a now redundant checkMartin Storsjö2014-11-07
| | | | | | | | | | When using the new first_trun flag instead of checking the track id, we don't need to have a special case for the separate_moof flag any longer. This simplifies the complicated codepath ever so slightly. Signed-off-by: Martin Storsjö <martin@martin.st>