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 *reinit_filters;
00165 int nb_reinit_filters;
00166 SpecifierOpt *fix_sub_duration;
00167 int nb_fix_sub_duration;
00168 SpecifierOpt *pass;
00169 int nb_pass;
00170 SpecifierOpt *passlogfiles;
00171 int nb_passlogfiles;
00172 } OptionsContext;
00173
00174 typedef struct InputFilter {
00175 AVFilterContext *filter;
00176 struct InputStream *ist;
00177 struct FilterGraph *graph;
00178 uint8_t *name;
00179 } InputFilter;
00180
00181 typedef struct OutputFilter {
00182 AVFilterContext *filter;
00183 struct OutputStream *ost;
00184 struct FilterGraph *graph;
00185 uint8_t *name;
00186
00187
00188 AVFilterInOut *out_tmp;
00189 } OutputFilter;
00190
00191 typedef struct FilterGraph {
00192 int index;
00193 const char *graph_desc;
00194
00195 AVFilterGraph *graph;
00196
00197 InputFilter **inputs;
00198 int nb_inputs;
00199 OutputFilter **outputs;
00200 int nb_outputs;
00201 } FilterGraph;
00202
00203 typedef struct InputStream {
00204 int file_index;
00205 AVStream *st;
00206 int discard;
00207 int decoding_needed;
00208 AVCodec *dec;
00209 AVFrame *decoded_frame;
00210
00211 int64_t start;
00212
00213
00214 int64_t next_dts;
00215 int64_t dts;
00216
00217 int64_t next_pts;
00218 int64_t pts;
00219 int wrap_correction_done;
00220
00221 int64_t filter_in_rescale_delta_last;
00222
00223 double ts_scale;
00224 int is_start;
00225 int saw_first_ts;
00226 int showed_multi_packet_warning;
00227 AVDictionary *opts;
00228 AVRational framerate;
00229 int top_field_first;
00230
00231 int resample_height;
00232 int resample_width;
00233 int resample_pix_fmt;
00234
00235 int resample_sample_fmt;
00236 int resample_sample_rate;
00237 int resample_channels;
00238 uint64_t resample_channel_layout;
00239
00240 int fix_sub_duration;
00241 struct {
00242 int got_output;
00243 int ret;
00244 AVSubtitle subtitle;
00245 } prev_sub;
00246
00247 struct sub2video {
00248 int64_t last_pts;
00249 int64_t end_pts;
00250 AVFilterBufferRef *ref;
00251 int w, h;
00252 } sub2video;
00253
00254
00255 FrameBuffer *buffer_pool;
00256 int dr1;
00257
00258
00259
00260 InputFilter **filters;
00261 int nb_filters;
00262
00263 int reinit_filters;
00264 } InputStream;
00265
00266 typedef struct InputFile {
00267 AVFormatContext *ctx;
00268 int eof_reached;
00269 int eagain;
00270 int ist_index;
00271 int64_t ts_offset;
00272 int nb_streams;
00273
00274 int nb_streams_warn;
00275 int rate_emu;
00276
00277 #if HAVE_PTHREADS
00278 pthread_t thread;
00279 int finished;
00280 int joined;
00281 pthread_mutex_t fifo_lock;
00282 pthread_cond_t fifo_cond;
00283 AVFifoBuffer *fifo;
00284 #endif
00285 } InputFile;
00286
00287 typedef struct OutputStream {
00288 int file_index;
00289 int index;
00290 int source_index;
00291 AVStream *st;
00292 int encoding_needed;
00293 int frame_number;
00294
00295
00296 struct InputStream *sync_ist;
00297 int64_t sync_opts;
00298
00299
00300 int64_t first_pts;
00301 AVBitStreamFilterContext *bitstream_filters;
00302 AVCodec *enc;
00303 int64_t max_frames;
00304 AVFrame *filtered_frame;
00305
00306
00307 AVRational frame_rate;
00308 int force_fps;
00309 int top_field_first;
00310
00311 float frame_aspect_ratio;
00312
00313
00314 int64_t *forced_kf_pts;
00315 int forced_kf_count;
00316 int forced_kf_index;
00317 char *forced_keyframes;
00318
00319
00320 int audio_channels_map[SWR_CH_MAX];
00321 int audio_channels_mapped;
00322
00323 char *logfile_prefix;
00324 FILE *logfile;
00325
00326 OutputFilter *filter;
00327 char *avfilter;
00328
00329 int64_t sws_flags;
00330 int64_t swr_filter_type;
00331 int64_t swr_dither_method;
00332 double swr_dither_scale;
00333 AVDictionary *opts;
00334 int finished;
00335 int unavailable;
00336 int stream_copy;
00337 const char *attachment_filename;
00338 int copy_initial_nonkeyframes;
00339 int copy_prior_start;
00340
00341 int keep_pix_fmt;
00342 } OutputStream;
00343
00344 typedef struct OutputFile {
00345 AVFormatContext *ctx;
00346 AVDictionary *opts;
00347 int ost_index;
00348 int64_t recording_time;
00349 int64_t start_time;
00350 uint64_t limit_filesize;
00351
00352 int shortest;
00353 } OutputFile;
00354
00355 extern InputStream **input_streams;
00356 extern int nb_input_streams;
00357 extern InputFile **input_files;
00358 extern int nb_input_files;
00359
00360 extern OutputStream **output_streams;
00361 extern int nb_output_streams;
00362 extern OutputFile **output_files;
00363 extern int nb_output_files;
00364
00365 extern FilterGraph **filtergraphs;
00366 extern int nb_filtergraphs;
00367
00368 extern char *vstats_filename;
00369
00370 extern float audio_drift_threshold;
00371 extern float dts_delta_threshold;
00372 extern float dts_error_threshold;
00373
00374 extern int audio_volume;
00375 extern int audio_sync_method;
00376 extern int video_sync_method;
00377 extern int do_benchmark;
00378 extern int do_benchmark_all;
00379 extern int do_deinterlace;
00380 extern int do_hex_dump;
00381 extern int do_pkt_dump;
00382 extern int copy_ts;
00383 extern int copy_tb;
00384 extern int debug_ts;
00385 extern int exit_on_error;
00386 extern int print_stats;
00387 extern int qp_hist;
00388 extern int stdin_interaction;
00389 extern int frame_bits_per_raw_sample;
00390 extern AVIOContext *progress_avio;
00391
00392 extern const AVIOInterruptCB int_cb;
00393
00394 extern const OptionDef options[];
00395
00396 void term_init(void);
00397 void term_exit(void);
00398
00399 void reset_options(OptionsContext *o, int is_input);
00400 void show_usage(void);
00401
00402 void opt_output_file(void *optctx, const char *filename);
00403
00404 void assert_avoptions(AVDictionary *m);
00405
00406 int guess_input_channel_layout(InputStream *ist);
00407
00408 enum AVPixelFormat choose_pixel_fmt(AVStream *st, AVCodec *codec, enum AVPixelFormat target);
00409 void choose_sample_fmt(AVStream *st, AVCodec *codec);
00410
00411 int configure_filtergraph(FilterGraph *fg);
00412 int configure_output_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out);
00413 int ist_in_filtergraph(FilterGraph *fg, InputStream *ist);
00414 FilterGraph *init_simple_filtergraph(InputStream *ist, OutputStream *ost);
00415
00416 #endif