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