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