annotate ffmpeg/ffmpeg.h @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents 6840f77b83aa
children
rev   line source
yading@10 1 /*
yading@10 2 * This file is part of FFmpeg.
yading@10 3 *
yading@10 4 * FFmpeg is free software; you can redistribute it and/or
yading@10 5 * modify it under the terms of the GNU Lesser General Public
yading@10 6 * License as published by the Free Software Foundation; either
yading@10 7 * version 2.1 of the License, or (at your option) any later version.
yading@10 8 *
yading@10 9 * FFmpeg is distributed in the hope that it will be useful,
yading@10 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@10 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@10 12 * Lesser General Public License for more details.
yading@10 13 *
yading@10 14 * You should have received a copy of the GNU Lesser General Public
yading@10 15 * License along with FFmpeg; if not, write to the Free Software
yading@10 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@10 17 */
yading@10 18
yading@10 19 #ifndef FFMPEG_H
yading@10 20 #define FFMPEG_H
yading@10 21
yading@10 22 #include "config.h"
yading@10 23
yading@10 24 #include <stdint.h>
yading@10 25 #include <stdio.h>
yading@10 26 #include <signal.h>
yading@10 27
yading@10 28 #if HAVE_PTHREADS
yading@10 29 #include <pthread.h>
yading@10 30 #endif
yading@10 31
yading@10 32 #include "cmdutils.h"
yading@10 33
yading@10 34 #include "libavformat/avformat.h"
yading@10 35 #include "libavformat/avio.h"
yading@10 36
yading@10 37 #include "libavcodec/avcodec.h"
yading@10 38
yading@10 39 #include "libavfilter/avfilter.h"
yading@10 40
yading@10 41 #include "libavutil/avutil.h"
yading@10 42 #include "libavutil/dict.h"
yading@10 43 #include "libavutil/eval.h"
yading@10 44 #include "libavutil/fifo.h"
yading@10 45 #include "libavutil/pixfmt.h"
yading@10 46 #include "libavutil/rational.h"
yading@10 47
yading@10 48 #include "libswresample/swresample.h"
yading@10 49
yading@10 50 #define VSYNC_AUTO -1
yading@10 51 #define VSYNC_PASSTHROUGH 0
yading@10 52 #define VSYNC_CFR 1
yading@10 53 #define VSYNC_VFR 2
yading@10 54 #define VSYNC_DROP 0xff
yading@10 55
yading@10 56 #define MAX_STREAMS 1024 /* arbitrary sanity check value */
yading@10 57
yading@10 58 /* select an input stream for an output stream */
yading@10 59 typedef struct StreamMap {
yading@10 60 int disabled; /* 1 is this mapping is disabled by a negative map */
yading@10 61 int file_index;
yading@10 62 int stream_index;
yading@10 63 int sync_file_index;
yading@10 64 int sync_stream_index;
yading@10 65 char *linklabel; /* name of an output link, for mapping lavfi outputs */
yading@10 66 } StreamMap;
yading@10 67
yading@10 68 typedef struct {
yading@10 69 int file_idx, stream_idx, channel_idx; // input
yading@10 70 int ofile_idx, ostream_idx; // output
yading@10 71 } AudioChannelMap;
yading@10 72
yading@10 73 typedef struct OptionsContext {
yading@10 74 OptionGroup *g;
yading@10 75
yading@10 76 /* input/output options */
yading@10 77 int64_t start_time;
yading@10 78 const char *format;
yading@10 79
yading@10 80 SpecifierOpt *codec_names;
yading@10 81 int nb_codec_names;
yading@10 82 SpecifierOpt *audio_channels;
yading@10 83 int nb_audio_channels;
yading@10 84 SpecifierOpt *audio_sample_rate;
yading@10 85 int nb_audio_sample_rate;
yading@10 86 SpecifierOpt *frame_rates;
yading@10 87 int nb_frame_rates;
yading@10 88 SpecifierOpt *frame_sizes;
yading@10 89 int nb_frame_sizes;
yading@10 90 SpecifierOpt *frame_pix_fmts;
yading@10 91 int nb_frame_pix_fmts;
yading@10 92
yading@10 93 /* input options */
yading@10 94 int64_t input_ts_offset;
yading@10 95 int rate_emu;
yading@10 96
yading@10 97 SpecifierOpt *ts_scale;
yading@10 98 int nb_ts_scale;
yading@10 99 SpecifierOpt *dump_attachment;
yading@10 100 int nb_dump_attachment;
yading@10 101
yading@10 102 /* output options */
yading@10 103 StreamMap *stream_maps;
yading@10 104 int nb_stream_maps;
yading@10 105 AudioChannelMap *audio_channel_maps; /* one info entry per -map_channel */
yading@10 106 int nb_audio_channel_maps; /* number of (valid) -map_channel settings */
yading@10 107 int metadata_global_manual;
yading@10 108 int metadata_streams_manual;
yading@10 109 int metadata_chapters_manual;
yading@10 110 const char **attachments;
yading@10 111 int nb_attachments;
yading@10 112
yading@10 113 int chapters_input_file;
yading@10 114
yading@10 115 int64_t recording_time;
yading@10 116 int64_t stop_time;
yading@10 117 uint64_t limit_filesize;
yading@10 118 float mux_preload;
yading@10 119 float mux_max_delay;
yading@10 120 int shortest;
yading@10 121
yading@10 122 int video_disable;
yading@10 123 int audio_disable;
yading@10 124 int subtitle_disable;
yading@10 125 int data_disable;
yading@10 126
yading@10 127 /* indexed by output file stream index */
yading@10 128 int *streamid_map;
yading@10 129 int nb_streamid_map;
yading@10 130
yading@10 131 SpecifierOpt *metadata;
yading@10 132 int nb_metadata;
yading@10 133 SpecifierOpt *max_frames;
yading@10 134 int nb_max_frames;
yading@10 135 SpecifierOpt *bitstream_filters;
yading@10 136 int nb_bitstream_filters;
yading@10 137 SpecifierOpt *codec_tags;
yading@10 138 int nb_codec_tags;
yading@10 139 SpecifierOpt *sample_fmts;
yading@10 140 int nb_sample_fmts;
yading@10 141 SpecifierOpt *qscale;
yading@10 142 int nb_qscale;
yading@10 143 SpecifierOpt *forced_key_frames;
yading@10 144 int nb_forced_key_frames;
yading@10 145 SpecifierOpt *force_fps;
yading@10 146 int nb_force_fps;
yading@10 147 SpecifierOpt *frame_aspect_ratios;
yading@10 148 int nb_frame_aspect_ratios;
yading@10 149 SpecifierOpt *rc_overrides;
yading@10 150 int nb_rc_overrides;
yading@10 151 SpecifierOpt *intra_matrices;
yading@10 152 int nb_intra_matrices;
yading@10 153 SpecifierOpt *inter_matrices;
yading@10 154 int nb_inter_matrices;
yading@10 155 SpecifierOpt *top_field_first;
yading@10 156 int nb_top_field_first;
yading@10 157 SpecifierOpt *metadata_map;
yading@10 158 int nb_metadata_map;
yading@10 159 SpecifierOpt *presets;
yading@10 160 int nb_presets;
yading@10 161 SpecifierOpt *copy_initial_nonkeyframes;
yading@10 162 int nb_copy_initial_nonkeyframes;
yading@10 163 SpecifierOpt *copy_prior_start;
yading@10 164 int nb_copy_prior_start;
yading@10 165 SpecifierOpt *filters;
yading@10 166 int nb_filters;
yading@10 167 SpecifierOpt *filter_scripts;
yading@10 168 int nb_filter_scripts;
yading@10 169 SpecifierOpt *reinit_filters;
yading@10 170 int nb_reinit_filters;
yading@10 171 SpecifierOpt *fix_sub_duration;
yading@10 172 int nb_fix_sub_duration;
yading@10 173 SpecifierOpt *canvas_sizes;
yading@10 174 int nb_canvas_sizes;
yading@10 175 SpecifierOpt *pass;
yading@10 176 int nb_pass;
yading@10 177 SpecifierOpt *passlogfiles;
yading@10 178 int nb_passlogfiles;
yading@10 179 SpecifierOpt *guess_layout_max;
yading@10 180 int nb_guess_layout_max;
yading@10 181 } OptionsContext;
yading@10 182
yading@10 183 typedef struct InputFilter {
yading@10 184 AVFilterContext *filter;
yading@10 185 struct InputStream *ist;
yading@10 186 struct FilterGraph *graph;
yading@10 187 uint8_t *name;
yading@10 188 } InputFilter;
yading@10 189
yading@10 190 typedef struct OutputFilter {
yading@10 191 AVFilterContext *filter;
yading@10 192 struct OutputStream *ost;
yading@10 193 struct FilterGraph *graph;
yading@10 194 uint8_t *name;
yading@10 195
yading@10 196 /* temporary storage until stream maps are processed */
yading@10 197 AVFilterInOut *out_tmp;
yading@10 198 } OutputFilter;
yading@10 199
yading@10 200 typedef struct FilterGraph {
yading@10 201 int index;
yading@10 202 const char *graph_desc;
yading@10 203
yading@10 204 AVFilterGraph *graph;
yading@10 205 int reconfiguration;
yading@10 206
yading@10 207 InputFilter **inputs;
yading@10 208 int nb_inputs;
yading@10 209 OutputFilter **outputs;
yading@10 210 int nb_outputs;
yading@10 211 } FilterGraph;
yading@10 212
yading@10 213 typedef struct InputStream {
yading@10 214 int file_index;
yading@10 215 AVStream *st;
yading@10 216 int discard; /* true if stream data should be discarded */
yading@10 217 int decoding_needed; /* true if the packets must be decoded in 'raw_fifo' */
yading@10 218 AVCodec *dec;
yading@10 219 AVFrame *decoded_frame;
yading@10 220 AVFrame *filter_frame; /* a ref of decoded_frame, to be sent to filters */
yading@10 221
yading@10 222 int64_t start; /* time when read started */
yading@10 223 /* predicted dts of the next packet read for this stream or (when there are
yading@10 224 * several frames in a packet) of the next frame in current packet (in AV_TIME_BASE units) */
yading@10 225 int64_t next_dts;
yading@10 226 int64_t dts; ///< dts of the last packet read for this stream (in AV_TIME_BASE units)
yading@10 227
yading@10 228 int64_t next_pts; ///< synthetic pts for the next decode frame (in AV_TIME_BASE units)
yading@10 229 int64_t pts; ///< current pts of the decoded frame (in AV_TIME_BASE units)
yading@10 230 int wrap_correction_done;
yading@10 231
yading@10 232 int64_t filter_in_rescale_delta_last;
yading@10 233
yading@10 234 double ts_scale;
yading@10 235 int is_start; /* is 1 at the start and after a discontinuity */
yading@10 236 int saw_first_ts;
yading@10 237 int showed_multi_packet_warning;
yading@10 238 AVDictionary *opts;
yading@10 239 AVRational framerate; /* framerate forced with -r */
yading@10 240 int top_field_first;
yading@10 241 int guess_layout_max;
yading@10 242
yading@10 243 int resample_height;
yading@10 244 int resample_width;
yading@10 245 int resample_pix_fmt;
yading@10 246
yading@10 247 int resample_sample_fmt;
yading@10 248 int resample_sample_rate;
yading@10 249 int resample_channels;
yading@10 250 uint64_t resample_channel_layout;
yading@10 251
yading@10 252 int fix_sub_duration;
yading@10 253 struct { /* previous decoded subtitle and related variables */
yading@10 254 int got_output;
yading@10 255 int ret;
yading@10 256 AVSubtitle subtitle;
yading@10 257 } prev_sub;
yading@10 258
yading@10 259 struct sub2video {
yading@10 260 int64_t last_pts;
yading@10 261 int64_t end_pts;
yading@10 262 AVFrame *frame;
yading@10 263 int w, h;
yading@10 264 } sub2video;
yading@10 265
yading@10 266 int dr1;
yading@10 267
yading@10 268 /* decoded data from this stream goes into all those filters
yading@10 269 * currently video and audio only */
yading@10 270 InputFilter **filters;
yading@10 271 int nb_filters;
yading@10 272
yading@10 273 int reinit_filters;
yading@10 274 } InputStream;
yading@10 275
yading@10 276 typedef struct InputFile {
yading@10 277 AVFormatContext *ctx;
yading@10 278 int eof_reached; /* true if eof reached */
yading@10 279 int eagain; /* true if last read attempt returned EAGAIN */
yading@10 280 int ist_index; /* index of first stream in input_streams */
yading@10 281 int64_t ts_offset;
yading@10 282 int64_t last_ts;
yading@10 283 int nb_streams; /* number of stream that ffmpeg is aware of; may be different
yading@10 284 from ctx.nb_streams if new streams appear during av_read_frame() */
yading@10 285 int nb_streams_warn; /* number of streams that the user was warned of */
yading@10 286 int rate_emu;
yading@10 287
yading@10 288 #if HAVE_PTHREADS
yading@10 289 pthread_t thread; /* thread reading from this file */
yading@10 290 int finished; /* the thread has exited */
yading@10 291 int joined; /* the thread has been joined */
yading@10 292 pthread_mutex_t fifo_lock; /* lock for access to fifo */
yading@10 293 pthread_cond_t fifo_cond; /* the main thread will signal on this cond after reading from fifo */
yading@10 294 AVFifoBuffer *fifo; /* demuxed packets are stored here; freed by the main thread */
yading@10 295 #endif
yading@10 296 } InputFile;
yading@10 297
yading@10 298 enum forced_keyframes_const {
yading@10 299 FKF_N,
yading@10 300 FKF_N_FORCED,
yading@10 301 FKF_PREV_FORCED_N,
yading@10 302 FKF_PREV_FORCED_T,
yading@10 303 FKF_T,
yading@10 304 FKF_NB
yading@10 305 };
yading@10 306
yading@10 307 extern const char *const forced_keyframes_const_names[];
yading@10 308
yading@10 309 typedef struct OutputStream {
yading@10 310 int file_index; /* file index */
yading@10 311 int index; /* stream index in the output file */
yading@10 312 int source_index; /* InputStream index */
yading@10 313 AVStream *st; /* stream in the output file */
yading@10 314 int encoding_needed; /* true if encoding needed for this stream */
yading@10 315 int frame_number;
yading@10 316 /* input pts and corresponding output pts
yading@10 317 for A/V sync */
yading@10 318 struct InputStream *sync_ist; /* input stream to sync against */
yading@10 319 int64_t sync_opts; /* output frame counter, could be changed to some true timestamp */ // FIXME look at frame_number
yading@10 320 /* pts of the first frame encoded for this stream, used for limiting
yading@10 321 * recording time */
yading@10 322 int64_t first_pts;
yading@10 323 AVBitStreamFilterContext *bitstream_filters;
yading@10 324 AVCodec *enc;
yading@10 325 int64_t max_frames;
yading@10 326 AVFrame *filtered_frame;
yading@10 327
yading@10 328 /* video only */
yading@10 329 AVRational frame_rate;
yading@10 330 int force_fps;
yading@10 331 int top_field_first;
yading@10 332
yading@10 333 AVRational frame_aspect_ratio;
yading@10 334
yading@10 335 /* forced key frames */
yading@10 336 int64_t *forced_kf_pts;
yading@10 337 int forced_kf_count;
yading@10 338 int forced_kf_index;
yading@10 339 char *forced_keyframes;
yading@10 340 AVExpr *forced_keyframes_pexpr;
yading@10 341 double forced_keyframes_expr_const_values[FKF_NB];
yading@10 342
yading@10 343 /* audio only */
yading@10 344 int audio_channels_map[SWR_CH_MAX]; /* list of the channels id to pick from the source stream */
yading@10 345 int audio_channels_mapped; /* number of channels in audio_channels_map */
yading@10 346
yading@10 347 char *logfile_prefix;
yading@10 348 FILE *logfile;
yading@10 349
yading@10 350 OutputFilter *filter;
yading@10 351 char *avfilter;
yading@10 352
yading@10 353 int64_t sws_flags;
yading@10 354 AVDictionary *opts;
yading@10 355 AVDictionary *swr_opts;
yading@10 356 AVDictionary *resample_opts;
yading@10 357 int finished; /* no more packets should be written for this stream */
yading@10 358 int unavailable; /* true if the steram is unavailable (possibly temporarily) */
yading@10 359 int stream_copy;
yading@10 360 const char *attachment_filename;
yading@10 361 int copy_initial_nonkeyframes;
yading@10 362 int copy_prior_start;
yading@10 363
yading@10 364 int keep_pix_fmt;
yading@10 365 } OutputStream;
yading@10 366
yading@10 367 typedef struct OutputFile {
yading@10 368 AVFormatContext *ctx;
yading@10 369 AVDictionary *opts;
yading@10 370 int ost_index; /* index of the first stream in output_streams */
yading@10 371 int64_t recording_time; ///< desired length of the resulting file in microseconds == AV_TIME_BASE units
yading@10 372 int64_t start_time; ///< start time in microseconds == AV_TIME_BASE units
yading@10 373 uint64_t limit_filesize; /* filesize limit expressed in bytes */
yading@10 374
yading@10 375 int shortest;
yading@10 376 } OutputFile;
yading@10 377
yading@10 378 extern InputStream **input_streams;
yading@10 379 extern int nb_input_streams;
yading@10 380 extern InputFile **input_files;
yading@10 381 extern int nb_input_files;
yading@10 382
yading@10 383 extern OutputStream **output_streams;
yading@10 384 extern int nb_output_streams;
yading@10 385 extern OutputFile **output_files;
yading@10 386 extern int nb_output_files;
yading@10 387
yading@10 388 extern FilterGraph **filtergraphs;
yading@10 389 extern int nb_filtergraphs;
yading@10 390
yading@10 391 extern char *vstats_filename;
yading@10 392
yading@10 393 extern float audio_drift_threshold;
yading@10 394 extern float dts_delta_threshold;
yading@10 395 extern float dts_error_threshold;
yading@10 396
yading@10 397 extern int audio_volume;
yading@10 398 extern int audio_sync_method;
yading@10 399 extern int video_sync_method;
yading@10 400 extern int do_benchmark;
yading@10 401 extern int do_benchmark_all;
yading@10 402 extern int do_deinterlace;
yading@10 403 extern int do_hex_dump;
yading@10 404 extern int do_pkt_dump;
yading@10 405 extern int copy_ts;
yading@10 406 extern int copy_tb;
yading@10 407 extern int debug_ts;
yading@10 408 extern int exit_on_error;
yading@10 409 extern int print_stats;
yading@10 410 extern int qp_hist;
yading@10 411 extern int stdin_interaction;
yading@10 412 extern int frame_bits_per_raw_sample;
yading@10 413 extern AVIOContext *progress_avio;
yading@10 414
yading@10 415 extern const AVIOInterruptCB int_cb;
yading@10 416
yading@10 417 extern const OptionDef options[];
yading@10 418
yading@10 419 void term_init(void);
yading@10 420 void term_exit(void);
yading@10 421
yading@10 422 void reset_options(OptionsContext *o, int is_input);
yading@10 423 void show_usage(void);
yading@10 424
yading@10 425 void opt_output_file(void *optctx, const char *filename);
yading@10 426
yading@10 427 void assert_avoptions(AVDictionary *m);
yading@10 428
yading@10 429 int guess_input_channel_layout(InputStream *ist);
yading@10 430
yading@10 431 enum AVPixelFormat choose_pixel_fmt(AVStream *st, AVCodec *codec, enum AVPixelFormat target);
yading@10 432 void choose_sample_fmt(AVStream *st, AVCodec *codec);
yading@10 433
yading@10 434 int configure_filtergraph(FilterGraph *fg);
yading@10 435 int configure_output_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out);
yading@10 436 int ist_in_filtergraph(FilterGraph *fg, InputStream *ist);
yading@10 437 FilterGraph *init_simple_filtergraph(InputStream *ist, OutputStream *ost);
yading@10 438
yading@10 439 int ffmpeg_parse_options(int argc, char **argv);
yading@10 440
yading@10 441 #endif /* FFMPEG_H */