Commit | Line | Data |
---|---|---|
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 | ||
51 | /* select an input stream for an output stream */ | |
52 | typedef struct StreamMap { | |
c1ef30a6 | 53 | int disabled; /* 1 is this mapping is disabled by a negative map */ |
f5e66827 AK |
54 | int file_index; |
55 | int stream_index; | |
56 | int sync_file_index; | |
57 | int sync_stream_index; | |
c1ef30a6 | 58 | char *linklabel; /* name of an output link, for mapping lavfi outputs */ |
f5e66827 AK |
59 | } StreamMap; |
60 | ||
c1ef30a6 | 61 | /* select an input file for an output file */ |
f5e66827 | 62 | typedef struct MetadataMap { |
c1ef30a6 DB |
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 | |
f5e66827 AK |
66 | } MetadataMap; |
67 | ||
68 | typedef struct OptionsContext { | |
77bd1bc7 AK |
69 | OptionGroup *g; |
70 | ||
f5e66827 AK |
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; | |
811bd078 | 91 | int accurate_seek; |
f5e66827 AK |
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; | |
3c0df905 | 116 | int shortest; |
f5e66827 AK |
117 | |
118 | int video_disable; | |
119 | int audio_disable; | |
120 | int subtitle_disable; | |
121 | int data_disable; | |
122 | ||
123 | /* indexed by output file stream index */ | |
124 | int *streamid_map; | |
125 | int nb_streamid_map; | |
126 | ||
127 | SpecifierOpt *metadata; | |
128 | int nb_metadata; | |
129 | SpecifierOpt *max_frames; | |
130 | int nb_max_frames; | |
131 | SpecifierOpt *bitstream_filters; | |
132 | int nb_bitstream_filters; | |
133 | SpecifierOpt *codec_tags; | |
134 | int nb_codec_tags; | |
135 | SpecifierOpt *sample_fmts; | |
136 | int nb_sample_fmts; | |
137 | SpecifierOpt *qscale; | |
138 | int nb_qscale; | |
139 | SpecifierOpt *forced_key_frames; | |
140 | int nb_forced_key_frames; | |
141 | SpecifierOpt *force_fps; | |
142 | int nb_force_fps; | |
143 | SpecifierOpt *frame_aspect_ratios; | |
144 | int nb_frame_aspect_ratios; | |
145 | SpecifierOpt *rc_overrides; | |
146 | int nb_rc_overrides; | |
147 | SpecifierOpt *intra_matrices; | |
148 | int nb_intra_matrices; | |
149 | SpecifierOpt *inter_matrices; | |
150 | int nb_inter_matrices; | |
151 | SpecifierOpt *top_field_first; | |
152 | int nb_top_field_first; | |
153 | SpecifierOpt *metadata_map; | |
154 | int nb_metadata_map; | |
155 | SpecifierOpt *presets; | |
156 | int nb_presets; | |
157 | SpecifierOpt *copy_initial_nonkeyframes; | |
158 | int nb_copy_initial_nonkeyframes; | |
159 | SpecifierOpt *filters; | |
160 | int nb_filters; | |
a4208b9b AK |
161 | SpecifierOpt *filter_scripts; |
162 | int nb_filter_scripts; | |
038c0b1e AK |
163 | SpecifierOpt *pass; |
164 | int nb_pass; | |
bbcedade AK |
165 | SpecifierOpt *passlogfiles; |
166 | int nb_passlogfiles; | |
f5e66827 AK |
167 | } OptionsContext; |
168 | ||
169 | typedef struct InputFilter { | |
170 | AVFilterContext *filter; | |
171 | struct InputStream *ist; | |
172 | struct FilterGraph *graph; | |
173 | uint8_t *name; | |
174 | } InputFilter; | |
175 | ||
176 | typedef struct OutputFilter { | |
177 | AVFilterContext *filter; | |
178 | struct OutputStream *ost; | |
179 | struct FilterGraph *graph; | |
180 | uint8_t *name; | |
181 | ||
182 | /* temporary storage until stream maps are processed */ | |
183 | AVFilterInOut *out_tmp; | |
184 | } OutputFilter; | |
185 | ||
186 | typedef struct FilterGraph { | |
187 | int index; | |
188 | const char *graph_desc; | |
189 | ||
190 | AVFilterGraph *graph; | |
191 | ||
192 | InputFilter **inputs; | |
193 | int nb_inputs; | |
194 | OutputFilter **outputs; | |
195 | int nb_outputs; | |
196 | } FilterGraph; | |
197 | ||
198 | typedef struct InputStream { | |
199 | int file_index; | |
200 | AVStream *st; | |
201 | int discard; /* true if stream data should be discarded */ | |
202 | int decoding_needed; /* true if the packets must be decoded in 'raw_fifo' */ | |
203 | AVCodec *dec; | |
204 | AVFrame *decoded_frame; | |
9b2dc295 | 205 | AVFrame *filter_frame; /* a ref of decoded_frame, to be sent to filters */ |
f5e66827 AK |
206 | |
207 | int64_t start; /* time when read started */ | |
208 | /* predicted dts of the next packet read for this stream or (when there are | |
209 | * several frames in a packet) of the next frame in current packet */ | |
210 | int64_t next_dts; | |
211 | /* dts of the last packet read for this stream */ | |
212 | int64_t last_dts; | |
213 | PtsCorrectionContext pts_ctx; | |
214 | double ts_scale; | |
215 | int is_start; /* is 1 at the start and after a discontinuity */ | |
216 | int showed_multi_packet_warning; | |
217 | AVDictionary *opts; | |
218 | AVRational framerate; /* framerate forced with -r */ | |
219 | ||
220 | int resample_height; | |
221 | int resample_width; | |
222 | int resample_pix_fmt; | |
223 | ||
224 | int resample_sample_fmt; | |
225 | int resample_sample_rate; | |
226 | int resample_channels; | |
227 | uint64_t resample_channel_layout; | |
228 | ||
f5e66827 AK |
229 | /* decoded data from this stream goes into all those filters |
230 | * currently video and audio only */ | |
231 | InputFilter **filters; | |
232 | int nb_filters; | |
233 | } InputStream; | |
234 | ||
235 | typedef struct InputFile { | |
236 | AVFormatContext *ctx; | |
237 | int eof_reached; /* true if eof reached */ | |
0b26ef42 | 238 | int eagain; /* true if last read attempt returned EAGAIN */ |
f5e66827 | 239 | int ist_index; /* index of first stream in ist_table */ |
f5e66827 | 240 | int64_t ts_offset; |
811bd078 | 241 | int64_t start_time; /* user-specified start time in AV_TIME_BASE or AV_NOPTS_VALUE */ |
488a0fa6 | 242 | int64_t recording_time; |
f5e66827 AK |
243 | int nb_streams; /* number of stream that avconv is aware of; may be different |
244 | from ctx.nb_streams if new streams appear during av_read_frame() */ | |
245 | int rate_emu; | |
811bd078 | 246 | int accurate_seek; |
f5e66827 AK |
247 | |
248 | #if HAVE_PTHREADS | |
249 | pthread_t thread; /* thread reading from this file */ | |
250 | int finished; /* the thread has exited */ | |
251 | int joined; /* the thread has been joined */ | |
252 | pthread_mutex_t fifo_lock; /* lock for access to fifo */ | |
253 | pthread_cond_t fifo_cond; /* the main thread will signal on this cond after reading from fifo */ | |
254 | AVFifoBuffer *fifo; /* demuxed packets are stored here; freed by the main thread */ | |
255 | #endif | |
256 | } InputFile; | |
257 | ||
258 | typedef struct OutputStream { | |
259 | int file_index; /* file index */ | |
260 | int index; /* stream index in the output file */ | |
261 | int source_index; /* InputStream index */ | |
262 | AVStream *st; /* stream in the output file */ | |
263 | int encoding_needed; /* true if encoding needed for this stream */ | |
264 | int frame_number; | |
265 | /* input pts and corresponding output pts | |
266 | for A/V sync */ | |
267 | // double sync_ipts; /* dts from the AVPacket of the demuxer in second units */ | |
268 | struct InputStream *sync_ist; /* input stream to sync against */ | |
269 | int64_t sync_opts; /* output frame counter, could be changed to some true timestamp */ // FIXME look at frame_number | |
270 | /* pts of the first frame encoded for this stream, used for limiting | |
271 | * recording time */ | |
272 | int64_t first_pts; | |
76d23f40 AK |
273 | /* dts of the last packet sent to the muxer */ |
274 | int64_t last_mux_dts; | |
f5e66827 AK |
275 | AVBitStreamFilterContext *bitstream_filters; |
276 | AVCodec *enc; | |
277 | int64_t max_frames; | |
278 | AVFrame *filtered_frame; | |
279 | ||
280 | /* video only */ | |
281 | AVRational frame_rate; | |
282 | int force_fps; | |
283 | int top_field_first; | |
284 | ||
285 | float frame_aspect_ratio; | |
f5e66827 AK |
286 | |
287 | /* forced key frames */ | |
288 | int64_t *forced_kf_pts; | |
289 | int forced_kf_count; | |
290 | int forced_kf_index; | |
291 | char *forced_keyframes; | |
292 | ||
bbcedade | 293 | char *logfile_prefix; |
f5e66827 AK |
294 | FILE *logfile; |
295 | ||
296 | OutputFilter *filter; | |
297 | char *avfilter; | |
298 | ||
299 | int64_t sws_flags; | |
300 | AVDictionary *opts; | |
5c7db097 | 301 | AVDictionary *resample_opts; |
57d24225 | 302 | int finished; /* no more packets should be written for this stream */ |
f5e66827 AK |
303 | int stream_copy; |
304 | const char *attachment_filename; | |
305 | int copy_initial_nonkeyframes; | |
306 | ||
716d413c | 307 | enum AVPixelFormat pix_fmts[2]; |
c872d310 AK |
308 | |
309 | AVCodecParserContext *parser; | |
f5e66827 AK |
310 | } OutputStream; |
311 | ||
312 | typedef struct OutputFile { | |
313 | AVFormatContext *ctx; | |
314 | AVDictionary *opts; | |
315 | int ost_index; /* index of the first stream in output_streams */ | |
316 | int64_t recording_time; /* desired length of the resulting file in microseconds */ | |
317 | int64_t start_time; /* start time in microseconds */ | |
318 | uint64_t limit_filesize; | |
3c0df905 AK |
319 | |
320 | int shortest; | |
f5e66827 AK |
321 | } OutputFile; |
322 | ||
323 | extern InputStream **input_streams; | |
324 | extern int nb_input_streams; | |
325 | extern InputFile **input_files; | |
326 | extern int nb_input_files; | |
327 | ||
328 | extern OutputStream **output_streams; | |
329 | extern int nb_output_streams; | |
330 | extern OutputFile **output_files; | |
331 | extern int nb_output_files; | |
332 | ||
333 | extern FilterGraph **filtergraphs; | |
334 | extern int nb_filtergraphs; | |
335 | ||
f5e66827 AK |
336 | extern char *vstats_filename; |
337 | ||
338 | extern float audio_drift_threshold; | |
339 | extern float dts_delta_threshold; | |
340 | ||
341 | extern int audio_volume; | |
342 | extern int audio_sync_method; | |
343 | extern int video_sync_method; | |
344 | extern int do_benchmark; | |
345 | extern int do_deinterlace; | |
346 | extern int do_hex_dump; | |
347 | extern int do_pkt_dump; | |
348 | extern int copy_ts; | |
349 | extern int copy_tb; | |
f5e66827 AK |
350 | extern int exit_on_error; |
351 | extern int print_stats; | |
352 | extern int qp_hist; | |
f5e66827 AK |
353 | |
354 | extern const AVIOInterruptCB int_cb; | |
355 | ||
356 | extern const OptionDef options[]; | |
357 | ||
358 | void reset_options(OptionsContext *o); | |
359 | void show_usage(void); | |
360 | ||
f5e66827 AK |
361 | void opt_output_file(void *optctx, const char *filename); |
362 | ||
363 | void assert_avoptions(AVDictionary *m); | |
364 | ||
365 | int guess_input_channel_layout(InputStream *ist); | |
366 | ||
367 | int configure_filtergraph(FilterGraph *fg); | |
368 | int configure_output_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out); | |
fe2147e9 AK |
369 | int ist_in_filtergraph(FilterGraph *fg, InputStream *ist); |
370 | FilterGraph *init_simple_filtergraph(InputStream *ist, OutputStream *ost); | |
f5e66827 | 371 | |
77bd1bc7 AK |
372 | int avconv_parse_options(int argc, char **argv); |
373 | ||
f5e66827 | 374 | #endif /* AVCONV_H */ |