avconv: rename InputStream.opts to InputStream.decoder_opts
[libav.git] / avconv.h
CommitLineData
f5e66827
AK
1/*
2 * This file is part of Libav.
3 *
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.
8 *
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.
13 *
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
17 */
18
19#ifndef AVCONV_H
20#define AVCONV_H
21
22#include "config.h"
23
24#include <stdint.h>
25#include <stdio.h>
26
27#if HAVE_PTHREADS
28#include <pthread.h>
29#endif
30
31#include "cmdutils.h"
32
33#include "libavformat/avformat.h"
34#include "libavformat/avio.h"
35
36#include "libavcodec/avcodec.h"
37
38#include "libavfilter/avfilter.h"
f5e66827
AK
39
40#include "libavutil/avutil.h"
41#include "libavutil/dict.h"
42#include "libavutil/fifo.h"
43#include "libavutil/pixfmt.h"
44#include "libavutil/rational.h"
45
46#define VSYNC_AUTO -1
47#define VSYNC_PASSTHROUGH 0
48#define VSYNC_CFR 1
49#define VSYNC_VFR 2
50
07fd0a22
AK
51enum HWAccelID {
52 HWACCEL_NONE = 0,
53 HWACCEL_AUTO,
7671dd7c 54 HWACCEL_VDPAU,
35177ba7 55 HWACCEL_DXVA2,
07fd0a22
AK
56};
57
58typedef struct HWAccel {
59 const char *name;
60 int (*init)(AVCodecContext *s);
61 enum HWAccelID id;
62 enum AVPixelFormat pix_fmt;
63} HWAccel;
64
f5e66827
AK
65/* select an input stream for an output stream */
66typedef struct StreamMap {
c1ef30a6 67 int disabled; /* 1 is this mapping is disabled by a negative map */
f5e66827
AK
68 int file_index;
69 int stream_index;
70 int sync_file_index;
71 int sync_stream_index;
c1ef30a6 72 char *linklabel; /* name of an output link, for mapping lavfi outputs */
f5e66827
AK
73} StreamMap;
74
c1ef30a6 75/* select an input file for an output file */
f5e66827 76typedef struct MetadataMap {
c1ef30a6
DB
77 int file; // file index
78 char type; // type of metadata to copy -- (g)lobal, (s)tream, (c)hapter or (p)rogram
79 int index; // stream/chapter/program number
f5e66827
AK
80} MetadataMap;
81
82typedef struct OptionsContext {
77bd1bc7
AK
83 OptionGroup *g;
84
f5e66827
AK
85 /* input/output options */
86 int64_t start_time;
87 const char *format;
88
89 SpecifierOpt *codec_names;
90 int nb_codec_names;
91 SpecifierOpt *audio_channels;
92 int nb_audio_channels;
93 SpecifierOpt *audio_sample_rate;
94 int nb_audio_sample_rate;
95 SpecifierOpt *frame_rates;
96 int nb_frame_rates;
97 SpecifierOpt *frame_sizes;
98 int nb_frame_sizes;
99 SpecifierOpt *frame_pix_fmts;
100 int nb_frame_pix_fmts;
101
102 /* input options */
103 int64_t input_ts_offset;
104 int rate_emu;
811bd078 105 int accurate_seek;
f5e66827
AK
106
107 SpecifierOpt *ts_scale;
108 int nb_ts_scale;
109 SpecifierOpt *dump_attachment;
110 int nb_dump_attachment;
07fd0a22
AK
111 SpecifierOpt *hwaccels;
112 int nb_hwaccels;
113 SpecifierOpt *hwaccel_devices;
114 int nb_hwaccel_devices;
f5e66827
AK
115
116 /* output options */
117 StreamMap *stream_maps;
118 int nb_stream_maps;
119 /* first item specifies output metadata, second is input */
120 MetadataMap (*meta_data_maps)[2];
121 int nb_meta_data_maps;
122 int metadata_global_manual;
123 int metadata_streams_manual;
124 int metadata_chapters_manual;
125 const char **attachments;
126 int nb_attachments;
127
128 int chapters_input_file;
129
130 int64_t recording_time;
131 uint64_t limit_filesize;
132 float mux_preload;
133 float mux_max_delay;
3c0df905 134 int shortest;
f5e66827
AK
135
136 int video_disable;
137 int audio_disable;
138 int subtitle_disable;
139 int data_disable;
140
141 /* indexed by output file stream index */
142 int *streamid_map;
143 int nb_streamid_map;
144
145 SpecifierOpt *metadata;
146 int nb_metadata;
147 SpecifierOpt *max_frames;
148 int nb_max_frames;
149 SpecifierOpt *bitstream_filters;
150 int nb_bitstream_filters;
151 SpecifierOpt *codec_tags;
152 int nb_codec_tags;
153 SpecifierOpt *sample_fmts;
154 int nb_sample_fmts;
155 SpecifierOpt *qscale;
156 int nb_qscale;
157 SpecifierOpt *forced_key_frames;
158 int nb_forced_key_frames;
159 SpecifierOpt *force_fps;
160 int nb_force_fps;
161 SpecifierOpt *frame_aspect_ratios;
162 int nb_frame_aspect_ratios;
163 SpecifierOpt *rc_overrides;
164 int nb_rc_overrides;
165 SpecifierOpt *intra_matrices;
166 int nb_intra_matrices;
167 SpecifierOpt *inter_matrices;
168 int nb_inter_matrices;
169 SpecifierOpt *top_field_first;
170 int nb_top_field_first;
171 SpecifierOpt *metadata_map;
172 int nb_metadata_map;
173 SpecifierOpt *presets;
174 int nb_presets;
175 SpecifierOpt *copy_initial_nonkeyframes;
176 int nb_copy_initial_nonkeyframes;
177 SpecifierOpt *filters;
178 int nb_filters;
a4208b9b
AK
179 SpecifierOpt *filter_scripts;
180 int nb_filter_scripts;
038c0b1e
AK
181 SpecifierOpt *pass;
182 int nb_pass;
bbcedade
AK
183 SpecifierOpt *passlogfiles;
184 int nb_passlogfiles;
f5e66827
AK
185} OptionsContext;
186
187typedef struct InputFilter {
188 AVFilterContext *filter;
189 struct InputStream *ist;
190 struct FilterGraph *graph;
191 uint8_t *name;
192} InputFilter;
193
194typedef struct OutputFilter {
195 AVFilterContext *filter;
196 struct OutputStream *ost;
197 struct FilterGraph *graph;
198 uint8_t *name;
199
200 /* temporary storage until stream maps are processed */
201 AVFilterInOut *out_tmp;
202} OutputFilter;
203
204typedef struct FilterGraph {
205 int index;
206 const char *graph_desc;
207
208 AVFilterGraph *graph;
209
210 InputFilter **inputs;
211 int nb_inputs;
212 OutputFilter **outputs;
213 int nb_outputs;
214} FilterGraph;
215
216typedef struct InputStream {
217 int file_index;
218 AVStream *st;
219 int discard; /* true if stream data should be discarded */
220 int decoding_needed; /* true if the packets must be decoded in 'raw_fifo' */
221 AVCodec *dec;
222 AVFrame *decoded_frame;
9b2dc295 223 AVFrame *filter_frame; /* a ref of decoded_frame, to be sent to filters */
f5e66827
AK
224
225 int64_t start; /* time when read started */
226 /* predicted dts of the next packet read for this stream or (when there are
227 * several frames in a packet) of the next frame in current packet */
228 int64_t next_dts;
229 /* dts of the last packet read for this stream */
230 int64_t last_dts;
231 PtsCorrectionContext pts_ctx;
232 double ts_scale;
f5e66827 233 int showed_multi_packet_warning;
f3a6ad22 234 AVDictionary *decoder_opts;
f5e66827
AK
235 AVRational framerate; /* framerate forced with -r */
236
237 int resample_height;
238 int resample_width;
239 int resample_pix_fmt;
240
241 int resample_sample_fmt;
242 int resample_sample_rate;
243 int resample_channels;
244 uint64_t resample_channel_layout;
245
f5e66827
AK
246 /* decoded data from this stream goes into all those filters
247 * currently video and audio only */
248 InputFilter **filters;
249 int nb_filters;
07fd0a22
AK
250
251 /* hwaccel options */
252 enum HWAccelID hwaccel_id;
253 char *hwaccel_device;
254
255 /* hwaccel context */
256 enum HWAccelID active_hwaccel_id;
257 void *hwaccel_ctx;
258 void (*hwaccel_uninit)(AVCodecContext *s);
259 int (*hwaccel_get_buffer)(AVCodecContext *s, AVFrame *frame, int flags);
260 int (*hwaccel_retrieve_data)(AVCodecContext *s, AVFrame *frame);
261 enum AVPixelFormat hwaccel_pix_fmt;
262 enum AVPixelFormat hwaccel_retrieved_pix_fmt;
47543450
AK
263
264 /* stats */
265 // combined size of all the packets read
266 uint64_t data_size;
267 /* number of packets successfully read for this stream */
268 uint64_t nb_packets;
269 // number of frames/samples retrieved from the decoder
270 uint64_t frames_decoded;
271 uint64_t samples_decoded;
f5e66827
AK
272} InputStream;
273
274typedef struct InputFile {
275 AVFormatContext *ctx;
276 int eof_reached; /* true if eof reached */
0b26ef42 277 int eagain; /* true if last read attempt returned EAGAIN */
f5e66827 278 int ist_index; /* index of first stream in ist_table */
f5e66827 279 int64_t ts_offset;
811bd078 280 int64_t start_time; /* user-specified start time in AV_TIME_BASE or AV_NOPTS_VALUE */
488a0fa6 281 int64_t recording_time;
f5e66827
AK
282 int nb_streams; /* number of stream that avconv is aware of; may be different
283 from ctx.nb_streams if new streams appear during av_read_frame() */
284 int rate_emu;
811bd078 285 int accurate_seek;
f5e66827
AK
286
287#if HAVE_PTHREADS
288 pthread_t thread; /* thread reading from this file */
289 int finished; /* the thread has exited */
290 int joined; /* the thread has been joined */
291 pthread_mutex_t fifo_lock; /* lock for access to fifo */
292 pthread_cond_t fifo_cond; /* the main thread will signal on this cond after reading from fifo */
293 AVFifoBuffer *fifo; /* demuxed packets are stored here; freed by the main thread */
294#endif
295} InputFile;
296
297typedef struct OutputStream {
298 int file_index; /* file index */
299 int index; /* stream index in the output file */
300 int source_index; /* InputStream index */
301 AVStream *st; /* stream in the output file */
302 int encoding_needed; /* true if encoding needed for this stream */
303 int frame_number;
304 /* input pts and corresponding output pts
305 for A/V sync */
306 // double sync_ipts; /* dts from the AVPacket of the demuxer in second units */
307 struct InputStream *sync_ist; /* input stream to sync against */
308 int64_t sync_opts; /* output frame counter, could be changed to some true timestamp */ // FIXME look at frame_number
309 /* pts of the first frame encoded for this stream, used for limiting
310 * recording time */
311 int64_t first_pts;
76d23f40
AK
312 /* dts of the last packet sent to the muxer */
313 int64_t last_mux_dts;
f5e66827
AK
314 AVBitStreamFilterContext *bitstream_filters;
315 AVCodec *enc;
316 int64_t max_frames;
317 AVFrame *filtered_frame;
318
319 /* video only */
320 AVRational frame_rate;
321 int force_fps;
322 int top_field_first;
323
324 float frame_aspect_ratio;
f5e66827
AK
325
326 /* forced key frames */
327 int64_t *forced_kf_pts;
328 int forced_kf_count;
329 int forced_kf_index;
330 char *forced_keyframes;
331
bbcedade 332 char *logfile_prefix;
f5e66827
AK
333 FILE *logfile;
334
335 OutputFilter *filter;
336 char *avfilter;
337
338 int64_t sws_flags;
339 AVDictionary *opts;
5c7db097 340 AVDictionary *resample_opts;
57d24225 341 int finished; /* no more packets should be written for this stream */
f5e66827
AK
342 int stream_copy;
343 const char *attachment_filename;
344 int copy_initial_nonkeyframes;
345
716d413c 346 enum AVPixelFormat pix_fmts[2];
c872d310
AK
347
348 AVCodecParserContext *parser;
baeb59d8
AK
349
350 /* stats */
351 // combined size of all the packets written
352 uint64_t data_size;
47543450
AK
353 // number of packets send to the muxer
354 uint64_t packets_written;
355 // number of frames/samples sent to the encoder
356 uint64_t frames_encoded;
357 uint64_t samples_encoded;
f5e66827
AK
358} OutputStream;
359
360typedef struct OutputFile {
361 AVFormatContext *ctx;
362 AVDictionary *opts;
363 int ost_index; /* index of the first stream in output_streams */
364 int64_t recording_time; /* desired length of the resulting file in microseconds */
365 int64_t start_time; /* start time in microseconds */
366 uint64_t limit_filesize;
3c0df905
AK
367
368 int shortest;
f5e66827
AK
369} OutputFile;
370
371extern InputStream **input_streams;
372extern int nb_input_streams;
373extern InputFile **input_files;
374extern int nb_input_files;
375
376extern OutputStream **output_streams;
377extern int nb_output_streams;
378extern OutputFile **output_files;
379extern int nb_output_files;
380
381extern FilterGraph **filtergraphs;
382extern int nb_filtergraphs;
383
f5e66827
AK
384extern char *vstats_filename;
385
386extern float audio_drift_threshold;
387extern float dts_delta_threshold;
388
389extern int audio_volume;
390extern int audio_sync_method;
391extern int video_sync_method;
392extern int do_benchmark;
393extern int do_deinterlace;
394extern int do_hex_dump;
395extern int do_pkt_dump;
396extern int copy_ts;
397extern int copy_tb;
f5e66827
AK
398extern int exit_on_error;
399extern int print_stats;
400extern int qp_hist;
f5e66827
AK
401
402extern const AVIOInterruptCB int_cb;
403
404extern const OptionDef options[];
405
07fd0a22
AK
406extern const HWAccel hwaccels[];
407
f5e66827
AK
408void reset_options(OptionsContext *o);
409void show_usage(void);
410
f5e66827
AK
411void opt_output_file(void *optctx, const char *filename);
412
413void assert_avoptions(AVDictionary *m);
414
415int guess_input_channel_layout(InputStream *ist);
416
417int configure_filtergraph(FilterGraph *fg);
418int configure_output_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out);
fe2147e9
AK
419int ist_in_filtergraph(FilterGraph *fg, InputStream *ist);
420FilterGraph *init_simple_filtergraph(InputStream *ist, OutputStream *ost);
f5e66827 421
77bd1bc7
AK
422int avconv_parse_options(int argc, char **argv);
423
7671dd7c 424int vdpau_init(AVCodecContext *s);
35177ba7 425int dxva2_init(AVCodecContext *s);
7671dd7c 426
f5e66827 427#endif /* AVCONV_H */