907 lines · 24.4 KB · C
RawDownload
/* * 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 FFTOOLS_FFMPEG_H#define FFTOOLS_FFMPEG_H #include "config.h" #include <stdatomic.h>#include <stdint.h>#include <stdio.h>#include <signal.h> #include "cmdutils.h"#include "ffmpeg_sched.h"#include "sync_queue.h" #include "libavformat/avformat.h"#include "libavformat/avio.h" #include "libavcodec/avcodec.h"#include "libavcodec/bsf.h" #include "libavfilter/avfilter.h" #include "libavutil/avutil.h"#include "libavutil/dict.h"#include "libavutil/eval.h"#include "libavutil/fifo.h"#include "libavutil/hwcontext.h"#include "libavutil/pixfmt.h"#include "libavutil/rational.h"#include "libavutil/thread.h"#include "libavutil/threadmessage.h" #include "libswresample/swresample.h" // deprecated features#define FFMPEG_OPT_QPHIST 1#define FFMPEG_OPT_ADRIFT_THRESHOLD 1#define FFMPEG_OPT_ENC_TIME_BASE_NUM 1#define FFMPEG_OPT_TOP 1#define FFMPEG_OPT_FORCE_KF_SOURCE_NO_DROP 1#define FFMPEG_OPT_VSYNC_DROP 1#define FFMPEG_OPT_VSYNC 1#define FFMPEG_OPT_FILTER_SCRIPT 1 #define FFMPEG_ERROR_RATE_EXCEEDED FFERRTAG('E', 'R', 'E', 'D') enum VideoSyncMethod {    VSYNC_AUTO = -1,    VSYNC_PASSTHROUGH,    VSYNC_CFR,    VSYNC_VFR,    VSYNC_VSCFR,#if FFMPEG_OPT_VSYNC_DROP    VSYNC_DROP,#endif}; enum EncTimeBase {    ENC_TIME_BASE_DEMUX  = -1,    ENC_TIME_BASE_FILTER = -2,}; enum HWAccelID {    HWACCEL_NONE = 0,    HWACCEL_AUTO,    HWACCEL_GENERIC,}; enum FrameOpaque {    FRAME_OPAQUE_SUB_HEARTBEAT = 1,    FRAME_OPAQUE_EOF,    FRAME_OPAQUE_SEND_COMMAND,}; enum PacketOpaque {    PKT_OPAQUE_SUB_HEARTBEAT = 1,    PKT_OPAQUE_FIX_SUB_DURATION,}; enum LatencyProbe {    LATENCY_PROBE_DEMUX,    LATENCY_PROBE_DEC_PRE,    LATENCY_PROBE_DEC_POST,    LATENCY_PROBE_FILTER_PRE,    LATENCY_PROBE_FILTER_POST,    LATENCY_PROBE_ENC_PRE,    LATENCY_PROBE_ENC_POST,    LATENCY_PROBE_NB,}; typedef struct HWDevice {    const char *name;    enum AVHWDeviceType type;    AVBufferRef *device_ref;} HWDevice; enum ViewSpecifierType {    // no specifier given    VIEW_SPECIFIER_TYPE_NONE = 0,    // val is view index    VIEW_SPECIFIER_TYPE_IDX,    // val is view ID    VIEW_SPECIFIER_TYPE_ID,    // specify view by its position, val is AV_STEREO3D_VIEW_LEFT/RIGHT    VIEW_SPECIFIER_TYPE_POS,    // use all views, val is ignored    VIEW_SPECIFIER_TYPE_ALL,}; typedef struct ViewSpecifier {    enum ViewSpecifierType type;    unsigned               val;} ViewSpecifier; /* select an input stream for an output stream */typedef struct StreamMap {    int disabled;           /* 1 is this mapping is disabled by a negative map */    int file_index;    int stream_index;    char *linklabel;       /* name of an output link, for mapping lavfi outputs */     ViewSpecifier vs;} StreamMap; typedef struct OptionsContext {    OptionGroup *g;     /* input/output options */    int64_t start_time;    int64_t start_time_eof;    int seek_timestamp;    const char *format;     SpecifierOptList codec_names;    SpecifierOptList audio_ch_layouts;    SpecifierOptList audio_channels;    SpecifierOptList audio_sample_rate;    SpecifierOptList frame_rates;    SpecifierOptList max_frame_rates;    SpecifierOptList frame_sizes;    SpecifierOptList frame_pix_fmts;     /* input options */    int64_t input_ts_offset;    int loop;    int rate_emu;    float readrate;    double readrate_initial_burst;    int accurate_seek;    int thread_queue_size;    int input_sync_ref;    int find_stream_info;     SpecifierOptList ts_scale;    SpecifierOptList dump_attachment;    SpecifierOptList hwaccels;    SpecifierOptList hwaccel_devices;    SpecifierOptList hwaccel_output_formats;    SpecifierOptList autorotate;    SpecifierOptList apply_cropping;     /* output options */    StreamMap *stream_maps;    int     nb_stream_maps;    const char **attachments;    int       nb_attachments;     int chapters_input_file;     int64_t recording_time;    int64_t stop_time;    int64_t limit_filesize;    float mux_preload;    float mux_max_delay;    float shortest_buf_duration;    int shortest;    int bitexact;     int video_disable;    int audio_disable;    int subtitle_disable;    int data_disable;     // keys are stream indices    AVDictionary *streamid;     SpecifierOptList metadata;    SpecifierOptList max_frames;    SpecifierOptList bitstream_filters;    SpecifierOptList codec_tags;    SpecifierOptList sample_fmts;    SpecifierOptList qscale;    SpecifierOptList forced_key_frames;    SpecifierOptList fps_mode;    SpecifierOptList force_fps;    SpecifierOptList frame_aspect_ratios;    SpecifierOptList display_rotations;    SpecifierOptList display_hflips;    SpecifierOptList display_vflips;    SpecifierOptList rc_overrides;    SpecifierOptList intra_matrices;    SpecifierOptList inter_matrices;    SpecifierOptList chroma_intra_matrices;#if FFMPEG_OPT_TOP    SpecifierOptList top_field_first;#endif    SpecifierOptList metadata_map;    SpecifierOptList presets;    SpecifierOptList copy_initial_nonkeyframes;    SpecifierOptList copy_prior_start;    SpecifierOptList filters;#if FFMPEG_OPT_FILTER_SCRIPT    SpecifierOptList filter_scripts;#endif    SpecifierOptList reinit_filters;    SpecifierOptList fix_sub_duration;    SpecifierOptList fix_sub_duration_heartbeat;    SpecifierOptList canvas_sizes;    SpecifierOptList pass;    SpecifierOptList passlogfiles;    SpecifierOptList max_muxing_queue_size;    SpecifierOptList muxing_queue_data_threshold;    SpecifierOptList guess_layout_max;    SpecifierOptList apad;    SpecifierOptList discard;    SpecifierOptList disposition;    SpecifierOptList program;    SpecifierOptList stream_groups;    SpecifierOptList time_bases;    SpecifierOptList enc_time_bases;    SpecifierOptList autoscale;    SpecifierOptList bits_per_raw_sample;    SpecifierOptList enc_stats_pre;    SpecifierOptList enc_stats_post;    SpecifierOptList mux_stats;    SpecifierOptList enc_stats_pre_fmt;    SpecifierOptList enc_stats_post_fmt;    SpecifierOptList mux_stats_fmt;} OptionsContext; enum IFilterFlags {    IFILTER_FLAG_AUTOROTATE     = (1 << 0),    IFILTER_FLAG_REINIT         = (1 << 1),    IFILTER_FLAG_CFR            = (1 << 2),    IFILTER_FLAG_CROP           = (1 << 3),}; typedef struct InputFilterOptions {    int64_t             trim_start_us;    int64_t             trim_end_us;     uint8_t            *name;     /* When IFILTER_FLAG_CFR is set, the stream is guaranteed to be CFR with     * this framerate.     *     * Otherwise, this is an estimate that should not be relied upon to be     * accurate */    AVRational          framerate;     unsigned            crop_top;    unsigned            crop_bottom;    unsigned            crop_left;    unsigned            crop_right;     int                 sub2video_width;    int                 sub2video_height;     // a combination of IFILTER_FLAG_*    unsigned            flags;     AVFrame            *fallback;} InputFilterOptions; enum OFilterFlags {    OFILTER_FLAG_DISABLE_CONVERT    = (1 << 0),    // produce 24-bit audio    OFILTER_FLAG_AUDIO_24BIT        = (1 << 1),    OFILTER_FLAG_AUTOSCALE          = (1 << 2),}; typedef struct OutputFilterOptions {    // Caller-provided name for this output    char               *name;     // Codec used for encoding, may be NULL    const AVCodec      *enc;     int64_t             trim_start_us;    int64_t             trim_duration_us;    int64_t             ts_offset;     /* Desired output timebase.     * Numerator can be one of EncTimeBase values, or 0 when no preference.     */    AVRational          output_tb;     AVDictionary       *sws_opts;    AVDictionary       *swr_opts;     const char         *nb_threads;     // A combination of OFilterFlags.    unsigned            flags;     int                 format;    int                 width;    int                 height;    enum AVColorSpace   color_space;    enum AVColorRange   color_range;     enum VideoSyncMethod vsync_method;    AVRational           frame_rate;    AVRational           max_frame_rate;     int                 sample_rate;    AVChannelLayout     ch_layout;     const int                *formats;    const int                *sample_rates;    const AVChannelLayout    *ch_layouts;    const AVRational         *frame_rates;    const enum AVColorSpace  *color_spaces;    const enum AVColorRange  *color_ranges;     // for simple filtergraphs only, view specifier passed    // along to the decoder    const ViewSpecifier *vs;} OutputFilterOptions; typedef struct InputFilter {    struct FilterGraph *graph;    uint8_t            *name;} InputFilter; typedef struct OutputFilter {    const AVClass       *class;     struct FilterGraph  *graph;    uint8_t             *name;     /* for filters that are not yet bound to an output stream,     * this stores the output linklabel, if any */    int                  bound;    uint8_t             *linklabel;     char                *apad;     enum AVMediaType     type;     atomic_uint_least64_t nb_frames_dup;    atomic_uint_least64_t nb_frames_drop;} OutputFilter; typedef struct FilterGraph {    const AVClass *class;    int            index;     InputFilter   **inputs;    int          nb_inputs;    OutputFilter **outputs;    int         nb_outputs;} FilterGraph; enum DecoderFlags {    DECODER_FLAG_FIX_SUB_DURATION = (1 << 0),    // input timestamps are unreliable (guessed by demuxer)    DECODER_FLAG_TS_UNRELIABLE    = (1 << 1),    // decoder should override timestamps by fixed framerate    // from DecoderOpts.framerate    DECODER_FLAG_FRAMERATE_FORCED = (1 << 2),#if FFMPEG_OPT_TOP    DECODER_FLAG_TOP_FIELD_FIRST  = (1 << 3),#endif    DECODER_FLAG_SEND_END_TS      = (1 << 4),    // force bitexact decoding    DECODER_FLAG_BITEXACT         = (1 << 5),}; typedef struct DecoderOpts {    int                         flags;     char                       *name;    void                       *log_parent;     const AVCodec              *codec;    const AVCodecParameters    *par;     /* hwaccel options */    enum HWAccelID              hwaccel_id;    enum AVHWDeviceType         hwaccel_device_type;    char                       *hwaccel_device;    enum AVPixelFormat          hwaccel_output_format;     AVRational                  time_base;     // Either forced (when DECODER_FLAG_FRAMERATE_FORCED is set) or    // estimated (otherwise) video framerate.    AVRational                  framerate;} DecoderOpts; typedef struct Decoder {    const AVClass   *class;     enum AVMediaType type;     const uint8_t   *subtitle_header;    int              subtitle_header_size;     // number of frames/samples retrieved from the decoder    uint64_t         frames_decoded;    uint64_t         samples_decoded;    uint64_t         decode_errors;} Decoder; typedef struct InputStream {    const AVClass        *class;     /* parent source */    struct InputFile     *file;     int                   index;     AVStream             *st;    int                   user_set_discard;     /**     * Codec parameters - to be used by the decoding/streamcopy code.     * st->codecpar should not be accessed, because it may be modified     * concurrently by the demuxing thread.     */    AVCodecParameters    *par;    Decoder              *decoder;    const AVCodec        *dec;     /* framerate forced with -r */    AVRational            framerate;#if FFMPEG_OPT_TOP    int                   top_field_first;#endif     int                   fix_sub_duration;     /* decoded data from this stream goes into all those filters     * currently video and audio only */    InputFilter         **filters;    int                nb_filters;} InputStream; typedef struct InputFile {    const AVClass   *class;     int              index;     AVFormatContext *ctx;    int64_t          input_ts_offset;    int              input_sync_ref;    /**     * Effective format start time based on enabled streams.     */    int64_t          start_time_effective;    int64_t          ts_offset;    /* user-specified start time in AV_TIME_BASE or AV_NOPTS_VALUE */    int64_t          start_time;     /* streams that ffmpeg is aware of;     * there may be extra streams in ctx that are not mapped to an InputStream     * if new streams appear dynamically during demuxing */    InputStream    **streams;    int           nb_streams;} InputFile; enum forced_keyframes_const {    FKF_N,    FKF_N_FORCED,    FKF_PREV_FORCED_N,    FKF_PREV_FORCED_T,    FKF_T,    FKF_NB}; #define ABORT_ON_FLAG_EMPTY_OUTPUT        (1 <<  0)

Lines 1–500 of 907.

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