FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
avcodec.h
Go to the documentation of this file.
1 /*
2  * copyright (c) 2001 Fabrice Bellard
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_AVCODEC_H
22 #define AVCODEC_AVCODEC_H
23 
24 /**
25  * @file
26  * @ingroup libavc
27  * Libavcodec external API header
28  */
29 
30 #include <errno.h>
31 #include "libavutil/samplefmt.h"
32 #include "libavutil/attributes.h"
33 #include "libavutil/avutil.h"
34 #include "libavutil/buffer.h"
35 #include "libavutil/cpu.h"
37 #include "libavutil/dict.h"
38 #include "libavutil/frame.h"
39 #include "libavutil/log.h"
40 #include "libavutil/pixfmt.h"
41 #include "libavutil/rational.h"
42 
43 #include "version.h"
44 
45 /**
46  * @defgroup libavc Encoding/Decoding Library
47  * @{
48  *
49  * @defgroup lavc_decoding Decoding
50  * @{
51  * @}
52  *
53  * @defgroup lavc_encoding Encoding
54  * @{
55  * @}
56  *
57  * @defgroup lavc_codec Codecs
58  * @{
59  * @defgroup lavc_codec_native Native Codecs
60  * @{
61  * @}
62  * @defgroup lavc_codec_wrappers External library wrappers
63  * @{
64  * @}
65  * @defgroup lavc_codec_hwaccel Hardware Accelerators bridge
66  * @{
67  * @}
68  * @}
69  * @defgroup lavc_internal Internal
70  * @{
71  * @}
72  * @}
73  *
74  */
75 
76 /**
77  * @defgroup lavc_core Core functions/structures.
78  * @ingroup libavc
79  *
80  * Basic definitions, functions for querying libavcodec capabilities,
81  * allocating core structures, etc.
82  * @{
83  */
84 
85 
86 /**
87  * Identify the syntax and semantics of the bitstream.
88  * The principle is roughly:
89  * Two decoders with the same ID can decode the same streams.
90  * Two encoders with the same ID can encode compatible streams.
91  * There may be slight deviations from the principle due to implementation
92  * details.
93  *
94  * If you add a codec ID to this list, add it so that
95  * 1. no value of a existing codec ID changes (that would break ABI),
96  * 2. Give it a value which when taken as ASCII is recognized uniquely by a human as this specific codec.
97  * This ensures that 2 forks can independently add AVCodecIDs without producing conflicts.
98  *
99  * After adding new codec IDs, do not forget to add an entry to the codec
100  * descriptor list and bump libavcodec minor version.
101  */
102 enum AVCodecID {
104 
105  /* video codecs */
107  AV_CODEC_ID_MPEG2VIDEO, ///< preferred ID for MPEG-1/2 video decoding
108 #if FF_API_XVMC
109  AV_CODEC_ID_MPEG2VIDEO_XVMC,
110 #endif /* FF_API_XVMC */
293 
294  AV_CODEC_ID_BRENDER_PIX= MKBETAG('B','P','I','X'),
295  AV_CODEC_ID_Y41P = MKBETAG('Y','4','1','P'),
296  AV_CODEC_ID_ESCAPE130 = MKBETAG('E','1','3','0'),
297  AV_CODEC_ID_EXR = MKBETAG('0','E','X','R'),
298  AV_CODEC_ID_AVRP = MKBETAG('A','V','R','P'),
299 
300  AV_CODEC_ID_012V = MKBETAG('0','1','2','V'),
301  AV_CODEC_ID_G2M = MKBETAG( 0 ,'G','2','M'),
302  AV_CODEC_ID_AVUI = MKBETAG('A','V','U','I'),
303  AV_CODEC_ID_AYUV = MKBETAG('A','Y','U','V'),
304  AV_CODEC_ID_TARGA_Y216 = MKBETAG('T','2','1','6'),
305  AV_CODEC_ID_V308 = MKBETAG('V','3','0','8'),
306  AV_CODEC_ID_V408 = MKBETAG('V','4','0','8'),
307  AV_CODEC_ID_YUV4 = MKBETAG('Y','U','V','4'),
308  AV_CODEC_ID_SANM = MKBETAG('S','A','N','M'),
309  AV_CODEC_ID_PAF_VIDEO = MKBETAG('P','A','F','V'),
310  AV_CODEC_ID_AVRN = MKBETAG('A','V','R','n'),
311  AV_CODEC_ID_CPIA = MKBETAG('C','P','I','A'),
312  AV_CODEC_ID_XFACE = MKBETAG('X','F','A','C'),
313  AV_CODEC_ID_SGIRLE = MKBETAG('S','G','I','R'),
314  AV_CODEC_ID_MVC1 = MKBETAG('M','V','C','1'),
315  AV_CODEC_ID_MVC2 = MKBETAG('M','V','C','2'),
316  AV_CODEC_ID_SNOW = MKBETAG('S','N','O','W'),
317  AV_CODEC_ID_WEBP = MKBETAG('W','E','B','P'),
318  AV_CODEC_ID_SMVJPEG = MKBETAG('S','M','V','J'),
319  AV_CODEC_ID_HEVC = MKBETAG('H','2','6','5'),
320 #define AV_CODEC_ID_H265 AV_CODEC_ID_HEVC
321  AV_CODEC_ID_VP7 = MKBETAG('V','P','7','0'),
322 
323  /* various PCM "codecs" */
324  AV_CODEC_ID_FIRST_AUDIO = 0x10000, ///< A dummy id pointing at the start of audio codecs
358 
359  /* various ADPCM codecs */
391  AV_CODEC_ID_ADPCM_VIMA = MKBETAG('V','I','M','A'),
392  AV_CODEC_ID_VIMA = MKBETAG('V','I','M','A'),
393  AV_CODEC_ID_ADPCM_AFC = MKBETAG('A','F','C',' '),
394  AV_CODEC_ID_ADPCM_IMA_OKI = MKBETAG('O','K','I',' '),
395  AV_CODEC_ID_ADPCM_DTK = MKBETAG('D','T','K',' '),
396  AV_CODEC_ID_ADPCM_IMA_RAD = MKBETAG('R','A','D',' '),
397  AV_CODEC_ID_ADPCM_G726LE = MKBETAG('6','2','7','G'),
398 
399  /* AMR */
402 
403  /* RealAudio codecs*/
406 
407  /* various DPCM codecs */
412 
413  /* audio codecs */
414  AV_CODEC_ID_MP2 = 0x15000,
415  AV_CODEC_ID_MP3, ///< preferred ID for decoding MPEG audio layer 1, 2 or 3
432  AV_CODEC_ID_GSM, ///< as in Berlin toast format
444  AV_CODEC_ID_GSM_MS, /* as found in WAV */
446 #if FF_API_VOXWARE
448 #endif
483  AV_CODEC_ID_FFWAVESYNTH = MKBETAG('F','F','W','S'),
484  AV_CODEC_ID_SONIC = MKBETAG('S','O','N','C'),
485  AV_CODEC_ID_SONIC_LS = MKBETAG('S','O','N','L'),
486  AV_CODEC_ID_PAF_AUDIO = MKBETAG('P','A','F','A'),
487  AV_CODEC_ID_OPUS = MKBETAG('O','P','U','S'),
488  AV_CODEC_ID_TAK = MKBETAG('t','B','a','K'),
489  AV_CODEC_ID_EVRC = MKBETAG('s','e','v','c'),
490  AV_CODEC_ID_SMV = MKBETAG('s','s','m','v'),
491  AV_CODEC_ID_DSD_LSBF = MKBETAG('D','S','D','L'),
492  AV_CODEC_ID_DSD_MSBF = MKBETAG('D','S','D','M'),
495 
496  /* subtitle codecs */
497  AV_CODEC_ID_FIRST_SUBTITLE = 0x17000, ///< A dummy ID pointing at the start of subtitle codecs.
500  AV_CODEC_ID_TEXT, ///< raw UTF-8 text
507  AV_CODEC_ID_MICRODVD = MKBETAG('m','D','V','D'),
508  AV_CODEC_ID_EIA_608 = MKBETAG('c','6','0','8'),
509  AV_CODEC_ID_JACOSUB = MKBETAG('J','S','U','B'),
510  AV_CODEC_ID_SAMI = MKBETAG('S','A','M','I'),
511  AV_CODEC_ID_REALTEXT = MKBETAG('R','T','X','T'),
512  AV_CODEC_ID_SUBVIEWER1 = MKBETAG('S','b','V','1'),
513  AV_CODEC_ID_SUBVIEWER = MKBETAG('S','u','b','V'),
514  AV_CODEC_ID_SUBRIP = MKBETAG('S','R','i','p'),
515  AV_CODEC_ID_WEBVTT = MKBETAG('W','V','T','T'),
516  AV_CODEC_ID_MPL2 = MKBETAG('M','P','L','2'),
517  AV_CODEC_ID_VPLAYER = MKBETAG('V','P','l','r'),
518  AV_CODEC_ID_PJS = MKBETAG('P','h','J','S'),
519  AV_CODEC_ID_ASS = MKBETAG('A','S','S',' '), ///< ASS as defined in Matroska
520 
521  /* other specific kind of codecs (generally used for attachments) */
522  AV_CODEC_ID_FIRST_UNKNOWN = 0x18000, ///< A dummy ID pointing at the start of various fake codecs.
523  AV_CODEC_ID_TTF = 0x18000,
524  AV_CODEC_ID_BINTEXT = MKBETAG('B','T','X','T'),
525  AV_CODEC_ID_XBIN = MKBETAG('X','B','I','N'),
526  AV_CODEC_ID_IDF = MKBETAG( 0 ,'I','D','F'),
527  AV_CODEC_ID_OTF = MKBETAG( 0 ,'O','T','F'),
528  AV_CODEC_ID_SMPTE_KLV = MKBETAG('K','L','V','A'),
529  AV_CODEC_ID_DVD_NAV = MKBETAG('D','N','A','V'),
530  AV_CODEC_ID_TIMED_ID3 = MKBETAG('T','I','D','3'),
531  AV_CODEC_ID_BIN_DATA = MKBETAG('D','A','T','A'),
532 
533 
534  AV_CODEC_ID_PROBE = 0x19000, ///< codec_id is not known (like AV_CODEC_ID_NONE) but lavf should attempt to identify it
535 
536  AV_CODEC_ID_MPEG2TS = 0x20000, /**< _FAKE_ codec to indicate a raw MPEG-2 TS
537  * stream (only used by libavformat) */
538  AV_CODEC_ID_MPEG4SYSTEMS = 0x20001, /**< _FAKE_ codec to indicate a MPEG-4 Systems
539  * stream (only used by libavformat) */
540  AV_CODEC_ID_FFMETADATA = 0x21000, ///< Dummy codec for streams containing only metadata information.
541 
542 #if FF_API_CODEC_ID
543 #include "old_codec_ids.h"
544 #endif
545 };
546 
547 /**
548  * This struct describes the properties of a single codec described by an
549  * AVCodecID.
550  * @see avcodec_descriptor_get()
551  */
552 typedef struct AVCodecDescriptor {
553  enum AVCodecID id;
555  /**
556  * Name of the codec described by this descriptor. It is non-empty and
557  * unique for each codec descriptor. It should contain alphanumeric
558  * characters and '_' only.
559  */
560  const char *name;
561  /**
562  * A more descriptive name for this codec. May be NULL.
563  */
564  const char *long_name;
565  /**
566  * Codec properties, a combination of AV_CODEC_PROP_* flags.
567  */
568  int props;
569 
570  /**
571  * MIME type(s) associated with the codec.
572  * May be NULL; if not, a NULL-terminated array of MIME types.
573  * The first item is always non-NULL and is the preferred MIME type.
574  */
575  const char *const *mime_types;
578 /**
579  * Codec uses only intra compression.
580  * Video codecs only.
581  */
582 #define AV_CODEC_PROP_INTRA_ONLY (1 << 0)
583 /**
584  * Codec supports lossy compression. Audio and video codecs only.
585  * @note a codec may support both lossy and lossless
586  * compression modes
587  */
588 #define AV_CODEC_PROP_LOSSY (1 << 1)
589 /**
590  * Codec supports lossless compression. Audio and video codecs only.
591  */
592 #define AV_CODEC_PROP_LOSSLESS (1 << 2)
593 /**
594  * Codec supports frame reordering. That is, the coded order (the order in which
595  * the encoded packets are output by the encoders / stored / input to the
596  * decoders) may be different from the presentation order of the corresponding
597  * frames.
598  *
599  * For codecs that do not have this property set, PTS and DTS should always be
600  * equal.
601  */
602 #define AV_CODEC_PROP_REORDER (1 << 3)
603 /**
604  * Subtitle codec is bitmap based
605  * Decoded AVSubtitle data can be read from the AVSubtitleRect->pict field.
606  */
607 #define AV_CODEC_PROP_BITMAP_SUB (1 << 16)
608 /**
609  * Subtitle codec is text based.
610  * Decoded AVSubtitle data can be read from the AVSubtitleRect->ass field.
611  */
612 #define AV_CODEC_PROP_TEXT_SUB (1 << 17)
614 /**
615  * @ingroup lavc_decoding
616  * Required number of additionally allocated bytes at the end of the input bitstream for decoding.
617  * This is mainly needed because some optimized bitstream readers read
618  * 32 or 64 bit at once and could read over the end.<br>
619  * Note: If the first 23 bits of the additional bytes are not 0, then damaged
620  * MPEG bitstreams could cause overread and segfault.
621  */
622 #define FF_INPUT_BUFFER_PADDING_SIZE 32
624 /**
625  * @ingroup lavc_encoding
626  * minimum encoding buffer size
627  * Used to avoid some checks during header writing.
628  */
629 #define FF_MIN_BUFFER_SIZE 16384
632 /**
633  * @ingroup lavc_encoding
634  * motion estimation type.
635  */
637  ME_ZERO = 1, ///< no search, that is use 0,0 vector whenever one is needed
641  ME_EPZS, ///< enhanced predictive zonal search
642  ME_X1, ///< reserved for experiments
643  ME_HEX, ///< hexagon based search
644  ME_UMH, ///< uneven multi-hexagon search
645  ME_TESA, ///< transformed exhaustive search algorithm
646  ME_ITER=50, ///< iterative search
647 };
649 /**
650  * @ingroup lavc_decoding
651  */
653  /* We leave some space between them for extensions (drop some
654  * keyframes for intra-only or drop just some bidir frames). */
655  AVDISCARD_NONE =-16, ///< discard nothing
656  AVDISCARD_DEFAULT = 0, ///< discard useless packets like 0 size packets in avi
657  AVDISCARD_NONREF = 8, ///< discard all non reference
658  AVDISCARD_BIDIR = 16, ///< discard all bidirectional frames
659  AVDISCARD_NONINTRA= 24, ///< discard all non intra frames
660  AVDISCARD_NONKEY = 32, ///< discard all frames except keyframes
661  AVDISCARD_ALL = 48, ///< discard all
662 };
674  AV_AUDIO_SERVICE_TYPE_NB , ///< Not part of ABI
675 };
677 /**
678  * @ingroup lavc_encoding
679  */
680 typedef struct RcOverride{
683  int qscale; // If this is 0 then quality_factor will be used instead.
687 #if FF_API_MAX_BFRAMES
688 /**
689  * @deprecated there is no libavcodec-wide limit on the number of B-frames
690  */
691 #define FF_MAX_B_FRAMES 16
692 #endif
694 /* encoding support
695  These flags can be passed in AVCodecContext.flags before initialization.
696  Note: Not everything is supported yet.
697 */
699 /**
700  * Allow decoders to produce frames with data planes that are not aligned
701  * to CPU requirements (e.g. due to cropping).
702  */
703 #define CODEC_FLAG_UNALIGNED 0x0001
704 #define CODEC_FLAG_QSCALE 0x0002 ///< Use fixed qscale.
705 #define CODEC_FLAG_4MV 0x0004 ///< 4 MV per MB allowed / advanced prediction for H.263.
706 #define CODEC_FLAG_OUTPUT_CORRUPT 0x0008 ///< Output even those frames that might be corrupted
707 #define CODEC_FLAG_QPEL 0x0010 ///< Use qpel MC.
708 #if FF_API_GMC
709 /**
710  * @deprecated use the "gmc" private option of the libxvid encoder
711  */
712 #define CODEC_FLAG_GMC 0x0020 ///< Use GMC.
713 #endif
714 #if FF_API_MV0
715 /**
716  * @deprecated use the flag "mv0" in the "mpv_flags" private option of the
717  * mpegvideo encoders
718  */
719 #define CODEC_FLAG_MV0 0x0040
720 #endif
721 #if FF_API_INPUT_PRESERVED
722 /**
723  * @deprecated passing reference-counted frames to the encoders replaces this
724  * flag
725  */
726 #define CODEC_FLAG_INPUT_PRESERVED 0x0100
727 #endif
728 #define CODEC_FLAG_PASS1 0x0200 ///< Use internal 2pass ratecontrol in first pass mode.
729 #define CODEC_FLAG_PASS2 0x0400 ///< Use internal 2pass ratecontrol in second pass mode.
730 #define CODEC_FLAG_GRAY 0x2000 ///< Only decode/encode grayscale.
731 #if FF_API_EMU_EDGE
732 /**
733  * @deprecated edges are not used/required anymore. I.e. this flag is now always
734  * set.
735  */
736 #define CODEC_FLAG_EMU_EDGE 0x4000
737 #endif
738 #define CODEC_FLAG_PSNR 0x8000 ///< error[?] variables will be set during encoding.
739 #define CODEC_FLAG_TRUNCATED 0x00010000 /** Input bitstream might be truncated at a random
740  location instead of only at frame boundaries. */
741 #if FF_API_NORMALIZE_AQP
742 /**
743  * @deprecated use the flag "naq" in the "mpv_flags" private option of the
744  * mpegvideo encoders
745  */
746 #define CODEC_FLAG_NORMALIZE_AQP 0x00020000
747 #endif
748 #define CODEC_FLAG_INTERLACED_DCT 0x00040000 ///< Use interlaced DCT.
749 #define CODEC_FLAG_LOW_DELAY 0x00080000 ///< Force low delay.
750 #define CODEC_FLAG_GLOBAL_HEADER 0x00400000 ///< Place global headers in extradata instead of every keyframe.
751 #define CODEC_FLAG_BITEXACT 0x00800000 ///< Use only bitexact stuff (except (I)DCT).
752 /* Fx : Flag for h263+ extra options */
753 #define CODEC_FLAG_AC_PRED 0x01000000 ///< H.263 advanced intra coding / MPEG-4 AC prediction
754 #define CODEC_FLAG_LOOP_FILTER 0x00000800 ///< loop filter
755 #define CODEC_FLAG_INTERLACED_ME 0x20000000 ///< interlaced motion estimation
756 #define CODEC_FLAG_CLOSED_GOP 0x80000000
757 #define CODEC_FLAG2_FAST 0x00000001 ///< Allow non spec compliant speedup tricks.
758 #define CODEC_FLAG2_NO_OUTPUT 0x00000004 ///< Skip bitstream encoding.
759 #define CODEC_FLAG2_LOCAL_HEADER 0x00000008 ///< Place global headers at every keyframe instead of in extradata.
760 #define CODEC_FLAG2_DROP_FRAME_TIMECODE 0x00002000 ///< timecode is in drop frame format. DEPRECATED!!!!
761 #define CODEC_FLAG2_IGNORE_CROP 0x00010000 ///< Discard cropping information from SPS.
763 #define CODEC_FLAG2_CHUNKS 0x00008000 ///< Input bitstream might be truncated at a packet boundaries instead of only at frame boundaries.
764 #define CODEC_FLAG2_SHOW_ALL 0x00400000 ///< Show all frames before the first keyframe
765 #define CODEC_FLAG2_EXPORT_MVS 0x10000000 ///< Export motion vectors through frame side data
766 #define CODEC_FLAG2_SKIP_MANUAL 0x20000000 ///< Do not skip samples and export skip information as frame side data
768 /* Unsupported options :
769  * Syntax Arithmetic coding (SAC)
770  * Reference Picture Selection
771  * Independent Segment Decoding */
772 /* /Fx */
773 /* codec capabilities */
775 #define CODEC_CAP_DRAW_HORIZ_BAND 0x0001 ///< Decoder can use draw_horiz_band callback.
776 /**
777  * Codec uses get_buffer() for allocating buffers and supports custom allocators.
778  * If not set, it might not use get_buffer() at all or use operations that
779  * assume the buffer was allocated by avcodec_default_get_buffer.
780  */
781 #define CODEC_CAP_DR1 0x0002
782 #define CODEC_CAP_TRUNCATED 0x0008
783 #if FF_API_XVMC
784 /* Codec can export data for HW decoding. This flag indicates that
785  * the codec would call get_format() with list that might contain HW accelerated
786  * pixel formats (XvMC, VDPAU, VAAPI, etc). The application can pick any of them
787  * including raw image format.
788  * The application can use the passed context to determine bitstream version,
789  * chroma format, resolution etc.
790  */
791 #define CODEC_CAP_HWACCEL 0x0010
792 #endif /* FF_API_XVMC */
793 /**
794  * Encoder or decoder requires flushing with NULL input at the end in order to
795  * give the complete and correct output.
796  *
797  * NOTE: If this flag is not set, the codec is guaranteed to never be fed with
798  * with NULL data. The user can still send NULL data to the public encode
799  * or decode function, but libavcodec will not pass it along to the codec
800  * unless this flag is set.
801  *
802  * Decoders:
803  * The decoder has a non-zero delay and needs to be fed with avpkt->data=NULL,
804  * avpkt->size=0 at the end to get the delayed data until the decoder no longer
805  * returns frames.
806  *
807  * Encoders:
808  * The encoder needs to be fed with NULL data at the end of encoding until the
809  * encoder no longer returns data.
810  *
811  * NOTE: For encoders implementing the AVCodec.encode2() function, setting this
812  * flag also means that the encoder must set the pts and duration for
813  * each output packet. If this flag is not set, the pts and duration will
814  * be determined by libavcodec from the input frame.
815  */
816 #define CODEC_CAP_DELAY 0x0020
817 /**
818  * Codec can be fed a final frame with a smaller size.
819  * This can be used to prevent truncation of the last audio samples.
820  */
821 #define CODEC_CAP_SMALL_LAST_FRAME 0x0040
822 #if FF_API_CAP_VDPAU
823 /**
824  * Codec can export data for HW decoding (VDPAU).
825  */
826 #define CODEC_CAP_HWACCEL_VDPAU 0x0080
827 #endif
828 /**
829  * Codec can output multiple frames per AVPacket
830  * Normally demuxers return one frame at a time, demuxers which do not do
831  * are connected to a parser to split what they return into proper frames.
832  * This flag is reserved to the very rare category of codecs which have a
833  * bitstream that cannot be split into frames without timeconsuming
834  * operations like full decoding. Demuxers carring such bitstreams thus
835  * may return multiple frames in a packet. This has many disadvantages like
836  * prohibiting stream copy in many cases thus it should only be considered
837  * as a last resort.
838  */
839 #define CODEC_CAP_SUBFRAMES 0x0100
840 /**
841  * Codec is experimental and is thus avoided in favor of non experimental
842  * encoders
843  */
844 #define CODEC_CAP_EXPERIMENTAL 0x0200
845 /**
846  * Codec should fill in channel configuration and samplerate instead of container
847  */
848 #define CODEC_CAP_CHANNEL_CONF 0x0400
849 #if FF_API_NEG_LINESIZES
850 /**
851  * @deprecated no codecs use this capability
852  */
853 #define CODEC_CAP_NEG_LINESIZES 0x0800
854 #endif
855 /**
856  * Codec supports frame-level multithreading.
857  */
858 #define CODEC_CAP_FRAME_THREADS 0x1000
859 /**
860  * Codec supports slice-based (or partition-based) multithreading.
861  */
862 #define CODEC_CAP_SLICE_THREADS 0x2000
863 /**
864  * Codec supports changed parameters at any point.
865  */
866 #define CODEC_CAP_PARAM_CHANGE 0x4000
867 /**
868  * Codec supports avctx->thread_count == 0 (auto).
869  */
870 #define CODEC_CAP_AUTO_THREADS 0x8000
871 /**
872  * Audio encoder supports receiving a different number of samples in each call.
873  */
874 #define CODEC_CAP_VARIABLE_FRAME_SIZE 0x10000
875 /**
876  * Codec is intra only.
877  */
878 #define CODEC_CAP_INTRA_ONLY 0x40000000
879 /**
880  * Codec is lossless.
881  */
882 #define CODEC_CAP_LOSSLESS 0x80000000
884 #if FF_API_MB_TYPE
885 //The following defines may change, don't expect compatibility if you use them.
886 #define MB_TYPE_INTRA4x4 0x0001
887 #define MB_TYPE_INTRA16x16 0x0002 //FIXME H.264-specific
888 #define MB_TYPE_INTRA_PCM 0x0004 //FIXME H.264-specific
889 #define MB_TYPE_16x16 0x0008
890 #define MB_TYPE_16x8 0x0010
891 #define MB_TYPE_8x16 0x0020
892 #define MB_TYPE_8x8 0x0040
893 #define MB_TYPE_INTERLACED 0x0080
894 #define MB_TYPE_DIRECT2 0x0100 //FIXME
895 #define MB_TYPE_ACPRED 0x0200
896 #define MB_TYPE_GMC 0x0400
897 #define MB_TYPE_SKIP 0x0800
898 #define MB_TYPE_P0L0 0x1000
899 #define MB_TYPE_P1L0 0x2000
900 #define MB_TYPE_P0L1 0x4000
901 #define MB_TYPE_P1L1 0x8000
902 #define MB_TYPE_L0 (MB_TYPE_P0L0 | MB_TYPE_P1L0)
903 #define MB_TYPE_L1 (MB_TYPE_P0L1 | MB_TYPE_P1L1)
904 #define MB_TYPE_L0L1 (MB_TYPE_L0 | MB_TYPE_L1)
905 #define MB_TYPE_QUANT 0x00010000
906 #define MB_TYPE_CBP 0x00020000
907 //Note bits 24-31 are reserved for codec specific use (h264 ref0, mpeg1 0mv, ...)
908 #endif
910 /**
911  * Pan Scan area.
912  * This specifies the area which should be displayed.
913  * Note there may be multiple such areas for one frame.
914  */
915 typedef struct AVPanScan{
916  /**
917  * id
918  * - encoding: Set by user.
919  * - decoding: Set by libavcodec.
920  */
921  int id;
923  /**
924  * width and height in 1/16 pel
925  * - encoding: Set by user.
926  * - decoding: Set by libavcodec.
927  */
928  int width;
929  int height;
931  /**
932  * position of the top left corner in 1/16 pel for up to 3 fields/frames
933  * - encoding: Set by user.
934  * - decoding: Set by libavcodec.
935  */
936  int16_t position[3][2];
937 }AVPanScan;
939 #if FF_API_QSCALE_TYPE
940 #define FF_QSCALE_TYPE_MPEG1 0
941 #define FF_QSCALE_TYPE_MPEG2 1
942 #define FF_QSCALE_TYPE_H264 2
943 #define FF_QSCALE_TYPE_VP56 3
944 #endif
945 
946 #if FF_API_GET_BUFFER
947 #define FF_BUFFER_TYPE_INTERNAL 1
948 #define FF_BUFFER_TYPE_USER 2 ///< direct rendering buffers (image is (de)allocated by user)
949 #define FF_BUFFER_TYPE_SHARED 4 ///< Buffer from somewhere else; don't deallocate image (data/base), all other tables are not shared.
950 #define FF_BUFFER_TYPE_COPY 8 ///< Just a (modified) copy of some other buffer, don't deallocate anything.
952 #define FF_BUFFER_HINTS_VALID 0x01 // Buffer hints value is meaningful (if 0 ignore).
953 #define FF_BUFFER_HINTS_READABLE 0x02 // Codec will read from buffer.
954 #define FF_BUFFER_HINTS_PRESERVE 0x04 // User must not alter buffer content.
955 #define FF_BUFFER_HINTS_REUSABLE 0x08 // Codec will reuse the buffer (update).
956 #endif
957 
958 /**
959  * The decoder will keep a reference to the frame and may reuse it later.
960  */
961 #define AV_GET_BUFFER_FLAG_REF (1 << 0)
962 
963 /**
964  * @defgroup lavc_packet AVPacket
965  *
966  * Types and functions for working with AVPacket.
967  * @{
968  */
972 
973  /**
974  * An AV_PKT_DATA_PARAM_CHANGE side data packet is laid out as follows:
975  * @code
976  * u32le param_flags
977  * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT)
978  * s32le channel_count
979  * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT)
980  * u64le channel_layout
981  * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE)
982  * s32le sample_rate
983  * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS)
984  * s32le width
985  * s32le height
986  * @endcode
987  */
989 
990  /**
991  * An AV_PKT_DATA_H263_MB_INFO side data packet contains a number of
992  * structures with info about macroblocks relevant to splitting the
993  * packet into smaller packets on macroblock edges (e.g. as for RFC 2190).
994  * That is, it does not necessarily contain info about all macroblocks,
995  * as long as the distance between macroblocks in the info is smaller
996  * than the target payload size.
997  * Each MB info structure is 12 bytes, and is laid out as follows:
998  * @code
999  * u32le bit offset from the start of the packet
1000  * u8 current quantizer at the start of the macroblock
1001  * u8 GOB number
1002  * u16le macroblock address within the GOB
1003  * u8 horizontal MV predictor
1004  * u8 vertical MV predictor
1005  * u8 horizontal MV predictor for block number 3
1006  * u8 vertical MV predictor for block number 3
1007  * @endcode
1008  */
1010 
1011  /**
1012  * This side data should be associated with an audio stream and contains
1013  * ReplayGain information in form of the AVReplayGain struct.
1014  */
1016 
1017  /**
1018  * This side data contains a 3x3 transformation matrix describing an affine
1019  * transformation that needs to be applied to the decoded video frames for
1020  * correct presentation.
1021  *
1022  * See libavutil/display.h for a detailed description of the data.
1023  */
1025 
1026  /**
1027  * This side data should be associated with a video stream and contains
1028  * Stereoscopic 3D information in form of the AVStereo3D struct.
1029  */
1031 
1032  /**
1033  * Recommmends skipping the specified number of samples
1034  * @code
1035  * u32le number of samples to skip from start of this packet
1036  * u32le number of samples to skip from end of this packet
1037  * u8 reason for start skip
1038  * u8 reason for end skip (0=padding silence, 1=convergence)
1039  * @endcode
1040  */
1042 
1043  /**
1044  * An AV_PKT_DATA_JP_DUALMONO side data packet indicates that
1045  * the packet may contain "dual mono" audio specific to Japanese DTV
1046  * and if it is true, recommends only the selected channel to be used.
1047  * @code
1048  * u8 selected channels (0=mail/left, 1=sub/right, 2=both)
1049  * @endcode
1050  */
1052 
1053  /**
1054  * A list of zero terminated key/value strings. There is no end marker for
1055  * the list, so it is required to rely on the side data size to stop.
1056  */
1058 
1059  /**
1060  * Subtitle event position
1061  * @code
1062  * u32le x1
1063  * u32le y1
1064  * u32le x2
1065  * u32le y2
1066  * @endcode
1067  */
1069 
1070  /**
1071  * Data found in BlockAdditional element of matroska container. There is
1072  * no end marker for the data, so it is required to rely on the side data
1073  * size to recognize the end. 8 byte id (as found in BlockAddId) followed
1074  * by data.
1075  */
1077 
1078  /**
1079  * The optional first identifier line of a WebVTT cue.
1080  */
1082 
1083  /**
1084  * The optional settings (rendering instructions) that immediately
1085  * follow the timestamp specifier of a WebVTT cue.
1086  */
1088 
1089  /**
1090  * A list of zero terminated key/value strings. There is no end marker for
1091  * the list, so it is required to rely on the side data size to stop. This
1092  * side data includes updated metadata which appeared in the stream.
1093  */
1095 };
1097 typedef struct AVPacketSideData {
1099  int size;
1102 
1103 /**
1104  * This structure stores compressed data. It is typically exported by demuxers
1105  * and then passed as input to decoders, or received as output from encoders and
1106  * then passed to muxers.
1107  *
1108  * For video, it should typically contain one compressed frame. For audio it may
1109  * contain several compressed frames.
1110  *
1111  * AVPacket is one of the few structs in FFmpeg, whose size is a part of public
1112  * ABI. Thus it may be allocated on stack and no new fields can be added to it
1113  * without libavcodec and libavformat major bump.
1114  *
1115  * The semantics of data ownership depends on the buf or destruct (deprecated)
1116  * fields. If either is set, the packet data is dynamically allocated and is
1117  * valid indefinitely until av_free_packet() is called (which in turn calls
1118  * av_buffer_unref()/the destruct callback to free the data). If neither is set,
1119  * the packet data is typically backed by some static buffer somewhere and is
1120  * only valid for a limited time (e.g. until the next read call when demuxing).
1121  *
1122  * The side data is always allocated with av_malloc() and is freed in
1123  * av_free_packet().
1124  */
1125 typedef struct AVPacket {
1126  /**
1127  * A reference to the reference-counted buffer where the packet data is
1128  * stored.
1129  * May be NULL, then the packet data is not reference-counted.
1130  */
1131  AVBufferRef *buf;
1132  /**
1133  * Presentation timestamp in AVStream->time_base units; the time at which
1134  * the decompressed packet will be presented to the user.
1135  * Can be AV_NOPTS_VALUE if it is not stored in the file.
1136  * pts MUST be larger or equal to dts as presentation cannot happen before
1137  * decompression, unless one wants to view hex dumps. Some formats misuse
1138  * the terms dts and pts/cts to mean something different. Such timestamps
1139  * must be converted to true pts/dts before they are stored in AVPacket.
1140  */
1141  int64_t pts;
1142  /**
1143  * Decompression timestamp in AVStream->time_base units; the time at which
1144  * the packet is decompressed.
1145  * Can be AV_NOPTS_VALUE if it is not stored in the file.
1146  */
1147  int64_t dts;
1149  int size;
1150  int stream_index;
1151  /**
1152  * A combination of AV_PKT_FLAG values
1153  */
1154  int flags;
1155  /**
1156  * Additional packet data that can be provided by the container.
1157  * Packet can contain several types of side information.
1158  */
1160  int side_data_elems;
1161 
1162  /**
1163  * Duration of this packet in AVStream->time_base units, 0 if unknown.
1164  * Equals next_pts - this_pts in presentation order.
1165  */
1166  int duration;
1167 #if FF_API_DESTRUCT_PACKET
1169  void (*destruct)(struct AVPacket *);
1171  void *priv;
1172 #endif
1173  int64_t pos; ///< byte position in stream, -1 if unknown
1174 
1175  /**
1176  * Time difference in AVStream->time_base units from the pts of this
1177  * packet to the point at which the output from the decoder has converged
1178  * independent from the availability of previous frames. That is, the
1179  * frames are virtually identical no matter if decoding started from
1180  * the very first frame or from this keyframe.
1181  * Is AV_NOPTS_VALUE if unknown.
1182  * This field is not the display duration of the current packet.
1183  * This field has no meaning if the packet does not have AV_PKT_FLAG_KEY
1184  * set.
1185  *
1186  * The purpose of this field is to allow seeking in streams that have no
1187  * keyframes in the conventional sense. It corresponds to the
1188  * recovery point SEI in H.264 and match_time_delta in NUT. It is also
1189  * essential for some types of subtitle streams to ensure that all
1190  * subtitles are correctly displayed after seeking.
1191  */
1192  int64_t convergence_duration;
1194 #define AV_PKT_FLAG_KEY 0x0001 ///< The packet contains a keyframe
1195 #define AV_PKT_FLAG_CORRUPT 0x0002 ///< The packet content is corrupted
1202 };
1203 /**
1204  * @}
1205  */
1206 
1207 struct AVCodecInternal;
1212  AV_FIELD_TT, //< Top coded_first, top displayed first
1213  AV_FIELD_BB, //< Bottom coded first, bottom displayed first
1214  AV_FIELD_TB, //< Top coded first, bottom displayed first
1215  AV_FIELD_BT, //< Bottom coded first, top displayed first
1216 };
1217 
1218 /**
1219  * main external API structure.
1220  * New fields can be added to the end with minor version bumps.
1221  * Removal, reordering and changes to existing fields require a major
1222  * version bump.
1223  * Please use AVOptions (av_opt* / av_set/get*()) to access these fields from user
1224  * applications.
1225  * sizeof(AVCodecContext) must not be used outside libav*.
1226  */
1227 typedef struct AVCodecContext {
1228  /**
1229  * information on struct for av_log
1230  * - set by avcodec_alloc_context3
1231  */
1233  int log_level_offset;
1235  enum AVMediaType codec_type; /* see AVMEDIA_TYPE_xxx */
1236  const struct AVCodec *codec;
1237 #if FF_API_CODEC_NAME
1238  /**
1239  * @deprecated this field is not used for anything in libavcodec
1240  */
1242  char codec_name[32];
1243 #endif
1244  enum AVCodecID codec_id; /* see AV_CODEC_ID_xxx */
1245 
1246  /**
1247  * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
1248  * This is used to work around some encoder bugs.
1249  * A demuxer should set this to what is stored in the field used to identify the codec.
1250  * If there are multiple such fields in a container then the demuxer should choose the one
1251  * which maximizes the information about the used codec.
1252  * If the codec tag field in a container is larger than 32 bits then the demuxer should
1253  * remap the longer ID to 32 bits with a table or other structure. Alternatively a new
1254  * extra_codec_tag + size could be added but for this a clear advantage must be demonstrated
1255  * first.
1256  * - encoding: Set by user, if not then the default based on codec_id will be used.
1257  * - decoding: Set by user, will be converted to uppercase by libavcodec during init.
1258  */
1259  unsigned int codec_tag;
1260 
1261  /**
1262  * fourcc from the AVI stream header (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
1263  * This is used to work around some encoder bugs.
1264  * - encoding: unused
1265  * - decoding: Set by user, will be converted to uppercase by libavcodec during init.
1266  */
1267  unsigned int stream_codec_tag;
1269  void *priv_data;
1270 
1271  /**
1272  * Private context used for internal data.
1273  *
1274  * Unlike priv_data, this is not codec-specific. It is used in general
1275  * libavcodec functions.
1276  */
1277  struct AVCodecInternal *internal;
1278 
1279  /**
1280  * Private data of the user, can be used to carry app specific stuff.
1281  * - encoding: Set by user.
1282  * - decoding: Set by user.
1283  */
1284  void *opaque;
1285 
1286  /**
1287  * the average bitrate
1288  * - encoding: Set by user; unused for constant quantizer encoding.
1289  * - decoding: Set by libavcodec. 0 or some bitrate if this info is available in the stream.
1290  */
1291  int bit_rate;
1292 
1293  /**
1294  * number of bits the bitstream is allowed to diverge from the reference.
1295  * the reference can be CBR (for CBR pass1) or VBR (for pass2)
1296  * - encoding: Set by user; unused for constant quantizer encoding.
1297  * - decoding: unused
1298  */
1299  int bit_rate_tolerance;
1300 
1301  /**
1302  * Global quality for codecs which cannot change it per frame.
1303  * This should be proportional to MPEG-1/2/4 qscale.
1304  * - encoding: Set by user.
1305  * - decoding: unused
1306  */
1307  int global_quality;
1308 
1309  /**
1310  * - encoding: Set by user.
1311  * - decoding: unused
1312  */
1314 #define FF_COMPRESSION_DEFAULT -1
1315 
1316  /**
1317  * CODEC_FLAG_*.
1318  * - encoding: Set by user.
1319  * - decoding: Set by user.
1320  */
1321  int flags;
1322 
1323  /**
1324  * CODEC_FLAG2_*
1325  * - encoding: Set by user.
1326  * - decoding: Set by user.
1327  */
1328  int flags2;
1329 
1330  /**
1331  * some codecs need / can use extradata like Huffman tables.
1332  * mjpeg: Huffman tables
1333  * rv10: additional flags
1334  * mpeg4: global headers (they can be in the bitstream or here)
1335  * The allocated memory should be FF_INPUT_BUFFER_PADDING_SIZE bytes larger
1336  * than extradata_size to avoid problems if it is read with the bitstream reader.
1337  * The bytewise contents of extradata must not depend on the architecture or CPU endianness.
1338  * - encoding: Set/allocated/freed by libavcodec.
1339  * - decoding: Set/allocated/freed by user.
1340  */
1342  int extradata_size;
1343 
1344  /**
1345  * This is the fundamental unit of time (in seconds) in terms
1346  * of which frame timestamps are represented. For fixed-fps content,
1347  * timebase should be 1/framerate and timestamp increments should be
1348  * identically 1.
1349  * This often, but not always is the inverse of the frame rate or field rate
1350  * for video.
1351  * - encoding: MUST be set by user.
1352  * - decoding: the use of this field for decoding is deprecated.
1353  * Use framerate instead.
1354  */
1356 
1357  /**
1358  * For some codecs, the time base is closer to the field rate than the frame rate.
1359  * Most notably, H.264 and MPEG-2 specify time_base as half of frame duration
1360  * if no telecine is used ...
1361  *
1362  * Set to time_base ticks per frame. Default 1, e.g., H.264/MPEG-2 set it to 2.
1363  */
1364  int ticks_per_frame;
1365 
1366  /**
1367  * Codec delay.
1368  *
1369  * Encoding: Number of frames delay there will be from the encoder input to
1370  * the decoder output. (we assume the decoder matches the spec)
1371  * Decoding: Number of frames delay in addition to what a standard decoder
1372  * as specified in the spec would produce.
1373  *
1374  * Video:
1375  * Number of frames the decoded output will be delayed relative to the
1376  * encoded input.
1377  *
1378  * Audio:
1379  * For encoding, this field is unused (see initial_padding).
1380  *
1381  * For decoding, this is the number of samples the decoder needs to
1382  * output before the decoder's output is valid. When seeking, you should
1383  * start decoding this many samples prior to your desired seek point.
1384  *
1385  * - encoding: Set by libavcodec.
1386  * - decoding: Set by libavcodec.
1387  */
1388  int delay;
1389 
1390 
1391  /* video only */
1392  /**
1393  * picture width / height.
1394  * - encoding: MUST be set by user.
1395  * - decoding: May be set by the user before opening the decoder if known e.g.
1396  * from the container. Some decoders will require the dimensions
1397  * to be set by the caller. During decoding, the decoder may
1398  * overwrite those values as required.
1399  */
1400  int width, height;
1401 
1402  /**
1403  * Bitstream width / height, may be different from width/height e.g. when
1404  * the decoded frame is cropped before being output or lowres is enabled.
1405  * - encoding: unused
1406  * - decoding: May be set by the user before opening the decoder if known
1407  * e.g. from the container. During decoding, the decoder may
1408  * overwrite those values as required.
1409  */
1411 
1412 #if FF_API_ASPECT_EXTENDED
1413 #define FF_ASPECT_EXTENDED 15
1414 #endif
1415 
1416  /**
1417  * the number of pictures in a group of pictures, or 0 for intra_only
1418  * - encoding: Set by user.
1419  * - decoding: unused
1420  */
1421  int gop_size;
1422 
1423  /**
1424  * Pixel format, see AV_PIX_FMT_xxx.
1425  * May be set by the demuxer if known from headers.
1426  * May be overridden by the decoder if it knows better.
1427  * - encoding: Set by user.
1428  * - decoding: Set by user if known, overridden by libavcodec if known
1429  */
1430  enum AVPixelFormat pix_fmt;
1431 
1432  /**
1433  * Motion estimation algorithm used for video coding.
1434  * 1 (zero), 2 (full), 3 (log), 4 (phods), 5 (epzs), 6 (x1), 7 (hex),
1435  * 8 (umh), 9 (iter), 10 (tesa) [7, 8, 10 are x264 specific, 9 is snow specific]
1436  * - encoding: MUST be set by user.
1437  * - decoding: unused
1438  */
1439  int me_method;
1440 
1441  /**
1442  * If non NULL, 'draw_horiz_band' is called by the libavcodec
1443  * decoder to draw a horizontal band. It improves cache usage. Not
1444  * all codecs can do that. You must check the codec capabilities
1445  * beforehand.
1446  * When multithreading is used, it may be called from multiple threads
1447  * at the same time; threads might draw different parts of the same AVFrame,
1448  * or multiple AVFrames, and there is no guarantee that slices will be drawn
1449  * in order.
1450  * The function is also used by hardware acceleration APIs.
1451  * It is called at least once during frame decoding to pass
1452  * the data needed for hardware render.
1453  * In that mode instead of pixel data, AVFrame points to
1454  * a structure specific to the acceleration API. The application
1455  * reads the structure and can change some fields to indicate progress
1456  * or mark state.
1457  * - encoding: unused
1458  * - decoding: Set by user.
1459  * @param height the height of the slice
1460  * @param y the y position of the slice
1461  * @param type 1->top field, 2->bottom field, 3->frame
1462  * @param offset offset into the AVFrame.data from which the slice should be read
1463  */
1464  void (*draw_horiz_band)(struct AVCodecContext *s,
1465  const AVFrame *src, int offset[AV_NUM_DATA_POINTERS],
1466  int y, int type, int height);
1467 
1468  /**
1469  * callback to negotiate the pixelFormat
1470  * @param fmt is the list of formats which are supported by the codec,
1471  * it is terminated by -1 as 0 is a valid format, the formats are ordered by quality.
1472  * The first is always the native one.
1473  * @note The callback may be called again immediately if initialization for
1474  * the selected (hardware-accelerated) pixel format failed.
1475  * @warning Behavior is undefined if the callback returns a value not
1476  * in the fmt list of formats.
1477  * @return the chosen format
1478  * - encoding: unused
1479  * - decoding: Set by user, if not set the native format will be chosen.
1480  */
1481  enum AVPixelFormat (*get_format)(struct AVCodecContext *s, const enum AVPixelFormat * fmt);
1482 
1483  /**
1484  * maximum number of B-frames between non-B-frames
1485  * Note: The output will be delayed by max_b_frames+1 relative to the input.
1486  * - encoding: Set by user.
1487  * - decoding: unused
1488  */
1489  int max_b_frames;
1490 
1491  /**
1492  * qscale factor between IP and B-frames
1493  * If > 0 then the last P-frame quantizer will be used (q= lastp_q*factor+offset).
1494  * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset).
1495  * - encoding: Set by user.
1496  * - decoding: unused
1497  */
1498  float b_quant_factor;
1499 
1500  /** obsolete FIXME remove */
1502 #define FF_RC_STRATEGY_XVID 1
1504  int b_frame_strategy;
1505 
1506  /**
1507  * qscale offset between IP and B-frames
1508  * - encoding: Set by user.
1509  * - decoding: unused
1510  */
1511  float b_quant_offset;
1512 
1513  /**
1514  * Size of the frame reordering buffer in the decoder.
1515  * For MPEG-2 it is 1 IPB or 0 low delay IP.
1516  * - encoding: Set by libavcodec.
1517  * - decoding: Set by libavcodec.
1518  */
1519  int has_b_frames;
1520 
1521  /**
1522  * 0-> h263 quant 1-> mpeg quant
1523  * - encoding: Set by user.
1524  * - decoding: unused
1525  */
1526  int mpeg_quant;
1527 
1528  /**
1529  * qscale factor between P and I-frames
1530  * If > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset).
1531  * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset).
1532  * - encoding: Set by user.
1533  * - decoding: unused
1534  */
1535  float i_quant_factor;
1536 
1537  /**
1538  * qscale offset between P and I-frames
1539  * - encoding: Set by user.
1540  * - decoding: unused
1541  */
1542  float i_quant_offset;
1543 
1544  /**
1545  * luminance masking (0-> disabled)
1546  * - encoding: Set by user.
1547  * - decoding: unused
1548  */
1549  float lumi_masking;
1550 
1551  /**
1552  * temporary complexity masking (0-> disabled)
1553  * - encoding: Set by user.
1554  * - decoding: unused
1555  */
1556  float temporal_cplx_masking;
1557 
1558  /**
1559  * spatial complexity masking (0-> disabled)
1560  * - encoding: Set by user.
1561  * - decoding: unused
1562  */
1563  float spatial_cplx_masking;
1564 
1565  /**
1566  * p block masking (0-> disabled)
1567  * - encoding: Set by user.
1568  * - decoding: unused
1569  */
1570  float p_masking;
1571 
1572  /**
1573  * darkness masking (0-> disabled)
1574  * - encoding: Set by user.
1575  * - decoding: unused
1576  */
1577  float dark_masking;
1578 
1579  /**
1580  * slice count
1581  * - encoding: Set by libavcodec.
1582  * - decoding: Set by user (or 0).
1583  */
1584  int slice_count;
1585  /**
1586  * prediction method (needed for huffyuv)
1587  * - encoding: Set by user.
1588  * - decoding: unused
1589  */
1591 #define FF_PRED_LEFT 0
1592 #define FF_PRED_PLANE 1
1593 #define FF_PRED_MEDIAN 2
1594 
1595  /**
1596  * slice offsets in the frame in bytes
1597  * - encoding: Set/allocated by libavcodec.
1598  * - decoding: Set/allocated by user (or NULL).
1599  */
1600  int *slice_offset;
1601 
1602  /**
1603  * sample aspect ratio (0 if unknown)
1604  * That is the width of a pixel divided by the height of the pixel.
1605  * Numerator and denominator must be relatively prime and smaller than 256 for some video standards.
1606  * - encoding: Set by user.
1607  * - decoding: Set by libavcodec.
1608  */
1610 
1611  /**
1612  * motion estimation comparison function
1613  * - encoding: Set by user.
1614  * - decoding: unused
1615  */
1616  int me_cmp;
1617  /**
1618  * subpixel motion estimation comparison function
1619  * - encoding: Set by user.
1620  * - decoding: unused
1621  */
1622  int me_sub_cmp;
1623  /**
1624  * macroblock comparison function (not supported yet)
1625  * - encoding: Set by user.
1626  * - decoding: unused
1627  */
1628  int mb_cmp;
1629  /**
1630  * interlaced DCT comparison function
1631  * - encoding: Set by user.
1632  * - decoding: unused
1633  */
1635 #define FF_CMP_SAD 0
1636 #define FF_CMP_SSE 1
1637 #define FF_CMP_SATD 2
1638 #define FF_CMP_DCT 3
1639 #define FF_CMP_PSNR 4
1640 #define FF_CMP_BIT 5
1641 #define FF_CMP_RD 6
1642 #define FF_CMP_ZERO 7
1643 #define FF_CMP_VSAD 8
1644 #define FF_CMP_VSSE 9
1645 #define FF_CMP_NSSE 10
1646 #define FF_CMP_W53 11
1647 #define FF_CMP_W97 12
1648 #define FF_CMP_DCTMAX 13
1649 #define FF_CMP_DCT264 14
1650 #define FF_CMP_CHROMA 256
1651 
1652  /**
1653  * ME diamond size & shape
1654  * - encoding: Set by user.
1655  * - decoding: unused
1656  */
1657  int dia_size;
1658 
1659  /**
1660  * amount of previous MV predictors (2a+1 x 2a+1 square)
1661  * - encoding: Set by user.
1662  * - decoding: unused
1663  */
1665 
1666  /**
1667  * prepass for motion estimation
1668  * - encoding: Set by user.
1669  * - decoding: unused
1670  */
1671  int pre_me;
1672 
1673  /**
1674  * motion estimation prepass comparison function
1675  * - encoding: Set by user.
1676  * - decoding: unused
1677  */
1678  int me_pre_cmp;
1679 
1680  /**
1681  * ME prepass diamond size & shape
1682  * - encoding: Set by user.
1683  * - decoding: unused
1684  */
1685  int pre_dia_size;
1686 
1687  /**
1688  * subpel ME quality
1689  * - encoding: Set by user.
1690  * - decoding: unused
1691  */
1692  int me_subpel_quality;
1693 
1694 #if FF_API_AFD
1695  /**
1696  * DTG active format information (additional aspect ratio
1697  * information only used in DVB MPEG-2 transport streams)
1698  * 0 if not set.
1699  *
1700  * - encoding: unused
1701  * - decoding: Set by decoder.
1702  * @deprecated Deprecated in favor of AVSideData
1703  */
1705 #define FF_DTG_AFD_SAME 8
1706 #define FF_DTG_AFD_4_3 9
1707 #define FF_DTG_AFD_16_9 10
1708 #define FF_DTG_AFD_14_9 11
1709 #define FF_DTG_AFD_4_3_SP_14_9 13
1710 #define FF_DTG_AFD_16_9_SP_14_9 14
1711 #define FF_DTG_AFD_SP_4_3 15
1712 #endif /* FF_API_AFD */
1713 
1714  /**
1715  * maximum motion estimation search range in subpel units
1716  * If 0 then no limit.
1717  *
1718  * - encoding: Set by user.
1719  * - decoding: unused
1720  */
1721  int me_range;
1722 
1723  /**
1724  * intra quantizer bias
1725  * - encoding: Set by user.
1726  * - decoding: unused
1727  */
1729 #define FF_DEFAULT_QUANT_BIAS 999999
1730 
1731  /**
1732  * inter quantizer bias
1733  * - encoding: Set by user.
1734  * - decoding: unused
1735  */
1736  int inter_quant_bias;
1737 
1738  /**
1739  * slice flags
1740  * - encoding: unused
1741  * - decoding: Set by user.
1742  */
1744 #define SLICE_FLAG_CODED_ORDER 0x0001 ///< draw_horiz_band() is called in coded order instead of display
1745 #define SLICE_FLAG_ALLOW_FIELD 0x0002 ///< allow draw_horiz_band() with field slices (MPEG2 field pics)
1746 #define SLICE_FLAG_ALLOW_PLANE 0x0004 ///< allow draw_horiz_band() with 1 component at a time (SVQ1)
1747 
1748 #if FF_API_XVMC
1749  /**
1750  * XVideo Motion Acceleration
1751  * - encoding: forbidden
1752  * - decoding: set by decoder
1753  * @deprecated XvMC doesn't need it anymore.
1754  */
1755  attribute_deprecated int xvmc_acceleration;
1756 #endif /* FF_API_XVMC */
1757 
1758  /**
1759  * macroblock decision mode
1760  * - encoding: Set by user.
1761  * - decoding: unused
1762  */
1764 #define FF_MB_DECISION_SIMPLE 0 ///< uses mb_cmp
1765 #define FF_MB_DECISION_BITS 1 ///< chooses the one which needs the fewest bits
1766 #define FF_MB_DECISION_RD 2 ///< rate distortion
1767 
1768  /**
1769  * custom intra quantization matrix
1770  * - encoding: Set by user, can be NULL.
1771  * - decoding: Set by libavcodec.
1772  */
1773  uint16_t *intra_matrix;
1774 
1775  /**
1776  * custom inter quantization matrix
1777  * - encoding: Set by user, can be NULL.
1778  * - decoding: Set by libavcodec.
1779  */
1780  uint16_t *inter_matrix;
1781 
1782  /**
1783  * scene change detection threshold
1784  * 0 is default, larger means fewer detected scene changes.
1785  * - encoding: Set by user.
1786  * - decoding: unused
1787  */
1789 
1790  /**
1791  * noise reduction strength
1792  * - encoding: Set by user.
1793  * - decoding: unused
1794  */
1795  int noise_reduction;
1796 
1797 #if FF_API_MPV_OPT
1798  /**
1799  * @deprecated this field is unused
1800  */
1802  int me_threshold;
1803 
1804  /**
1805  * @deprecated this field is unused
1806  */
1808  int mb_threshold;
1809 #endif
1810 
1811  /**
1812  * precision of the intra DC coefficient - 8
1813  * - encoding: Set by user.
1814  * - decoding: unused
1815  */
1816  int intra_dc_precision;
1817 
1818  /**
1819  * Number of macroblock rows at the top which are skipped.
1820  * - encoding: unused
1821  * - decoding: Set by user.
1822  */
1823  int skip_top;
1824 
1825  /**
1826  * Number of macroblock rows at the bottom which are skipped.
1827  * - encoding: unused
1828  * - decoding: Set by user.
1829  */
1830  int skip_bottom;
1831 
1832 #if FF_API_MPV_OPT
1833  /**
1834  * @deprecated use encoder private options instead
1835  */
1837  float border_masking;
1838 #endif
1839 
1840  /**
1841  * minimum MB lagrange multipler
1842  * - encoding: Set by user.
1843  * - decoding: unused
1844  */
1845  int mb_lmin;
1846 
1847  /**
1848  * maximum MB lagrange multipler
1849  * - encoding: Set by user.
1850  * - decoding: unused
1851  */
1852  int mb_lmax;
1853 
1854  /**
1855  *
1856  * - encoding: Set by user.
1857  * - decoding: unused
1858  */
1860 
1861  /**
1862  *
1863  * - encoding: Set by user.
1864  * - decoding: unused
1865  */
1866  int bidir_refine;
1867 
1868  /**
1869  *
1870  * - encoding: Set by user.
1871  * - decoding: unused
1872  */
1873  int brd_scale;
1874 
1875  /**
1876  * minimum GOP size
1877  * - encoding: Set by user.
1878  * - decoding: unused
1879  */
1880  int keyint_min;
1881 
1882  /**
1883  * number of reference frames
1884  * - encoding: Set by user.
1885  * - decoding: Set by lavc.
1886  */
1887  int refs;
1888 
1889  /**
1890  * chroma qp offset from luma
1891  * - encoding: Set by user.
1892  * - decoding: unused
1893  */
1894  int chromaoffset;
1895 
1896 #if FF_API_UNUSED_MEMBERS
1897  /**
1898  * Multiplied by qscale for each frame and added to scene_change_score.
1899  * - encoding: Set by user.
1900  * - decoding: unused
1901  */
1903 #endif
1904 
1905  /**
1906  *
1907  * Note: Value depends upon the compare function used for fullpel ME.
1908  * - encoding: Set by user.
1909  * - decoding: unused
1910  */
1911  int mv0_threshold;
1912 
1913  /**
1914  * Adjust sensitivity of b_frame_strategy 1.
1915  * - encoding: Set by user.
1916  * - decoding: unused
1917  */
1918  int b_sensitivity;
1919 
1920  /**
1921  * Chromaticity coordinates of the source primaries.
1922  * - encoding: Set by user
1923  * - decoding: Set by libavcodec
1924  */
1926 
1927  /**
1928  * Color Transfer Characteristic.
1929  * - encoding: Set by user
1930  * - decoding: Set by libavcodec
1931  */
1933 
1934  /**
1935  * YUV colorspace type.
1936  * - encoding: Set by user
1937  * - decoding: Set by libavcodec
1938  */
1939  enum AVColorSpace colorspace;
1940 
1941  /**
1942  * MPEG vs JPEG YUV range.
1943  * - encoding: Set by user
1944  * - decoding: Set by libavcodec
1945  */
1947 
1948  /**
1949  * This defines the location of chroma samples.
1950  * - encoding: Set by user
1951  * - decoding: Set by libavcodec
1952  */
1954 
1955  /**
1956  * Number of slices.
1957  * Indicates number of picture subdivisions. Used for parallelized
1958  * decoding.
1959  * - encoding: Set by user
1960  * - decoding: unused
1961  */
1962  int slices;
1963 
1964  /** Field order
1965  * - encoding: set by libavcodec
1966  * - decoding: Set by user.
1967  */
1969 
1970  /* audio only */
1971  int sample_rate; ///< samples per second
1972  int channels; ///< number of audio channels
1973 
1974  /**
1975  * audio sample format
1976  * - encoding: Set by user.
1977  * - decoding: Set by libavcodec.
1978  */
1979  enum AVSampleFormat sample_fmt; ///< sample format
1980 
1981  /* The following data should not be initialized. */
1982  /**
1983  * Number of samples per channel in an audio frame.
1984  *
1985  * - encoding: set by libavcodec in avcodec_open2(). Each submitted frame
1986  * except the last must contain exactly frame_size samples per channel.
1987  * May be 0 when the codec has CODEC_CAP_VARIABLE_FRAME_SIZE set, then the
1988  * frame size is not restricted.
1989  * - decoding: may be set by some decoders to indicate constant frame size
1990  */
1991  int frame_size;
1992 
1993  /**
1994  * Frame counter, set by libavcodec.
1995  *
1996  * - decoding: total number of frames returned from the decoder so far.
1997  * - encoding: total number of frames passed to the encoder so far.
1998  *
1999  * @note the counter is not incremented if encoding/decoding resulted in
2000  * an error.
2001  */
2002  int frame_number;
2003 
2004  /**
2005  * number of bytes per packet if constant and known or 0
2006  * Used by some WAV based audio codecs.
2007  */
2008  int block_align;
2009 
2010  /**
2011  * Audio cutoff bandwidth (0 means "automatic")
2012  * - encoding: Set by user.
2013  * - decoding: unused
2014  */
2015  int cutoff;
2016 
2017 #if FF_API_REQUEST_CHANNELS
2018  /**
2019  * Decoder should decode to this many channels if it can (0 for default)
2020  * - encoding: unused
2021  * - decoding: Set by user.
2022  * @deprecated Deprecated in favor of request_channel_layout.
2023  */
2025 #endif
2026 
2027  /**
2028  * Audio channel layout.
2029  * - encoding: set by user.
2030  * - decoding: set by user, may be overwritten by libavcodec.
2031  */
2032  uint64_t channel_layout;
2033 
2034  /**
2035  * Request decoder to use this channel layout if it can (0 for default)
2036  * - encoding: unused
2037  * - decoding: Set by user.
2038  */
2039  uint64_t request_channel_layout;
2040 
2041  /**
2042  * Type of service that the audio stream conveys.
2043  * - encoding: Set by user.
2044  * - decoding: Set by libavcodec.
2045  */
2047 
2048  /**
2049  * desired sample format
2050  * - encoding: Not used.
2051  * - decoding: Set by user.
2052  * Decoder will decode to this format if it can.
2053  */
2055 
2056 #if FF_API_GET_BUFFER
2057  /**
2058  * Called at the beginning of each frame to get a buffer for it.
2059  *
2060  * The function will set AVFrame.data[], AVFrame.linesize[].
2061  * AVFrame.extended_data[] must also be set, but it should be the same as
2062  * AVFrame.data[] except for planar audio with more channels than can fit
2063  * in AVFrame.data[]. In that case, AVFrame.data[] shall still contain as
2064  * many data pointers as it can hold.
2065  *
2066  * if CODEC_CAP_DR1 is not set then get_buffer() must call
2067  * avcodec_default_get_buffer() instead of providing buffers allocated by
2068  * some other means.
2069  *
2070  * AVFrame.data[] should be 32- or 16-byte-aligned unless the CPU doesn't
2071  * need it. avcodec_default_get_buffer() aligns the output buffer properly,
2072  * but if get_buffer() is overridden then alignment considerations should
2073  * be taken into account.
2074  *
2075  * @see avcodec_default_get_buffer()
2076  *
2077  * Video:
2078  *
2079  * If pic.reference is set then the frame will be read later by libavcodec.
2080  * avcodec_align_dimensions2() should be used to find the required width and
2081  * height, as they normally need to be rounded up to the next multiple of 16.
2082  *
2083  * If frame multithreading is used and thread_safe_callbacks is set,
2084  * it may be called from a different thread, but not from more than one at
2085  * once. Does not need to be reentrant.
2086  *
2087  * @see release_buffer(), reget_buffer()
2088  * @see avcodec_align_dimensions2()
2089  *
2090  * Audio:
2091  *
2092  * Decoders request a buffer of a particular size by setting
2093  * AVFrame.nb_samples prior to calling get_buffer(). The decoder may,
2094  * however, utilize only part of the buffer by setting AVFrame.nb_samples
2095  * to a smaller value in the output frame.
2096  *
2097  * Decoders cannot use the buffer after returning from
2098  * avcodec_decode_audio4(), so they will not call release_buffer(), as it
2099  * is assumed to be released immediately upon return. In some rare cases,
2100  * a decoder may need to call get_buffer() more than once in a single
2101  * call to avcodec_decode_audio4(). In that case, when get_buffer() is
2102  * called again after it has already been called once, the previously
2103  * acquired buffer is assumed to be released at that time and may not be
2104  * reused by the decoder.
2105  *
2106  * As a convenience, av_samples_get_buffer_size() and
2107  * av_samples_fill_arrays() in libavutil may be used by custom get_buffer()
2108  * functions to find the required data size and to fill data pointers and
2109  * linesize. In AVFrame.linesize, only linesize[0] may be set for audio
2110  * since all planes must be the same size.
2111  *
2112  * @see av_samples_get_buffer_size(), av_samples_fill_arrays()
2113  *
2114  * - encoding: unused
2115  * - decoding: Set by libavcodec, user can override.
2116  *
2117  * @deprecated use get_buffer2()
2118  */
2120  int (*get_buffer)(struct AVCodecContext *c, AVFrame *pic);
2121 
2122  /**
2123  * Called to release buffers which were allocated with get_buffer.
2124  * A released buffer can be reused in get_buffer().
2125  * pic.data[*] must be set to NULL.
2126  * May be called from a different thread if frame multithreading is used,
2127  * but not by more than one thread at once, so does not need to be reentrant.
2128  * - encoding: unused
2129  * - decoding: Set by libavcodec, user can override.
2130  *
2131  * @deprecated custom freeing callbacks should be set from get_buffer2()
2132  */
2134  void (*release_buffer)(struct AVCodecContext *c, AVFrame *pic);
2135 
2136  /**
2137  * Called at the beginning of a frame to get cr buffer for it.
2138  * Buffer type (size, hints) must be the same. libavcodec won't check it.
2139  * libavcodec will pass previous buffer in pic, function should return
2140  * same buffer or new buffer with old frame "painted" into it.
2141  * If pic.data[0] == NULL must behave like get_buffer().
2142  * if CODEC_CAP_DR1 is not set then reget_buffer() must call
2143  * avcodec_default_reget_buffer() instead of providing buffers allocated by
2144  * some other means.
2145  * - encoding: unused
2146  * - decoding: Set by libavcodec, user can override.
2147  */
2149  int (*reget_buffer)(struct AVCodecContext *c, AVFrame *pic);
2150 #endif
2151 
2152  /**
2153  * This callback is called at the beginning of each frame to get data
2154  * buffer(s) for it. There may be one contiguous buffer for all the data or
2155  * there may be a buffer per each data plane or anything in between. What
2156  * this means is, you may set however many entries in buf[] you feel necessary.
2157  * Each buffer must be reference-counted using the AVBuffer API (see description
2158  * of buf[] below).
2159  *
2160  * The following fields will be set in the frame before this callback is
2161  * called:
2162  * - format
2163  * - width, height (video only)
2164  * - sample_rate, channel_layout, nb_samples (audio only)
2165  * Their values may differ from the corresponding values in
2166  * AVCodecContext. This callback must use the frame values, not the codec
2167  * context values, to calculate the required buffer size.
2168  *
2169  * This callback must fill the following fields in the frame:
2170  * - data[]
2171  * - linesize[]
2172  * - extended_data:
2173  * * if the data is planar audio with more than 8 channels, then this
2174  * callback must allocate and fill extended_data to contain all pointers
2175  * to all data planes. data[] must hold as many pointers as it can.
2176  * extended_data must be allocated with av_malloc() and will be freed in
2177  * av_frame_unref().
2178  * * otherwise exended_data must point to data
2179  * - buf[] must contain one or more pointers to AVBufferRef structures. Each of
2180  * the frame's data and extended_data pointers must be contained in these. That
2181  * is, one AVBufferRef for each allocated chunk of memory, not necessarily one
2182  * AVBufferRef per data[] entry. See: av_buffer_create(), av_buffer_alloc(),
2183  * and av_buffer_ref().
2184  * - extended_buf and nb_extended_buf must be allocated with av_malloc() by
2185  * this callback and filled with the extra buffers if there are more
2186  * buffers than buf[] can hold. extended_buf will be freed in
2187  * av_frame_unref().
2188  *
2189  * If CODEC_CAP_DR1 is not set then get_buffer2() must call
2190  * avcodec_default_get_buffer2() instead of providing buffers allocated by
2191  * some other means.
2192  *
2193  * Each data plane must be aligned to the maximum required by the target
2194  * CPU.
2195  *
2196  * @see avcodec_default_get_buffer2()
2197  *
2198  * Video:
2199  *
2200  * If AV_GET_BUFFER_FLAG_REF is set in flags then the frame may be reused
2201  * (read and/or written to if it is writable) later by libavcodec.
2202  *
2203  * avcodec_align_dimensions2() should be used to find the required width and
2204  * height, as they normally need to be rounded up to the next multiple of 16.
2205  *
2206  * Some decoders do not support linesizes changing between frames.
2207  *
2208  * If frame multithreading is used and thread_safe_callbacks is set,
2209  * this callback may be called from a different thread, but not from more
2210  * than one at once. Does not need to be reentrant.
2211  *
2212  * @see avcodec_align_dimensions2()
2213  *
2214  * Audio:
2215  *
2216  * Decoders request a buffer of a particular size by setting
2217  * AVFrame.nb_samples prior to calling get_buffer2(). The decoder may,
2218  * however, utilize only part of the buffer by setting AVFrame.nb_samples
2219  * to a smaller value in the output frame.
2220  *
2221  * As a convenience, av_samples_get_buffer_size() and
2222  * av_samples_fill_arrays() in libavutil may be used by custom get_buffer2()
2223  * functions to find the required data size and to fill data pointers and
2224  * linesize. In AVFrame.linesize, only linesize[0] may be set for audio
2225  * since all planes must be the same size.
2226  *
2227  * @see av_samples_get_buffer_size(), av_samples_fill_arrays()
2228  *
2229  * - encoding: unused
2230  * - decoding: Set by libavcodec, user can override.
2231  */
2232  int (*get_buffer2)(struct AVCodecContext *s, AVFrame *frame, int flags);
2233 
2234  /**
2235  * If non-zero, the decoded audio and video frames returned from
2236  * avcodec_decode_video2() and avcodec_decode_audio4() are reference-counted
2237  * and are valid indefinitely. The caller must free them with
2238  * av_frame_unref() when they are not needed anymore.
2239  * Otherwise, the decoded frames must not be freed by the caller and are
2240  * only valid until the next decode call.
2241  *
2242  * - encoding: unused
2243  * - decoding: set by the caller before avcodec_open2().
2244  */
2245  int refcounted_frames;
2246 
2247  /* - encoding parameters */
2248  float qcompress; ///< amount of qscale change between easy & hard scenes (0.0-1.0)
2249  float qblur; ///< amount of qscale smoothing over time (0.0-1.0)
2250 
2251  /**
2252  * minimum quantizer
2253  * - encoding: Set by user.
2254  * - decoding: unused
2255  */
2256  int qmin;
2257 
2258  /**
2259  * maximum quantizer
2260  * - encoding: Set by user.
2261  * - decoding: unused
2262  */
2263  int qmax;
2264 
2265  /**
2266  * maximum quantizer difference between frames
2267  * - encoding: Set by user.
2268  * - decoding: unused
2269  */
2270  int max_qdiff;
2271 
2272 #if FF_API_MPV_OPT
2273  /**
2274  * @deprecated use encoder private options instead
2275  */
2277  float rc_qsquish;
2278 
2280  float rc_qmod_amp;
2282  int rc_qmod_freq;
2283 #endif
2284 
2285  /**
2286  * decoder bitstream buffer size
2287  * - encoding: Set by user.
2288  * - decoding: unused
2289  */
2290  int rc_buffer_size;
2291 
2292  /**
2293  * ratecontrol override, see RcOverride
2294  * - encoding: Allocated/set/freed by user.
2295  * - decoding: unused
2296  */
2299 
2300 #if FF_API_MPV_OPT
2301  /**
2302  * @deprecated use encoder private options instead
2303  */
2305  const char *rc_eq;
2306 #endif
2307 
2308  /**
2309  * maximum bitrate
2310  * - encoding: Set by user.
2311  * - decoding: Set by libavcodec.
2312  */
2313  int rc_max_rate;
2314 
2315  /**
2316  * minimum bitrate
2317  * - encoding: Set by user.
2318  * - decoding: unused
2319  */
2320  int rc_min_rate;
2321 
2322 #if FF_API_MPV_OPT
2323  /**
2324  * @deprecated use encoder private options instead
2325  */
2327  float rc_buffer_aggressivity;
2328 
2330  float rc_initial_cplx;
2331 #endif
2332 
2333  /**
2334  * Ratecontrol attempt to use, at maximum, <value> of what can be used without an underflow.
2335  * - encoding: Set by user.
2336  * - decoding: unused.
2337  */
2339 
2340  /**
2341  * Ratecontrol attempt to use, at least, <value> times the amount needed to prevent a vbv overflow.
2342  * - encoding: Set by user.
2343  * - decoding: unused.
2344  */
2346 
2347  /**
2348  * Number of bits which should be loaded into the rc buffer before decoding starts.
2349  * - encoding: Set by user.
2350  * - decoding: unused
2351  */
2354 #define FF_CODER_TYPE_VLC 0
2355 #define FF_CODER_TYPE_AC 1
2356 #define FF_CODER_TYPE_RAW 2
2357 #define FF_CODER_TYPE_RLE 3
2358 #if FF_API_UNUSED_MEMBERS
2359 #define FF_CODER_TYPE_DEFLATE 4
2360 #endif /* FF_API_UNUSED_MEMBERS */
2361  /**
2362  * coder type
2363  * - encoding: Set by user.
2364  * - decoding: unused
2365  */
2366  int coder_type;
2367 
2368  /**
2369  * context model
2370  * - encoding: Set by user.
2371  * - decoding: unused
2372  */
2373  int context_model;
2374 
2375 #if FF_API_MPV_OPT
2376  /**
2377  * @deprecated use encoder private options instead
2378  */
2380  int lmin;
2381 
2382  /**
2383  * @deprecated use encoder private options instead
2384  */
2386  int lmax;
2387 #endif
2388 
2389  /**
2390  * frame skip threshold
2391  * - encoding: Set by user.
2392  * - decoding: unused
2393  */
2395 
2396  /**
2397  * frame skip factor
2398  * - encoding: Set by user.
2399  * - decoding: unused
2400  */
2401  int frame_skip_factor;
2402 
2403  /**
2404  * frame skip exponent
2405  * - encoding: Set by user.
2406  * - decoding: unused
2407  */
2408  int frame_skip_exp;
2409 
2410  /**
2411  * frame skip comparison function
2412  * - encoding: Set by user.
2413  * - decoding: unused
2414  */
2415  int frame_skip_cmp;
2416 
2417  /**
2418  * trellis RD quantization
2419  * - encoding: Set by user.
2420  * - decoding: unused
2421  */
2422  int trellis;
2423 
2424  /**
2425  * - encoding: Set by user.
2426  * - decoding: unused
2427  */
2429 
2430  /**
2431  * - encoding: Set by user.
2432  * - decoding: unused
2433  */
2435 
2436  /**
2437  * GOP timecode frame start number
2438  * - encoding: Set by user, in non drop frame format
2439  * - decoding: Set by libavcodec (timecode in the 25 bits format, -1 if unset)
2440  */
2441  int64_t timecode_frame_start;
2442 
2443  /* The RTP callback: This function is called */
2444  /* every time the encoder has a packet to send. */
2445  /* It depends on the encoder if the data starts */
2446  /* with a Start Code (it should). H.263 does. */
2447  /* mb_nb contains the number of macroblocks */
2448  /* encoded in the RTP payload. */
2449  void (*rtp_callback)(struct AVCodecContext *avctx, void *data, int size, int mb_nb);
2451  int rtp_payload_size; /* The size of the RTP payload: the coder will */
2452  /* do its best to deliver a chunk with size */
2453  /* below rtp_payload_size, the chunk will start */
2454  /* with a start code on some codecs like H.263. */
2455  /* This doesn't take account of any particular */
2456  /* headers inside the transmitted RTP payload. */
2457 
2458  /* statistics, used for 2-pass encoding */
2459  int mv_bits;
2463  int i_count;
2464  int p_count;
2466  int misc_bits;
2467 
2468  /**
2469  * number of bits used for the previously encoded frame
2470  * - encoding: Set by libavcodec.
2471  * - decoding: unused
2472  */
2473  int frame_bits;
2474 
2475  /**
2476  * pass1 encoding statistics output buffer
2477  * - encoding: Set by libavcodec.
2478  * - decoding: unused
2479  */
2480  char *stats_out;
2481 
2482  /**
2483  * pass2 encoding statistics input buffer
2484  * Concatenated stuff from stats_out of pass1 should be placed here.
2485  * - encoding: Allocated/set/freed by user.
2486  * - decoding: unused
2487  */
2488  char *stats_in;
2489 
2490  /**
2491  * Work around bugs in encoders which sometimes cannot be detected automatically.
2492  * - encoding: Set by user
2493  * - decoding: Set by user
2494  */
2496 #define FF_BUG_AUTODETECT 1 ///< autodetection
2497 #if FF_API_OLD_MSMPEG4
2498 #define FF_BUG_OLD_MSMPEG4 2
2499 #endif
2500 #define FF_BUG_XVID_ILACE 4
2501 #define FF_BUG_UMP4 8
2502 #define FF_BUG_NO_PADDING 16
2503 #define FF_BUG_AMV 32
2504 #if FF_API_AC_VLC
2505 #define FF_BUG_AC_VLC 0 ///< Will be removed, libavcodec can now handle these non-compliant files by default.
2506 #endif
2507 #define FF_BUG_QPEL_CHROMA 64
2508 #define FF_BUG_STD_QPEL 128
2509 #define FF_BUG_QPEL_CHROMA2 256
2510 #define FF_BUG_DIRECT_BLOCKSIZE 512
2511 #define FF_BUG_EDGE 1024
2512 #define FF_BUG_HPEL_CHROMA 2048
2513 #define FF_BUG_DC_CLIP 4096
2514 #define FF_BUG_MS 8192 ///< Work around various bugs in Microsoft's broken decoders.
2515 #define FF_BUG_TRUNCATED 16384
2516 
2517  /**
2518  * strictly follow the standard (MPEG4, ...).
2519  * - encoding: Set by user.
2520  * - decoding: Set by user.
2521  * Setting this to STRICT or higher means the encoder and decoder will
2522  * generally do stupid things, whereas setting it to unofficial or lower
2523  * will mean the encoder might produce output that is not supported by all
2524  * spec-compliant decoders. Decoders don't differentiate between normal,
2525  * unofficial and experimental (that is, they always try to decode things
2526  * when they can) unless they are explicitly asked to behave stupidly
2527  * (=strictly conform to the specs)
2528  */
2530 #define FF_COMPLIANCE_VERY_STRICT 2 ///< Strictly conform to an older more strict version of the spec or reference software.
2531 #define FF_COMPLIANCE_STRICT 1 ///< Strictly conform to all the things in the spec no matter what consequences.
2532 #define FF_COMPLIANCE_NORMAL 0
2533 #define FF_COMPLIANCE_UNOFFICIAL -1 ///< Allow unofficial extensions
2534 #define FF_COMPLIANCE_EXPERIMENTAL -2 ///< Allow nonstandardized experimental things.
2535 
2536  /**
2537  * error concealment flags
2538  * - encoding: unused
2539  * - decoding: Set by user.
2540  */
2542 #define FF_EC_GUESS_MVS 1
2543 #define FF_EC_DEBLOCK 2
2544 #define FF_EC_FAVOR_INTER 256
2545 
2546  /**
2547  * debug
2548  * - encoding: Set by user.
2549  * - decoding: Set by user.
2550  */
2551  int debug;
2552 #define FF_DEBUG_PICT_INFO 1
2553 #define FF_DEBUG_RC 2
2554 #define FF_DEBUG_BITSTREAM 4
2555 #define FF_DEBUG_MB_TYPE 8
2556 #define FF_DEBUG_QP 16
2557 #if FF_API_DEBUG_MV
2558 /**
2559  * @deprecated this option does nothing
2560  */
2561 #define FF_DEBUG_MV 32
2562 #endif
2563 #define FF_DEBUG_DCT_COEFF 0x00000040
2564 #define FF_DEBUG_SKIP 0x00000080
2565 #define FF_DEBUG_STARTCODE 0x00000100
2566 #if FF_API_UNUSED_MEMBERS
2567 #define FF_DEBUG_PTS 0x00000200
2568 #endif /* FF_API_UNUSED_MEMBERS */
2569 #define FF_DEBUG_ER 0x00000400
2570 #define FF_DEBUG_MMCO 0x00000800
2571 #define FF_DEBUG_BUGS 0x00001000
2572 #if FF_API_DEBUG_MV
2573 #define FF_DEBUG_VIS_QP 0x00002000 ///< only access through AVOptions from outside libavcodec
2574 #define FF_DEBUG_VIS_MB_TYPE 0x00004000 ///< only access through AVOptions from outside libavcodec
2575 #endif
2576 #define FF_DEBUG_BUFFERS 0x00008000
2577 #define FF_DEBUG_THREADS 0x00010000
2578 #define FF_DEBUG_NOMC 0x01000000
2579 
2580 #if FF_API_DEBUG_MV
2581  /**
2582  * debug
2583  * Code outside libavcodec should access this field using AVOptions
2584  * - encoding: Set by user.
2585  * - decoding: Set by user.
2586  */
2588 #define FF_DEBUG_VIS_MV_P_FOR 0x00000001 //visualize forward predicted MVs of P frames
2589 #define FF_DEBUG_VIS_MV_B_FOR 0x00000002 //visualize forward predicted MVs of B frames
2590 #define FF_DEBUG_VIS_MV_B_BACK 0x00000004 //visualize backward predicted MVs of B frames
2591 #endif
2592 
2593  /**
2594  * Error recognition; may misdetect some more or less valid parts as errors.
2595  * - encoding: unused
2596  * - decoding: Set by user.
2597  */
2598  int err_recognition;
2599 
2600 /**
2601  * Verify checksums embedded in the bitstream (could be of either encoded or
2602  * decoded data, depending on the codec) and print an error message on mismatch.
2603  * If AV_EF_EXPLODE is also set, a mismatching checksum will result in the
2604  * decoder returning an error.
2605  */
2606 #define AV_EF_CRCCHECK (1<<0)
2607 #define AV_EF_BITSTREAM (1<<1) ///< detect bitstream specification deviations
2608 #define AV_EF_BUFFER (1<<2) ///< detect improper bitstream length
2609 #define AV_EF_EXPLODE (1<<3) ///< abort decoding on minor error detection
2611 #define AV_EF_IGNORE_ERR (1<<15) ///< ignore errors and continue
2612 #define AV_EF_CAREFUL (1<<16) ///< consider things that violate the spec, are fast to calculate and have not been seen in the wild as errors
2613 #define AV_EF_COMPLIANT (1<<17) ///< consider all spec non compliances as errors
2614 #define AV_EF_AGGRESSIVE (1<<18) ///< consider things that a sane encoder should not do as an error
2615 
2616 
2617  /**
2618  * opaque 64bit number (generally a PTS) that will be reordered and
2619  * output in AVFrame.reordered_opaque
2620  * - encoding: unused
2621  * - decoding: Set by user.
2622  */
2623  int64_t reordered_opaque;
2624 
2625  /**
2626  * Hardware accelerator in use
2627  * - encoding: unused.
2628  * - decoding: Set by libavcodec
2629  */
2630  struct AVHWAccel *hwaccel;
2631 
2632  /**
2633  * Hardware accelerator context.
2634  * For some hardware accelerators, a global context needs to be
2635  * provided by the user. In that case, this holds display-dependent
2636  * data FFmpeg cannot instantiate itself. Please refer to the
2637  * FFmpeg HW accelerator documentation to know how to fill this
2638  * is. e.g. for VA API, this is a struct vaapi_context.
2639  * - encoding: unused
2640  * - decoding: Set by user
2641  */
2642  void *hwaccel_context;
2643 
2644  /**
2645  * error
2646  * - encoding: Set by libavcodec if flags&CODEC_FLAG_PSNR.
2647  * - decoding: unused
2648  */
2649  uint64_t error[AV_NUM_DATA_POINTERS];
2650 
2651  /**
2652  * DCT algorithm, see FF_DCT_* below
2653  * - encoding: Set by user.
2654  * - decoding: unused
2655  */
2657 #define FF_DCT_AUTO 0
2658 #define FF_DCT_FASTINT 1
2659 #if FF_API_UNUSED_MEMBERS
2660 #define FF_DCT_INT 2
2661 #endif /* FF_API_UNUSED_MEMBERS */
2662 #define FF_DCT_MMX 3
2663 #define FF_DCT_ALTIVEC 5
2664 #define FF_DCT_FAAN 6
2665 
2666  /**
2667  * IDCT algorithm, see FF_IDCT_* below.
2668  * - encoding: Set by user.
2669  * - decoding: Set by user.
2670  */
2672 #define FF_IDCT_AUTO 0
2673 #define FF_IDCT_INT 1
2674 #define FF_IDCT_SIMPLE 2
2675 #define FF_IDCT_SIMPLEMMX 3
2676 #define FF_IDCT_ARM 7
2677 #define FF_IDCT_ALTIVEC 8
2678 #if FF_API_ARCH_SH4
2679 #define FF_IDCT_SH4 9
2680 #endif
2681 #define FF_IDCT_SIMPLEARM 10
2682 #if FF_API_UNUSED_MEMBERS
2683 #define FF_IDCT_IPP 13
2684 #endif /* FF_API_UNUSED_MEMBERS */
2685 #define FF_IDCT_XVID 14
2686 #if FF_API_IDCT_XVIDMMX
2687 #define FF_IDCT_XVIDMMX 14
2688 #endif /* FF_API_IDCT_XVIDMMX */
2689 #define FF_IDCT_SIMPLEARMV5TE 16
2690 #define FF_IDCT_SIMPLEARMV6 17
2691 #if FF_API_ARCH_SPARC
2692 #define FF_IDCT_SIMPLEVIS 18
2693 #endif
2694 #define FF_IDCT_FAAN 20
2695 #define FF_IDCT_SIMPLENEON 22
2696 #if FF_API_ARCH_ALPHA
2697 #define FF_IDCT_SIMPLEALPHA 23
2698 #endif
2699 #define FF_IDCT_SIMPLEAUTO 128
2700 
2701  /**
2702  * bits per sample/pixel from the demuxer (needed for huffyuv).
2703  * - encoding: Set by libavcodec.
2704  * - decoding: Set by user.
2705  */
2707 
2708  /**
2709  * Bits per sample/pixel of internal libavcodec pixel/sample format.
2710  * - encoding: set by user.
2711  * - decoding: set by libavcodec.
2712  */
2713  int bits_per_raw_sample;
2714 
2715 #if FF_API_LOWRES
2716  /**
2717  * low resolution decoding, 1-> 1/2 size, 2->1/4 size
2718  * - encoding: unused
2719  * - decoding: Set by user.
2720  * Code outside libavcodec should access this field using:
2721  * av_codec_{get,set}_lowres(avctx)
2722  */
2723  int lowres;
2724 #endif
2725 
2726  /**
2727  * the picture in the bitstream
2728  * - encoding: Set by libavcodec.
2729  * - decoding: unused
2730  */
2732 
2733  /**
2734  * thread count
2735  * is used to decide how many independent tasks should be passed to execute()
2736  * - encoding: Set by user.
2737  * - decoding: Set by user.
2738  */
2739  int thread_count;
2740 
2741  /**
2742  * Which multithreading methods to use.
2743  * Use of FF_THREAD_FRAME will increase decoding delay by one frame per thread,
2744  * so clients which cannot provide future frames should not use it.
2745  *
2746  * - encoding: Set by user, otherwise the default is used.
2747  * - decoding: Set by user, otherwise the default is used.
2748  */
2750 #define FF_THREAD_FRAME 1 ///< Decode more than one frame at once
2751 #define FF_THREAD_SLICE 2 ///< Decode more than one part of a single frame at once
2752 
2753  /**
2754  * Which multithreading methods are in use by the codec.
2755  * - encoding: Set by libavcodec.
2756  * - decoding: Set by libavcodec.
2757  */
2758  int active_thread_type;
2759 
2760  /**
2761  * Set by the client if its custom get_buffer() callback can be called
2762  * synchronously from another thread, which allows faster multithreaded decoding.
2763  * draw_horiz_band() will be called from other threads regardless of this setting.
2764  * Ignored if the default get_buffer() is used.
2765  * - encoding: Set by user.
2766  * - decoding: Set by user.
2767  */
2769 
2770  /**
2771  * The codec may call this to execute several independent things.
2772  * It will return only after finishing all tasks.
2773  * The user may replace this with some multithreaded implementation,
2774  * the default implementation will execute the parts serially.
2775  * @param count the number of things to execute
2776  * - encoding: Set by libavcodec, user can override.
2777  * - decoding: Set by libavcodec, user can override.
2778  */
2779  int (*execute)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg), void *arg2, int *ret, int count, int size);
2780 
2781  /**
2782  * The codec may call this to execute several independent things.
2783  * It will return only after finishing all tasks.
2784  * The user may replace this with some multithreaded implementation,
2785  * the default implementation will execute the parts serially.
2786  * Also see avcodec_thread_init and e.g. the --enable-pthread configure option.
2787  * @param c context passed also to func
2788  * @param count the number of things to execute
2789  * @param arg2 argument passed unchanged to func
2790  * @param ret return values of executed functions, must have space for "count" values. May be NULL.
2791  * @param func function that will be called count times, with jobnr from 0 to count-1.
2792  * threadnr will be in the range 0 to c->thread_count-1 < MAX_THREADS and so that no
2793  * two instances of func executing at the same time will have the same threadnr.
2794  * @return always 0 currently, but code should handle a future improvement where when any call to func
2795  * returns < 0 no further calls to func may be done and < 0 is returned.
2796  * - encoding: Set by libavcodec, user can override.
2797  * - decoding: Set by libavcodec, user can override.
2798  */
2799  int (*execute2)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg, int jobnr, int threadnr), void *arg2, int *ret, int count);
2800 
2801 #if FF_API_THREAD_OPAQUE
2802  /**
2803  * @deprecated this field should not be used from outside of lavc
2804  */
2806  void *thread_opaque;
2807 #endif
2808 
2809  /**
2810  * noise vs. sse weight for the nsse comparison function
2811  * - encoding: Set by user.
2812  * - decoding: unused
2813  */
2814  int nsse_weight;
2815 
2816  /**
2817  * profile
2818  * - encoding: Set by user.
2819  * - decoding: Set by libavcodec.
2820  */
2821  int profile;
2822 #define FF_PROFILE_UNKNOWN -99
2823 #define FF_PROFILE_RESERVED -100
2825 #define FF_PROFILE_AAC_MAIN 0
2826 #define FF_PROFILE_AAC_LOW 1
2827 #define FF_PROFILE_AAC_SSR 2
2828 #define FF_PROFILE_AAC_LTP 3
2829 #define FF_PROFILE_AAC_HE 4
2830 #define FF_PROFILE_AAC_HE_V2 28
2831 #define FF_PROFILE_AAC_LD 22
2832 #define FF_PROFILE_AAC_ELD 38
2833 #define FF_PROFILE_MPEG2_AAC_LOW 128
2834 #define FF_PROFILE_MPEG2_AAC_HE 131
2836 #define FF_PROFILE_DTS 20
2837 #define FF_PROFILE_DTS_ES 30
2838 #define FF_PROFILE_DTS_96_24 40
2839 #define FF_PROFILE_DTS_HD_HRA 50
2840 #define FF_PROFILE_DTS_HD_MA 60
2842 #define FF_PROFILE_MPEG2_422 0
2843 #define FF_PROFILE_MPEG2_HIGH 1
2844 #define FF_PROFILE_MPEG2_SS 2
2845 #define FF_PROFILE_MPEG2_SNR_SCALABLE 3
2846 #define FF_PROFILE_MPEG2_MAIN 4
2847 #define FF_PROFILE_MPEG2_SIMPLE 5
2849 #define FF_PROFILE_H264_CONSTRAINED (1<<9) // 8+1; constraint_set1_flag
2850 #define FF_PROFILE_H264_INTRA (1<<11) // 8+3; constraint_set3_flag
2852 #define FF_PROFILE_H264_BASELINE 66
2853 #define FF_PROFILE_H264_CONSTRAINED_BASELINE (66|FF_PROFILE_H264_CONSTRAINED)
2854 #define FF_PROFILE_H264_MAIN 77
2855 #define FF_PROFILE_H264_EXTENDED 88
2856 #define FF_PROFILE_H264_HIGH 100
2857 #define FF_PROFILE_H264_HIGH_10 110
2858 #define FF_PROFILE_H264_HIGH_10_INTRA (110|FF_PROFILE_H264_INTRA)
2859 #define FF_PROFILE_H264_HIGH_422 122
2860 #define FF_PROFILE_H264_HIGH_422_INTRA (122|FF_PROFILE_H264_INTRA)
2861 #define FF_PROFILE_H264_HIGH_444 144
2862 #define FF_PROFILE_H264_HIGH_444_PREDICTIVE 244
2863 #define FF_PROFILE_H264_HIGH_444_INTRA (244|FF_PROFILE_H264_INTRA)
2864 #define FF_PROFILE_H264_CAVLC_444 44
2866 #define FF_PROFILE_VC1_SIMPLE 0
2867 #define FF_PROFILE_VC1_MAIN 1
2868 #define FF_PROFILE_VC1_COMPLEX 2
2869 #define FF_PROFILE_VC1_ADVANCED 3
2871 #define FF_PROFILE_MPEG4_SIMPLE 0
2872 #define FF_PROFILE_MPEG4_SIMPLE_SCALABLE 1
2873 #define FF_PROFILE_MPEG4_CORE 2
2874 #define FF_PROFILE_MPEG4_MAIN 3
2875 #define FF_PROFILE_MPEG4_N_BIT 4
2876 #define FF_PROFILE_MPEG4_SCALABLE_TEXTURE 5
2877 #define FF_PROFILE_MPEG4_SIMPLE_FACE_ANIMATION 6
2878 #define FF_PROFILE_MPEG4_BASIC_ANIMATED_TEXTURE 7
2879 #define FF_PROFILE_MPEG4_HYBRID 8
2880 #define FF_PROFILE_MPEG4_ADVANCED_REAL_TIME 9
2881 #define FF_PROFILE_MPEG4_CORE_SCALABLE 10
2882 #define FF_PROFILE_MPEG4_ADVANCED_CODING 11
2883 #define FF_PROFILE_MPEG4_ADVANCED_CORE 12
2884 #define FF_PROFILE_MPEG4_ADVANCED_SCALABLE_TEXTURE 13
2885 #define FF_PROFILE_MPEG4_SIMPLE_STUDIO 14
2886 #define FF_PROFILE_MPEG4_ADVANCED_SIMPLE 15
2888 #define FF_PROFILE_JPEG2000_CSTREAM_RESTRICTION_0 0
2889 #define FF_PROFILE_JPEG2000_CSTREAM_RESTRICTION_1 1
2890 #define FF_PROFILE_JPEG2000_CSTREAM_NO_RESTRICTION 2
2891 #define FF_PROFILE_JPEG2000_DCINEMA_2K 3
2892 #define FF_PROFILE_JPEG2000_DCINEMA_4K 4
2893 
2895 #define FF_PROFILE_HEVC_MAIN 1
2896 #define FF_PROFILE_HEVC_MAIN_10 2
2897 #define FF_PROFILE_HEVC_MAIN_STILL_PICTURE 3
2898 #define FF_PROFILE_HEVC_REXT 4
2899 
2900  /**
2901  * level
2902  * - encoding: Set by user.
2903  * - decoding: Set by libavcodec.
2904  */
2905  int level;
2906 #define FF_LEVEL_UNKNOWN -99
2907 
2908  /**
2909  * Skip loop filtering for selected frames.
2910  * - encoding: unused
2911  * - decoding: Set by user.
2912  */
2914 
2915  /**
2916  * Skip IDCT/dequantization for selected frames.
2917  * - encoding: unused
2918  * - decoding: Set by user.
2919  */
2920  enum AVDiscard skip_idct;
2921 
2922  /**
2923  * Skip decoding for selected frames.
2924  * - encoding: unused
2925  * - decoding: Set by user.
2926  */
2927  enum AVDiscard skip_frame;
2928 
2929  /**
2930  * Header containing style information for text subtitles.
2931  * For SUBTITLE_ASS subtitle type, it should contain the whole ASS
2932  * [Script Info] and [V4+ Styles] section, plus the [Events] line and
2933  * the Format line following. It shouldn't include any Dialogue line.
2934  * - encoding: Set/allocated/freed by user (before avcodec_open2())
2935  * - decoding: Set/allocated/freed by libavcodec (by avcodec_open2())
2936  */
2939 
2940 #if FF_API_ERROR_RATE
2941  /**
2942  * @deprecated use the 'error_rate' private AVOption of the mpegvideo
2943  * encoders
2944  */
2946  int error_rate;
2947 #endif
2948 
2949 #if FF_API_CODEC_PKT
2950  /**
2951  * @deprecated this field is not supposed to be accessed from outside lavc
2952  */
2954  AVPacket *pkt;
2955 #endif
2956 
2957  /**
2958  * VBV delay coded in the last frame (in periods of a 27 MHz clock).
2959  * Used for compliant TS muxing.
2960  * - encoding: Set by libavcodec.
2961  * - decoding: unused.
2962  */
2963  uint64_t vbv_delay;
2964 
2965  /**
2966  * Encoding only. Allow encoders to output packets that do not contain any
2967  * encoded data, only side data.
2968  *
2969  * Some encoders need to output such packets, e.g. to update some stream
2970  * parameters at the end of encoding.
2971  *
2972  * All callers are strongly recommended to set this option to 1 and update
2973  * their code to deal with such packets, since this behaviour may become
2974  * always enabled in the future (then this option will be deprecated and
2975  * later removed). To avoid ABI issues when this happens, the callers should
2976  * use AVOptions to set this field.
2977  */
2979 
2980  /**
2981  * Audio only. The number of "priming" samples (padding) inserted by the
2982  * encoder at the beginning of the audio. I.e. this number of leading
2983  * decoded samples must be discarded by the caller to get the original audio
2984  * without leading padding.
2985  *
2986  * - decoding: unused
2987  * - encoding: Set by libavcodec. The timestamps on the output packets are
2988  * adjusted by the encoder so that they always refer to the
2989  * first sample of the data actually contained in the packet,
2990  * including any added padding. E.g. if the timebase is
2991  * 1/samplerate and the timestamp of the first input sample is
2992  * 0, the timestamp of the first output packet will be
2993  * -initial_padding.
2994  */
2995  int initial_padding;
2996 
2997  /**
2998  * - decoding: For codecs that store a framerate value in the compressed
2999  * bitstream, the decoder may export it here. { 0, 1} when
3000  * unknown.
3001  * - encoding: unused
3002  */
3004 
3005  /**
3006  * Timebase in which pkt_dts/pts and AVPacket.dts/pts are.
3007  * Code outside libavcodec should access this field using:
3008  * av_codec_{get,set}_pkt_timebase(avctx)
3009  * - encoding unused.
3010  * - decoding set by user.
3011  */
3013 
3014  /**
3015  * AVCodecDescriptor
3016  * Code outside libavcodec should access this field using:
3017  * av_codec_{get,set}_codec_descriptor(avctx)
3018  * - encoding: unused.
3019  * - decoding: set by libavcodec.
3020  */
3022 
3023 #if !FF_API_LOWRES
3024  /**
3025  * low resolution decoding, 1-> 1/2 size, 2->1/4 size
3026  * - encoding: unused
3027  * - decoding: Set by user.
3028  * Code outside libavcodec should access this field using:
3029  * av_codec_{get,set}_lowres(avctx)
3030  */
3031  int lowres;
3032 #endif
3033 
3034  /**
3035  * Current statistics for PTS correction.
3036  * - decoding: maintained and used by libavcodec, not intended to be used by user apps
3037  * - encoding: unused
3038  */
3039  int64_t pts_correction_num_faulty_pts; /// Number of incorrect PTS values so far
3040  int64_t pts_correction_num_faulty_dts; /// Number of incorrect DTS values so far
3041  int64_t pts_correction_last_pts; /// PTS of the last frame
3042  int64_t pts_correction_last_dts; /// DTS of the last frame
3043 
3044  /**
3045  * Character encoding of the input subtitles file.
3046  * - decoding: set by user
3047  * - encoding: unused
3048  */
3049  char *sub_charenc;
3050 
3051  /**
3052  * Subtitles character encoding mode. Formats or codecs might be adjusting
3053  * this setting (if they are doing the conversion themselves for instance).
3054  * - decoding: set by libavcodec
3055  * - encoding: unused
3056  */
3058 #define FF_SUB_CHARENC_MODE_DO_NOTHING -1 ///< do nothing (demuxer outputs a stream supposed to be already in UTF-8, or the codec is bitmap for instance)
3059 #define FF_SUB_CHARENC_MODE_AUTOMATIC 0 ///< libavcodec will select the mode itself
3060 #define FF_SUB_CHARENC_MODE_PRE_DECODER 1 ///< the AVPacket data needs to be recoded to UTF-8 before being fed to the decoder, requires iconv
3061 
3062  /**
3063  * Skip processing alpha if supported by codec.
3064  * Note that if the format uses pre-multiplied alpha (common with VP6,
3065  * and recommended due to better video quality/compression)
3066  * the image will look as if alpha-blended onto a black background.
3067  * However for formats that do not use pre-multiplied alpha
3068  * there might be serious artefacts (though e.g. libswscale currently
3069  * assumes pre-multiplied alpha anyway).
3070  * Code outside libavcodec should access this field using AVOptions
3071  *
3072  * - decoding: set by user
3073  * - encoding: unused
3074  */
3075  int skip_alpha;
3076 
3077  /**
3078  * Number of samples to skip after a discontinuity
3079  * - decoding: unused
3080  * - encoding: set by libavcodec
3081  */
3082  int seek_preroll;
3083 
3084 #if !FF_API_DEBUG_MV
3085  /**
3086  * debug motion vectors
3087  * Code outside libavcodec should access this field using AVOptions
3088  * - encoding: Set by user.
3089  * - decoding: Set by user.
3090  */
3091  int debug_mv;
3092 #define FF_DEBUG_VIS_MV_P_FOR 0x00000001 //visualize forward predicted MVs of P frames
3093 #define FF_DEBUG_VIS_MV_B_FOR 0x00000002 //visualize forward predicted MVs of B frames
3094 #define FF_DEBUG_VIS_MV_B_BACK 0x00000004 //visualize backward predicted MVs of B frames
3095 #endif
3096 
3097  /**
3098  * custom intra quantization matrix
3099  * Code outside libavcodec should access this field using av_codec_g/set_chroma_intra_matrix()
3100  * - encoding: Set by user, can be NULL.
3101  * - decoding: unused.
3102  */
3103  uint16_t *chroma_intra_matrix;
3104 
3105  /**
3106  * dump format separator.
3107  * can be ", " or "\n " or anything else
3108  * Code outside libavcodec should access this field using AVOptions
3109  * (NO direct access).
3110  * - encoding: Set by user.
3111  * - decoding: Set by user.
3112  */
3114 
3115  /**
3116  * ',' seperated list of allowed decoders.
3117  * If NULL then all are allowed
3118  * - encoding: unused
3119  * - decoding: set by user through AVOPtions (NO direct access)
3120  */
3121  char *codec_whitelist;
3122 } AVCodecContext;
3123 
3126 
3129 
3130 int av_codec_get_lowres(const AVCodecContext *avctx);
3131 void av_codec_set_lowres(AVCodecContext *avctx, int val);
3132 
3133 int av_codec_get_seek_preroll(const AVCodecContext *avctx);
3134 void av_codec_set_seek_preroll(AVCodecContext *avctx, int val);
3135 
3136 uint16_t *av_codec_get_chroma_intra_matrix(const AVCodecContext *avctx);
3137 void av_codec_set_chroma_intra_matrix(AVCodecContext *avctx, uint16_t *val);
3138 
3139 /**
3140  * AVProfile.
3141  */
3142 typedef struct AVProfile {
3143  int profile;
3144  const char *name; ///< short name for the profile
3145 } AVProfile;
3146 
3147 typedef struct AVCodecDefault AVCodecDefault;
3148 
3149 struct AVSubtitle;
3150 
3151 /**
3152  * AVCodec.
3153  */
3154 typedef struct AVCodec {
3155  /**
3156  * Name of the codec implementation.
3157  * The name is globally unique among encoders and among decoders (but an
3158  * encoder and a decoder can share the same name).
3159  * This is the primary way to find a codec from the user perspective.
3160  */
3161  const char *name;
3162  /**
3163  * Descriptive name for the codec, meant to be more human readable than name.
3164  * You should use the NULL_IF_CONFIG_SMALL() macro to define it.
3165  */
3166  const char *long_name;
3168  enum AVCodecID id;
3169  /**
3170  * Codec capabilities.
3171  * see CODEC_CAP_*
3172  */
3174  const AVRational *supported_framerates; ///< array of supported framerates, or NULL if any, array is terminated by {0,0}
3175  const enum AVPixelFormat *pix_fmts; ///< array of supported pixel formats, or NULL if unknown, array is terminated by -1
3176  const int *supported_samplerates; ///< array of supported audio samplerates, or NULL if unknown, array is terminated by 0
3177  const enum AVSampleFormat *sample_fmts; ///< array of supported sample formats, or NULL if unknown, array is terminated by -1
3178  const uint64_t *channel_layouts; ///< array of support channel layouts, or NULL if unknown. array is terminated by 0
3179 #if FF_API_LOWRES
3180  uint8_t max_lowres; ///< maximum value for lowres supported by the decoder, no direct access, use av_codec_get_max_lowres()
3181 #endif
3182  const AVClass *priv_class; ///< AVClass for the private context
3183  const AVProfile *profiles; ///< array of recognized profiles, or NULL if unknown, array is terminated by {FF_PROFILE_UNKNOWN}
3184 
3185  /*****************************************************************
3186  * No fields below this line are part of the public API. They
3187  * may not be used outside of libavcodec and can be changed and
3188  * removed at will.
3189  * New public fields should be added right above.
3190  *****************************************************************
3191  */
3193  struct AVCodec *next;
3194  /**
3195  * @name Frame-level threading support functions
3196  * @{
3197  */
3198  /**
3199  * If defined, called on thread contexts when they are created.
3200  * If the codec allocates writable tables in init(), re-allocate them here.
3201  * priv_data will be set to a copy of the original.
3202  */
3203  int (*init_thread_copy)(AVCodecContext *);
3204  /**
3205  * Copy necessary context variables from a previous thread context to the current one.
3206  * If not defined, the next thread will start automatically; otherwise, the codec
3207  * must call ff_thread_finish_setup().
3208  *
3209  * dst and src will (rarely) point to the same context, in which case memcpy should be skipped.
3210  */
3212  /** @} */
3213 
3214  /**
3215  * Private codec-specific defaults.
3216  */
3217  const AVCodecDefault *defaults;
3218 
3219  /**
3220  * Initialize codec static data, called from avcodec_register().
3221  */
3222  void (*init_static_data)(struct AVCodec *codec);
3225  int (*encode_sub)(AVCodecContext *, uint8_t *buf, int buf_size,
3226  const struct AVSubtitle *sub);
3227  /**
3228  * Encode data to an AVPacket.
3229  *
3230  * @param avctx codec context
3231  * @param avpkt output AVPacket (may contain a user-provided buffer)
3232  * @param[in] frame AVFrame containing the raw data to be encoded
3233  * @param[out] got_packet_ptr encoder sets to 0 or 1 to indicate that a
3234  * non-empty packet was returned in avpkt.
3235  * @return 0 on success, negative error code on failure
3236  */
3237  int (*encode2)(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame,
3238  int *got_packet_ptr);
3239  int (*decode)(AVCodecContext *, void *outdata, int *outdata_size, AVPacket *avpkt);
3240  int (*close)(AVCodecContext *);
3241  /**
3242  * Flush buffers.
3243  * Will be called when seeking
3244  */
3245  void (*flush)(AVCodecContext *);
3246 } AVCodec;
3247 
3248 int av_codec_get_max_lowres(const AVCodec *codec);
3249 
3250 struct MpegEncContext;
3251 
3252 /**
3253  * @defgroup lavc_hwaccel AVHWAccel
3254  * @{
3255  */
3256 typedef struct AVHWAccel {
3257  /**
3258  * Name of the hardware accelerated codec.
3259  * The name is globally unique among encoders and among decoders (but an
3260  * encoder and a decoder can share the same name).
3261  */
3262  const char *name;
3263 
3264  /**
3265  * Type of codec implemented by the hardware accelerator.
3266  *
3267  * See AVMEDIA_TYPE_xxx
3268  */
3269  enum AVMediaType type;
3270 
3271  /**
3272  * Codec implemented by the hardware accelerator.
3273  *
3274  * See AV_CODEC_ID_xxx
3275  */
3276  enum AVCodecID id;
3277 
3278  /**
3279  * Supported pixel format.
3280  *
3281  * Only hardware accelerated formats are supported here.
3282  */
3283  enum AVPixelFormat pix_fmt;
3284 
3285  /**
3286  * Hardware accelerated codec capabilities.
3287  * see FF_HWACCEL_CODEC_CAP_*
3288  */
3289  int capabilities;
3290 
3291  /*****************************************************************
3292  * No fields below this line are part of the public API. They
3293  * may not be used outside of libavcodec and can be changed and
3294  * removed at will.
3295  * New public fields should be added right above.
3296  *****************************************************************
3297  */
3298  struct AVHWAccel *next;
3299 
3300  /**
3301  * Allocate a custom buffer
3302  */
3303  int (*alloc_frame)(AVCodecContext *avctx, AVFrame *frame);
3304 
3305  /**
3306  * Called at the beginning of each frame or field picture.
3307  *
3308  * Meaningful frame information (codec specific) is guaranteed to
3309  * be parsed at this point. This function is mandatory.
3310  *
3311  * Note that buf can be NULL along with buf_size set to 0.
3312  * Otherwise, this means the whole frame is available at this point.
3313  *
3314  * @param avctx the codec context
3315  * @param buf the frame data buffer base
3316  * @param buf_size the size of the frame in bytes
3317  * @return zero if successful, a negative value otherwise
3318  */
3319  int (*start_frame)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size);
3320 
3321  /**
3322  * Callback for each slice.
3323  *
3324  * Meaningful slice information (codec specific) is guaranteed to
3325  * be parsed at this point. This function is mandatory.
3326  * The only exception is XvMC, that works on MB level.
3327  *
3328  * @param avctx the codec context
3329  * @param buf the slice data buffer base
3330  * @param buf_size the size of the slice in bytes
3331  * @return zero if successful, a negative value otherwise
3332  */
3333  int (*decode_slice)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size);
3334 
3335  /**
3336  * Called at the end of each frame or field picture.
3337  *
3338  * The whole picture is parsed at this point and can now be sent
3339  * to the hardware accelerator. This function is mandatory.
3340  *
3341  * @param avctx the codec context
3342  * @return zero if successful, a negative value otherwise
3343  */
3344  int (*end_frame)(AVCodecContext *avctx);
3345 
3346  /**
3347  * Size of per-frame hardware accelerator private data.
3348  *
3349  * Private data is allocated with av_mallocz() before
3350  * AVCodecContext.get_buffer() and deallocated after
3351  * AVCodecContext.release_buffer().
3352  */
3354 
3355  /**
3356  * Called for every Macroblock in a slice.
3357  *
3358  * XvMC uses it to replace the ff_mpv_decode_mb().
3359  * Instead of decoding to raw picture, MB parameters are
3360  * stored in an array provided by the video driver.
3361  *
3362  * @param s the mpeg context
3363  */
3364  void (*decode_mb)(struct MpegEncContext *s);
3365 
3366  /**
3367  * Initialize the hwaccel private data.
3368  *
3369  * This will be called from ff_get_format(), after hwaccel and
3370  * hwaccel_context are set and the hwaccel private data in AVCodecInternal
3371  * is allocated.
3372  */
3373  int (*init)(AVCodecContext *avctx);
3374 
3375  /**
3376  * Uninitialize the hwaccel private data.
3377  *
3378  * This will be called from get_format() or avcodec_close(), after hwaccel
3379  * and hwaccel_context are already uninitialized.
3380  */
3381  int (*uninit)(AVCodecContext *avctx);
3382 
3383  /**
3384  * Size of the private data to allocate in
3385  * AVCodecInternal.hwaccel_priv_data.
3386  */
3387  int priv_data_size;
3388 } AVHWAccel;
3389 
3390 /**
3391  * Hardware acceleration should be used for decoding even if the codec level
3392  * used is unknown or higher than the maximum supported level reported by the
3393  * hardware driver.
3394  */
3395 #define AV_HWACCEL_FLAG_IGNORE_LEVEL (1 << 0)
3396 
3397 /**
3398  * @}
3399  */
3400 
3401 /**
3402  * @defgroup lavc_picture AVPicture
3403  *
3404  * Functions for working with AVPicture
3405  * @{
3406  */
3407 
3408 /**
3409  * Picture data structure.
3410  *
3411  * Up to four components can be stored into it, the last component is
3412  * alpha.
3413  */
3414 typedef struct AVPicture {
3415  uint8_t *data[AV_NUM_DATA_POINTERS]; ///< pointers to the image data planes
3416  int linesize[AV_NUM_DATA_POINTERS]; ///< number of bytes per line
3417 } AVPicture;
3418 
3419 /**
3420  * @}
3421  */
3424  SUBTITLE_NONE,
3426  SUBTITLE_BITMAP, ///< A bitmap, pict will be set
3427 
3428  /**
3429  * Plain text, the text field must be set by the decoder and is
3430  * authoritative. ass and pict fields may contain approximations.
3431  */
3432  SUBTITLE_TEXT,
3433 
3434  /**
3435  * Formatted text, the ass field must be set by the decoder and is
3436  * authoritative. pict and text fields may contain approximations.
3437  */
3438  SUBTITLE_ASS,
3439 };
3441 #define AV_SUBTITLE_FLAG_FORCED 0x00000001
3443 typedef struct AVSubtitleRect {
3444  int x; ///< top left corner of pict, undefined when pict is not set
3445  int y; ///< top left corner of pict, undefined when pict is not set
3446  int w; ///< width of pict, undefined when pict is not set
3447  int h; ///< height of pict, undefined when pict is not set
3448  int nb_colors; ///< number of colors in pict, undefined when pict is not set
3449 
3450  /**
3451  * data+linesize for the bitmap of this subtitle.
3452  * can be set for text/ass as well once they where rendered
3453  */
3455  enum AVSubtitleType type;
3457  char *text; ///< 0 terminated plain UTF-8 text
3458 
3459  /**
3460  * 0 terminated ASS/SSA compatible event line.
3461  * The presentation of this is unaffected by the other values in this
3462  * struct.
3463  */
3464  char *ass;
3466  int flags;
3467 } AVSubtitleRect;
3469 typedef struct AVSubtitle {
3470  uint16_t format; /* 0 = graphics */
3471  uint32_t start_display_time; /* relative to packet pts, in ms */
3472  uint32_t end_display_time; /* relative to packet pts, in ms */
3473  unsigned num_rects;
3475  int64_t pts; ///< Same as packet pts, in AV_TIME_BASE
3476 } AVSubtitle;
3477 
3478 /**
3479  * If c is NULL, returns the first registered codec,
3480  * if c is non-NULL, returns the next registered codec after c,
3481  * or NULL if c is the last one.
3482  */
3483 AVCodec *av_codec_next(const AVCodec *c);
3484 
3485 /**
3486  * Return the LIBAVCODEC_VERSION_INT constant.
3487  */
3488 unsigned avcodec_version(void);
3489 
3490 /**
3491  * Return the libavcodec build-time configuration.
3492  */
3493 const char *avcodec_configuration(void);
3494 
3495 /**
3496  * Return the libavcodec license.
3497  */
3498 const char *avcodec_license(void);
3499 
3500 /**
3501  * Register the codec codec and initialize libavcodec.
3502  *
3503  * @warning either this function or avcodec_register_all() must be called
3504  * before any other libavcodec functions.
3505  *
3506  * @see avcodec_register_all()
3507  */
3508 void avcodec_register(AVCodec *codec);
3509 
3510 /**
3511  * Register all the codecs, parsers and bitstream filters which were enabled at
3512  * configuration time. If you do not call this function you can select exactly
3513  * which formats you want to support, by using the individual registration
3514  * functions.
3515  *
3516  * @see avcodec_register
3517  * @see av_register_codec_parser
3518  * @see av_register_bitstream_filter
3519  */
3520 void avcodec_register_all(void);
3521 
3522 /**
3523  * Allocate an AVCodecContext and set its fields to default values. The
3524  * resulting struct should be freed with avcodec_free_context().
3525  *
3526  * @param codec if non-NULL, allocate private data and initialize defaults
3527  * for the given codec. It is illegal to then call avcodec_open2()
3528  * with a different codec.
3529  * If NULL, then the codec-specific defaults won't be initialized,
3530  * which may result in suboptimal default settings (this is
3531  * important mainly for encoders, e.g. libx264).
3532  *
3533  * @return An AVCodecContext filled with default values or NULL on failure.
3534  * @see avcodec_get_context_defaults
3535  */
3537 
3538 /**
3539  * Free the codec context and everything associated with it and write NULL to
3540  * the provided pointer.
3541  */
3542 void avcodec_free_context(AVCodecContext **avctx);
3543 
3544 /**
3545  * Set the fields of the given AVCodecContext to default values corresponding
3546  * to the given codec (defaults may be codec-dependent).
3547  *
3548  * Do not call this function if a non-NULL codec has been passed
3549  * to avcodec_alloc_context3() that allocated this AVCodecContext.
3550  * If codec is non-NULL, it is illegal to call avcodec_open2() with a
3551  * different codec on this AVCodecContext.
3552  */
3554 
3555 /**
3556  * Get the AVClass for AVCodecContext. It can be used in combination with
3557  * AV_OPT_SEARCH_FAKE_OBJ for examining options.
3558  *
3559  * @see av_opt_find().
3560  */
3561 const AVClass *avcodec_get_class(void);
3562 
3563 /**
3564  * Get the AVClass for AVFrame. It can be used in combination with
3565  * AV_OPT_SEARCH_FAKE_OBJ for examining options.
3566  *
3567  * @see av_opt_find().
3568  */
3569 const AVClass *avcodec_get_frame_class(void);
3570 
3571 /**
3572  * Get the AVClass for AVSubtitleRect. It can be used in combination with
3573  * AV_OPT_SEARCH_FAKE_OBJ for examining options.
3574  *
3575  * @see av_opt_find().
3576  */
3578 
3579 /**
3580  * Copy the settings of the source AVCodecContext into the destination
3581  * AVCodecContext. The resulting destination codec context will be
3582  * unopened, i.e. you are required to call avcodec_open2() before you
3583  * can use this AVCodecContext to decode/encode video/audio data.
3584  *
3585  * @param dest target codec context, should be initialized with
3586  * avcodec_alloc_context3(NULL), but otherwise uninitialized
3587  * @param src source codec context
3588  * @return AVERROR() on error (e.g. memory allocation error), 0 on success
3589  */
3591 
3592 #if FF_API_AVFRAME_LAVC
3593 /**
3594  * @deprecated use av_frame_alloc()
3595  */
3597 AVFrame *avcodec_alloc_frame(void);
3598 
3599 /**
3600  * Set the fields of the given AVFrame to default values.
3601  *
3602  * @param frame The AVFrame of which the fields should be set to default values.
3603  *
3604  * @deprecated use av_frame_unref()
3605  */
3607 void avcodec_get_frame_defaults(AVFrame *frame);
3608 
3609 /**
3610  * Free the frame and any dynamically allocated objects in it,
3611  * e.g. extended_data.
3612  *
3613  * @param frame frame to be freed. The pointer will be set to NULL.
3614  *
3615  * @warning this function does NOT free the data buffers themselves
3616  * (it does not know how, since they might have been allocated with
3617  * a custom get_buffer()).
3618  *
3619  * @deprecated use av_frame_free()
3620  */
3622 void avcodec_free_frame(AVFrame **frame);
3623 #endif
3624 
3625 /**
3626  * Initialize the AVCodecContext to use the given AVCodec. Prior to using this
3627  * function the context has to be allocated with avcodec_alloc_context3().
3628  *
3629  * The functions avcodec_find_decoder_by_name(), avcodec_find_encoder_by_name(),
3630  * avcodec_find_decoder() and avcodec_find_encoder() provide an easy way for
3631  * retrieving a codec.
3632  *
3633  * @warning This function is not thread safe!
3634  *
3635  * @code
3636  * avcodec_register_all();
3637  * av_dict_set(&opts, "b", "2.5M", 0);
3638  * codec = avcodec_find_decoder(AV_CODEC_ID_H264);
3639  * if (!codec)
3640  * exit(1);
3641  *
3642  * context = avcodec_alloc_context3(codec);
3643  *
3644  * if (avcodec_open2(context, codec, opts) < 0)
3645  * exit(1);
3646  * @endcode
3647  *
3648  * @param avctx The context to initialize.
3649  * @param codec The codec to open this context for. If a non-NULL codec has been
3650  * previously passed to avcodec_alloc_context3() or
3651  * avcodec_get_context_defaults3() for this context, then this
3652  * parameter MUST be either NULL or equal to the previously passed
3653  * codec.
3654  * @param options A dictionary filled with AVCodecContext and codec-private options.
3655  * On return this object will be filled with options that were not found.
3656  *
3657  * @return zero on success, a negative value on error
3658  * @see avcodec_alloc_context3(), avcodec_find_decoder(), avcodec_find_encoder(),
3659  * av_dict_set(), av_opt_find().
3660  */
3661 int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options);
3662 
3663 /**
3664  * Close a given AVCodecContext and free all the data associated with it
3665  * (but not the AVCodecContext itself).
3666  *
3667  * Calling this function on an AVCodecContext that hasn't been opened will free
3668  * the codec-specific data allocated in avcodec_alloc_context3() /
3669  * avcodec_get_context_defaults3() with a non-NULL codec. Subsequent calls will
3670  * do nothing.
3671  */
3672 int avcodec_close(AVCodecContext *avctx);
3673 
3674 /**
3675  * Free all allocated data in the given subtitle struct.
3676  *
3677  * @param sub AVSubtitle to free.
3678  */
3679 void avsubtitle_free(AVSubtitle *sub);
3680 
3681 /**
3682  * @}
3683  */
3684 
3685 /**
3686  * @addtogroup lavc_packet
3687  * @{
3688  */
3689 
3690 #if FF_API_DESTRUCT_PACKET
3691 /**
3692  * Default packet destructor.
3693  * @deprecated use the AVBuffer API instead
3694  */
3697 #endif
3698 
3699 /**
3700  * Initialize optional fields of a packet with default values.
3701  *
3702  * Note, this does not touch the data and size members, which have to be
3703  * initialized separately.
3704  *
3705  * @param pkt packet
3706  */
3707 void av_init_packet(AVPacket *pkt);
3708 
3709 /**
3710  * Allocate the payload of a packet and initialize its fields with
3711  * default values.
3712  *
3713  * @param pkt packet
3714  * @param size wanted payload size
3715  * @return 0 if OK, AVERROR_xxx otherwise
3716  */
3717 int av_new_packet(AVPacket *pkt, int size);
3718 
3719 /**
3720  * Reduce packet size, correctly zeroing padding
3721  *
3722  * @param pkt packet
3723  * @param size new size
3724  */
3725 void av_shrink_packet(AVPacket *pkt, int size);
3726 
3727 /**
3728  * Increase packet size, correctly zeroing padding
3729  *
3730  * @param pkt packet
3731  * @param grow_by number of bytes by which to increase the size of the packet
3732  */
3733 int av_grow_packet(AVPacket *pkt, int grow_by);
3734 
3735 /**
3736  * Initialize a reference-counted packet from av_malloc()ed data.
3737  *
3738  * @param pkt packet to be initialized. This function will set the data, size,
3739  * buf and destruct fields, all others are left untouched.
3740  * @param data Data allocated by av_malloc() to be used as packet data. If this
3741  * function returns successfully, the data is owned by the underlying AVBuffer.
3742  * The caller may not access the data through other means.
3743  * @param size size of data in bytes, without the padding. I.e. the full buffer
3744  * size is assumed to be size + FF_INPUT_BUFFER_PADDING_SIZE.
3745  *
3746  * @return 0 on success, a negative AVERROR on error
3747  */
3749 
3750 /**
3751  * @warning This is a hack - the packet memory allocation stuff is broken. The
3752  * packet is allocated if it was not really allocated.
3753  */
3754 int av_dup_packet(AVPacket *pkt);
3755 
3756 /**
3757  * Copy packet, including contents
3758  *
3759  * @return 0 on success, negative AVERROR on fail
3760  */
3761 int av_copy_packet(AVPacket *dst, const AVPacket *src);
3762 
3763 /**
3764  * Copy packet side data
3765  *
3766  * @return 0 on success, negative AVERROR on fail
3767  */
3768 int av_copy_packet_side_data(AVPacket *dst, const AVPacket *src);
3769 
3770 /**
3771  * Free a packet.
3772  *
3773  * @param pkt packet to free
3774  */
3775 void av_free_packet(AVPacket *pkt);
3776 
3777 /**
3778  * Allocate new information of a packet.
3779  *
3780  * @param pkt packet
3781  * @param type side information type
3782  * @param size side information size
3783  * @return pointer to fresh allocated data or NULL otherwise
3784  */
3786  int size);
3787 
3788 /**
3789  * Shrink the already allocated side data buffer
3790  *
3791  * @param pkt packet
3792  * @param type side information type
3793  * @param size new side information size
3794  * @return 0 on success, < 0 on failure
3795  */
3797  int size);
3798 
3799 /**
3800  * Get side information from packet.
3801  *
3802  * @param pkt packet
3803  * @param type desired side information type
3804  * @param size pointer for side information size to store (optional)
3805  * @return pointer to data if present or NULL otherwise
3806  */
3808  int *size);
3809 
3811 
3813 
3814 /**
3815  * Pack a dictionary for use in side_data.
3816  *
3817  * @param dict The dictionary to pack.
3818  * @param size pointer to store the size of the returned data
3819  * @return pointer to data if successful, NULL otherwise
3820  */
3822 /**
3823  * Unpack a dictionary from side_data.
3824  *
3825  * @param data data from side_data
3826  * @param size size of the data
3827  * @param dict the metadata storage dictionary
3828  * @return 0 on success, < 0 on failure
3829  */
3830 int av_packet_unpack_dictionary(const uint8_t *data, int size, AVDictionary **dict);
3831 
3832 
3833 /**
3834  * Convenience function to free all the side data stored.
3835  * All the other fields stay untouched.
3836  *
3837  * @param pkt packet
3838  */
3840 
3841 /**
3842  * Setup a new reference to the data described by a given packet
3843  *
3844  * If src is reference-counted, setup dst as a new reference to the
3845  * buffer in src. Otherwise allocate a new buffer in dst and copy the
3846  * data from src into it.
3847  *
3848  * All the other fields are copied from src.
3849  *
3850  * @see av_packet_unref
3851  *
3852  * @param dst Destination packet
3853  * @param src Source packet
3854  *
3855  * @return 0 on success, a negative AVERROR on error.
3856  */
3857 int av_packet_ref(AVPacket *dst, const AVPacket *src);
3858 
3859 /**
3860  * Wipe the packet.
3861  *
3862  * Unreference the buffer referenced by the packet and reset the
3863  * remaining packet fields to their default values.
3864  *
3865  * @param pkt The packet to be unreferenced.
3866  */
3868 
3869 /**
3870  * Move every field in src to dst and reset src.
3871  *
3872  * @see av_packet_unref
3873  *
3874  * @param src Source packet, will be reset
3875  * @param dst Destination packet
3876  */
3878 
3879 /**
3880  * Copy only "properties" fields from src to dst.
3881  *
3882  * Properties for the purpose of this function are all the fields
3883  * beside those related to the packet data (buf, data, size)
3884  *
3885  * @param dst Destination packet
3886  * @param src Source packet
3887  *
3888  * @return 0 on success AVERROR on failure.
3889  *
3890  */
3891 int av_packet_copy_props(AVPacket *dst, const AVPacket *src);
3892 
3893 /**
3894  * Convert valid timing fields (timestamps / durations) in a packet from one
3895  * timebase to another. Timestamps with unknown values (AV_NOPTS_VALUE) will be
3896  * ignored.
3897  *
3898  * @param pkt packet on which the conversion will be performed
3899  * @param tb_src source timebase, in which the timing fields in pkt are
3900  * expressed
3901  * @param tb_dst destination timebase, to which the timing fields will be
3902  * converted
3903  */
3904 void av_packet_rescale_ts(AVPacket *pkt, AVRational tb_src, AVRational tb_dst);
3905 
3906 /**
3907  * @}
3908  */
3909 
3910 /**
3911  * @addtogroup lavc_decoding
3912  * @{
3913  */
3914 
3915 /**
3916  * Find a registered decoder with a matching codec ID.
3917  *
3918  * @param id AVCodecID of the requested decoder
3919  * @return A decoder if one was found, NULL otherwise.
3920  */
3922 
3923 /**
3924  * Find a registered decoder with the specified name.
3925  *
3926  * @param name name of the requested decoder
3927  * @return A decoder if one was found, NULL otherwise.
3928  */
3930 
3931 #if FF_API_GET_BUFFER
3935 #endif
3936 
3937 /**
3938  * The default callback for AVCodecContext.get_buffer2(). It is made public so
3939  * it can be called by custom get_buffer2() implementations for decoders without
3940  * CODEC_CAP_DR1 set.
3941  */
3943 
3944 #if FF_API_EMU_EDGE
3945 /**
3946  * Return the amount of padding in pixels which the get_buffer callback must
3947  * provide around the edge of the image for codecs which do not have the
3948  * CODEC_FLAG_EMU_EDGE flag.
3949  *
3950  * @return Required padding in pixels.
3951  *
3952  * @deprecated CODEC_FLAG_EMU_EDGE is deprecated, so this function is no longer
3953  * needed
3954  */
3956 unsigned avcodec_get_edge_width(void);
3957 #endif
3958 
3959 /**
3960  * Modify width and height values so that they will result in a memory
3961  * buffer that is acceptable for the codec if you do not use any horizontal
3962  * padding.
3963  *
3964  * May only be used if a codec with CODEC_CAP_DR1 has been opened.
3965  */
3967 
3968 /**
3969  * Modify width and height values so that they will result in a memory
3970  * buffer that is acceptable for the codec if you also ensure that all
3971  * line sizes are a multiple of the respective linesize_align[i].
3972  *
3973  * May only be used if a codec with CODEC_CAP_DR1 has been opened.
3974  */
3976  int linesize_align[AV_NUM_DATA_POINTERS]);
3977 
3978 /**
3979  * Converts AVChromaLocation to swscale x/y chroma position.
3980  *
3981  * The positions represent the chroma (0,0) position in a coordinates system
3982  * with luma (0,0) representing the origin and luma(1,1) representing 256,256
3983  *
3984  * @param xpos horizontal chroma sample position
3985  * @param ypos vertical chroma sample position
3986  */
3987 int avcodec_enum_to_chroma_pos(int *xpos, int *ypos, enum AVChromaLocation pos);
3988 
3989 /**
3990  * Converts swscale x/y chroma position to AVChromaLocation.
3991  *
3992  * The positions represent the chroma (0,0) position in a coordinates system
3993  * with luma (0,0) representing the origin and luma(1,1) representing 256,256
3994  *
3995  * @param xpos horizontal chroma sample position
3996  * @param ypos vertical chroma sample position
3997  */
3998 enum AVChromaLocation avcodec_chroma_pos_to_enum(int xpos, int ypos);
3999 
4000 #if FF_API_OLD_DECODE_AUDIO
4001 /**
4002  * Wrapper function which calls avcodec_decode_audio4.
4003  *
4004  * @deprecated Use avcodec_decode_audio4 instead.
4005  *
4006  * Decode the audio frame of size avpkt->size from avpkt->data into samples.
4007  * Some decoders may support multiple frames in a single AVPacket, such
4008  * decoders would then just decode the first frame. In this case,
4009  * avcodec_decode_audio3 has to be called again with an AVPacket that contains
4010  * the remaining data in order to decode the second frame etc.
4011  * If no frame
4012  * could be outputted, frame_size_ptr is zero. Otherwise, it is the
4013  * decompressed frame size in bytes.
4014  *
4015  * @warning You must set frame_size_ptr to the allocated size of the
4016  * output buffer before calling avcodec_decode_audio3().
4017  *
4018  * @warning The input buffer must be FF_INPUT_BUFFER_PADDING_SIZE larger than
4019  * the actual read bytes because some optimized bitstream readers read 32 or 64
4020  * bits at once and could read over the end.
4021  *
4022  * @warning The end of the input buffer avpkt->data should be set to 0 to ensure that
4023  * no overreading happens for damaged MPEG streams.
4024  *
4025  * @warning You must not provide a custom get_buffer() when using
4026  * avcodec_decode_audio3(). Doing so will override it with
4027  * avcodec_default_get_buffer. Use avcodec_decode_audio4() instead,
4028  * which does allow the application to provide a custom get_buffer().
4029  *
4030  * @note You might have to align the input buffer avpkt->data and output buffer
4031  * samples. The alignment requirements depend on the CPU: On some CPUs it isn't
4032  * necessary at all, on others it won't work at all if not aligned and on others
4033  * it will work but it will have an impact on performance.
4034  *
4035  * In practice, avpkt->data should have 4 byte alignment at minimum and
4036  * samples should be 16 byte aligned unless the CPU doesn't need it
4037  * (AltiVec and SSE do).
4038  *
4039  * @note Codecs which have the CODEC_CAP_DELAY capability set have a delay
4040  * between input and output, these need to be fed with avpkt->data=NULL,
4041  * avpkt->size=0 at the end to return the remaining frames.
4042  *
4043  * @param avctx the codec context
4044  * @param[out] samples the output buffer, sample type in avctx->sample_fmt
4045  * If the sample format is planar, each channel plane will
4046  * be the same size, with no padding between channels.
4047  * @param[in,out] frame_size_ptr the output buffer size in bytes
4048  * @param[in] avpkt The input AVPacket containing the input buffer.
4049  * You can create such packet with av_init_packet() and by then setting
4050  * data and size, some decoders might in addition need other fields.
4051  * All decoders are designed to use the least fields possible though.
4052  * @return On error a negative value is returned, otherwise the number of bytes
4053  * used or zero if no frame data was decompressed (used) from the input AVPacket.
4054  */
4055 attribute_deprecated int avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples,
4056  int *frame_size_ptr,
4057  AVPacket *avpkt);
4058 #endif
4059 
4060 /**
4061  * Decode the audio frame of size avpkt->size from avpkt->data into frame.
4062  *
4063  * Some decoders may support multiple frames in a single AVPacket. Such
4064  * decoders would then just decode the first frame and the return value would be
4065  * less than the packet size. In this case, avcodec_decode_audio4 has to be
4066  * called again with an AVPacket containing the remaining data in order to
4067  * decode the second frame, etc... Even if no frames are returned, the packet
4068  * needs to be fed to the decoder with remaining data until it is completely
4069  * consumed or an error occurs.
4070  *
4071  * Some decoders (those marked with CODEC_CAP_DELAY) have a delay between input
4072  * and output. This means that for some packets they will not immediately
4073  * produce decoded output and need to be flushed at the end of decoding to get
4074  * all the decoded data. Flushing is done by calling this function with packets
4075  * with avpkt->data set to NULL and avpkt->size set to 0 until it stops
4076  * returning samples. It is safe to flush even those decoders that are not
4077  * marked with CODEC_CAP_DELAY, then no samples will be returned.
4078  *
4079  * @warning The input buffer, avpkt->data must be FF_INPUT_BUFFER_PADDING_SIZE
4080  * larger than the actual read bytes because some optimized bitstream
4081  * readers read 32 or 64 bits at once and could read over the end.
4082  *
4083  * @param avctx the codec context
4084  * @param[out] frame The AVFrame in which to store decoded audio samples.
4085  * The decoder will allocate a buffer for the decoded frame by
4086  * calling the AVCodecContext.get_buffer2() callback.
4087  * When AVCodecContext.refcounted_frames is set to 1, the frame is
4088  * reference counted and the returned reference belongs to the
4089  * caller. The caller must release the frame using av_frame_unref()
4090  * when the frame is no longer needed. The caller may safely write
4091  * to the frame if av_frame_is_writable() returns 1.
4092  * When AVCodecContext.refcounted_frames is set to 0, the returned
4093  * reference belongs to the decoder and is valid only until the
4094  * next call to this function or until closing or flushing the
4095  * decoder. The caller may not write to it.
4096  * @param[out] got_frame_ptr Zero if no frame could be decoded, otherwise it is
4097  * non-zero. Note that this field being set to zero
4098  * does not mean that an error has occurred. For
4099  * decoders with CODEC_CAP_DELAY set, no given decode
4100  * call is guaranteed to produce a frame.
4101  * @param[in] avpkt The input AVPacket containing the input buffer.
4102  * At least avpkt->data and avpkt->size should be set. Some
4103  * decoders might also require additional fields to be set.
4104  * @return A negative error code is returned if an error occurred during
4105  * decoding, otherwise the number of bytes consumed from the input
4106  * AVPacket is returned.
4107  */
4109  int *got_frame_ptr, const AVPacket *avpkt);
4110 
4111 /**
4112  * Decode the video frame of size avpkt->size from avpkt->data into picture.
4113  * Some decoders may support multiple frames in a single AVPacket, such
4114  * decoders would then just decode the first frame.
4115  *
4116  * @warning The input buffer must be FF_INPUT_BUFFER_PADDING_SIZE larger than
4117  * the actual read bytes because some optimized bitstream readers read 32 or 64
4118  * bits at once and could read over the end.
4119  *
4120  * @warning The end of the input buffer buf should be set to 0 to ensure that
4121  * no overreading happens for damaged MPEG streams.
4122  *
4123  * @note Codecs which have the CODEC_CAP_DELAY capability set have a delay
4124  * between input and output, these need to be fed with avpkt->data=NULL,
4125  * avpkt->size=0 at the end to return the remaining frames.
4126  *
4127  * @param avctx the codec context
4128  * @param[out] picture The AVFrame in which the decoded video frame will be stored.
4129  * Use av_frame_alloc() to get an AVFrame. The codec will
4130  * allocate memory for the actual bitmap by calling the
4131  * AVCodecContext.get_buffer2() callback.
4132  * When AVCodecContext.refcounted_frames is set to 1, the frame is
4133  * reference counted and the returned reference belongs to the
4134  * caller. The caller must release the frame using av_frame_unref()
4135  * when the frame is no longer needed. The caller may safely write
4136  * to the frame if av_frame_is_writable() returns 1.
4137  * When AVCodecContext.refcounted_frames is set to 0, the returned
4138  * reference belongs to the decoder and is valid only until the
4139  * next call to this function or until closing or flushing the
4140  * decoder. The caller may not write to it.
4141  *
4142  * @param[in] avpkt The input AVPacket containing the input buffer.
4143  * You can create such packet with av_init_packet() and by then setting
4144  * data and size, some decoders might in addition need other fields like
4145  * flags&AV_PKT_FLAG_KEY. All decoders are designed to use the least
4146  * fields possible.
4147  * @param[in,out] got_picture_ptr Zero if no frame could be decompressed, otherwise, it is nonzero.
4148  * @return On error a negative value is returned, otherwise the number of bytes
4149  * used or zero if no frame could be decompressed.
4150  */
4151 int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture,
4152  int *got_picture_ptr,
4153  const AVPacket *avpkt);
4154 
4155 /**
4156  * Decode a subtitle message.
4157  * Return a negative value on error, otherwise return the number of bytes used.
4158  * If no subtitle could be decompressed, got_sub_ptr is zero.
4159  * Otherwise, the subtitle is stored in *sub.
4160  * Note that CODEC_CAP_DR1 is not available for subtitle codecs. This is for
4161  * simplicity, because the performance difference is expect to be negligible
4162  * and reusing a get_buffer written for video codecs would probably perform badly
4163  * due to a potentially very different allocation pattern.
4164  *
4165  * Some decoders (those marked with CODEC_CAP_DELAY) have a delay between input
4166  * and output. This means that for some packets they will not immediately
4167  * produce decoded output and need to be flushed at the end of decoding to get
4168  * all the decoded data. Flushing is done by calling this function with packets
4169  * with avpkt->data set to NULL and avpkt->size set to 0 until it stops
4170  * returning subtitles. It is safe to flush even those decoders that are not
4171  * marked with CODEC_CAP_DELAY, then no subtitles will be returned.
4172  *
4173  * @param avctx the codec context
4174  * @param[out] sub The Preallocated AVSubtitle in which the decoded subtitle will be stored,
4175  * must be freed with avsubtitle_free if *got_sub_ptr is set.
4176  * @param[in,out] got_sub_ptr Zero if no subtitle could be decompressed, otherwise, it is nonzero.
4177  * @param[in] avpkt The input AVPacket containing the input buffer.
4178  */
4180  int *got_sub_ptr,
4181  AVPacket *avpkt);
4182 
4183 /**
4184  * @defgroup lavc_parsing Frame parsing
4185  * @{
4186  */
4190  AV_PICTURE_STRUCTURE_TOP_FIELD, //< coded as top field
4191  AV_PICTURE_STRUCTURE_BOTTOM_FIELD, //< coded as bottom field
4192  AV_PICTURE_STRUCTURE_FRAME, //< coded as frame
4193 };
4195 typedef struct AVCodecParserContext {
4196  void *priv_data;
4198  int64_t frame_offset; /* offset of the current frame */
4199  int64_t cur_offset; /* current offset
4200  (incremented by each av_parser_parse()) */
4201  int64_t next_frame_offset; /* offset of the next frame */
4202  /* video info */
4203  int pict_type; /* XXX: Put it back in AVCodecContext. */
4204  /**
4205  * This field is used for proper frame duration computation in lavf.
4206  * It signals, how much longer the frame duration of the current frame
4207  * is compared to normal frame duration.
4208  *
4209  * frame_duration = (1 + repeat_pict) * time_base
4210  *
4211  * It is used by codecs like H.264 to display telecined material.
4212  */
4213  int repeat_pict; /* XXX: Put it back in AVCodecContext. */
4214  int64_t pts; /* pts of the current frame */
4215  int64_t dts; /* dts of the current frame */
4216 
4217  /* private data */
4218  int64_t last_pts;
4219  int64_t last_dts;
4220  int fetch_timestamp;
4222 #define AV_PARSER_PTS_NB 4
4228  int flags;
4229 #define PARSER_FLAG_COMPLETE_FRAMES 0x0001
4230 #define PARSER_FLAG_ONCE 0x0002
4231 /// Set if the parser has a valid file offset
4232 #define PARSER_FLAG_FETCHED_OFFSET 0x0004
4233 #define PARSER_FLAG_USE_CODEC_TS 0x1000
4235  int64_t offset; ///< byte offset from starting packet start
4237 
4238  /**
4239  * Set by parser to 1 for key frames and 0 for non-key frames.
4240  * It is initialized to -1, so if the parser doesn't set this flag,
4241  * old-style fallback using AV_PICTURE_TYPE_I picture type as key frames
4242  * will be used.
4243  */
4244  int key_frame;
4245 
4246  /**
4247  * Time difference in stream time base units from the pts of this
4248  * packet to the point at which the output from the decoder has converged
4249  * independent from the availability of previous frames. That is, the
4250  * frames are virtually identical no matter if decoding started from
4251  * the very first frame or from this keyframe.
4252  * Is AV_NOPTS_VALUE if unknown.
4253  * This field is not the display duration of the current frame.
4254  * This field has no meaning if the packet does not have AV_PKT_FLAG_KEY
4255  * set.
4256  *
4257  * The purpose of this field is to allow seeking in streams that have no
4258  * keyframes in the conventional sense. It corresponds to the
4259  * recovery point SEI in H.264 and match_time_delta in NUT. It is also
4260  * essential for some types of subtitle streams to ensure that all
4261  * subtitles are correctly displayed after seeking.
4262  */
4263  int64_t convergence_duration;
4264 
4265  // Timestamp generation support:
4266  /**
4267  * Synchronization point for start of timestamp generation.
4268  *
4269  * Set to >0 for sync point, 0 for no sync point and <0 for undefined
4270  * (default).
4271  *
4272  * For example, this corresponds to presence of H.264 buffering period
4273  * SEI message.
4274  */
4275  int dts_sync_point;
4276 
4277  /**
4278  * Offset of the current timestamp against last timestamp sync point in
4279  * units of AVCodecContext.time_base.
4280  *
4281  * Set to INT_MIN when dts_sync_point unused. Otherwise, it must
4282  * contain a valid timestamp offset.
4283  *
4284  * Note that the timestamp of sync point has usually a nonzero
4285  * dts_ref_dts_delta, which refers to the previous sync point. Offset of
4286  * the next frame after timestamp sync point will be usually 1.
4287  *
4288  * For example, this corresponds to H.264 cpb_removal_delay.
4289  */
4290  int dts_ref_dts_delta;
4291 
4292  /**
4293  * Presentation delay of current frame in units of AVCodecContext.time_base.
4294  *
4295  * Set to INT_MIN when dts_sync_point unused. Otherwise, it must
4296  * contain valid non-negative timestamp delta (presentation time of a frame
4297  * must not lie in the past).
4298  *
4299  * This delay represents the difference between decoding and presentation
4300  * time of the frame.
4301  *
4302  * For example, this corresponds to H.264 dpb_output_delay.
4303  */
4304  int pts_dts_delta;
4305 
4306  /**
4307  * Position of the packet in file.
4308  *
4309  * Analogous to cur_frame_pts/dts
4310  */
4312 
4313  /**
4314  * Byte position of currently parsed frame in stream.
4315  */
4316  int64_t pos;
4317 
4318  /**
4319  * Previous frame byte position.
4320  */
4321  int64_t last_pos;
4322 
4323  /**
4324  * Duration of the current frame.
4325  * For audio, this is in units of 1 / AVCodecContext.sample_rate.
4326  * For all other types, this is in units of AVCodecContext.time_base.
4327  */
4328  int duration;
4331 
4332  /**
4333  * Indicate whether a picture is coded as a frame, top field or bottom field.
4334  *
4335  * For example, H.264 field_pic_flag equal to 0 corresponds to
4336  * AV_PICTURE_STRUCTURE_FRAME. An H.264 picture with field_pic_flag
4337  * equal to 1 and bottom_field_flag equal to 0 corresponds to
4338  * AV_PICTURE_STRUCTURE_TOP_FIELD.
4339  */
4341 
4342  /**
4343  * Picture number incremented in presentation or output order.
4344  * This field may be reinitialized at the first picture of a new sequence.
4345  *
4346  * For example, this corresponds to H.264 PicOrderCnt.
4347  */
4351 typedef struct AVCodecParser {
4352  int codec_ids[5]; /* several codec IDs are permitted */
4356  AVCodecContext *avctx,
4357  const uint8_t **poutbuf, int *poutbuf_size,
4358  const uint8_t *buf, int buf_size);
4360  int (*split)(AVCodecContext *avctx, const uint8_t *buf, int buf_size);
4361  struct AVCodecParser *next;
4362 } AVCodecParser;
4363 
4365 
4368 
4369 /**
4370  * Parse a packet.
4371  *
4372  * @param s parser context.
4373  * @param avctx codec context.
4374  * @param poutbuf set to pointer to parsed buffer or NULL if not yet finished.
4375  * @param poutbuf_size set to size of parsed buffer or zero if not yet finished.
4376  * @param buf input buffer.
4377  * @param buf_size input length, to signal EOF, this should be 0 (so that the last frame can be output).
4378  * @param pts input presentation timestamp.
4379  * @param dts input decoding timestamp.
4380  * @param pos input byte position in stream.
4381  * @return the number of bytes of the input bitstream used.
4382  *
4383  * Example:
4384  * @code
4385  * while(in_len){
4386  * len = av_parser_parse2(myparser, AVCodecContext, &data, &size,
4387  * in_data, in_len,
4388  * pts, dts, pos);
4389  * in_data += len;
4390  * in_len -= len;
4391  *
4392  * if(size)
4393  * decode_frame(data, size);
4394  * }
4395  * @endcode
4396  */
4398  AVCodecContext *avctx,
4399  uint8_t **poutbuf, int *poutbuf_size,
4400  const uint8_t *buf, int buf_size,
4401  int64_t pts, int64_t dts,
4402  int64_t pos);
4403 
4404 /**
4405  * @return 0 if the output buffer is a subset of the input, 1 if it is allocated and must be freed
4406  * @deprecated use AVBitStreamFilter
4407  */
4409  AVCodecContext *avctx,
4410  uint8_t **poutbuf, int *poutbuf_size,
4411  const uint8_t *buf, int buf_size, int keyframe);
4413 
4414 /**
4415  * @}
4416  * @}
4417  */
4418 
4419 /**
4420  * @addtogroup lavc_encoding
4421  * @{
4422  */
4423 
4424 /**
4425  * Find a registered encoder with a matching codec ID.
4426  *
4427  * @param id AVCodecID of the requested encoder
4428  * @return An encoder if one was found, NULL otherwise.
4429  */
4431 
4432 /**
4433  * Find a registered encoder with the specified name.
4434  *
4435  * @param name name of the requested encoder
4436  * @return An encoder if one was found, NULL otherwise.
4437  */
4439 
4440 #if FF_API_OLD_ENCODE_AUDIO
4441 /**
4442  * Encode an audio frame from samples into buf.
4443  *
4444  * @deprecated Use avcodec_encode_audio2 instead.
4445  *
4446  * @note The output buffer should be at least FF_MIN_BUFFER_SIZE bytes large.
4447  * However, for codecs with avctx->frame_size equal to 0 (e.g. PCM) the user
4448  * will know how much space is needed because it depends on the value passed
4449  * in buf_size as described below. In that case a lower value can be used.
4450  *
4451  * @param avctx the codec context
4452  * @param[out] buf the output buffer
4453  * @param[in] buf_size the output buffer size
4454  * @param[in] samples the input buffer containing the samples
4455  * The number of samples read from this buffer is frame_size*channels,
4456  * both of which are defined in avctx.
4457  * For codecs which have avctx->frame_size equal to 0 (e.g. PCM) the number of
4458  * samples read from samples is equal to:
4459  * buf_size * 8 / (avctx->channels * av_get_bits_per_sample(avctx->codec_id))
4460  * This also implies that av_get_bits_per_sample() must not return 0 for these
4461  * codecs.
4462  * @return On error a negative value is returned, on success zero or the number
4463  * of bytes used to encode the data read from the input buffer.
4464  */
4466  uint8_t *buf, int buf_size,
4467  const short *samples);
4468 #endif
4469 
4470 /**
4471  * Encode a frame of audio.
4472  *
4473  * Takes input samples from frame and writes the next output packet, if
4474  * available, to avpkt. The output packet does not necessarily contain data for
4475  * the most recent frame, as encoders can delay, split, and combine input frames
4476  * internally as needed.
4477  *
4478  * @param avctx codec context
4479  * @param avpkt output AVPacket.
4480  * The user can supply an output buffer by setting
4481  * avpkt->data and avpkt->size prior to calling the
4482  * function, but if the size of the user-provided data is not
4483  * large enough, encoding will fail. If avpkt->data and
4484  * avpkt->size are set, avpkt->destruct must also be set. All
4485  * other AVPacket fields will be reset by the encoder using
4486  * av_init_packet(). If avpkt->data is NULL, the encoder will
4487  * allocate it. The encoder will set avpkt->size to the size
4488  * of the output packet.
4489  *
4490  * If this function fails or produces no output, avpkt will be
4491  * freed using av_free_packet() (i.e. avpkt->destruct will be
4492  * called to free the user supplied buffer).
4493  * @param[in] frame AVFrame containing the raw audio data to be encoded.
4494  * May be NULL when flushing an encoder that has the
4495  * CODEC_CAP_DELAY capability set.
4496  * If CODEC_CAP_VARIABLE_FRAME_SIZE is set, then each frame
4497  * can have any number of samples.
4498  * If it is not set, frame->nb_samples must be equal to
4499  * avctx->frame_size for all frames except the last.
4500  * The final frame may be smaller than avctx->frame_size.
4501  * @param[out] got_packet_ptr This field is set to 1 by libavcodec if the
4502  * output packet is non-empty, and to 0 if it is
4503  * empty. If the function returns an error, the
4504  * packet can be assumed to be invalid, and the
4505  * value of got_packet_ptr is undefined and should
4506  * not be used.
4507  * @return 0 on success, negative error code on failure
4508  */
4509 int avcodec_encode_audio2(AVCodecContext *avctx, AVPacket *avpkt,
4510  const AVFrame *frame, int *got_packet_ptr);
4511 
4512 #if FF_API_OLD_ENCODE_VIDEO
4513 /**
4514  * @deprecated use avcodec_encode_video2() instead.
4515  *
4516  * Encode a video frame from pict into buf.
4517  * The input picture should be
4518  * stored using a specific format, namely avctx.pix_fmt.
4519  *
4520  * @param avctx the codec context
4521  * @param[out] buf the output buffer for the bitstream of encoded frame
4522  * @param[in] buf_size the size of the output buffer in bytes
4523  * @param[in] pict the input picture to encode
4524  * @return On error a negative value is returned, on success zero or the number
4525  * of bytes used from the output buffer.
4526  */
4528 int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
4529  const AVFrame *pict);
4530 #endif
4531 
4532 /**
4533  * Encode a frame of video.
4534  *
4535  * Takes input raw video data from frame and writes the next output packet, if
4536  * available, to avpkt. The output packet does not necessarily contain data for
4537  * the most recent frame, as encoders can delay and reorder input frames
4538  * internally as needed.
4539  *
4540  * @param avctx codec context
4541  * @param avpkt output AVPacket.
4542  * The user can supply an output buffer by setting
4543  * avpkt->data and avpkt->size prior to calling the
4544  * function, but if the size of the user-provided data is not
4545  * large enough, encoding will fail. All other AVPacket fields
4546  * will be reset by the encoder using av_init_packet(). If
4547  * avpkt->data is NULL, the encoder will allocate it.
4548  * The encoder will set avpkt->size to the size of the
4549  * output packet. The returned data (if any) belongs to the
4550  * caller, he is responsible for freeing it.
4551  *
4552  * If this function fails or produces no output, avpkt will be
4553  * freed using av_free_packet() (i.e. avpkt->destruct will be
4554  * called to free the user supplied buffer).
4555  * @param[in] frame AVFrame containing the raw video data to be encoded.
4556  * May be NULL when flushing an encoder that has the
4557  * CODEC_CAP_DELAY capability set.
4558  * @param[out] got_packet_ptr This field is set to 1 by libavcodec if the
4559  * output packet is non-empty, and to 0 if it is
4560  * empty. If the function returns an error, the
4561  * packet can be assumed to be invalid, and the
4562  * value of got_packet_ptr is undefined and should
4563  * not be used.
4564  * @return 0 on success, negative error code on failure
4565  */
4566 int avcodec_encode_video2(AVCodecContext *avctx, AVPacket *avpkt,
4567  const AVFrame *frame, int *got_packet_ptr);
4568 
4569 int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
4570  const AVSubtitle *sub);
4571 
4572 
4573 /**
4574  * @}
4575  */
4576 
4577 #if FF_API_AVCODEC_RESAMPLE
4578 /**
4579  * @defgroup lavc_resample Audio resampling
4580  * @ingroup libavc
4581  * @deprecated use libswresample instead
4582  *
4583  * @{
4584  */
4585 struct ReSampleContext;
4586 struct AVResampleContext;
4587 
4588 typedef struct ReSampleContext ReSampleContext;
4589 
4590 /**
4591  * Initialize audio resampling context.
4592  *
4593  * @param output_channels number of output channels
4594  * @param input_channels number of input channels
4595  * @param output_rate output sample rate
4596  * @param input_rate input sample rate
4597  * @param sample_fmt_out requested output sample format
4598  * @param sample_fmt_in input sample format
4599  * @param filter_length length of each FIR filter in the filterbank relative to the cutoff frequency
4600  * @param log2_phase_count log2 of the number of entries in the polyphase filterbank
4601  * @param linear if 1 then the used FIR filter will be linearly interpolated
4602  between the 2 closest, if 0 the closest will be used
4603  * @param cutoff cutoff frequency, 1.0 corresponds to half the output sampling rate
4604  * @return allocated ReSampleContext, NULL if error occurred
4605  */
4608  int output_rate, int input_rate,
4609  enum AVSampleFormat sample_fmt_out,
4610  enum AVSampleFormat sample_fmt_in,
4611  int filter_length, int log2_phase_count,
4612  int linear, double cutoff);
4613 
4615 int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples);
4616 
4617 /**
4618  * Free resample context.
4619  *
4620  * @param s a non-NULL pointer to a resample context previously
4621  * created with av_audio_resample_init()
4622  */
4625 
4626 
4627 /**
4628  * Initialize an audio resampler.
4629  * Note, if either rate is not an integer then simply scale both rates up so they are.
4630  * @param filter_length length of each FIR filter in the filterbank relative to the cutoff freq
4631  * @param log2_phase_count log2 of the number of entries in the polyphase filterbank
4632  * @param linear If 1 then the used FIR filter will be linearly interpolated
4633  between the 2 closest, if 0 the closest will be used
4634  * @param cutoff cutoff frequency, 1.0 corresponds to half the output sampling rate
4635  */
4637 struct AVResampleContext *av_resample_init(int out_rate, int in_rate, int filter_length, int log2_phase_count, int linear, double cutoff);
4638 
4639 /**
4640  * Resample an array of samples using a previously configured context.
4641  * @param src an array of unconsumed samples
4642  * @param consumed the number of samples of src which have been consumed are returned here
4643  * @param src_size the number of unconsumed samples available
4644  * @param dst_size the amount of space in samples available in dst
4645  * @param update_ctx If this is 0 then the context will not be modified, that way several channels can be resampled with the same context.
4646  * @return the number of samples written in dst or -1 if an error occurred
4647  */
4649 int av_resample(struct AVResampleContext *c, short *dst, short *src, int *consumed, int src_size, int dst_size, int update_ctx);
4650 
4651 
4652 /**
4653  * Compensate samplerate/timestamp drift. The compensation is done by changing
4654  * the resampler parameters, so no audible clicks or similar distortions occur
4655  * @param compensation_distance distance in output samples over which the compensation should be performed
4656  * @param sample_delta number of output samples which should be output less
4657  *
4658  * example: av_resample_compensate(c, 10, 500)
4659  * here instead of 510 samples only 500 samples would be output
4660  *
4661  * note, due to rounding the actual compensation might be slightly different,
4662  * especially if the compensation_distance is large and the in_rate used during init is small
4663  */
4665 void av_resample_compensate(struct AVResampleContext *c, int sample_delta, int compensation_distance);
4667 void av_resample_close(struct AVResampleContext *c);
4668 
4669 /**
4670  * @}
4671  */
4672 #endif
4673 
4674 /**
4675  * @addtogroup lavc_picture
4676  * @{
4677  */
4678 
4679 /**
4680  * Allocate memory for the pixels of a picture and setup the AVPicture
4681  * fields for it.
4682  *
4683  * Call avpicture_free() to free it.
4684  *
4685  * @param picture the picture structure to be filled in
4686  * @param pix_fmt the pixel format of the picture
4687  * @param width the width of the picture
4688  * @param height the height of the picture
4689  * @return zero if successful, a negative error code otherwise
4690  *
4691  * @see av_image_alloc(), avpicture_fill()
4692  */
4693 int avpicture_alloc(AVPicture *picture, enum AVPixelFormat pix_fmt, int width, int height);
4694 
4695 /**
4696  * Free a picture previously allocated by avpicture_alloc().
4697  * The data buffer used by the AVPicture is freed, but the AVPicture structure
4698  * itself is not.
4699  *
4700  * @param picture the AVPicture to be freed
4701  */
4702 void avpicture_free(AVPicture *picture);
4703 
4704 /**
4705  * Setup the picture fields based on the specified image parameters
4706  * and the provided image data buffer.
4707  *
4708  * The picture fields are filled in by using the image data buffer
4709  * pointed to by ptr.
4710  *
4711  * If ptr is NULL, the function will fill only the picture linesize
4712  * array and return the required size for the image buffer.
4713  *
4714  * To allocate an image buffer and fill the picture data in one call,
4715  * use avpicture_alloc().
4716  *
4717  * @param picture the picture to be filled in
4718  * @param ptr buffer where the image data is stored, or NULL
4719  * @param pix_fmt the pixel format of the image
4720  * @param width the width of the image in pixels
4721  * @param height the height of the image in pixels
4722  * @return the size in bytes required for src, a negative error code
4723  * in case of failure
4724  *
4725  * @see av_image_fill_arrays()
4726  */
4727 int avpicture_fill(AVPicture *picture, const uint8_t *ptr,
4728  enum AVPixelFormat pix_fmt, int width, int height);
4729 
4730 /**
4731  * Copy pixel data from an AVPicture into a buffer.
4732  *
4733  * avpicture_get_size() can be used to compute the required size for
4734  * the buffer to fill.
4735  *
4736  * @param src source picture with filled data
4737  * @param pix_fmt picture pixel format
4738  * @param width picture width
4739  * @param height picture height
4740  * @param dest destination buffer
4741  * @param dest_size destination buffer size in bytes
4742  * @return the number of bytes written to dest, or a negative value
4743  * (error code) on error, for example if the destination buffer is not
4744  * big enough
4745  *
4746  * @see av_image_copy_to_buffer()
4747  */
4749  int width, int height,
4750  unsigned char *dest, int dest_size);
4751 
4752 /**
4753  * Calculate the size in bytes that a picture of the given width and height
4754  * would occupy if stored in the given picture format.
4755  *
4756  * @param pix_fmt picture pixel format
4757  * @param width picture width
4758  * @param height picture height
4759  * @return the computed picture buffer size or a negative error code
4760  * in case of error
4761  *
4762  * @see av_image_get_buffer_size().
4763  */
4765 
4766 #if FF_API_DEINTERLACE
4767 /**
4768  * deinterlace - if not supported return -1
4769  *
4770  * @deprecated - use yadif (in libavfilter) instead
4771  */
4773 int avpicture_deinterlace(AVPicture *dst, const AVPicture *src,
4774  enum AVPixelFormat pix_fmt, int width, int height);
4775 #endif
4776 /**
4777  * Copy image src to dst. Wraps av_image_copy().
4778  */
4779 void av_picture_copy(AVPicture *dst, const AVPicture *src,
4780  enum AVPixelFormat pix_fmt, int width, int height);
4781 
4782 /**
4783  * Crop image top and left side.
4784  */
4785 int av_picture_crop(AVPicture *dst, const AVPicture *src,
4786  enum AVPixelFormat pix_fmt, int top_band, int left_band);
4787 
4788 /**
4789  * Pad image.
4790  */
4791 int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width, enum AVPixelFormat pix_fmt,
4792  int padtop, int padbottom, int padleft, int padright, int *color);
4793 
4794 /**
4795  * @}
4796  */
4797 
4798 /**
4799  * @defgroup lavc_misc Utility functions
4800  * @ingroup libavc
4801  *
4802  * Miscellaneous utility functions related to both encoding and decoding
4803  * (or neither).
4804  * @{
4805  */
4806 
4807 /**
4808  * @defgroup lavc_misc_pixfmt Pixel formats
4809  *
4810  * Functions for working with pixel formats.
4811  * @{
4812  */
4813 
4814 /**
4815  * Utility function to access log2_chroma_w log2_chroma_h from
4816  * the pixel format AVPixFmtDescriptor.
4817  *
4818  * This function asserts that pix_fmt is valid. See av_pix_fmt_get_chroma_sub_sample
4819  * for one that returns a failure code and continues in case of invalid
4820  * pix_fmts.
4821  *
4822  * @param[in] pix_fmt the pixel format
4823  * @param[out] h_shift store log2_chroma_w
4824  * @param[out] v_shift store log2_chroma_h
4825  *
4826  * @see av_pix_fmt_get_chroma_sub_sample
4827  */
4828 
4829 void avcodec_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift);
4830 
4831 /**
4832  * Return a value representing the fourCC code associated to the
4833  * pixel format pix_fmt, or 0 if no associated fourCC code can be
4834  * found.
4835  */
4837 
4838 /**
4839  * @deprecated see av_get_pix_fmt_loss()
4840  */
4841 int avcodec_get_pix_fmt_loss(enum AVPixelFormat dst_pix_fmt, enum AVPixelFormat src_pix_fmt,
4842  int has_alpha);
4843 
4844 /**
4845  * Find the best pixel format to convert to given a certain source pixel
4846  * format. When converting from one pixel format to another, information loss
4847  * may occur. For example, when converting from RGB24 to GRAY, the color
4848  * information will be lost. Similarly, other losses occur when converting from
4849  * some formats to other formats. avcodec_find_best_pix_fmt_of_2() searches which of
4850  * the given pixel formats should be used to suffer the least amount of loss.
4851  * The pixel formats from which it chooses one, are determined by the
4852  * pix_fmt_list parameter.
4853  *
4854  *
4855  * @param[in] pix_fmt_list AV_PIX_FMT_NONE terminated array of pixel formats to choose from
4856  * @param[in] src_pix_fmt source pixel format
4857  * @param[in] has_alpha Whether the source pixel format alpha channel is used.
4858  * @param[out] loss_ptr Combination of flags informing you what kind of losses will occur.
4859  * @return The best pixel format to convert to or -1 if none was found.
4860  */
4861 enum AVPixelFormat avcodec_find_best_pix_fmt_of_list(const enum AVPixelFormat *pix_fmt_list,
4862  enum AVPixelFormat src_pix_fmt,
4863  int has_alpha, int *loss_ptr);
4864 
4865 /**
4866  * @deprecated see av_find_best_pix_fmt_of_2()
4867  */
4868 enum AVPixelFormat avcodec_find_best_pix_fmt_of_2(enum AVPixelFormat dst_pix_fmt1, enum AVPixelFormat dst_pix_fmt2,
4869  enum AVPixelFormat src_pix_fmt, int has_alpha, int *loss_ptr);
4870 
4872 #if AV_HAVE_INCOMPATIBLE_LIBAV_ABI
4873 enum AVPixelFormat