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