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