h264: simplify calls to ff_er_add_slice().
[FFMpeg-mirror/mplayer-patches.git] / avconv.h
blobdefdf59c4af0658d6df32df171796d8a9210fcea
1 /*
2 * This file is part of Libav.
4 * Libav is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * Libav is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with Libav; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifndef AVCONV_H
20 #define AVCONV_H
22 #include "config.h"
24 #include <stdint.h>
25 #include <stdio.h>
27 #if HAVE_PTHREADS
28 #include <pthread.h>
29 #endif
31 #include "cmdutils.h"
33 #include "libavformat/avformat.h"
34 #include "libavformat/avio.h"
36 #include "libavcodec/avcodec.h"
38 #include "libavfilter/avfilter.h"
39 #include "libavfilter/avfiltergraph.h"
41 #include "libavutil/avutil.h"
42 #include "libavutil/dict.h"
43 #include "libavutil/fifo.h"
44 #include "libavutil/pixfmt.h"
45 #include "libavutil/rational.h"
47 #define VSYNC_AUTO -1
48 #define VSYNC_PASSTHROUGH 0
49 #define VSYNC_CFR 1
50 #define VSYNC_VFR 2
52 /* select an input stream for an output stream */
53 typedef struct StreamMap {
54 int disabled; /* 1 is this mapping is disabled by a negative map */
55 int file_index;
56 int stream_index;
57 int sync_file_index;
58 int sync_stream_index;
59 char *linklabel; /* name of an output link, for mapping lavfi outputs */
60 } StreamMap;
62 /* select an input file for an output file */
63 typedef struct MetadataMap {
64 int file; // file index
65 char type; // type of metadata to copy -- (g)lobal, (s)tream, (c)hapter or (p)rogram
66 int index; // stream/chapter/program number
67 } MetadataMap;
69 typedef struct OptionsContext {
70 OptionGroup *g;
72 /* input/output options */
73 int64_t start_time;
74 const char *format;
76 SpecifierOpt *codec_names;
77 int nb_codec_names;
78 SpecifierOpt *audio_channels;
79 int nb_audio_channels;
80 SpecifierOpt *audio_sample_rate;
81 int nb_audio_sample_rate;
82 SpecifierOpt *frame_rates;
83 int nb_frame_rates;
84 SpecifierOpt *frame_sizes;
85 int nb_frame_sizes;
86 SpecifierOpt *frame_pix_fmts;
87 int nb_frame_pix_fmts;
89 /* input options */
90 int64_t input_ts_offset;
91 int rate_emu;
93 SpecifierOpt *ts_scale;
94 int nb_ts_scale;
95 SpecifierOpt *dump_attachment;
96 int nb_dump_attachment;
98 /* output options */
99 StreamMap *stream_maps;
100 int nb_stream_maps;
101 /* first item specifies output metadata, second is input */
102 MetadataMap (*meta_data_maps)[2];
103 int nb_meta_data_maps;
104 int metadata_global_manual;
105 int metadata_streams_manual;
106 int metadata_chapters_manual;
107 const char **attachments;
108 int nb_attachments;
110 int chapters_input_file;
112 int64_t recording_time;
113 uint64_t limit_filesize;
114 float mux_preload;
115 float mux_max_delay;
116 int shortest;
118 int video_disable;
119 int audio_disable;
120 int subtitle_disable;
121 int data_disable;
123 /* indexed by output file stream index */
124 int *streamid_map;
125 int nb_streamid_map;
127 SpecifierOpt *metadata;
128 int nb_metadata;
129 SpecifierOpt *max_frames;
130 int nb_max_frames;
131 SpecifierOpt *bitstream_filters;
132 int nb_bitstream_filters;
133 SpecifierOpt *codec_tags;
134 int nb_codec_tags;
135 SpecifierOpt *sample_fmts;
136 int nb_sample_fmts;
137 SpecifierOpt *qscale;
138 int nb_qscale;
139 SpecifierOpt *forced_key_frames;
140 int nb_forced_key_frames;
141 SpecifierOpt *force_fps;
142 int nb_force_fps;
143 SpecifierOpt *frame_aspect_ratios;
144 int nb_frame_aspect_ratios;
145 SpecifierOpt *rc_overrides;
146 int nb_rc_overrides;
147 SpecifierOpt *intra_matrices;
148 int nb_intra_matrices;
149 SpecifierOpt *inter_matrices;
150 int nb_inter_matrices;
151 SpecifierOpt *top_field_first;
152 int nb_top_field_first;
153 SpecifierOpt *metadata_map;
154 int nb_metadata_map;
155 SpecifierOpt *presets;
156 int nb_presets;
157 SpecifierOpt *copy_initial_nonkeyframes;
158 int nb_copy_initial_nonkeyframes;
159 SpecifierOpt *filters;
160 int nb_filters;
161 SpecifierOpt *pass;
162 int nb_pass;
163 SpecifierOpt *passlogfiles;
164 int nb_passlogfiles;
165 } OptionsContext;
167 typedef struct InputFilter {
168 AVFilterContext *filter;
169 struct InputStream *ist;
170 struct FilterGraph *graph;
171 uint8_t *name;
172 } InputFilter;
174 typedef struct OutputFilter {
175 AVFilterContext *filter;
176 struct OutputStream *ost;
177 struct FilterGraph *graph;
178 uint8_t *name;
180 /* temporary storage until stream maps are processed */
181 AVFilterInOut *out_tmp;
182 } OutputFilter;
184 typedef struct FilterGraph {
185 int index;
186 const char *graph_desc;
188 AVFilterGraph *graph;
190 InputFilter **inputs;
191 int nb_inputs;
192 OutputFilter **outputs;
193 int nb_outputs;
194 } FilterGraph;
196 typedef struct InputStream {
197 int file_index;
198 AVStream *st;
199 int discard; /* true if stream data should be discarded */
200 int decoding_needed; /* true if the packets must be decoded in 'raw_fifo' */
201 AVCodec *dec;
202 AVFrame *decoded_frame;
204 int64_t start; /* time when read started */
205 /* predicted dts of the next packet read for this stream or (when there are
206 * several frames in a packet) of the next frame in current packet */
207 int64_t next_dts;
208 /* dts of the last packet read for this stream */
209 int64_t last_dts;
210 PtsCorrectionContext pts_ctx;
211 double ts_scale;
212 int is_start; /* is 1 at the start and after a discontinuity */
213 int showed_multi_packet_warning;
214 AVDictionary *opts;
215 AVRational framerate; /* framerate forced with -r */
217 int resample_height;
218 int resample_width;
219 int resample_pix_fmt;
221 int resample_sample_fmt;
222 int resample_sample_rate;
223 int resample_channels;
224 uint64_t resample_channel_layout;
226 /* a pool of free buffers for decoded data */
227 FrameBuffer *buffer_pool;
229 /* decoded data from this stream goes into all those filters
230 * currently video and audio only */
231 InputFilter **filters;
232 int nb_filters;
233 } InputStream;
235 typedef struct InputFile {
236 AVFormatContext *ctx;
237 int eof_reached; /* true if eof reached */
238 int eagain; /* true if last read attempt returned EAGAIN */
239 int ist_index; /* index of first stream in ist_table */
240 int64_t ts_offset;
241 int nb_streams; /* number of stream that avconv is aware of; may be different
242 from ctx.nb_streams if new streams appear during av_read_frame() */
243 int rate_emu;
245 #if HAVE_PTHREADS
246 pthread_t thread; /* thread reading from this file */
247 int finished; /* the thread has exited */
248 int joined; /* the thread has been joined */
249 pthread_mutex_t fifo_lock; /* lock for access to fifo */
250 pthread_cond_t fifo_cond; /* the main thread will signal on this cond after reading from fifo */
251 AVFifoBuffer *fifo; /* demuxed packets are stored here; freed by the main thread */
252 #endif
253 } InputFile;
255 typedef struct OutputStream {
256 int file_index; /* file index */
257 int index; /* stream index in the output file */
258 int source_index; /* InputStream index */
259 AVStream *st; /* stream in the output file */
260 int encoding_needed; /* true if encoding needed for this stream */
261 int frame_number;
262 /* input pts and corresponding output pts
263 for A/V sync */
264 // double sync_ipts; /* dts from the AVPacket of the demuxer in second units */
265 struct InputStream *sync_ist; /* input stream to sync against */
266 int64_t sync_opts; /* output frame counter, could be changed to some true timestamp */ // FIXME look at frame_number
267 /* pts of the first frame encoded for this stream, used for limiting
268 * recording time */
269 int64_t first_pts;
270 AVBitStreamFilterContext *bitstream_filters;
271 AVCodec *enc;
272 int64_t max_frames;
273 AVFrame *filtered_frame;
275 /* video only */
276 AVRational frame_rate;
277 int force_fps;
278 int top_field_first;
280 float frame_aspect_ratio;
282 /* forced key frames */
283 int64_t *forced_kf_pts;
284 int forced_kf_count;
285 int forced_kf_index;
286 char *forced_keyframes;
288 char *logfile_prefix;
289 FILE *logfile;
291 OutputFilter *filter;
292 char *avfilter;
294 int64_t sws_flags;
295 AVDictionary *opts;
296 int finished; /* no more packets should be written for this stream */
297 int stream_copy;
298 const char *attachment_filename;
299 int copy_initial_nonkeyframes;
301 enum AVPixelFormat pix_fmts[2];
302 } OutputStream;
304 typedef struct OutputFile {
305 AVFormatContext *ctx;
306 AVDictionary *opts;
307 int ost_index; /* index of the first stream in output_streams */
308 int64_t recording_time; /* desired length of the resulting file in microseconds */
309 int64_t start_time; /* start time in microseconds */
310 uint64_t limit_filesize;
312 int shortest;
313 } OutputFile;
315 extern InputStream **input_streams;
316 extern int nb_input_streams;
317 extern InputFile **input_files;
318 extern int nb_input_files;
320 extern OutputStream **output_streams;
321 extern int nb_output_streams;
322 extern OutputFile **output_files;
323 extern int nb_output_files;
325 extern FilterGraph **filtergraphs;
326 extern int nb_filtergraphs;
328 extern char *vstats_filename;
330 extern float audio_drift_threshold;
331 extern float dts_delta_threshold;
333 extern int audio_volume;
334 extern int audio_sync_method;
335 extern int video_sync_method;
336 extern int do_benchmark;
337 extern int do_deinterlace;
338 extern int do_hex_dump;
339 extern int do_pkt_dump;
340 extern int copy_ts;
341 extern int copy_tb;
342 extern int exit_on_error;
343 extern int print_stats;
344 extern int qp_hist;
346 extern const AVIOInterruptCB int_cb;
348 extern const OptionDef options[];
350 void reset_options(OptionsContext *o);
351 void show_usage(void);
353 int opt_cpuflags(void *optctx, const char *opt, const char *arg);
355 void opt_output_file(void *optctx, const char *filename);
357 void assert_avoptions(AVDictionary *m);
359 int guess_input_channel_layout(InputStream *ist);
361 int configure_filtergraph(FilterGraph *fg);
362 int configure_output_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out);
363 int ist_in_filtergraph(FilterGraph *fg, InputStream *ist);
364 FilterGraph *init_simple_filtergraph(InputStream *ist, OutputStream *ost);
366 int avconv_parse_options(int argc, char **argv);
368 #endif /* AVCONV_H */