00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef FFMPEG_H
00020 #define FFMPEG_H
00021
00022 #include "config.h"
00023
00024 #include <stdint.h>
00025 #include <stdio.h>
00026 #include <signal.h>
00027
00028 #if HAVE_PTHREADS
00029 #include <pthread.h>
00030 #endif
00031
00032 #include "cmdutils.h"
00033
00034 #include "libavformat/avformat.h"
00035 #include "libavformat/avio.h"
00036
00037 #include "libavcodec/avcodec.h"
00038
00039 #include "libavfilter/avfilter.h"
00040 #include "libavfilter/avfiltergraph.h"
00041
00042 #include "libavutil/avutil.h"
00043 #include "libavutil/dict.h"
00044 #include "libavutil/fifo.h"
00045 #include "libavutil/pixfmt.h"
00046 #include "libavutil/rational.h"
00047
00048 #include "libswresample/swresample.h"
00049
00050 #define VSYNC_AUTO -1
00051 #define VSYNC_PASSTHROUGH 0
00052 #define VSYNC_CFR 1
00053 #define VSYNC_VFR 2
00054 #define VSYNC_DROP 0xff
00055
00056 #define MAX_STREAMS 1024
00057
00058
00059 typedef struct StreamMap {
00060 int disabled;
00061 int file_index;
00062 int stream_index;
00063 int sync_file_index;
00064 int sync_stream_index;
00065 char *linklabel;
00066 } StreamMap;
00067
00068 typedef struct {
00069 int file_idx, stream_idx, channel_idx;
00070 int ofile_idx, ostream_idx;
00071 } AudioChannelMap;
00072
00073 typedef struct OptionsContext {
00074
00075 int64_t start_time;
00076 const char *format;
00077
00078 SpecifierOpt *codec_names;
00079 int nb_codec_names;
00080 SpecifierOpt *audio_channels;
00081 int nb_audio_channels;
00082 SpecifierOpt *audio_sample_rate;
00083 int nb_audio_sample_rate;
00084 SpecifierOpt *frame_rates;
00085 int nb_frame_rates;
00086 SpecifierOpt *frame_sizes;
00087 int nb_frame_sizes;
00088 SpecifierOpt *frame_pix_fmts;
00089 int nb_frame_pix_fmts;
00090
00091
00092 int64_t input_ts_offset;
00093 int rate_emu;
00094
00095 SpecifierOpt *ts_scale;
00096 int nb_ts_scale;
00097 SpecifierOpt *dump_attachment;
00098 int nb_dump_attachment;
00099
00100
00101 StreamMap *stream_maps;
00102 int nb_stream_maps;
00103 AudioChannelMap *audio_channel_maps;
00104 int nb_audio_channel_maps;
00105 int metadata_global_manual;
00106 int metadata_streams_manual;
00107 int metadata_chapters_manual;
00108 const char **attachments;
00109 int nb_attachments;
00110
00111 int chapters_input_file;
00112
00113 int64_t recording_time;
00114 uint64_t limit_filesize;
00115 float mux_preload;
00116 float mux_max_delay;
00117 int shortest;
00118
00119 int video_disable;
00120 int audio_disable;
00121 int subtitle_disable;
00122 int data_disable;
00123
00124
00125 int *streamid_map;
00126 int nb_streamid_map;
00127
00128 SpecifierOpt *metadata;
00129 int nb_metadata;
00130 SpecifierOpt *max_frames;
00131 int nb_max_frames;
00132 SpecifierOpt *bitstream_filters;
00133 int nb_bitstream_filters;
00134 SpecifierOpt *codec_tags;
00135 int nb_codec_tags;
00136 SpecifierOpt *sample_fmts;
00137 int nb_sample_fmts;
00138 SpecifierOpt *qscale;
00139 int nb_qscale;
00140 SpecifierOpt *forced_key_frames;
00141 int nb_forced_key_frames;
00142 SpecifierOpt *force_fps;
00143 int nb_force_fps;
00144 SpecifierOpt *frame_aspect_ratios;
00145 int nb_frame_aspect_ratios;
00146 SpecifierOpt *rc_overrides;
00147 int nb_rc_overrides;
00148 SpecifierOpt *intra_matrices;
00149 int nb_intra_matrices;
00150 SpecifierOpt *inter_matrices;
00151 int nb_inter_matrices;
00152 SpecifierOpt *top_field_first;
00153 int nb_top_field_first;
00154 SpecifierOpt *metadata_map;
00155 int nb_metadata_map;
00156 SpecifierOpt *presets;
00157 int nb_presets;
00158 SpecifierOpt *copy_initial_nonkeyframes;
00159 int nb_copy_initial_nonkeyframes;
00160 SpecifierOpt *copy_prior_start;
00161 int nb_copy_prior_start;
00162 SpecifierOpt *filters;
00163 int nb_filters;
00164 SpecifierOpt *fix_sub_duration;
00165 int nb_fix_sub_duration;
00166 SpecifierOpt *pass;
00167 int nb_pass;
00168 SpecifierOpt *passlogfiles;
00169 int nb_passlogfiles;
00170 } OptionsContext;
00171
00172 typedef struct InputFilter {
00173 AVFilterContext *filter;
00174 struct InputStream *ist;
00175 struct FilterGraph *graph;
00176 uint8_t *name;
00177 } InputFilter;
00178
00179 typedef struct OutputFilter {
00180 AVFilterContext *filter;
00181 struct OutputStream *ost;
00182 struct FilterGraph *graph;
00183 uint8_t *name;
00184
00185
00186 AVFilterInOut *out_tmp;
00187 } OutputFilter;
00188
00189 typedef struct FilterGraph {
00190 int index;
00191 const char *graph_desc;
00192
00193 AVFilterGraph *graph;
00194
00195 InputFilter **inputs;
00196 int nb_inputs;
00197 OutputFilter **outputs;
00198 int nb_outputs;
00199 } FilterGraph;
00200
00201 typedef struct InputStream {
00202 int file_index;
00203 AVStream *st;
00204 int discard;
00205 int decoding_needed;
00206 AVCodec *dec;
00207 AVFrame *decoded_frame;
00208
00209 int64_t start;
00210
00211
00212 int64_t next_dts;
00213 int64_t dts;
00214
00215 int64_t next_pts;
00216 int64_t pts;
00217 int wrap_correction_done;
00218 double ts_scale;
00219 int is_start;
00220 int saw_first_ts;
00221 int showed_multi_packet_warning;
00222 AVDictionary *opts;
00223 AVRational framerate;
00224 int top_field_first;
00225
00226 int resample_height;
00227 int resample_width;
00228 int resample_pix_fmt;
00229
00230 int resample_sample_fmt;
00231 int resample_sample_rate;
00232 int resample_channels;
00233 uint64_t resample_channel_layout;
00234
00235 int fix_sub_duration;
00236 struct {
00237 int got_output;
00238 int ret;
00239 AVSubtitle subtitle;
00240 } prev_sub;
00241
00242 struct sub2video {
00243 int64_t last_pts;
00244 AVFilterBufferRef *ref;
00245 int w, h;
00246 } sub2video;
00247
00248
00249 FrameBuffer *buffer_pool;
00250 int dr1;
00251
00252
00253
00254 InputFilter **filters;
00255 int nb_filters;
00256 } InputStream;
00257
00258 typedef struct InputFile {
00259 AVFormatContext *ctx;
00260 int eof_reached;
00261 int eagain;
00262 int ist_index;
00263 int64_t ts_offset;
00264 int nb_streams;
00265
00266 int nb_streams_warn;
00267 int rate_emu;
00268
00269 #if HAVE_PTHREADS
00270 pthread_t thread;
00271 int finished;
00272 int joined;
00273 pthread_mutex_t fifo_lock;
00274 pthread_cond_t fifo_cond;
00275 AVFifoBuffer *fifo;
00276 #endif
00277 } InputFile;
00278
00279 typedef struct OutputStream {
00280 int file_index;
00281 int index;
00282 int source_index;
00283 AVStream *st;
00284 int encoding_needed;
00285 int frame_number;
00286
00287
00288 struct InputStream *sync_ist;
00289 int64_t sync_opts;
00290
00291
00292 int64_t first_pts;
00293 AVBitStreamFilterContext *bitstream_filters;
00294 AVCodec *enc;
00295 int64_t max_frames;
00296 AVFrame *filtered_frame;
00297
00298
00299 AVRational frame_rate;
00300 int force_fps;
00301 int top_field_first;
00302
00303 float frame_aspect_ratio;
00304 float last_quality;
00305
00306
00307 int64_t *forced_kf_pts;
00308 int forced_kf_count;
00309 int forced_kf_index;
00310 char *forced_keyframes;
00311
00312
00313 int audio_channels_map[SWR_CH_MAX];
00314 int audio_channels_mapped;
00315
00316 char *logfile_prefix;
00317 FILE *logfile;
00318
00319 OutputFilter *filter;
00320 char *avfilter;
00321
00322 int64_t sws_flags;
00323 int64_t swr_dither_method;
00324 double swr_dither_scale;
00325 AVDictionary *opts;
00326 int finished;
00327 int unavailable;
00328 int stream_copy;
00329 const char *attachment_filename;
00330 int copy_initial_nonkeyframes;
00331 int copy_prior_start;
00332
00333 int keep_pix_fmt;
00334 } OutputStream;
00335
00336 typedef struct OutputFile {
00337 AVFormatContext *ctx;
00338 AVDictionary *opts;
00339 int ost_index;
00340 int64_t recording_time;
00341 int64_t start_time;
00342 uint64_t limit_filesize;
00343
00344 int shortest;
00345 } OutputFile;
00346
00347 extern InputStream **input_streams;
00348 extern int nb_input_streams;
00349 extern InputFile **input_files;
00350 extern int nb_input_files;
00351
00352 extern OutputStream **output_streams;
00353 extern int nb_output_streams;
00354 extern OutputFile **output_files;
00355 extern int nb_output_files;
00356
00357 extern FilterGraph **filtergraphs;
00358 extern int nb_filtergraphs;
00359
00360 extern char *vstats_filename;
00361
00362 extern float audio_drift_threshold;
00363 extern float dts_delta_threshold;
00364 extern float dts_error_threshold;
00365
00366 extern int audio_volume;
00367 extern int audio_sync_method;
00368 extern int video_sync_method;
00369 extern int do_benchmark;
00370 extern int do_benchmark_all;
00371 extern int do_deinterlace;
00372 extern int do_hex_dump;
00373 extern int do_pkt_dump;
00374 extern int copy_ts;
00375 extern int copy_tb;
00376 extern int debug_ts;
00377 extern int exit_on_error;
00378 extern int print_stats;
00379 extern int qp_hist;
00380 extern int same_quant;
00381 extern int stdin_interaction;
00382 extern int frame_bits_per_raw_sample;
00383 extern AVIOContext *progress_avio;
00384
00385 extern const AVIOInterruptCB int_cb;
00386
00387 extern const OptionDef options[];
00388
00389 void term_init(void);
00390 void term_exit(void);
00391
00392 void reset_options(OptionsContext *o, int is_input);
00393 void show_usage(void);
00394
00395 void opt_output_file(void *optctx, const char *filename);
00396
00397 void assert_avoptions(AVDictionary *m);
00398
00399 int guess_input_channel_layout(InputStream *ist);
00400
00401 enum PixelFormat choose_pixel_fmt(AVStream *st, AVCodec *codec, enum PixelFormat target);
00402 void choose_sample_fmt(AVStream *st, AVCodec *codec);
00403
00404 int configure_filtergraph(FilterGraph *fg);
00405 int configure_output_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out);
00406 int ist_in_filtergraph(FilterGraph *fg, InputStream *ist);
00407 FilterGraph *init_simple_filtergraph(InputStream *ist, OutputStream *ost);
00408
00409 #endif