]> git.sesse.net Git - ffmpeg/blob - avconv.h
Use log2(x) instead of log(x) / log(2)
[ffmpeg] / 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 #include "libavfilter/avfiltergraph.h"
40
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"
46
47 #define VSYNC_AUTO       -1
48 #define VSYNC_PASSTHROUGH 0
49 #define VSYNC_CFR         1
50 #define VSYNC_VFR         2
51
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;
61
62 /**
63  * select an input file for an output file
64  */
65 typedef struct MetadataMap {
66     int  file;      ///< file index
67     char type;      ///< type of metadata to copy -- (g)lobal, (s)tream, (c)hapter or (p)rogram
68     int  index;     ///< stream/chapter/program number
69 } MetadataMap;
70
71 typedef struct OptionsContext {
72     /* input/output options */
73     int64_t start_time;
74     const char *format;
75
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;
88
89     /* input options */
90     int64_t input_ts_offset;
91     int rate_emu;
92
93     SpecifierOpt *ts_scale;
94     int        nb_ts_scale;
95     SpecifierOpt *dump_attachment;
96     int        nb_dump_attachment;
97
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;
109
110     int chapters_input_file;
111
112     int64_t recording_time;
113     uint64_t limit_filesize;
114     float mux_preload;
115     float mux_max_delay;
116
117     int video_disable;
118     int audio_disable;
119     int subtitle_disable;
120     int data_disable;
121
122     /* indexed by output file stream index */
123     int   *streamid_map;
124     int nb_streamid_map;
125
126     SpecifierOpt *metadata;
127     int        nb_metadata;
128     SpecifierOpt *max_frames;
129     int        nb_max_frames;
130     SpecifierOpt *bitstream_filters;
131     int        nb_bitstream_filters;
132     SpecifierOpt *codec_tags;
133     int        nb_codec_tags;
134     SpecifierOpt *sample_fmts;
135     int        nb_sample_fmts;
136     SpecifierOpt *qscale;
137     int        nb_qscale;
138     SpecifierOpt *forced_key_frames;
139     int        nb_forced_key_frames;
140     SpecifierOpt *force_fps;
141     int        nb_force_fps;
142     SpecifierOpt *frame_aspect_ratios;
143     int        nb_frame_aspect_ratios;
144     SpecifierOpt *rc_overrides;
145     int        nb_rc_overrides;
146     SpecifierOpt *intra_matrices;
147     int        nb_intra_matrices;
148     SpecifierOpt *inter_matrices;
149     int        nb_inter_matrices;
150     SpecifierOpt *top_field_first;
151     int        nb_top_field_first;
152     SpecifierOpt *metadata_map;
153     int        nb_metadata_map;
154     SpecifierOpt *presets;
155     int        nb_presets;
156     SpecifierOpt *copy_initial_nonkeyframes;
157     int        nb_copy_initial_nonkeyframes;
158     SpecifierOpt *filters;
159     int        nb_filters;
160 } OptionsContext;
161
162 typedef struct InputFilter {
163     AVFilterContext    *filter;
164     struct InputStream *ist;
165     struct FilterGraph *graph;
166     uint8_t            *name;
167 } InputFilter;
168
169 typedef struct OutputFilter {
170     AVFilterContext     *filter;
171     struct OutputStream *ost;
172     struct FilterGraph  *graph;
173     uint8_t             *name;
174
175     /* temporary storage until stream maps are processed */
176     AVFilterInOut       *out_tmp;
177 } OutputFilter;
178
179 typedef struct FilterGraph {
180     int            index;
181     const char    *graph_desc;
182
183     AVFilterGraph *graph;
184
185     InputFilter   **inputs;
186     int          nb_inputs;
187     OutputFilter **outputs;
188     int         nb_outputs;
189 } FilterGraph;
190
191 typedef struct InputStream {
192     int file_index;
193     AVStream *st;
194     int discard;             /* true if stream data should be discarded */
195     int decoding_needed;     /* true if the packets must be decoded in 'raw_fifo' */
196     AVCodec *dec;
197     AVFrame *decoded_frame;
198
199     int64_t       start;     /* time when read started */
200     /* predicted dts of the next packet read for this stream or (when there are
201      * several frames in a packet) of the next frame in current packet */
202     int64_t       next_dts;
203     /* dts of the last packet read for this stream */
204     int64_t       last_dts;
205     PtsCorrectionContext pts_ctx;
206     double ts_scale;
207     int is_start;            /* is 1 at the start and after a discontinuity */
208     int showed_multi_packet_warning;
209     AVDictionary *opts;
210     AVRational framerate;               /* framerate forced with -r */
211
212     int resample_height;
213     int resample_width;
214     int resample_pix_fmt;
215
216     int      resample_sample_fmt;
217     int      resample_sample_rate;
218     int      resample_channels;
219     uint64_t resample_channel_layout;
220
221     /* a pool of free buffers for decoded data */
222     FrameBuffer *buffer_pool;
223
224     /* decoded data from this stream goes into all those filters
225      * currently video and audio only */
226     InputFilter **filters;
227     int        nb_filters;
228 } InputStream;
229
230 typedef struct InputFile {
231     AVFormatContext *ctx;
232     int eof_reached;      /* true if eof reached */
233     int eagain;           /* true if last read attempt returned EAGAIN */
234     int ist_index;        /* index of first stream in ist_table */
235     int64_t ts_offset;
236     int nb_streams;       /* number of stream that avconv is aware of; may be different
237                              from ctx.nb_streams if new streams appear during av_read_frame() */
238     int rate_emu;
239
240 #if HAVE_PTHREADS
241     pthread_t thread;           /* thread reading from this file */
242     int finished;               /* the thread has exited */
243     int joined;                 /* the thread has been joined */
244     pthread_mutex_t fifo_lock;  /* lock for access to fifo */
245     pthread_cond_t  fifo_cond;  /* the main thread will signal on this cond after reading from fifo */
246     AVFifoBuffer *fifo;         /* demuxed packets are stored here; freed by the main thread */
247 #endif
248 } InputFile;
249
250 typedef struct OutputStream {
251     int file_index;          /* file index */
252     int index;               /* stream index in the output file */
253     int source_index;        /* InputStream index */
254     AVStream *st;            /* stream in the output file */
255     int encoding_needed;     /* true if encoding needed for this stream */
256     int frame_number;
257     /* input pts and corresponding output pts
258        for A/V sync */
259     // double sync_ipts;        /* dts from the AVPacket of the demuxer in second units */
260     struct InputStream *sync_ist; /* input stream to sync against */
261     int64_t sync_opts;       /* output frame counter, could be changed to some true timestamp */ // FIXME look at frame_number
262     /* pts of the first frame encoded for this stream, used for limiting
263      * recording time */
264     int64_t first_pts;
265     AVBitStreamFilterContext *bitstream_filters;
266     AVCodec *enc;
267     int64_t max_frames;
268     AVFrame *filtered_frame;
269
270     /* video only */
271     AVRational frame_rate;
272     int force_fps;
273     int top_field_first;
274
275     float frame_aspect_ratio;
276     float last_quality;
277
278     /* forced key frames */
279     int64_t *forced_kf_pts;
280     int forced_kf_count;
281     int forced_kf_index;
282     char *forced_keyframes;
283
284     FILE *logfile;
285
286     OutputFilter *filter;
287     char *avfilter;
288
289     int64_t sws_flags;
290     AVDictionary *opts;
291     int finished;        /* no more packets should be written for this stream */
292     int stream_copy;
293     const char *attachment_filename;
294     int copy_initial_nonkeyframes;
295
296     enum PixelFormat pix_fmts[2];
297 } OutputStream;
298
299 typedef struct OutputFile {
300     AVFormatContext *ctx;
301     AVDictionary *opts;
302     int ost_index;       /* index of the first stream in output_streams */
303     int64_t recording_time; /* desired length of the resulting file in microseconds */
304     int64_t start_time;     /* start time in microseconds */
305     uint64_t limit_filesize;
306 } OutputFile;
307
308 extern InputStream **input_streams;
309 extern int        nb_input_streams;
310 extern InputFile   **input_files;
311 extern int        nb_input_files;
312
313 extern OutputStream **output_streams;
314 extern int         nb_output_streams;
315 extern OutputFile   **output_files;
316 extern int         nb_output_files;
317
318 extern FilterGraph **filtergraphs;
319 extern int        nb_filtergraphs;
320
321 extern char *pass_logfilename_prefix;
322 extern char *vstats_filename;
323
324 extern float audio_drift_threshold;
325 extern float dts_delta_threshold;
326
327 extern int audio_volume;
328 extern int audio_sync_method;
329 extern int video_sync_method;
330 extern int do_benchmark;
331 extern int do_deinterlace;
332 extern int do_hex_dump;
333 extern int do_pkt_dump;
334 extern int copy_ts;
335 extern int copy_tb;
336 extern int opt_shortest;
337 extern int exit_on_error;
338 extern int print_stats;
339 extern int qp_hist;
340 extern int same_quant;
341
342 extern const AVIOInterruptCB int_cb;
343
344 extern const OptionDef options[];
345
346 void reset_options(OptionsContext *o);
347 void show_usage(void);
348
349 int opt_cpuflags(const char *opt, const char *arg);
350
351 void opt_output_file(void *optctx, const char *filename);
352
353 void assert_avoptions(AVDictionary *m);
354
355 int guess_input_channel_layout(InputStream *ist);
356
357 int configure_filtergraph(FilterGraph *fg);
358 int configure_output_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out);
359 int ist_in_filtergraph(FilterGraph *fg, InputStream *ist);
360 FilterGraph *init_simple_filtergraph(InputStream *ist, OutputStream *ost);
361
362 #endif /* AVCONV_H */