libheif
heif_sequences.h
Go to the documentation of this file.
1 /*
2  * HEIF codec.
3  * Copyright (c) 2025 Dirk Farin <dirk.farin@gmail.com>
4  *
5  * This file is part of libheif.
6  *
7  * libheif is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation, either version 3 of
10  * the License, or (at your option) any later version.
11  *
12  * libheif is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with libheif. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef LIBHEIF_HEIF_SEQUENCES_H
22 #define LIBHEIF_HEIF_SEQUENCES_H
23 
24 #include "libheif/heif.h"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 // forward declaration of structs defined in heif_tai_timestamps.h
33 
34 
35 // --- reading sequence tracks
36 
42 LIBHEIF_API
44 
52 LIBHEIF_API
54 
61 LIBHEIF_API
63 
64 
65 // A track, which may be an image sequence, a video track or a metadata track.
66 typedef struct heif_track heif_track;
67 
72 LIBHEIF_API
74 
80 LIBHEIF_API
82 
92 LIBHEIF_API
93 void heif_context_get_track_ids(const heif_context* ctx, uint32_t out_track_id_array[]);
94 
99 LIBHEIF_API
100 uint32_t heif_track_get_id(const heif_track* track);
101 
112 // Use id=0 for the first visual track.
113 LIBHEIF_API
115 
116 
117 typedef uint32_t heif_track_type;
118 
120 {
121  heif_track_type_video = heif_fourcc('v', 'i', 'd', 'e'),
123  heif_track_type_auxiliary = heif_fourcc('a', 'u', 'x', 'v'),
124  heif_track_type_metadata = heif_fourcc('m', 'e', 't', 'a')
126 
134 LIBHEIF_API
136 
137 
139 {
143 
144 LIBHEIF_API
146 
147 LIBHEIF_API
149 
150 LIBHEIF_API
152 
159 LIBHEIF_API
161 
167 #define heif_sequence_track_number_of_repetitions_infinite 0xFFFFFFFFu
168 
194 LIBHEIF_API
196 
197 
198 // --- reading visual tracks
199 
204 LIBHEIF_API
205 heif_error heif_track_get_image_resolution(const heif_track*, uint16_t* out_width, uint16_t* out_height);
206 
217 LIBHEIF_API
219  heif_image** out_img,
220  heif_colorspace colorspace,
221  heif_chroma chroma,
222  const heif_decoding_options* options);
223 
228 LIBHEIF_API
229 uint32_t heif_image_get_duration(const heif_image*);
230 
231 
232 // --- reading metadata track samples
233 
239 LIBHEIF_API
241 
248 LIBHEIF_API
250  const char** out_uri);
251 
252 
257 
262 LIBHEIF_API
264  heif_raw_sequence_sample** out_sample);
265 
270 LIBHEIF_API
272 
279 LIBHEIF_API
280 const uint8_t* heif_raw_sequence_sample_get_data(const heif_raw_sequence_sample*, size_t* out_array_size);
281 
286 LIBHEIF_API
288 
293 LIBHEIF_API
295 
296 
297 // --- writing sequences
298 
303 LIBHEIF_API
305 
306 // Number of times the sequence should be played in total (default = 1).
307 // Can be set to heif_sequence_maximum_number_of_repetitions.
308 LIBHEIF_API
309 void heif_context_set_number_of_sequence_repetitions(heif_context*, uint32_t number_of_repetitions);
310 
311 #define heif_sequence_maximum_number_of_repetitions 0
312 
319 {
324 
325 
327 
332 LIBHEIF_API
334 
335 LIBHEIF_API
337 
343 LIBHEIF_API
345 
358 LIBHEIF_API
360 
361 LIBHEIF_API
363  const heif_tai_clock_info*,
365 
366 LIBHEIF_API
369 
374 LIBHEIF_API
376  const char* track_id);
377 
378 
379 // --- writing visual tracks
380 
382 {
383  // Only independently decodable keyframes.
385 
386  // No frame reordering, usually an IPPPP structure.
388 
389  // All frame types are allowed, including frame reordering, to achieve
390  // the best compression ratio.
393 
394 
395 // Describes the intent of the encoded sequence content. Encoder plugins may
396 // use this to choose different default tunings (e.g. perceptual quality vs.
397 // rate-distortion) for slide-show-style image sequences vs. video.
398 //
399 // Pass `_auto` to let libheif pick a value. Today libheif derives the kind
400 // from the track's handler type (`pict` -> image_sequence, `vide` -> video);
401 // in the future it may use additional input signals (e.g. frame rate or
402 // frame-to-frame similarity). Plugins never see `_auto`: libheif resolves it
403 // to a concrete kind before passing the options to the encoder plugin.
405 {
410 
411 
413 {
414  uint8_t version;
415 
416  // version 1 options
417 
418  // Set this to the NCLX parameters to be used in the output images or set to NULL
419  // when the same parameters as in the input images should be used.
420  const heif_color_profile_nclx* output_nclx_profile;
421 
422  heif_color_conversion_options color_conversion_options;
423 
424  // version 2 options
425 
427  int keyframe_distance_min; // 0 - undefined
428  int keyframe_distance_max; // 0 - undefined
429 
431 
432  // version 3 options
433 
434  // Intent of the encoded content. Encoder plugins may use this to choose
435  // different tunings for slide-show-style image sequences vs. video.
436  // Set to `_auto` (the default) to let libheif pick. libheif resolves the
437  // value to a concrete kind before passing the options to the encoder
438  // plugin, so plugins never see `_auto`.
441 
442 
443 LIBHEIF_API
445 
453 LIBHEIF_API
455  const heif_sequence_encoding_options* src);
456 
457 LIBHEIF_API
459 
472 LIBHEIF_API
474  uint16_t width, uint16_t height,
475  heif_track_type track_type,
476  const heif_track_options* track_options,
477  const heif_sequence_encoding_options* encoding_options,
478  heif_track** out_track);
479 
483 LIBHEIF_API
484 void heif_image_set_duration(heif_image*, uint32_t duration);
485 
494 LIBHEIF_API
496  const heif_image* image,
497  heif_encoder* encoder,
498  const heif_sequence_encoding_options* sequence_encoding_options);
499 
510 LIBHEIF_API
512  heif_encoder* encoder);
513 
514 // --- metadata tracks
515 
526 LIBHEIF_API
528  const char* uri,
529  const heif_track_options* options,
530  heif_track** out_track);
531 
536 LIBHEIF_API
538 
542 LIBHEIF_API
543 heif_error heif_raw_sequence_sample_set_data(heif_raw_sequence_sample*, const uint8_t* data, size_t size);
544 
548 LIBHEIF_API
550 
554 LIBHEIF_API
556  const heif_raw_sequence_sample*);
557 
558 
559 // --- sample auxiliary data
560 
565 {
566  uint32_t type;
567  uint32_t parameter;
569 
573 LIBHEIF_API
575 
580 LIBHEIF_API
582 
583 
584 // --- GIMI content IDs
585 
592 LIBHEIF_API
594 
600 LIBHEIF_API
601 const char* heif_image_get_gimi_sample_content_id(const heif_image*);
602 
608 LIBHEIF_API
610 
615 LIBHEIF_API
616 void heif_image_set_gimi_sample_content_id(heif_image*, const char* contentID);
617 
622 LIBHEIF_API
624 
625 
626 // --- TAI timestamps
627 
628 // Note: functions for setting timestamps on images are in heif_tai_timestamps.h
629 
635 LIBHEIF_API
637 
645 LIBHEIF_API
647 
652 LIBHEIF_API
654  const heif_tai_timestamp_packet* timestamp);
655 
662 LIBHEIF_API
664 
665 
666 // --- track references
667 
669 {
670  heif_track_reference_type_description = heif_fourcc('c', 'd', 's', 'c'), // track_description
671  heif_track_reference_type_thumbnails = heif_fourcc('t', 'h', 'm', 'b'), // thumbnails
672  heif_track_reference_type_auxiliary = heif_fourcc('a', 'u', 'x', 'l') // auxiliary data (e.g. depth maps or alpha channel)
674 
679 LIBHEIF_API
680 void heif_track_add_reference_to_track(heif_track*, uint32_t reference_type, const heif_track* to_track);
681 
685 LIBHEIF_API
687 
697 LIBHEIF_API
698 void heif_track_get_track_reference_types(const heif_track*, uint32_t out_reference_types[]);
699 
703 LIBHEIF_API
704 size_t heif_track_get_number_of_track_reference_of_type(const heif_track*, uint32_t reference_type);
705 
710 LIBHEIF_API
711 size_t heif_track_get_references_from_track(const heif_track*, uint32_t reference_type, uint32_t out_to_track_id[]);
712 
719 LIBHEIF_API
720 size_t heif_track_find_referring_tracks(const heif_track*, uint32_t reference_type, uint32_t out_track_id[], size_t array_size);
721 
722 #ifdef __cplusplus
723 }
724 #endif
725 
726 #endif
struct heif_encoder heif_encoder
Opaque object that represents the encoder used to code the images.
Definition: heif_encoding.h:48
#define heif_fourcc(a, b, c, d)
Build a 32 bit integer from a 4-character code.
Definition: heif_library.h:63
struct heif_context heif_context
Definition: heif_library.h:89
int heif_context_has_sequence(const heif_context *)
Check whether there is an image sequence in the HEIF file.
size_t heif_track_get_references_from_track(const heif_track *, uint32_t reference_type, uint32_t out_to_track_id[])
List the track ids this track points to with the passed reference type.
size_t heif_track_get_number_of_track_reference_of_type(const heif_track *, uint32_t reference_type)
Get the number of references of the passed type.
void heif_image_set_gimi_sample_content_id(heif_image *, const char *contentID)
Set the GIMI content ID for an image sample.
void heif_raw_sequence_sample_set_duration(heif_raw_sequence_sample *, uint32_t duration)
Set the sample duration in track timescale units.
heif_error heif_track_options_enable_sample_tai_timestamps(heif_track_options *, const heif_tai_clock_info *, enum heif_sample_aux_info_presence)
uint32_t heif_track_type
Definition: heif_sequences.h:117
void heif_context_set_sequence_timescale(heif_context *, uint32_t timescale)
Set an independent global timescale for the sequence.
void heif_track_add_reference_to_track(heif_track *, uint32_t reference_type, const heif_track *to_track)
Add a reference between tracks.
heif_error heif_track_get_image_resolution(const heif_track *, uint16_t *out_width, uint16_t *out_height)
Get the image resolution of the track.
heif_sample_aux_info_presence
Specifies whether a 'sample auxiliary info' is stored with the samples.
Definition: heif_sequences.h:319
@ heif_sample_aux_info_presence_mandatory
Definition: heif_sequences.h:322
@ heif_sample_aux_info_presence_optional
Definition: heif_sequences.h:321
@ heif_sample_aux_info_presence_none
Definition: heif_sequences.h:320
heif_error heif_track_encode_sequence_image(heif_track *, const heif_image *image, heif_encoder *encoder, const heif_sequence_encoding_options *sequence_encoding_options)
Encode the image into a visual track.
int heif_context_number_of_sequence_tracks(const heif_context *)
Get the number of tracks in the HEIF file.
struct heif_sequence_encoding_options heif_sequence_encoding_options
uint32_t heif_track_get_sample_entry_type_of_first_cluster(const heif_track *)
Get the "sample entry type" of the first sample sample cluster in the track.
void heif_sequence_encoding_options_release(heif_sequence_encoding_options *)
struct heif_tai_clock_info heif_tai_clock_info
Definition: heif_sequences.h:31
void heif_track_get_track_reference_types(const heif_track *, uint32_t out_reference_types[])
List the reference types used in this track.
uint32_t heif_context_get_sequence_timescale(const heif_context *)
Get the timescale (clock ticks per second) for timing values in the sequence.
void heif_raw_sequence_sample_set_tai_timestamp(heif_raw_sequence_sample *sample, const heif_tai_timestamp_packet *timestamp)
Set the TAI timestamp for a raw sequence sample.
const char * heif_raw_sequence_sample_get_gimi_sample_content_id(const heif_raw_sequence_sample *)
Get the GIMI content ID stored in the metadata sample.
uint32_t heif_track_get_timescale(const heif_track *)
Get the timescale (clock ticks per second) for this track.
const heif_tai_clock_info * heif_track_get_tai_clock_info_of_first_cluster(heif_track *)
Returns the TAI clock info of the track.
void heif_track_options_set_gimi_track_id(heif_track_options *, const char *track_id)
Set the GIMI format track ID string.
const char * heif_image_get_gimi_sample_content_id(const heif_image *)
Get the GIMI content ID stored in the image sample.
int heif_raw_sequence_sample_has_tai_timestamp(const heif_raw_sequence_sample *)
Returns whether the raw (metadata) sample has a TAI timestamp attached to it (stored as SAI).
struct heif_raw_sequence_sample heif_raw_sequence_sample
Sequence sample object that can hold any raw byte data.
Definition: heif_sequences.h:256
heif_track * heif_context_get_track(const heif_context *, uint32_t id)
Get the heif_track object for the given track ID.
int heif_track_has_alpha_channel(const heif_track *)
heif_track_type_4cc
Definition: heif_sequences.h:120
@ heif_track_type_auxiliary
Definition: heif_sequences.h:123
@ heif_track_type_image_sequence
Definition: heif_sequences.h:122
@ heif_track_type_video
Definition: heif_sequences.h:121
@ heif_track_type_metadata
Definition: heif_sequences.h:124
heif_raw_sequence_sample * heif_raw_sequence_sample_alloc(void)
Allocate a new heif_raw_sequence_sample object.
heif_error heif_context_add_uri_metadata_sequence_track(heif_context *, const char *uri, const heif_track_options *options, heif_track **out_track)
Add a metadata track.
struct heif_track_options heif_track_options
Definition: heif_sequences.h:326
heif_track_reference_type
Definition: heif_sequences.h:669
@ heif_track_reference_type_thumbnails
Definition: heif_sequences.h:671
@ heif_track_reference_type_description
Definition: heif_sequences.h:670
@ heif_track_reference_type_auxiliary
Definition: heif_sequences.h:672
void heif_sequence_encoding_options_copy(heif_sequence_encoding_options *dst, const heif_sequence_encoding_options *src)
Copy fields from src into dst, respecting both structs' version numbers.
const heif_tai_timestamp_packet * heif_raw_sequence_sample_get_tai_timestamp(const heif_raw_sequence_sample *)
Get the TAI timestamp of the (metadata) sample.
heif_error heif_track_get_next_raw_sequence_sample(heif_track *, heif_raw_sequence_sample **out_sample)
Get the next raw sample from the (metadata) sequence track.
void heif_context_set_number_of_sequence_repetitions(heif_context *, uint32_t number_of_repetitions)
void heif_raw_sequence_sample_set_gimi_sample_content_id(heif_raw_sequence_sample *, const char *contentID)
Set the GIMI content ID for a (metadata) sample.
uint32_t heif_track_get_id(const heif_track *track)
Get the ID of the passed track.
heif_sequence_gop_structure
Definition: heif_sequences.h:382
@ heif_sequence_gop_structure_unrestricted
Definition: heif_sequences.h:391
@ heif_sequence_gop_structure_intra_only
Definition: heif_sequences.h:384
@ heif_sequence_gop_structure_lowdelay
Definition: heif_sequences.h:387
void heif_raw_sequence_sample_release(heif_raw_sequence_sample *)
Release a heif_raw_sequence_sample object.
void heif_track_options_enable_sample_gimi_content_ids(heif_track_options *, enum heif_sample_aux_info_presence)
heif_sequence_encoding_options * heif_sequence_encoding_options_alloc(void)
void heif_context_get_track_ids(const heif_context *ctx, uint32_t out_track_id_array[])
Returns the IDs for each of the tracks stored in the HEIF file.
heif_error heif_raw_sequence_sample_set_data(heif_raw_sequence_sample *, const uint8_t *data, size_t size)
Set the raw sequence sample data.
void heif_track_options_set_timescale(heif_track_options *, uint32_t timescale)
Set the track specific timescale.
heif_track_options * heif_track_options_alloc(void)
Allocate track options object that is required to set options for a new track.
const uint8_t * heif_raw_sequence_sample_get_data(const heif_raw_sequence_sample *, size_t *out_array_size)
Get a pointer to the data of the (metadata) sample.
void heif_track_get_sample_aux_info_types(const heif_track *, heif_sample_aux_info_type out_types[])
Get get the list of sample auxiliary data types used in the track.
size_t heif_track_get_number_of_track_reference_types(const heif_track *)
Return the number of different reference types used in this track's tref box.
void heif_track_options_set_interleaved_sample_aux_infos(heif_track_options *, int interleaved_flag)
Set whether the aux-info data should be stored interleaved with the sequence samples.
uint32_t heif_raw_sequence_sample_get_duration(const heif_raw_sequence_sample *)
Get the sample duration in clock ticks of this track.
void heif_track_release(heif_track *)
Free a heif_track object received from libheif.
void heif_image_set_duration(heif_image *, uint32_t duration)
Set the image display duration in the track's timescale units.
uint32_t heif_track_get_number_of_repetitions(const heif_track *)
How many times the media segment should be played according to the track's edit list.
heif_error heif_track_encode_end_of_sequence(heif_track *, heif_encoder *encoder)
When all sequence frames have been sent, you can to call this function to let the library know that n...
heif_error heif_track_get_urim_sample_entry_uri_of_first_cluster(const heif_track *, const char **out_uri)
Get the URI of the first sample cluster in an 'urim' track.
heif_error heif_track_decode_next_image(heif_track *track, heif_image **out_img, heif_colorspace colorspace, heif_chroma chroma, const heif_decoding_options *options)
Decode the next image in the passed sequence track.
size_t heif_raw_sequence_sample_get_data_size(const heif_raw_sequence_sample *)
Return the size of the raw data contained in the sample.
heif_auxiliary_track_info_type
Definition: heif_sequences.h:139
@ heif_auxiliary_track_info_type_unknown
Definition: heif_sequences.h:140
@ heif_auxiliary_track_info_type_alpha
Definition: heif_sequences.h:141
heif_error heif_context_add_visual_sequence_track(heif_context *, uint16_t width, uint16_t height, heif_track_type track_type, const heif_track_options *track_options, const heif_sequence_encoding_options *encoding_options, heif_track **out_track)
Add a visual track to the sequence.
struct heif_track heif_track
Definition: heif_sequences.h:66
struct heif_sample_aux_info_type heif_sample_aux_info_type
Contains the type of sample auxiliary data assigned to the track samples.
size_t heif_track_find_referring_tracks(const heif_track *, uint32_t reference_type, uint32_t out_track_id[], size_t array_size)
Find tracks that are referring to the current track through the passed reference_type.
void heif_track_options_release(heif_track_options *)
enum heif_auxiliary_track_info_type heif_track_get_auxiliary_info_type(const heif_track *)
const char * heif_track_get_auxiliary_info_type_urn(const heif_track *)
uint32_t heif_image_get_duration(const heif_image *)
Get the image display duration in clock ticks of this track.
heif_sequence_content_kind
Definition: heif_sequences.h:405
@ heif_sequence_content_kind_image_sequence
Definition: heif_sequences.h:407
@ heif_sequence_content_kind_video
Definition: heif_sequences.h:408
@ heif_sequence_content_kind_auto
Definition: heif_sequences.h:406
heif_error heif_track_add_raw_sequence_sample(heif_track *, const heif_raw_sequence_sample *)
Add a raw sequence sample (usually a metadata sample) to the (metadata) track.
heif_track_type heif_track_get_track_handler_type(const heif_track *)
Get the four-cc track handler type.
int heif_track_get_number_of_sample_aux_infos(const heif_track *)
Returns how many different types of sample auxiliary data units are assigned to this track's samples.
uint64_t heif_context_get_sequence_duration(const heif_context *)
Get the total duration of the sequence in timescale clock ticks.
const char * heif_track_get_gimi_track_content_id(const heif_track *)
Get the GIMI content ID for the track (as a whole).
struct heif_tai_timestamp_packet heif_tai_timestamp_packet
Definition: heif_sequences.h:32
Contains the type of sample auxiliary data assigned to the track samples.
Definition: heif_sequences.h:565
uint32_t parameter
Definition: heif_sequences.h:567
uint32_t type
Definition: heif_sequences.h:566
Definition: heif_sequences.h:413
uint8_t version
Definition: heif_sequences.h:414
enum heif_sequence_content_kind content_kind
Definition: heif_sequences.h:439
int keyframe_distance_max
Definition: heif_sequences.h:428
int keyframe_distance_min
Definition: heif_sequences.h:427
heif_color_conversion_options color_conversion_options
Definition: heif_sequences.h:422
const heif_color_profile_nclx * output_nclx_profile
Definition: heif_sequences.h:420
enum heif_sequence_gop_structure gop_structure
Definition: heif_sequences.h:426
int save_alpha_channel
Definition: heif_sequences.h:430