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