3170 lines · 111.2 KB · C
RawDownload
/* * copyright (c) 2001 Fabrice Bellard * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef AVCODEC_AVCODEC_H#define AVCODEC_AVCODEC_H /** * @file * @ingroup libavc * Libavcodec external API header */ #include "libavutil/samplefmt.h"#include "libavutil/attributes.h"#include "libavutil/avutil.h"#include "libavutil/buffer.h"#include "libavutil/dict.h"#include "libavutil/frame.h"#include "libavutil/log.h"#include "libavutil/pixfmt.h"#include "libavutil/rational.h" #include "codec.h"#include "codec_desc.h"#include "codec_par.h"#include "codec_id.h"#include "defs.h"#include "packet.h"#include "version_major.h"#ifndef HAVE_AV_CONFIG_H/* When included as part of the ffmpeg build, only include the major version * to avoid unnecessary rebuilds. When included externally, keep including * the full version information. */#include "version.h"#endif /** * @defgroup libavc libavcodec * Encoding/Decoding Library * * @{ * * @defgroup lavc_decoding Decoding * @{ * @} * * @defgroup lavc_encoding Encoding * @{ * @} * * @defgroup lavc_codec Codecs * @{ * @defgroup lavc_codec_native Native Codecs * @{ * @} * @defgroup lavc_codec_wrappers External library wrappers * @{ * @} * @defgroup lavc_codec_hwaccel Hardware Accelerators bridge * @{ * @} * @} * @defgroup lavc_internal Internal * @{ * @} * @} */ /** * @ingroup libavc * @defgroup lavc_encdec send/receive encoding and decoding API overview * @{ * * The avcodec_send_packet()/avcodec_receive_frame()/avcodec_send_frame()/ * avcodec_receive_packet() functions provide an encode/decode API, which * decouples input and output. * * The API is very similar for encoding/decoding and audio/video, and works as * follows: * - Set up and open the AVCodecContext as usual. * - Send valid input: *   - For decoding, call avcodec_send_packet() to give the decoder raw *     compressed data in an AVPacket. *   - For encoding, call avcodec_send_frame() to give the encoder an AVFrame *     containing uncompressed audio or video. * *   In both cases, it is recommended that AVPackets and AVFrames are *   refcounted, or libavcodec might have to copy the input data. (libavformat *   always returns refcounted AVPackets, and av_frame_get_buffer() allocates *   refcounted AVFrames.) * - Receive output in a loop. Periodically call one of the avcodec_receive_*() *   functions and process their output: *   - For decoding, call avcodec_receive_frame(). On success, it will return *     an AVFrame containing uncompressed audio or video data. *   - For encoding, call avcodec_receive_packet(). On success, it will return *     an AVPacket with a compressed frame. * *   Repeat this call until it returns AVERROR(EAGAIN) or an error. The *   AVERROR(EAGAIN) return value means that new input data is required to *   return new output. In this case, continue with sending input. For each *   input frame/packet, the codec will typically return 1 output frame/packet, *   but it can also be 0 or more than 1. * * At the beginning of decoding or encoding, the codec might accept multiple * input frames/packets without returning a frame, until its internal buffers * are filled. This situation is handled transparently if you follow the steps * outlined above. * * In theory, sending input can result in EAGAIN - this should happen only if * not all output was received. You can use this to structure alternative decode * or encode loops other than the one suggested above. For example, you could * try sending new input on each iteration, and try to receive output if that * returns EAGAIN. * * End of stream situations. These require "flushing" (aka draining) the codec, * as the codec might buffer multiple frames or packets internally for * performance or out of necessity (consider B-frames). * This is handled as follows: * - Instead of valid input, send NULL to the avcodec_send_packet() (decoding) *   or avcodec_send_frame() (encoding) functions. This will enter draining *   mode. * - Call avcodec_receive_frame() (decoding) or avcodec_receive_packet() *   (encoding) in a loop until AVERROR_EOF is returned. The functions will *   not return AVERROR(EAGAIN), unless you forgot to enter draining mode. * - Before decoding can be resumed again, the codec has to be reset with *   avcodec_flush_buffers(). * * Using the API as outlined above is highly recommended. But it is also * possible to call functions outside of this rigid schema. For example, you can * call avcodec_send_packet() repeatedly without calling * avcodec_receive_frame(). In this case, avcodec_send_packet() will succeed * until the codec's internal buffer has been filled up (which is typically of * size 1 per output frame, after initial input), and then reject input with * AVERROR(EAGAIN). Once it starts rejecting input, you have no choice but to * read at least some output. * * Not all codecs will follow a rigid and predictable dataflow; the only * guarantee is that an AVERROR(EAGAIN) return value on a send/receive call on * one end implies that a receive/send call on the other end will succeed, or * at least will not fail with AVERROR(EAGAIN). In general, no codec will * permit unlimited buffering of input or output. * * A codec is not allowed to return AVERROR(EAGAIN) for both sending and receiving. This * would be an invalid state, which could put the codec user into an endless * loop. The API has no concept of time either: it cannot happen that trying to * do avcodec_send_packet() results in AVERROR(EAGAIN), but a repeated call 1 second * later accepts the packet (with no other receive/flush API calls involved). * The API is a strict state machine, and the passage of time is not supposed * to influence it. Some timing-dependent behavior might still be deemed * acceptable in certain cases. But it must never result in both send/receive * returning EAGAIN at the same time at any point. It must also absolutely be * avoided that the current state is "unstable" and can "flip-flop" between * the send/receive APIs allowing progress. For example, it's not allowed that * the codec randomly decides that it actually wants to consume a packet now * instead of returning a frame, after it just returned AVERROR(EAGAIN) on an * avcodec_send_packet() call. * @} */ /** * @defgroup lavc_core Core functions/structures. * @ingroup libavc * * Basic definitions, functions for querying libavcodec capabilities, * allocating core structures, etc. * @{ */ /** * @ingroup lavc_encoding * minimum encoding buffer size * Used to avoid some checks during header writing. */#define AV_INPUT_BUFFER_MIN_SIZE 16384 /** * @ingroup lavc_encoding */typedef struct RcOverride{    int start_frame;    int end_frame;    int qscale; // If this is 0 then quality_factor will be used instead.    float quality_factor;} RcOverride; /* encoding support   These flags can be passed in AVCodecContext.flags before initialization.   Note: Not everything is supported yet.*/ /** * Allow decoders to produce frames with data planes that are not aligned * to CPU requirements (e.g. due to cropping). */#define AV_CODEC_FLAG_UNALIGNED       (1 <<  0)/** * Use fixed qscale. */#define AV_CODEC_FLAG_QSCALE          (1 <<  1)/** * 4 MV per MB allowed / advanced prediction for H.263. */#define AV_CODEC_FLAG_4MV             (1 <<  2)/** * Output even those frames that might be corrupted. */#define AV_CODEC_FLAG_OUTPUT_CORRUPT  (1 <<  3)/** * Use qpel MC. */#define AV_CODEC_FLAG_QPEL            (1 <<  4)/** * Don't output frames whose parameters differ from first * decoded frame in stream. */#define AV_CODEC_FLAG_DROPCHANGED     (1 <<  5)/** * Use internal 2pass ratecontrol in first pass mode. */#define AV_CODEC_FLAG_PASS1           (1 <<  9)/** * Use internal 2pass ratecontrol in second pass mode. */#define AV_CODEC_FLAG_PASS2           (1 << 10)/** * loop filter. */#define AV_CODEC_FLAG_LOOP_FILTER     (1 << 11)/** * Only decode/encode grayscale. */#define AV_CODEC_FLAG_GRAY            (1 << 13)/** * error[?] variables will be set during encoding. */#define AV_CODEC_FLAG_PSNR            (1 << 15)#if FF_API_FLAG_TRUNCATED/** * Input bitstream might be truncated at a random location * instead of only at frame boundaries. * * @deprecated use codec parsers for packetizing input */#define AV_CODEC_FLAG_TRUNCATED       (1 << 16)#endif/** * Use interlaced DCT. */#define AV_CODEC_FLAG_INTERLACED_DCT  (1 << 18)/** * Force low delay. */#define AV_CODEC_FLAG_LOW_DELAY       (1 << 19)/** * Place global headers in extradata instead of every keyframe. */#define AV_CODEC_FLAG_GLOBAL_HEADER   (1 << 22)/** * Use only bitexact stuff (except (I)DCT). */#define AV_CODEC_FLAG_BITEXACT        (1 << 23)/* Fx : Flag for H.263+ extra options *//** * H.263 advanced intra coding / MPEG-4 AC prediction */#define AV_CODEC_FLAG_AC_PRED         (1 << 24)/** * interlaced motion estimation */#define AV_CODEC_FLAG_INTERLACED_ME   (1 << 29)#define AV_CODEC_FLAG_CLOSED_GOP      (1U << 31) /** * Allow non spec compliant speedup tricks. */#define AV_CODEC_FLAG2_FAST           (1 <<  0)/** * Skip bitstream encoding. */#define AV_CODEC_FLAG2_NO_OUTPUT      (1 <<  2)/** * Place global headers at every keyframe instead of in extradata. */#define AV_CODEC_FLAG2_LOCAL_HEADER   (1 <<  3) /** * timecode is in drop frame format. DEPRECATED!!!! */#define AV_CODEC_FLAG2_DROP_FRAME_TIMECODE (1 << 13) /** * Input bitstream might be truncated at a packet boundaries * instead of only at frame boundaries. */#define AV_CODEC_FLAG2_CHUNKS         (1 << 15)/** * Discard cropping information from SPS. */#define AV_CODEC_FLAG2_IGNORE_CROP    (1 << 16) /** * Show all frames before the first keyframe */#define AV_CODEC_FLAG2_SHOW_ALL       (1 << 22)/** * Export motion vectors through frame side data */#define AV_CODEC_FLAG2_EXPORT_MVS     (1 << 28)/** * Do not skip samples and export skip information as frame side data */#define AV_CODEC_FLAG2_SKIP_MANUAL    (1 << 29)/** * Do not reset ASS ReadOrder field on flush (subtitles decoding) */#define AV_CODEC_FLAG2_RO_FLUSH_NOOP  (1 << 30) /* Unsupported options : *              Syntax Arithmetic coding (SAC) *              Reference Picture Selection *              Independent Segment Decoding *//* /Fx *//* codec capabilities */ /* Exported side data.   These flags can be passed in AVCodecContext.export_side_data before initialization.*//** * Export motion vectors through frame side data */#define AV_CODEC_EXPORT_DATA_MVS         (1 << 0)/** * Export encoder Producer Reference Time through packet side data */#define AV_CODEC_EXPORT_DATA_PRFT        (1 << 1)/** * Decoding only. * Export the AVVideoEncParams structure through frame side data. */#define AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS (1 << 2)/** * Decoding only. * Do not apply film grain, export it instead. */#define AV_CODEC_EXPORT_DATA_FILM_GRAIN (1 << 3) /** * The decoder will keep a reference to the frame and may reuse it later. */#define AV_GET_BUFFER_FLAG_REF (1 << 0) /** * The encoder will keep a reference to the packet and may reuse it later. */#define AV_GET_ENCODE_BUFFER_FLAG_REF (1 << 0) struct AVCodecInternal; /** * main external API structure. * New fields can be added to the end with minor version bumps. * Removal, reordering and changes to existing fields require a major * version bump. * You can use AVOptions (av_opt* / av_set/get*()) to access these fields from user * applications. * The name string for AVOptions options matches the associated command line * parameter name and can be found in libavcodec/options_table.h * The AVOption/command line parameter names differ in some cases from the C * structure field names for historic reasons or brevity. * sizeof(AVCodecContext) must not be used outside libav*. */typedef struct AVCodecContext {    /**     * information on struct for av_log     * - set by avcodec_alloc_context3     */    const AVClass *av_class;    int log_level_offset;     enum AVMediaType codec_type; /* see AVMEDIA_TYPE_xxx */    const struct AVCodec  *codec;    enum AVCodecID     codec_id; /* see AV_CODEC_ID_xxx */     /**     * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').     * This is used to work around some encoder bugs.     * A demuxer should set this to what is stored in the field used to identify the codec.     * If there are multiple such fields in a container then the demuxer should choose the one     * which maximizes the information about the used codec.     * If the codec tag field in a container is larger than 32 bits then the demuxer should     * remap the longer ID to 32 bits with a table or other structure. Alternatively a new     * extra_codec_tag + size could be added but for this a clear advantage must be demonstrated     * first.     * - encoding: Set by user, if not then the default based on codec_id will be used.     * - decoding: Set by user, will be converted to uppercase by libavcodec during init.     */    unsigned int codec_tag;     void *priv_data;     /**     * Private context used for internal data.     *     * Unlike priv_data, this is not codec-specific. It is used in general     * libavcodec functions.     */    struct AVCodecInternal *internal;     /**     * Private data of the user, can be used to carry app specific stuff.     * - encoding: Set by user.     * - decoding: Set by user.     */    void *opaque;     /**     * the average bitrate     * - encoding: Set by user; unused for constant quantizer encoding.     * - decoding: Set by user, may be overwritten by libavcodec     *             if this info is available in the stream     */    int64_t bit_rate;     /**     * number of bits the bitstream is allowed to diverge from the reference.     *           the reference can be CBR (for CBR pass1) or VBR (for pass2)     * - encoding: Set by user; unused for constant quantizer encoding.     * - decoding: unused     */    int bit_rate_tolerance;     /**     * Global quality for codecs which cannot change it per frame.     * This should be proportional to MPEG-1/2/4 qscale.     * - encoding: Set by user.     * - decoding: unused     */    int global_quality;     /**     * - encoding: Set by user.     * - decoding: unused     */    int compression_level;#define FF_COMPRESSION_DEFAULT -1     /**     * AV_CODEC_FLAG_*.     * - encoding: Set by user.     * - decoding: Set by user.     */    int flags;     /**     * AV_CODEC_FLAG2_*     * - encoding: Set by user.     * - decoding: Set by user.     */    int flags2;     /**     * some codecs need / can use extradata like Huffman tables.     * MJPEG: Huffman tables     * rv10: additional flags     * MPEG-4: global headers (they can be in the bitstream or here)     * The allocated memory should be AV_INPUT_BUFFER_PADDING_SIZE bytes larger     * than extradata_size to avoid problems if it is read with the bitstream reader.     * The bytewise contents of extradata must not depend on the architecture or CPU endianness.     * Must be allocated with the av_malloc() family of functions.     * - encoding: Set/allocated/freed by libavcodec.     * - decoding: Set/allocated/freed by user.     */    uint8_t *extradata;    int extradata_size;     /**     * This is the fundamental unit of time (in seconds) in terms     * of which frame timestamps are represented. For fixed-fps content,     * timebase should be 1/framerate and timestamp increments should be     * identically 1.     * This often, but not always is the inverse of the frame rate or field rate     * for video. 1/time_base is not the average frame rate if the frame rate is not     * constant.

Lines 1–500 of 3170.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t