FFmpeg
packet.h
Go to the documentation of this file.
1 /*
2  * AVPacket public API
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #ifndef AVCODEC_PACKET_H
22 #define AVCODEC_PACKET_H
23 
24 #include <stddef.h>
25 #include <stdint.h>
26 
27 #include "libavutil/attributes.h"
28 #include "libavutil/buffer.h"
29 #include "libavutil/dict.h"
30 #include "libavutil/rational.h"
31 #include "libavutil/version.h"
32 
34 
35 /**
36  * @defgroup lavc_packet_side_data AVPacketSideData
37  *
38  * Types and functions for working with AVPacketSideData.
39  * @{
40  */
42  /**
43  * An AV_PKT_DATA_PALETTE side data packet contains exactly AVPALETTE_SIZE
44  * bytes worth of palette. This side data signals that a new palette is
45  * present.
46  */
48 
49  /**
50  * The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format
51  * that the extradata buffer was changed and the receiving side should
52  * act upon it appropriately. The new extradata is embedded in the side
53  * data buffer and should be immediately used for processing the current
54  * frame or packet.
55  */
57 
58  /**
59  * An AV_PKT_DATA_PARAM_CHANGE side data packet is laid out as follows:
60  * @code
61  * u32le param_flags
62  * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT)
63  * s32le channel_count
64  * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT)
65  * u64le channel_layout
66  * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE)
67  * s32le sample_rate
68  * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS)
69  * s32le width
70  * s32le height
71  * @endcode
72  */
74 
75  /**
76  * An AV_PKT_DATA_H263_MB_INFO side data packet contains a number of
77  * structures with info about macroblocks relevant to splitting the
78  * packet into smaller packets on macroblock edges (e.g. as for RFC 2190).
79  * That is, it does not necessarily contain info about all macroblocks,
80  * as long as the distance between macroblocks in the info is smaller
81  * than the target payload size.
82  * Each MB info structure is 12 bytes, and is laid out as follows:
83  * @code
84  * u32le bit offset from the start of the packet
85  * u8 current quantizer at the start of the macroblock
86  * u8 GOB number
87  * u16le macroblock address within the GOB
88  * u8 horizontal MV predictor
89  * u8 vertical MV predictor
90  * u8 horizontal MV predictor for block number 3
91  * u8 vertical MV predictor for block number 3
92  * @endcode
93  */
95 
96  /**
97  * This side data should be associated with an audio stream and contains
98  * ReplayGain information in form of the AVReplayGain struct.
99  */
101 
102  /**
103  * This side data contains a 3x3 transformation matrix describing an affine
104  * transformation that needs to be applied to the decoded video frames for
105  * correct presentation.
106  *
107  * See libavutil/display.h for a detailed description of the data.
108  */
110 
111  /**
112  * This side data should be associated with a video stream and contains
113  * Stereoscopic 3D information in form of the AVStereo3D struct.
114  */
116 
117  /**
118  * This side data should be associated with an audio stream and corresponds
119  * to enum AVAudioServiceType.
120  */
122 
123  /**
124  * This side data contains quality related information from the encoder.
125  * @code
126  * u32le quality factor of the compressed frame. Allowed range is between 1 (good) and FF_LAMBDA_MAX (bad).
127  * u8 picture type
128  * u8 error count
129  * u16 reserved
130  * u64le[error count] sum of squared differences between encoder in and output
131  * @endcode
132  */
134 
135  /**
136  * This side data contains an integer value representing the stream index
137  * of a "fallback" track. A fallback track indicates an alternate
138  * track to use when the current track can not be decoded for some reason.
139  * e.g. no decoder available for codec.
140  */
142 
143  /**
144  * This side data corresponds to the AVCPBProperties struct.
145  */
147 
148  /**
149  * Recommmends skipping the specified number of samples
150  * @code
151  * u32le number of samples to skip from start of this packet
152  * u32le number of samples to skip from end of this packet
153  * u8 reason for start skip
154  * u8 reason for end skip (0=padding silence, 1=convergence)
155  * @endcode
156  */
158 
159  /**
160  * An AV_PKT_DATA_JP_DUALMONO side data packet indicates that
161  * the packet may contain "dual mono" audio specific to Japanese DTV
162  * and if it is true, recommends only the selected channel to be used.
163  * @code
164  * u8 selected channels (0=main/left, 1=sub/right, 2=both)
165  * @endcode
166  */
168 
169  /**
170  * A list of zero terminated key/value strings. There is no end marker for
171  * the list, so it is required to rely on the side data size to stop.
172  */
174 
175  /**
176  * Subtitle event position
177  * @code
178  * u32le x1
179  * u32le y1
180  * u32le x2
181  * u32le y2
182  * @endcode
183  */
185 
186  /**
187  * Data found in BlockAdditional element of matroska container. There is
188  * no end marker for the data, so it is required to rely on the side data
189  * size to recognize the end. 8 byte id (as found in BlockAddId) followed
190  * by data.
191  */
193 
194  /**
195  * The optional first identifier line of a WebVTT cue.
196  */
198 
199  /**
200  * The optional settings (rendering instructions) that immediately
201  * follow the timestamp specifier of a WebVTT cue.
202  */
204 
205  /**
206  * A list of zero terminated key/value strings. There is no end marker for
207  * the list, so it is required to rely on the side data size to stop. This
208  * side data includes updated metadata which appeared in the stream.
209  */
211 
212  /**
213  * MPEGTS stream ID as uint8_t, this is required to pass the stream ID
214  * information from the demuxer to the corresponding muxer.
215  */
217 
218  /**
219  * Mastering display metadata (based on SMPTE-2086:2014). This metadata
220  * should be associated with a video stream and contains data in the form
221  * of the AVMasteringDisplayMetadata struct.
222  */
224 
225  /**
226  * This side data should be associated with a video stream and corresponds
227  * to the AVSphericalMapping structure.
228  */
230 
231  /**
232  * Content light level (based on CTA-861.3). This metadata should be
233  * associated with a video stream and contains data in the form of the
234  * AVContentLightMetadata struct.
235  */
237 
238  /**
239  * ATSC A53 Part 4 Closed Captions. This metadata should be associated with
240  * a video stream. A53 CC bitstream is stored as uint8_t in AVPacketSideData.data.
241  * The number of bytes of CC data is AVPacketSideData.size.
242  */
244 
245  /**
246  * This side data is encryption initialization data.
247  * The format is not part of ABI, use av_encryption_init_info_* methods to
248  * access.
249  */
251 
252  /**
253  * This side data contains encryption info for how to decrypt the packet.
254  * The format is not part of ABI, use av_encryption_info_* methods to access.
255  */
257 
258  /**
259  * Active Format Description data consisting of a single byte as specified
260  * in ETSI TS 101 154 using AVActiveFormatDescription enum.
261  */
263 
264  /**
265  * Producer Reference Time data corresponding to the AVProducerReferenceTime struct,
266  * usually exported by some encoders (on demand through the prft flag set in the
267  * AVCodecContext export_side_data field).
268  */
270 
271  /**
272  * ICC profile data consisting of an opaque octet buffer following the
273  * format described by ISO 15076-1.
274  */
276 
277  /**
278  * DOVI configuration
279  * ref:
280  * dolby-vision-bitstreams-within-the-iso-base-media-file-format-v2.1.2, section 2.2
281  * dolby-vision-bitstreams-in-mpeg-2-transport-stream-multiplex-v1.2, section 3.3
282  * Tags are stored in struct AVDOVIDecoderConfigurationRecord.
283  */
285 
286  /**
287  * Timecode which conforms to SMPTE ST 12-1:2014. The data is an array of 4 uint32_t
288  * where the first uint32_t describes how many (1-3) of the other timecodes are used.
289  * The timecode format is described in the documentation of av_timecode_get_smpte_from_framenum()
290  * function in libavutil/timecode.h.
291  */
293 
294  /**
295  * HDR10+ dynamic metadata associated with a video frame. The metadata is in
296  * the form of the AVDynamicHDRPlus struct and contains
297  * information for color volume transform - application 4 of
298  * SMPTE 2094-40:2016 standard.
299  */
301 
302  /**
303  * IAMF Mix Gain Parameter Data associated with the audio frame. This metadata
304  * is in the form of the AVIAMFParamDefinition struct and contains information
305  * defined in sections 3.6.1 and 3.8.1 of the Immersive Audio Model and
306  * Formats standard.
307  */
309 
310  /**
311  * IAMF Demixing Info Parameter Data associated with the audio frame. This
312  * metadata is in the form of the AVIAMFParamDefinition struct and contains
313  * information defined in sections 3.6.1 and 3.8.2 of the Immersive Audio Model
314  * and Formats standard.
315  */
317 
318  /**
319  * IAMF Recon Gain Info Parameter Data associated with the audio frame. This
320  * metadata is in the form of the AVIAMFParamDefinition struct and contains
321  * information defined in sections 3.6.1 and 3.8.3 of the Immersive Audio Model
322  * and Formats standard.
323  */
325 
326  /**
327  * Ambient viewing environment metadata, as defined by H.274. This metadata
328  * should be associated with a video stream and contains data in the form
329  * of the AVAmbientViewingEnvironment struct.
330  */
332 
333  /**
334  * The number of side data types.
335  * This is not part of the public API/ABI in the sense that it may
336  * change when new side data types are added.
337  * This must stay the last enum value.
338  * If its value becomes huge, some code using it
339  * needs to be updated as it assumes it to be smaller than other limits.
340  */
342 };
343 
344 #if FF_API_QUALITY_FACTOR
345 #define AV_PKT_DATA_QUALITY_FACTOR AV_PKT_DATA_QUALITY_STATS //DEPRECATED
346 #endif
347 
348 /**
349  * This structure stores auxiliary information for decoding, presenting, or
350  * otherwise processing the coded stream. It is typically exported by demuxers
351  * and encoders and can be fed to decoders and muxers either in a per packet
352  * basis, or as global side data (applying to the entire coded stream).
353  *
354  * Global side data is handled as follows:
355  * - During demuxing, it may be exported through
356  * @ref AVStream.codecpar.side_data "AVStream's codec parameters", which can
357  * then be passed as input to decoders through the
358  * @ref AVCodecContext.coded_side_data "decoder context's side data", for
359  * initialization.
360  * - For muxing, it can be fed through @ref AVStream.codecpar.side_data
361  * "AVStream's codec parameters", typically the output of encoders through
362  * the @ref AVCodecContext.coded_side_data "encoder context's side data", for
363  * initialization.
364  *
365  * Packet specific side data is handled as follows:
366  * - During demuxing, it may be exported through @ref AVPacket.side_data
367  * "AVPacket's side data", which can then be passed as input to decoders.
368  * - For muxing, it can be fed through @ref AVPacket.side_data "AVPacket's
369  * side data", typically the output of encoders.
370  *
371  * Different modules may accept or export different types of side data
372  * depending on media type and codec. Refer to @ref AVPacketSideDataType for a
373  * list of defined types and where they may be found or used.
374  */
375 typedef struct AVPacketSideData {
376  uint8_t *data;
377  size_t size;
380 
381 /**
382  * Allocate a new packet side data.
383  *
384  * @param sd pointer to an array of side data to which the side data should
385  * be added. *sd may be NULL, in which case the array will be
386  * initialized.
387  * @param nb_sd pointer to an integer containing the number of entries in
388  * the array. The integer value will be increased by 1 on success.
389  * @param type side data type
390  * @param size desired side data size
391  * @param flags currently unused. Must be zero
392  *
393  * @return pointer to freshly allocated side data on success, or NULL otherwise.
394  */
397  size_t size, int flags);
398 
399 /**
400  * Wrap existing data as packet side data.
401  *
402  * @param sd pointer to an array of side data to which the side data should
403  * be added. *sd may be NULL, in which case the array will be
404  * initialized
405  * @param nb_sd pointer to an integer containing the number of entries in
406  * the array. The integer value will be increased by 1 on success.
407  * @param type side data type
408  * @param data a data array. It must be allocated with the av_malloc() family
409  * of functions. The ownership of the data is transferred to the
410  * side data array on success
411  * @param size size of the data array
412  * @param flags currently unused. Must be zero
413  *
414  * @return pointer to freshly allocated side data on success, or NULL otherwise
415  * On failure, the side data array is unchanged and the data remains
416  * owned by the caller.
417  */
420  void *data, size_t size, int flags);
421 
422 /**
423  * Get side information from a side data array.
424  *
425  * @param sd the array from which the side data should be fetched
426  * @param nb_sd value containing the number of entries in the array.
427  * @param type desired side information type
428  *
429  * @return pointer to side data if present or NULL otherwise
430  */
432  int nb_sd,
434 
435 /**
436  * Remove side data of the given type from a side data array.
437  *
438  * @param sd the array from which the side data should be removed
439  * @param nb_sd pointer to an integer containing the number of entries in
440  * the array. Will be reduced by the amount of entries removed
441  * upon return
442  * @param type side information type
443  */
444 void av_packet_side_data_remove(AVPacketSideData *sd, int *nb_sd,
446 
447 /**
448  * Convenience function to free all the side data stored in an array, and
449  * the array itself.
450  *
451  * @param sd pointer to array of side data to free. Will be set to NULL
452  * upon return.
453  * @param nb_sd pointer to an integer containing the number of entries in
454  * the array. Will be set to 0 upon return.
455  */
456 void av_packet_side_data_free(AVPacketSideData **sd, int *nb_sd);
457 
459 
460 /**
461  * @}
462  */
463 
464 /**
465  * @defgroup lavc_packet AVPacket
466  *
467  * Types and functions for working with AVPacket.
468  * @{
469  */
470 
471 /**
472  * This structure stores compressed data. It is typically exported by demuxers
473  * and then passed as input to decoders, or received as output from encoders and
474  * then passed to muxers.
475  *
476  * For video, it should typically contain one compressed frame. For audio it may
477  * contain several compressed frames. Encoders are allowed to output empty
478  * packets, with no compressed data, containing only side data
479  * (e.g. to update some stream parameters at the end of encoding).
480  *
481  * The semantics of data ownership depends on the buf field.
482  * If it is set, the packet data is dynamically allocated and is
483  * valid indefinitely until a call to av_packet_unref() reduces the
484  * reference count to 0.
485  *
486  * If the buf field is not set av_packet_ref() would make a copy instead
487  * of increasing the reference count.
488  *
489  * The side data is always allocated with av_malloc(), copied by
490  * av_packet_ref() and freed by av_packet_unref().
491  *
492  * sizeof(AVPacket) being a part of the public ABI is deprecated. once
493  * av_init_packet() is removed, new packets will only be able to be allocated
494  * with av_packet_alloc(), and new fields may be added to the end of the struct
495  * with a minor bump.
496  *
497  * @see av_packet_alloc
498  * @see av_packet_ref
499  * @see av_packet_unref
500  */
501 typedef struct AVPacket {
502  /**
503  * A reference to the reference-counted buffer where the packet data is
504  * stored.
505  * May be NULL, then the packet data is not reference-counted.
506  */
508  /**
509  * Presentation timestamp in AVStream->time_base units; the time at which
510  * the decompressed packet will be presented to the user.
511  * Can be AV_NOPTS_VALUE if it is not stored in the file.
512  * pts MUST be larger or equal to dts as presentation cannot happen before
513  * decompression, unless one wants to view hex dumps. Some formats misuse
514  * the terms dts and pts/cts to mean something different. Such timestamps
515  * must be converted to true pts/dts before they are stored in AVPacket.
516  */
517  int64_t pts;
518  /**
519  * Decompression timestamp in AVStream->time_base units; the time at which
520  * the packet is decompressed.
521  * Can be AV_NOPTS_VALUE if it is not stored in the file.
522  */
523  int64_t dts;
524  uint8_t *data;
525  int size;
527  /**
528  * A combination of AV_PKT_FLAG values
529  */
530  int flags;
531  /**
532  * Additional packet data that can be provided by the container.
533  * Packet can contain several types of side information.
534  */
537 
538  /**
539  * Duration of this packet in AVStream->time_base units, 0 if unknown.
540  * Equals next_pts - this_pts in presentation order.
541  */
542  int64_t duration;
543 
544  int64_t pos; ///< byte position in stream, -1 if unknown
545 
546  /**
547  * for some private data of the user
548  */
549  void *opaque;
550 
551  /**
552  * AVBufferRef for free use by the API user. FFmpeg will never check the
553  * contents of the buffer ref. FFmpeg calls av_buffer_unref() on it when
554  * the packet is unreferenced. av_packet_copy_props() calls create a new
555  * reference with av_buffer_ref() for the target packet's opaque_ref field.
556  *
557  * This is unrelated to the opaque field, although it serves a similar
558  * purpose.
559  */
561 
562  /**
563  * Time base of the packet's timestamps.
564  * In the future, this field may be set on packets output by encoders or
565  * demuxers, but its value will be by default ignored on input to decoders
566  * or muxers.
567  */
569 } AVPacket;
570 
571 #if FF_API_INIT_PACKET
573 typedef struct AVPacketList {
574  AVPacket pkt;
575  struct AVPacketList *next;
576 } AVPacketList;
577 #endif
578 
579 #define AV_PKT_FLAG_KEY 0x0001 ///< The packet contains a keyframe
580 #define AV_PKT_FLAG_CORRUPT 0x0002 ///< The packet content is corrupted
581 /**
582  * Flag is used to discard packets which are required to maintain valid
583  * decoder state but are not required for output and should be dropped
584  * after decoding.
585  **/
586 #define AV_PKT_FLAG_DISCARD 0x0004
587 /**
588  * The packet comes from a trusted source.
589  *
590  * Otherwise-unsafe constructs such as arbitrary pointers to data
591  * outside the packet may be followed.
592  */
593 #define AV_PKT_FLAG_TRUSTED 0x0008
594 /**
595  * Flag is used to indicate packets that contain frames that can
596  * be discarded by the decoder. I.e. Non-reference frames.
597  */
598 #define AV_PKT_FLAG_DISPOSABLE 0x0010
599 
603 };
604 
605 /**
606  * Allocate an AVPacket and set its fields to default values. The resulting
607  * struct must be freed using av_packet_free().
608  *
609  * @return An AVPacket filled with default values or NULL on failure.
610  *
611  * @note this only allocates the AVPacket itself, not the data buffers. Those
612  * must be allocated through other means such as av_new_packet.
613  *
614  * @see av_new_packet
615  */
617 
618 /**
619  * Create a new packet that references the same data as src.
620  *
621  * This is a shortcut for av_packet_alloc()+av_packet_ref().
622  *
623  * @return newly created AVPacket on success, NULL on error.
624  *
625  * @see av_packet_alloc
626  * @see av_packet_ref
627  */
629 
630 /**
631  * Free the packet, if the packet is reference counted, it will be
632  * unreferenced first.
633  *
634  * @param pkt packet to be freed. The pointer will be set to NULL.
635  * @note passing NULL is a no-op.
636  */
637 void av_packet_free(AVPacket **pkt);
638 
639 #if FF_API_INIT_PACKET
640 /**
641  * Initialize optional fields of a packet with default values.
642  *
643  * Note, this does not touch the data and size members, which have to be
644  * initialized separately.
645  *
646  * @param pkt packet
647  *
648  * @see av_packet_alloc
649  * @see av_packet_unref
650  *
651  * @deprecated This function is deprecated. Once it's removed,
652  sizeof(AVPacket) will not be a part of the ABI anymore.
653  */
655 void av_init_packet(AVPacket *pkt);
656 #endif
657 
658 /**
659  * Allocate the payload of a packet and initialize its fields with
660  * default values.
661  *
662  * @param pkt packet
663  * @param size wanted payload size
664  * @return 0 if OK, AVERROR_xxx otherwise
665  */
666 int av_new_packet(AVPacket *pkt, int size);
667 
668 /**
669  * Reduce packet size, correctly zeroing padding
670  *
671  * @param pkt packet
672  * @param size new size
673  */
674 void av_shrink_packet(AVPacket *pkt, int size);
675 
676 /**
677  * Increase packet size, correctly zeroing padding
678  *
679  * @param pkt packet
680  * @param grow_by number of bytes by which to increase the size of the packet
681  */
682 int av_grow_packet(AVPacket *pkt, int grow_by);
683 
684 /**
685  * Initialize a reference-counted packet from av_malloc()ed data.
686  *
687  * @param pkt packet to be initialized. This function will set the data, size,
688  * and buf fields, all others are left untouched.
689  * @param data Data allocated by av_malloc() to be used as packet data. If this
690  * function returns successfully, the data is owned by the underlying AVBuffer.
691  * The caller may not access the data through other means.
692  * @param size size of data in bytes, without the padding. I.e. the full buffer
693  * size is assumed to be size + AV_INPUT_BUFFER_PADDING_SIZE.
694  *
695  * @return 0 on success, a negative AVERROR on error
696  */
697 int av_packet_from_data(AVPacket *pkt, uint8_t *data, int size);
698 
699 /**
700  * Allocate new information of a packet.
701  *
702  * @param pkt packet
703  * @param type side information type
704  * @param size side information size
705  * @return pointer to fresh allocated data or NULL otherwise
706  */
708  size_t size);
709 
710 /**
711  * Wrap an existing array as a packet side data.
712  *
713  * @param pkt packet
714  * @param type side information type
715  * @param data the side data array. It must be allocated with the av_malloc()
716  * family of functions. The ownership of the data is transferred to
717  * pkt.
718  * @param size side information size
719  * @return a non-negative number on success, a negative AVERROR code on
720  * failure. On failure, the packet is unchanged and the data remains
721  * owned by the caller.
722  */
724  uint8_t *data, size_t size);
725 
726 /**
727  * Shrink the already allocated side data buffer
728  *
729  * @param pkt packet
730  * @param type side information type
731  * @param size new side information size
732  * @return 0 on success, < 0 on failure
733  */
735  size_t size);
736 
737 /**
738  * Get side information from packet.
739  *
740  * @param pkt packet
741  * @param type desired side information type
742  * @param size If supplied, *size will be set to the size of the side data
743  * or to zero if the desired side data is not present.
744  * @return pointer to data if present or NULL otherwise
745  */
747  size_t *size);
748 
749 /**
750  * Pack a dictionary for use in side_data.
751  *
752  * @param dict The dictionary to pack.
753  * @param size pointer to store the size of the returned data
754  * @return pointer to data if successful, NULL otherwise
755  */
756 uint8_t *av_packet_pack_dictionary(AVDictionary *dict, size_t *size);
757 /**
758  * Unpack a dictionary from side_data.
759  *
760  * @param data data from side_data
761  * @param size size of the data
762  * @param dict the metadata storage dictionary
763  * @return 0 on success, < 0 on failure
764  */
765 int av_packet_unpack_dictionary(const uint8_t *data, size_t size,
766  AVDictionary **dict);
767 
768 /**
769  * Convenience function to free all the side data stored.
770  * All the other fields stay untouched.
771  *
772  * @param pkt packet
773  */
775 
776 /**
777  * Setup a new reference to the data described by a given packet
778  *
779  * If src is reference-counted, setup dst as a new reference to the
780  * buffer in src. Otherwise allocate a new buffer in dst and copy the
781  * data from src into it.
782  *
783  * All the other fields are copied from src.
784  *
785  * @see av_packet_unref
786  *
787  * @param dst Destination packet. Will be completely overwritten.
788  * @param src Source packet
789  *
790  * @return 0 on success, a negative AVERROR on error. On error, dst
791  * will be blank (as if returned by av_packet_alloc()).
792  */
793 int av_packet_ref(AVPacket *dst, const AVPacket *src);
794 
795 /**
796  * Wipe the packet.
797  *
798  * Unreference the buffer referenced by the packet and reset the
799  * remaining packet fields to their default values.
800  *
801  * @param pkt The packet to be unreferenced.
802  */
804 
805 /**
806  * Move every field in src to dst and reset src.
807  *
808  * @see av_packet_unref
809  *
810  * @param src Source packet, will be reset
811  * @param dst Destination packet
812  */
814 
815 /**
816  * Copy only "properties" fields from src to dst.
817  *
818  * Properties for the purpose of this function are all the fields
819  * beside those related to the packet data (buf, data, size)
820  *
821  * @param dst Destination packet
822  * @param src Source packet
823  *
824  * @return 0 on success AVERROR on failure.
825  */
826 int av_packet_copy_props(AVPacket *dst, const AVPacket *src);
827 
828 /**
829  * Ensure the data described by a given packet is reference counted.
830  *
831  * @note This function does not ensure that the reference will be writable.
832  * Use av_packet_make_writable instead for that purpose.
833  *
834  * @see av_packet_ref
835  * @see av_packet_make_writable
836  *
837  * @param pkt packet whose data should be made reference counted.
838  *
839  * @return 0 on success, a negative AVERROR on error. On failure, the
840  * packet is unchanged.
841  */
843 
844 /**
845  * Create a writable reference for the data described by a given packet,
846  * avoiding data copy if possible.
847  *
848  * @param pkt Packet whose data should be made writable.
849  *
850  * @return 0 on success, a negative AVERROR on failure. On failure, the
851  * packet is unchanged.
852  */
854 
855 /**
856  * Convert valid timing fields (timestamps / durations) in a packet from one
857  * timebase to another. Timestamps with unknown values (AV_NOPTS_VALUE) will be
858  * ignored.
859  *
860  * @param pkt packet on which the conversion will be performed
861  * @param tb_src source timebase, in which the timing fields in pkt are
862  * expressed
863  * @param tb_dst destination timebase, to which the timing fields will be
864  * converted
865  */
866 void av_packet_rescale_ts(AVPacket *pkt, AVRational tb_src, AVRational tb_dst);
867 
868 /**
869  * @}
870  */
871 
872 #endif // AVCODEC_PACKET_H
AV_PKT_DATA_DISPLAYMATRIX
@ AV_PKT_DATA_DISPLAYMATRIX
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
Definition: packet.h:109
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: packet.c:427
AV_PKT_DATA_AMBIENT_VIEWING_ENVIRONMENT
@ AV_PKT_DATA_AMBIENT_VIEWING_ENVIRONMENT
Ambient viewing environment metadata, as defined by H.274.
Definition: packet.h:331
AV_PKT_DATA_QUALITY_STATS
@ AV_PKT_DATA_QUALITY_STATS
This side data contains quality related information from the encoder.
Definition: packet.h:133
AV_PKT_DATA_NEW_EXTRADATA
@ AV_PKT_DATA_NEW_EXTRADATA
The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format that the extradata buffer was...
Definition: packet.h:56
AV_PKT_DATA_MASTERING_DISPLAY_METADATA
@ AV_PKT_DATA_MASTERING_DISPLAY_METADATA
Mastering display metadata (based on SMPTE-2086:2014).
Definition: packet.h:223
rational.h
av_grow_packet
int av_grow_packet(AVPacket *pkt, int grow_by)
Increase packet size, correctly zeroing padding.
Definition: packet.c:121
AVPacketSideData
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
Definition: packet.h:375
AVPacket::data
uint8_t * data
Definition: packet.h:524
AV_PKT_DATA_ENCRYPTION_INIT_INFO
@ AV_PKT_DATA_ENCRYPTION_INIT_INFO
This side data is encryption initialization data.
Definition: packet.h:250
av_packet_shrink_side_data
int av_packet_shrink_side_data(AVPacket *pkt, enum AVPacketSideDataType type, size_t size)
Shrink the already allocated side data buffer.
Definition: packet.c:374
AV_PKT_DATA_FALLBACK_TRACK
@ AV_PKT_DATA_FALLBACK_TRACK
This side data contains an integer value representing the stream index of a "fallback" track.
Definition: packet.h:141
data
const char data[16]
Definition: mxf.c:148
av_packet_side_data_remove
void av_packet_side_data_remove(AVPacketSideData *sd, int *nb_sd, enum AVPacketSideDataType type)
Remove side data of the given type from a side data array.
Definition: packet.c:726
version_major.h
AV_PKT_DATA_S12M_TIMECODE
@ AV_PKT_DATA_S12M_TIMECODE
Timecode which conforms to SMPTE ST 12-1:2014.
Definition: packet.h:292
AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE
@ AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE
Definition: packet.h:601
AVPacket::duration
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: packet.h:542
AVDictionary
Definition: dict.c:34
av_packet_free_side_data
void av_packet_free_side_data(AVPacket *pkt)
Convenience function to free all the side data stored.
Definition: packet.c:188
av_packet_free
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition: packet.c:74
AV_PKT_DATA_DOVI_CONF
@ AV_PKT_DATA_DOVI_CONF
DOVI configuration ref: dolby-vision-bitstreams-within-the-iso-base-media-file-format-v2....
Definition: packet.h:284
AVPacketSideData::size
size_t size
Definition: packet.h:377
AV_PKT_DATA_REPLAYGAIN
@ AV_PKT_DATA_REPLAYGAIN
This side data should be associated with an audio stream and contains ReplayGain information in form ...
Definition: packet.h:100
AV_PKT_DATA_IAMF_RECON_GAIN_INFO_PARAM
@ AV_PKT_DATA_IAMF_RECON_GAIN_INFO_PARAM
IAMF Recon Gain Info Parameter Data associated with the audio frame.
Definition: packet.h:324
av_packet_add_side_data
int av_packet_add_side_data(AVPacket *pkt, enum AVPacketSideDataType type, uint8_t *data, size_t size)
Wrap an existing array as a packet side data.
Definition: packet.c:197
AV_PKT_DATA_PALETTE
@ AV_PKT_DATA_PALETTE
An AV_PKT_DATA_PALETTE side data packet contains exactly AVPALETTE_SIZE bytes worth of palette.
Definition: packet.h:47
AVPacket::opaque_ref
AVBufferRef * opaque_ref
AVBufferRef for free use by the API user.
Definition: packet.h:560
av_shrink_packet
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
Definition: packet.c:113
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
AV_PKT_DATA_WEBVTT_SETTINGS
@ AV_PKT_DATA_WEBVTT_SETTINGS
The optional settings (rendering instructions) that immediately follow the timestamp specifier of a W...
Definition: packet.h:203
AV_PKT_DATA_PARAM_CHANGE
@ AV_PKT_DATA_PARAM_CHANGE
An AV_PKT_DATA_PARAM_CHANGE side data packet is laid out as follows:
Definition: packet.h:73
pkt
AVPacket * pkt
Definition: movenc.c:60
AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS
@ AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS
Definition: packet.h:602
av_packet_side_data_name
const char * av_packet_side_data_name(enum AVPacketSideDataType type)
Definition: packet.c:269
av_new_packet
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: packet.c:98
AVPacketSideData::data
uint8_t * data
Definition: packet.h:376
AV_PKT_DATA_STEREO3D
@ AV_PKT_DATA_STEREO3D
This side data should be associated with a video stream and contains Stereoscopic 3D information in f...
Definition: packet.h:115
AV_PKT_DATA_SUBTITLE_POSITION
@ AV_PKT_DATA_SUBTITLE_POSITION
Subtitle event position.
Definition: packet.h:184
AVPacket::opaque
void * opaque
for some private data of the user
Definition: packet.h:549
av_packet_side_data_free
void av_packet_side_data_free(AVPacketSideData **sd, int *nb_sd)
Convenience function to free all the side data stored in an array, and the array itself.
Definition: packet.c:742
AVSideDataParamChangeFlags
AVSideDataParamChangeFlags
Definition: packet.h:600
AVPacket::buf
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition: packet.h:507
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AVPacketSideData::type
enum AVPacketSideDataType type
Definition: packet.h:378
av_packet_ref
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
Definition: packet.c:435
av_packet_move_ref
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
Definition: packet.c:484
AV_PKT_DATA_CONTENT_LIGHT_LEVEL
@ AV_PKT_DATA_CONTENT_LIGHT_LEVEL
Content light level (based on CTA-861.3).
Definition: packet.h:236
AV_PKT_DATA_NB
@ AV_PKT_DATA_NB
The number of side data types.
Definition: packet.h:341
av_packet_side_data_get
const AVPacketSideData * av_packet_side_data_get(const AVPacketSideData *sd, int nb_sd, enum AVPacketSideDataType type)
Get side information from a side data array.
Definition: packet.c:654
AV_PKT_DATA_SPHERICAL
@ AV_PKT_DATA_SPHERICAL
This side data should be associated with a video stream and corresponds to the AVSphericalMapping str...
Definition: packet.h:229
av_packet_from_data
int av_packet_from_data(AVPacket *pkt, uint8_t *data, int size)
Initialize a reference-counted packet from av_malloc()ed data.
Definition: packet.c:172
AVPacket::size
int size
Definition: packet.h:525
AV_PKT_DATA_DYNAMIC_HDR10_PLUS
@ AV_PKT_DATA_DYNAMIC_HDR10_PLUS
HDR10+ dynamic metadata associated with a video frame.
Definition: packet.h:300
size
int size
Definition: twinvq_data.h:10344
AV_PKT_DATA_METADATA_UPDATE
@ AV_PKT_DATA_METADATA_UPDATE
A list of zero terminated key/value strings.
Definition: packet.h:210
av_packet_unpack_dictionary
int av_packet_unpack_dictionary(const uint8_t *data, size_t size, AVDictionary **dict)
Unpack a dictionary from side_data.
Definition: packet.c:347
buffer.h
attribute_deprecated
#define attribute_deprecated
Definition: attributes.h:104
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:523
av_packet_side_data_add
AVPacketSideData * av_packet_side_data_add(AVPacketSideData **sd, int *nb_sd, enum AVPacketSideDataType type, void *data, size_t size, int flags)
Wrap existing data as packet side data.
Definition: packet.c:697
AV_PKT_DATA_PRFT
@ AV_PKT_DATA_PRFT
Producer Reference Time data corresponding to the AVProducerReferenceTime struct, usually exported by...
Definition: packet.h:269
attributes.h
av_packet_pack_dictionary
uint8_t * av_packet_pack_dictionary(AVDictionary *dict, size_t *size)
Pack a dictionary for use in side_data.
Definition: packet.c:312
av_packet_make_refcounted
int av_packet_make_refcounted(AVPacket *pkt)
Ensure the data described by a given packet is reference counted.
Definition: packet.c:490
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:530
av_packet_alloc
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition: packet.c:63
av_packet_rescale_ts
void av_packet_rescale_ts(AVPacket *pkt, AVRational tb_src, AVRational tb_dst)
Convert valid timing fields (timestamps / durations) in a packet from one timebase to another.
Definition: packet.c:531
AV_PKT_DATA_STRINGS_METADATA
@ AV_PKT_DATA_STRINGS_METADATA
A list of zero terminated key/value strings.
Definition: packet.h:173
av_packet_copy_props
int av_packet_copy_props(AVPacket *dst, const AVPacket *src)
Copy only "properties" fields from src to dst.
Definition: packet.c:390
AV_PKT_DATA_CPB_PROPERTIES
@ AV_PKT_DATA_CPB_PROPERTIES
This side data corresponds to the AVCPBProperties struct.
Definition: packet.h:146
AV_PKT_DATA_H263_MB_INFO
@ AV_PKT_DATA_H263_MB_INFO
An AV_PKT_DATA_H263_MB_INFO side data packet contains a number of structures with info about macroblo...
Definition: packet.h:94
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:517
av_packet_get_side_data
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
Get side information from packet.
Definition: packet.c:252
AV_PKT_DATA_ICC_PROFILE
@ AV_PKT_DATA_ICC_PROFILE
ICC profile data consisting of an opaque octet buffer following the format described by ISO 15076-1.
Definition: packet.h:275
AV_PKT_DATA_MPEGTS_STREAM_ID
@ AV_PKT_DATA_MPEGTS_STREAM_ID
MPEGTS stream ID as uint8_t, this is required to pass the stream ID information from the demuxer to t...
Definition: packet.h:216
version.h
AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL
@ AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL
Data found in BlockAdditional element of matroska container.
Definition: packet.h:192
AV_PKT_DATA_JP_DUALMONO
@ AV_PKT_DATA_JP_DUALMONO
An AV_PKT_DATA_JP_DUALMONO side data packet indicates that the packet may contain "dual mono" audio s...
Definition: packet.h:167
dict.h
av_packet_side_data_new
AVPacketSideData * av_packet_side_data_new(AVPacketSideData **psd, int *pnb_sd, enum AVPacketSideDataType type, size_t size, int flags)
Allocate a new packet side data.
Definition: packet.c:704
AVPacket::side_data
AVPacketSideData * side_data
Additional packet data that can be provided by the container.
Definition: packet.h:535
AV_PKT_DATA_WEBVTT_IDENTIFIER
@ AV_PKT_DATA_WEBVTT_IDENTIFIER
The optional first identifier line of a WebVTT cue.
Definition: packet.h:197
av_packet_new_side_data
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, size_t size)
Allocate new information of a packet.
Definition: packet.c:231
av_packet_make_writable
int av_packet_make_writable(AVPacket *pkt)
Create a writable reference for the data described by a given packet, avoiding data copy if possible.
Definition: packet.c:509
AV_PKT_DATA_AFD
@ AV_PKT_DATA_AFD
Active Format Description data consisting of a single byte as specified in ETSI TS 101 154 using AVAc...
Definition: packet.h:262
AV_PKT_DATA_SKIP_SAMPLES
@ AV_PKT_DATA_SKIP_SAMPLES
Recommmends skipping the specified number of samples.
Definition: packet.h:157
AVPacketSideDataType
AVPacketSideDataType
Definition: packet.h:41
AVPacket::stream_index
int stream_index
Definition: packet.h:526
AV_PKT_DATA_ENCRYPTION_INFO
@ AV_PKT_DATA_ENCRYPTION_INFO
This side data contains encryption info for how to decrypt the packet.
Definition: packet.h:256
AV_PKT_DATA_AUDIO_SERVICE_TYPE
@ AV_PKT_DATA_AUDIO_SERVICE_TYPE
This side data should be associated with an audio stream and corresponds to enum AVAudioServiceType.
Definition: packet.h:121
AV_PKT_DATA_A53_CC
@ AV_PKT_DATA_A53_CC
ATSC A53 Part 4 Closed Captions.
Definition: packet.h:243
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
AVPacket
This structure stores compressed data.
Definition: packet.h:501
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
AVPacket::pos
int64_t pos
byte position in stream, -1 if unknown
Definition: packet.h:544
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:474
AV_PKT_DATA_IAMF_MIX_GAIN_PARAM
@ AV_PKT_DATA_IAMF_MIX_GAIN_PARAM
IAMF Mix Gain Parameter Data associated with the audio frame.
Definition: packet.h:308
AVPacket::time_base
AVRational time_base
Time base of the packet's timestamps.
Definition: packet.h:568
AVPacket::side_data_elems
int side_data_elems
Definition: packet.h:536
av_packet_clone
AVPacket * av_packet_clone(const AVPacket *src)
Create a new packet that references the same data as src.
Definition: packet.c:471
AV_PKT_DATA_IAMF_DEMIXING_INFO_PARAM
@ AV_PKT_DATA_IAMF_DEMIXING_INFO_PARAM
IAMF Demixing Info Parameter Data associated with the audio frame.
Definition: packet.h:316