summaryrefslogtreecommitdiff
path: root/libavformat/movenc.c
Commit message (Collapse)AuthorAge
* 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>
* movenc: Allow to request not to use edit listsMartin Storsjö2014-11-07
| | | | | | | | | | | | | | | | | | | In this case, shift tracks to start from zero instead (potentially stretching the first sample in tracks that start later than the first one). Some software does not support edit lists at all, the adobe flash player seems to be one of these. This results in AV sync errors when edit lists are used to adjust AV sync. Some players, such as QuickTime, don't respect the duration for audio packets, so if an audio track starts later than the video track and the first audio sample gets a duration longer than the actual amount of data in it, the result will be out of sync. Based on patches by Michael Niedermayer. Signed-off-by: Martin Storsjö <martin@martin.st>
* lavf: use the format context strict_std_compliance instead of the codec oneAnton Khirnov2014-11-06
|
* movenc: Don't write any iso brands in ismv filesMartin Storsjö2014-10-30
| | | | | | We deviate slightly from the iso specs for these files. Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Don't write any tfdt atom for ismv filesMartin Storsjö2014-10-30
| | | | | | | | | The tfdt atom shouldn't be needed in those cases, we already write tfxd atoms for ismv anyway, which is roughly equivalent. This avoids having to declare the iso6 brand for ismv files. Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Write a 0 duration in mdhd and tkhd for an empty initial moovMartin Storsjö2014-10-30
| | | | | | | | | | | | | | ISO/IEC 14496-12:2012/Cor 1:2013 is explicit about how this should be handled. All zeros doesn't mean that the full file has got a zero duration, only that the track samples described within the initial moov have got zero duration. An all ones duration means an indeterminate duration. Keep writing a duration consisting of all ones for the ISM mode - older windows media player versions won't play a file if this is zero. (Newer windows media player versions play either version fine.) Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Add a flag for using default-base-is-moof in tfhd atomsMartin Storsjö2014-10-29
| | | | | | | | | | | | Similarly to the omit_tfhd_offset flag added in e7bf085b, this avoids writing absolute byte positions to the file, making them more easily streamable. This is a new feature from 14496-12:2012, so application support isn't necessarily too widespread yet (support for it in libav was added in 20f95f21f in July 2014). Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Signal iso6 in compatible_brands when using tfdtMartin Storsjö2014-10-29
| | | | Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Use a local variable consistentlyMartin Storsjö2014-10-29
| | | | Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Don't check the custom IO flag when using faststartMartin Storsjö2014-10-29
| | | | | | | | The custom IO flag actually never is set for muxers, only for demuxers, so the check was pointless (unless a user intentionally would set the flag to signal using custom IO). Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Don't use track_id to decide which track is the first in a moofMartin Storsjö2014-10-29
| | | | | | | | | | If one track doesn't have any samples within a moof, no traf/trun is written for it. When the omit_tfhd_offset flag is set, none of the tfhd atoms have any base_data_offset set, and the implicit offset (end of previous track fragment data, or start of the moof for the first trun) is used. Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Write tfdt atomsMartin Storsjö2014-10-14
| | | | | | | | | | | These allow getting the absolute start timestamp of a fragment without reading preceding timestamps. This fixes sync between tracks if starting from fragments in different streams that don't align exactly. This also is a prerequisite for producing DASH content. Signed-off-by: Martin Storsjö <martin@martin.st>
* movenc: Simplify code by using an existing local pointerMartin Storsjö2014-10-12
| | | | Signed-off-by: Martin Storsjö <martin@martin.st>