avconv: rename InputStream.opts to InputStream.decoder_opts
[libav.git] / avconv.h
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"
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
51 enum HWAccelID {
52 HWACCEL_NONE = 0,
53 HWACCEL_AUTO,
54 HWACCEL_VDPAU,
55 HWACCEL_DXVA2,
56 };
57
58 typedef struct HWAccel {
59 const char *name;
60 int (*init)(AVCodecContext *s);
61 enum HWAccelID id;
62 enum AVPixelFormat pix_fmt;
63 } HWAccel;
64
65 /* select an input stream for an output stream */
66 typedef struct StreamMap {
67 int disabled; /* 1 is this mapping is disabled by a negative map */
68 int file_index;
69 int stream_index;
70 int sync_file_index;
71 int sync_stream_index;
72 char *linklabel; /* name of an output link, for mapping lavfi outputs */
73 } StreamMap;
74
75 /* select an input file for an output file */
76 typedef struct MetadataMap {
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
80 } MetadataMap;
81
82 typedef struct OptionsContext {
83 OptionGroup *g;
84
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;
105 int accurate_seek;
106
107 SpecifierOpt *ts_scale;
108 int nb_ts_scale;
109 SpecifierOpt *dump_attachment;
110 int nb_dump_attachment;
111 SpecifierOpt *hwaccels;
112 int nb_hwaccels;
113 SpecifierOpt *hwaccel_devices;
114 int nb_hwaccel_devices;
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;
134 int shortest;
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;
179 SpecifierOpt *filter_scripts;
180 int nb_filter_scripts;
181 SpecifierOpt *pass;
182 int nb_pass;
183 SpecifierOpt *passlogfiles;
184 int nb_passlogfiles;
185 } OptionsContext;
186
187 typedef struct InputFilter {
188 AVFilterContext *filter;
189 struct InputStream *ist;
190 struct FilterGraph *graph;
191 uint8_t *name;
192 } InputFilter;
193
194 typedef 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
204 typedef 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
216 typedef 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;
223 AVFrame *filter_frame; /* a ref of decoded_frame, to be sent to filters */
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;
233 int showed_multi_packet_warning;
234 AVDictionary *decoder_opts;
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
246 /* decoded data from this stream goes into all those filters
247 * currently video and audio only */
248 InputFilter **filters;
249 int nb_filters;
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;
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;
272 } InputStream;
273
274 typedef struct InputFile {
275 AVFormatContext *ctx;
276 int eof_reached; /* true if eof reached */
277 int eagain; /* true if last read attempt returned EAGAIN */
278 int ist_index; /* index of first stream in ist_table */
279 int64_t ts_offset;
280 int64_t start_time; /* user-specified start time in AV_TIME_BASE or AV_NOPTS_VALUE */
281 int64_t recording_time;
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;
285 int accurate_seek;
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
297 typedef 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;
312 /* dts of the last packet sent to the muxer */
313 int64_t last_mux_dts;
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;
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
332 char *logfile_prefix;
333 FILE *logfile;
334
335 OutputFilter *filter;
336 char *avfilter;
337
338 int64_t sws_flags;
339 AVDictionary *opts;
340 AVDictionary *resample_opts;
341 int finished; /* no more packets should be written for this stream */
342 int stream_copy;
343 const char *attachment_filename;
344 int copy_initial_nonkeyframes;
345
346 enum AVPixelFormat pix_fmts[2];
347
348 AVCodecParserContext *parser;
349
350 /* stats */
351 // combined size of all the packets written
352 uint64_t data_size;
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;
358 } OutputStream;
359
360 typedef 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;
367
368 int shortest;
369 } OutputFile;
370
371 extern InputStream **input_streams;
372 extern int nb_input_streams;
373 extern InputFile **input_files;
374 extern int nb_input_files;
375
376 extern OutputStream **output_streams;
377 extern int nb_output_streams;
378 extern OutputFile **output_files;
379 extern int nb_output_files;
380
381 extern FilterGraph **filtergraphs;
382 extern int nb_filtergraphs;
383
384 extern char *vstats_filename;
385
386 extern float audio_drift_threshold;
387 extern float dts_delta_threshold;
388
389 extern int audio_volume;
390 extern int audio_sync_method;
391 extern int video_sync_method;
392 extern int do_benchmark;
393 extern int do_deinterlace;
394 extern int do_hex_dump;
395 extern int do_pkt_dump;
396 extern int copy_ts;
397 extern int copy_tb;
398 extern int exit_on_error;
399 extern int print_stats;
400 extern int qp_hist;
401
402 extern const AVIOInterruptCB int_cb;
403
404 extern const OptionDef options[];
405
406 extern const HWAccel hwaccels[];
407
408 void reset_options(OptionsContext *o);
409 void show_usage(void);
410
411 void opt_output_file(void *optctx, const char *filename);
412
413 void assert_avoptions(AVDictionary *m);
414
415 int guess_input_channel_layout(InputStream *ist);
416
417 int configure_filtergraph(FilterGraph *fg);
418 int configure_output_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out);
419 int ist_in_filtergraph(FilterGraph *fg, InputStream *ist);
420 FilterGraph *init_simple_filtergraph(InputStream *ist, OutputStream *ost);
421
422 int avconv_parse_options(int argc, char **argv);
423
424 int vdpau_init(AVCodecContext *s);
425 int dxva2_init(AVCodecContext *s);
426
427 #endif /* AVCONV_H */