libgpac
Documentation of the core library of GPAC
|
Macros | |
#define | GF_ISOM_FRAG_DEF_IS_SYNC 1 |
#define | GF_ISOM_FRAG_USE_SYNC_TABLE (1<<1) |
Enumerations | |
enum | GF_ISOStartFragmentFlags { GF_ISOM_FRAG_MOOF_FIRST = 1 } |
enum | GF_ISOTrackFragmentOption { GF_ISOM_TRAF_EMPTY , GF_ISOM_TRAF_RANDOM_ACCESS , GF_ISOM_TRAF_DATA_CACHE , GF_ISOM_TFHD_FORCE_MOOF_BASE_OFFSET , GF_ISOM_TRAF_USE_SAMPLE_DEPS_BOX , GF_ISOM_TRUN_FORCE , GF_ISOM_TRUN_SET_INTERLEAVE_ID , GF_ISOM_TRAF_TRUNS_FIRST , GF_ISOM_TRAF_TRUN_V1 , GF_ISOM_TRAF_USE_LARGE_TFDT } |
Functions | |
GF_Err | gf_isom_setup_track_fragment (GF_ISOFile *isom_file, GF_ISOTrackID TrackID, u32 DefaultSampleDescriptionIndex, u32 DefaultSampleDuration, u32 DefaultSampleSize, u8 DefaultSampleSyncFlags, u8 DefaultSamplePadding, u16 DefaultDegradationPriority, Bool force_traf_flags) |
GF_Err | gf_isom_change_track_fragment_defaults (GF_ISOFile *isom_file, GF_ISOTrackID TrackID, u32 DefaultSampleDescriptionIndex, u32 DefaultSampleDuration, u32 DefaultSampleSize, u8 DefaultSampleIsSync, u8 DefaultSamplePadding, u16 DefaultDegradationPriority, u8 force_traf_flags) |
GF_Err | gf_isom_finalize_for_fragment (GF_ISOFile *isom_file, u32 media_segment_type, Bool mvex_after_tracks) |
GF_Err | gf_isom_set_movie_duration (GF_ISOFile *isom_file, u64 duration, Bool remove_mehd) |
GF_Err | gf_isom_start_fragment (GF_ISOFile *isom_file, GF_ISOStartFragmentFlags moof_first) |
GF_Err | gf_isom_start_segment (GF_ISOFile *isom_file, const char *SegName, Bool memory_mode) |
GF_Err | gf_isom_set_traf_base_media_decode_time (GF_ISOFile *isom_file, GF_ISOTrackID TrackID, u64 decode_time) |
GF_Err | gf_isom_enable_mfra (GF_ISOFile *isom_file) |
GF_Err | gf_isom_set_traf_mss_timeext (GF_ISOFile *isom_file, GF_ISOTrackID reference_track_ID, u64 decode_traf_time, u64 traf_duration) |
GF_Err | gf_isom_close_segment (GF_ISOFile *isom_file, s32 subsegs_per_sidx, GF_ISOTrackID referenceTrackID, u64 ref_track_decode_time, s32 timestamp_shift, u64 ref_track_next_cts, Bool daisy_chain_sidx, Bool use_ssix, Bool last_segment, Bool close_segment_handle, u32 segment_marker_4cc, u64 *index_start_range, u64 *index_end_range, u64 *out_seg_size) |
GF_Err | gf_isom_flush_fragments (GF_ISOFile *isom_file, Bool last_segment) |
GF_Err | gf_isom_set_fragment_reference_time (GF_ISOFile *isom_file, GF_ISOTrackID reference_track_ID, u64 ntp, u64 timestamp) |
GF_Err | gf_isom_allocate_sidx (GF_ISOFile *isom_file, s32 subsegs_per_sidx, Bool daisy_chain_sidx, u32 nb_segs, u32 *frags_per_segment, u32 *start_range, u32 *end_range, Bool use_ssix) |
GF_Err | gf_isom_setup_track_fragment_template (GF_ISOFile *isom_file, GF_ISOTrackID TrackID, u8 *boxes, u32 boxes_size, u8 force_traf_flags) |
GF_Err | gf_isom_set_fragment_original_duration (GF_ISOFile *isom_file, GF_ISOTrackID TrackID, u32 orig_dur, u32 elapsed_dur) |
GF_Err | gf_isom_set_fragment_option (GF_ISOFile *isom_file, GF_ISOTrackID TrackID, GF_ISOTrackFragmentOption Code, u32 param) |
GF_Err | gf_isom_fragment_add_sample (GF_ISOFile *isom_file, GF_ISOTrackID TrackID, const GF_ISOSample *sample, u32 sampleDescriptionIndex, u32 Duration, u8 PaddingBits, u16 DegradationPriority, Bool redundantCoding) |
GF_Err | gf_isom_fragment_append_data (GF_ISOFile *isom_file, GF_ISOTrackID TrackID, u8 *data, u32 data_size, u8 PaddingBits) |
GF_Err | gf_isom_fragment_set_cenc_sai (GF_ISOFile *isom_file, GF_ISOTrackID trackID, u8 *sai_b, u32 sai_b_size, Bool use_subsample, Bool use_saio_32bit, Bool use_multikey) |
GF_Err | gf_isom_clone_pssh (GF_ISOFile *dst_file, GF_ISOFile *src_file, Bool in_moof) |
GF_Err | gf_isom_fragment_set_sample_roll_group (GF_ISOFile *isom_file, GF_ISOTrackID trackID, u32 sample_number, GF_ISOSampleRollType roll_type, s16 roll_distance) |
GF_Err | gf_isom_fragment_set_sample_rap_group (GF_ISOFile *isom_file, GF_ISOTrackID trackID, u32 sample_number_in_frag, Bool is_rap, u32 num_leading_samples) |
GF_Err | gf_isom_fragment_set_sample_flags (GF_ISOFile *isom_file, GF_ISOTrackID trackID, u32 is_leading, u32 dependsOn, u32 dependedOn, u32 redundant) |
GF_Err | gf_isom_fragment_set_sample_aux_info (GF_ISOFile *isom_file, u32 trackID, u32 sample_number_in_frag, u32 aux_type, u32 aux_info, u8 *data, u32 size) |
void | gf_isom_set_next_moof_number (GF_ISOFile *isom_file, u32 value) |
Movie Fragments Writing API Movie Fragments is a feature of ISO media files for fragmentation of a presentation meta-data and interleaving with its media data. This enables faster http fast start for big movies, and also reduces the risk of data loss in case of a recording crash, because meta data and media data can be written to disk at regular times This API provides simple function calls to setup such a movie and write it The process implies: 1- creating a movie in the usual way (track, stream descriptions, (IOD setup copyright, ...) 2- possibly add some samples in the regular fashion 3- setup track fragments for all track that will be written in a fragmented way (note that you can create/write a track that has no fragmentation at all) 4- finalize the movie for fragmentation (this will flush all meta-data and any media-data added to disk, ensuring all vital information for the presentation is stored on file and not lost in case of crash/poweroff) then 5-6 as often as desired 5- start a new movie fragment 6- add samples to each setup track
IMPORTANT NOTES: Movie Fragments can only be used in GF_ISOM_OPEN_WRITE mode (capturing) and no editing functionalities can be used the fragmented movie API uses TrackID and not TrackNumber
#define GF_ISOM_FRAG_DEF_IS_SYNC 1 |
flag indicating default samples are sync
#define GF_ISOM_FRAG_USE_SYNC_TABLE (1<<1) |
flag indicating a sync sample table shall be added in the track - cf CMAF rules
Track fragment options
GF_Err gf_isom_setup_track_fragment | ( | GF_ISOFile * | isom_file, |
GF_ISOTrackID | TrackID, | ||
u32 | DefaultSampleDescriptionIndex, | ||
u32 | DefaultSampleDuration, | ||
u32 | DefaultSampleSize, | ||
u8 | DefaultSampleSyncFlags, | ||
u8 | DefaultSamplePadding, | ||
u16 | DefaultDegradationPriority, | ||
Bool | force_traf_flags | ||
) |
sets up a track for fragmentation by specifying some default values for storage efficiency
isom_file | the target ISO file |
TrackID | ID of the target track |
DefaultSampleDescriptionIndex | the default description used by samples in this track |
DefaultSampleDuration | default duration of samples in this track |
DefaultSampleSize | default size of samples in this track (0 if unknown) |
DefaultSampleSyncFlags | combination of GF_ISOM_FRAG_* flags |
DefaultSamplePadding | default padding bits for samples in this track |
DefaultDegradationPriority | default degradation priority for samples in this track |
force_traf_flags | if GF_TRUE, will ignore these default in each traf but will still write them in moov |
GF_Err gf_isom_change_track_fragment_defaults | ( | GF_ISOFile * | isom_file, |
GF_ISOTrackID | TrackID, | ||
u32 | DefaultSampleDescriptionIndex, | ||
u32 | DefaultSampleDuration, | ||
u32 | DefaultSampleSize, | ||
u8 | DefaultSampleIsSync, | ||
u8 | DefaultSamplePadding, | ||
u16 | DefaultDegradationPriority, | ||
u8 | force_traf_flags | ||
) |
changes the default parameters of an existing trak fragment
isom_file | the target ISO file |
TrackID | ID of the target track |
DefaultSampleDescriptionIndex | the default description used by samples in this track |
DefaultSampleDuration | default duration of samples in this track |
DefaultSampleSize | default size of samples in this track (0 if unknown) |
DefaultSampleIsSync | default key-flag (RAP) of samples in this track |
DefaultSamplePadding | default padding bits for samples in this track |
DefaultDegradationPriority | default degradation priority for samples in this track |
force_traf_flags | if GF_TRUE, will ignore these default in each traf but will still write them in moov |
GF_Err gf_isom_finalize_for_fragment | ( | GF_ISOFile * | isom_file, |
u32 | media_segment_type, | ||
Bool | mvex_after_tracks | ||
) |
flushes data to disk and prepare movie fragmentation
isom_file | the target ISO file |
media_segment_type | 0 if no segments, 1 if regular segment, 2 if single segment |
mvex_after_tracks | forces writing mvex box after track boxes |
GF_Err gf_isom_set_movie_duration | ( | GF_ISOFile * | isom_file, |
u64 | duration, | ||
Bool | remove_mehd | ||
) |
sets the duration of the movie in case of movie fragments
isom_file | the target ISO file |
duration | the complete duration (movie and all fragments) in movie timescale |
remove_mehd | force removal of mehd box, only setting mvhd.duration to 0 |
GF_Err gf_isom_start_fragment | ( | GF_ISOFile * | isom_file, |
GF_ISOStartFragmentFlags | moof_first | ||
) |
starts a new movie fragment
isom_file | the target ISO file |
moof_first | if GF_TRUE, the moof will be written before the mdat |
GF_Err gf_isom_start_segment | ( | GF_ISOFile * | isom_file, |
const char * | SegName, | ||
Bool | memory_mode | ||
) |
starts a new segment in the file
isom_file | the target ISO file |
SegName | if not NULL, the output will be written in the SegName file. If NULL, segment will be created in same file as movie. The special name "_gpac_isobmff_redirect" is used to indicate that segment shall be written to a memory buffer passed to callback function set through gf_isom_set_write_callback |
memory_mode | if set, all samples writing is done in memory rather than on disk. Ignored in callback mode |
GF_Err gf_isom_set_traf_base_media_decode_time | ( | GF_ISOFile * | isom_file, |
GF_ISOTrackID | TrackID, | ||
u64 | decode_time | ||
) |
sets the baseMediaDecodeTime of the first sample of the given track
isom_file | the target ISO file |
TrackID | ID of the target track |
decode_time | the decode time in media timescale |
GF_Err gf_isom_enable_mfra | ( | GF_ISOFile * | isom_file | ) |
enables mfra (movie fragment random access computing) when writing movie fragments
isom_file | the target ISO file |
GF_Err gf_isom_set_traf_mss_timeext | ( | GF_ISOFile * | isom_file, |
GF_ISOTrackID | reference_track_ID, | ||
u64 | decode_traf_time, | ||
u64 | traf_duration | ||
) |
sets Microsoft Smooth Streaming traf 'tfxd' box info, written at the end of each traf
isom_file | the target ISO file |
reference_track_ID | ID of the reference track giving the media timescale |
decode_traf_time | decode time of the first sample in the segment in media timescale (hardcoded to 10MHz in Smooth) |
traf_duration | duration of all samples in the traf in media timescale (hardcoded to 10MHz in Smooth) |
GF_Err gf_isom_close_segment | ( | GF_ISOFile * | isom_file, |
s32 | subsegs_per_sidx, | ||
GF_ISOTrackID | referenceTrackID, | ||
u64 | ref_track_decode_time, | ||
s32 | timestamp_shift, | ||
u64 | ref_track_next_cts, | ||
Bool | daisy_chain_sidx, | ||
Bool | use_ssix, | ||
Bool | last_segment, | ||
Bool | close_segment_handle, | ||
u32 | segment_marker_4cc, | ||
u64 * | index_start_range, | ||
u64 * | index_end_range, | ||
u64 * | out_seg_size | ||
) |
closes current segment, producing a segment index box if desired
isom_file | the target ISO file |
subsegs_per_sidx | number of subsegments per sidx box; a negative value disables sidx, 0 forces a single sidx for the segment (or subsegment) |
referenceTrackID | the ID of the track used as a reference for the segment index box |
ref_track_decode_time | the decode time fo the first sample in the reference track for this segment |
timestamp_shift | the constant difference between media time and presentation time (derived from edit list) |
ref_track_next_cts | the CTS of the first sample in the reference track in the next segment |
daisy_chain_sidx | if GF_TRUE, indicates chained sidx shall be used. Otherwise, an array of indexes is used |
use_ssix | if GF_TRUE, produces an ssix box using I-frames as first level and all other frames as second level |
last_segment | indicates if this is the last segment of the session |
close_segment_handle | if set to GF_TRUE, the associated file if any will be closed |
segment_marker_4cc | a four character code used to insert an empty box at the end of the saegment with the given type. If 0, no such box is inserted |
index_start_range | set to the start offset in bytes of the segment in the media file |
index_end_range | set to the end offset in bytes of the segment in the media file |
out_seg_size | set to the segment size in bytes (optional, can be NULL) |
GF_Err gf_isom_flush_fragments | ( | GF_ISOFile * | isom_file, |
Bool | last_segment | ||
) |
writes any pending fragment to file for low-latency output.
isom_file | the target ISO file |
last_segment | indicates if this is the last segment of the session |
GF_Err gf_isom_set_fragment_reference_time | ( | GF_ISOFile * | isom_file, |
GF_ISOTrackID | reference_track_ID, | ||
u64 | ntp, | ||
u64 | timestamp | ||
) |
sets fragment prft box info, written just before the moof
isom_file | the target ISO file |
reference_track_ID | the ID of the track used as a reference for media timestamps |
ntp | absolute NTP time |
timestamp | media time corresponding to the NTP time, in reference track media timescale |
GF_Err gf_isom_allocate_sidx | ( | GF_ISOFile * | isom_file, |
s32 | subsegs_per_sidx, | ||
Bool | daisy_chain_sidx, | ||
u32 | nb_segs, | ||
u32 * | frags_per_segment, | ||
u32 * | start_range, | ||
u32 * | end_range, | ||
Bool | use_ssix | ||
) |
writes an empty sidx in the current movie.
The SIDX will be forced to have nb_segs entries, and nb_segs shall match the number of calls to gf_isom_close_segment that will follow. This avoids wasting time and disk space moving data around. Once gf_isom_close_segment has then been called nb_segs times, the pre-allocated SIDX is destroyed and successive calls to gf_isom_close_segment will create their own sidx, unless gf_isom_allocate_sidx is called again.
isom_file | the target ISO file |
subsegs_per_sidx | reserved to 0, currently ignored |
daisy_chain_sidx | reserved to 0, currently ignored |
nb_segs | number of entries in the segment index |
frags_per_segment | reserved, currently ignored |
start_range | set to the start offset in bytes of the segment index box |
end_range | set to the end offset in bytes of the segment index box |
use_ssix | if GF_TRUE, produces an ssix box using I-frames as first level and all other frames as second level |
GF_Err gf_isom_setup_track_fragment_template | ( | GF_ISOFile * | isom_file, |
GF_ISOTrackID | TrackID, | ||
u8 * | boxes, | ||
u32 | boxes_size, | ||
u8 | force_traf_flags | ||
) |
sets up track fragment defaults using the given template. The template shall be a serialized array of one or more trex boxes
isom_file | the target ISO file |
TrackID | ID of the target track |
boxes | serialized array of trex boxes |
boxes_size | size of the serialized array |
force_traf_flags | if GF_TRUE, will ignore these default in each traf but will still write them in moov |
GF_Err gf_isom_set_fragment_original_duration | ( | GF_ISOFile * | isom_file, |
GF_ISOTrackID | TrackID, | ||
u32 | orig_dur, | ||
u32 | elapsed_dur | ||
) |
sets up track fragment defaults using the given template. The template shall be a serialized array of one or more trex boxes
isom_file | the target ISO file |
TrackID | ID of the target track |
orig_dur | last sample original duration |
elapsed_dur | first sample elapsed duration |
GF_Err gf_isom_set_fragment_option | ( | GF_ISOFile * | isom_file, |
GF_ISOTrackID | TrackID, | ||
GF_ISOTrackFragmentOption | Code, | ||
u32 | param | ||
) |
sets a track fragment option. Options can be set at the beginning of each new fragment only, and for the lifetime of the fragment
isom_file | the target ISO file |
TrackID | ID of the target track |
Code | the option type to set |
param | the option value |
GF_Err gf_isom_fragment_add_sample | ( | GF_ISOFile * | isom_file, |
GF_ISOTrackID | TrackID, | ||
const GF_ISOSample * | sample, | ||
u32 | sampleDescriptionIndex, | ||
u32 | Duration, | ||
u8 | PaddingBits, | ||
u16 | DegradationPriority, | ||
Bool | redundantCoding | ||
) |
adds a sample to a fragmented track
isom_file | the target ISO file |
TrackID | destination track |
sample | sample to add |
sampleDescriptionIndex | sample description for this sample. If 0, the default one is used |
Duration | sample duration; the sample duration MUST be provided at least for the last sample (for intermediate samples, it is recomputed internally by the lib) |
PaddingBits | padding bits for the sample, or 0 |
DegradationPriority | for the sample, or 0 |
redundantCoding | indicates this is samples acts as a sync shadow point |
GF_Err gf_isom_fragment_append_data | ( | GF_ISOFile * | isom_file, |
GF_ISOTrackID | TrackID, | ||
u8 * | data, | ||
u32 | data_size, | ||
u8 | PaddingBits | ||
) |
appends data into last sample of track for video fragments/other media
isom_file | the target ISO file |
TrackID | destination track |
data | the data to append |
data_size | the size of the data to append |
PaddingBits | padding bits for the sample, or 0 |
GF_Err gf_isom_fragment_set_cenc_sai | ( | GF_ISOFile * | isom_file, |
GF_ISOTrackID | trackID, | ||
u8 * | sai_b, | ||
u32 | sai_b_size, | ||
Bool | use_subsample, | ||
Bool | use_saio_32bit, | ||
Bool | use_multikey | ||
) |
sets side information for common encryption for the last added sample
isom_file | the target ISO file |
trackID | the ID of the target track |
sai_b | buffer containing the SAI information of the sample |
sai_b_size | size of the SAI buffer. If sai_b is NULL or sai_b_size is 0, add a clear SAI data |
use_subsample | indicates if the media uses CENC subsamples |
use_saio_32bit | indicates if 32-bit saio shall be used |
use_multikey | indicates if multikey is in use (required to tag saiz/saio boxes) |
GF_Err gf_isom_clone_pssh | ( | GF_ISOFile * | dst_file, |
GF_ISOFile * | src_file, | ||
Bool | in_moof | ||
) |
clones PSSH data between two files
dst_file | the target ISO file |
src_file | the source ISO file |
in_moof | if GF_TRUE, indicates the pssh should be cloned in current moof box |
GF_Err gf_isom_fragment_set_sample_roll_group | ( | GF_ISOFile * | isom_file, |
GF_ISOTrackID | trackID, | ||
u32 | sample_number, | ||
GF_ISOSampleRollType | roll_type, | ||
s16 | roll_distance | ||
) |
sets roll information for a sample in a track fragment
isom_file | the target ISO file |
trackID | the ID of the target track |
sample_number | the sample number of the last sample |
roll_type | indicate the sample roll type |
roll_distance | set to the roll distance for a roll sample |
GF_Err gf_isom_fragment_set_sample_rap_group | ( | GF_ISOFile * | isom_file, |
GF_ISOTrackID | trackID, | ||
u32 | sample_number_in_frag, | ||
Bool | is_rap, | ||
u32 | num_leading_samples | ||
) |
sets rap information for a sample in a track fragment
isom_file | the target ISO file |
trackID | the ID of the target track |
sample_number_in_frag | the sample number of the sample in the traf |
is_rap | set to GF_TRUE to indicate the sample is a RAP sample (open-GOP), GF_FALSE otherwise |
num_leading_samples | set to the number of leading pictures for a RAP sample |
GF_Err gf_isom_fragment_set_sample_flags | ( | GF_ISOFile * | isom_file, |
GF_ISOTrackID | trackID, | ||
u32 | is_leading, | ||
u32 | dependsOn, | ||
u32 | dependedOn, | ||
u32 | redundant | ||
) |
sets sample dependency flags in a track fragment - see ISO/IEC 14496-12 and gf_filter_pck_set_dependency_flags
isom_file | the target ISO file |
trackID | the ID of the target track |
is_leading | indicates that the sample is a leading picture |
dependsOn | indicates the sample dependency towards other samples |
dependedOn | indicates the sample dependency from other samples |
redundant | indicates that the sample contains redundant coding |
GF_Err gf_isom_fragment_set_sample_aux_info | ( | GF_ISOFile * | isom_file, |
u32 | trackID, | ||
u32 | sample_number_in_frag, | ||
u32 | aux_type, | ||
u32 | aux_info, | ||
u8 * | data, | ||
u32 | size | ||
) |
adds sample auxiliary data
isom_file | the target ISO file |
trackID | the ID of the target track |
sample_number_in_frag | the sample number in the current fragment. Must be equal or larger to last auxiliary added |
aux_type | auxiliary sample data type, shall not be 0 |
aux_info | auxiliary sample data specific info type, may be 0 |
data | data to add |
size | size of data to add |
void gf_isom_set_next_moof_number | ( | GF_ISOFile * | isom_file, |
u32 | value | ||
) |
sets the number of the next moof to be produced
isom_file | the target ISO file |
value | the number of the next moof |