Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4349 | Serge | 1 | /* |
2 | * This file is part of FFmpeg. |
||
3 | * |
||
4 | * FFmpeg 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 | * FFmpeg 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 FFmpeg; if not, write to the Free Software |
||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||
17 | */ |
||
18 | |||
19 | #ifndef FFMPEG_H |
||
20 | #define FFMPEG_H |
||
21 | |||
22 | #include "config.h" |
||
23 | |||
24 | #include |
||
25 | #include |
||
26 | #include |
||
27 | |||
28 | #if HAVE_PTHREADS |
||
29 | #include |
||
30 | #endif |
||
31 | |||
32 | #include "cmdutils.h" |
||
33 | |||
34 | #include "libavformat/avformat.h" |
||
35 | #include "libavformat/avio.h" |
||
36 | |||
37 | #include "libavcodec/avcodec.h" |
||
38 | |||
39 | #include "libavfilter/avfilter.h" |
||
40 | |||
41 | #include "libavutil/avutil.h" |
||
42 | #include "libavutil/dict.h" |
||
43 | #include "libavutil/eval.h" |
||
44 | #include "libavutil/fifo.h" |
||
45 | #include "libavutil/pixfmt.h" |
||
46 | #include "libavutil/rational.h" |
||
47 | |||
48 | #include "libswresample/swresample.h" |
||
49 | |||
50 | #define VSYNC_AUTO -1 |
||
51 | #define VSYNC_PASSTHROUGH 0 |
||
52 | #define VSYNC_CFR 1 |
||
53 | #define VSYNC_VFR 2 |
||
54 | #define VSYNC_VSCFR 0xfe |
||
55 | #define VSYNC_DROP 0xff |
||
56 | |||
57 | #define MAX_STREAMS 1024 /* arbitrary sanity check value */ |
||
58 | |||
59 | /* select an input stream for an output stream */ |
||
60 | typedef struct StreamMap { |
||
61 | int disabled; /* 1 is this mapping is disabled by a negative map */ |
||
62 | int file_index; |
||
63 | int stream_index; |
||
64 | int sync_file_index; |
||
65 | int sync_stream_index; |
||
66 | char *linklabel; /* name of an output link, for mapping lavfi outputs */ |
||
67 | } StreamMap; |
||
68 | |||
69 | typedef struct { |
||
70 | int file_idx, stream_idx, channel_idx; // input |
||
71 | int ofile_idx, ostream_idx; // output |
||
72 | } AudioChannelMap; |
||
73 | |||
74 | typedef struct OptionsContext { |
||
75 | OptionGroup *g; |
||
76 | |||
77 | /* input/output options */ |
||
78 | int64_t start_time; |
||
79 | const char *format; |
||
80 | |||
81 | SpecifierOpt *codec_names; |
||
82 | int nb_codec_names; |
||
83 | SpecifierOpt *audio_channels; |
||
84 | int nb_audio_channels; |
||
85 | SpecifierOpt *audio_sample_rate; |
||
86 | int nb_audio_sample_rate; |
||
87 | SpecifierOpt *frame_rates; |
||
88 | int nb_frame_rates; |
||
89 | SpecifierOpt *frame_sizes; |
||
90 | int nb_frame_sizes; |
||
91 | SpecifierOpt *frame_pix_fmts; |
||
92 | int nb_frame_pix_fmts; |
||
93 | |||
94 | /* input options */ |
||
95 | int64_t input_ts_offset; |
||
96 | int rate_emu; |
||
97 | int accurate_seek; |
||
98 | |||
99 | SpecifierOpt *ts_scale; |
||
100 | int nb_ts_scale; |
||
101 | SpecifierOpt *dump_attachment; |
||
102 | int nb_dump_attachment; |
||
103 | |||
104 | /* output options */ |
||
105 | StreamMap *stream_maps; |
||
106 | int nb_stream_maps; |
||
107 | AudioChannelMap *audio_channel_maps; /* one info entry per -map_channel */ |
||
108 | int nb_audio_channel_maps; /* number of (valid) -map_channel settings */ |
||
109 | int metadata_global_manual; |
||
110 | int metadata_streams_manual; |
||
111 | int metadata_chapters_manual; |
||
112 | const char **attachments; |
||
113 | int nb_attachments; |
||
114 | |||
115 | int chapters_input_file; |
||
116 | |||
117 | int64_t recording_time; |
||
118 | int64_t stop_time; |
||
119 | uint64_t limit_filesize; |
||
120 | float mux_preload; |
||
121 | float mux_max_delay; |
||
122 | int shortest; |
||
123 | |||
124 | int video_disable; |
||
125 | int audio_disable; |
||
126 | int subtitle_disable; |
||
127 | int data_disable; |
||
128 | |||
129 | /* indexed by output file stream index */ |
||
130 | int *streamid_map; |
||
131 | int nb_streamid_map; |
||
132 | |||
133 | SpecifierOpt *metadata; |
||
134 | int nb_metadata; |
||
135 | SpecifierOpt *max_frames; |
||
136 | int nb_max_frames; |
||
137 | SpecifierOpt *bitstream_filters; |
||
138 | int nb_bitstream_filters; |
||
139 | SpecifierOpt *codec_tags; |
||
140 | int nb_codec_tags; |
||
141 | SpecifierOpt *sample_fmts; |
||
142 | int nb_sample_fmts; |
||
143 | SpecifierOpt *qscale; |
||
144 | int nb_qscale; |
||
145 | SpecifierOpt *forced_key_frames; |
||
146 | int nb_forced_key_frames; |
||
147 | SpecifierOpt *force_fps; |
||
148 | int nb_force_fps; |
||
149 | SpecifierOpt *frame_aspect_ratios; |
||
150 | int nb_frame_aspect_ratios; |
||
151 | SpecifierOpt *rc_overrides; |
||
152 | int nb_rc_overrides; |
||
153 | SpecifierOpt *intra_matrices; |
||
154 | int nb_intra_matrices; |
||
155 | SpecifierOpt *inter_matrices; |
||
156 | int nb_inter_matrices; |
||
157 | SpecifierOpt *top_field_first; |
||
158 | int nb_top_field_first; |
||
159 | SpecifierOpt *metadata_map; |
||
160 | int nb_metadata_map; |
||
161 | SpecifierOpt *presets; |
||
162 | int nb_presets; |
||
163 | SpecifierOpt *copy_initial_nonkeyframes; |
||
164 | int nb_copy_initial_nonkeyframes; |
||
165 | SpecifierOpt *copy_prior_start; |
||
166 | int nb_copy_prior_start; |
||
167 | SpecifierOpt *filters; |
||
168 | int nb_filters; |
||
169 | SpecifierOpt *filter_scripts; |
||
170 | int nb_filter_scripts; |
||
171 | SpecifierOpt *reinit_filters; |
||
172 | int nb_reinit_filters; |
||
173 | SpecifierOpt *fix_sub_duration; |
||
174 | int nb_fix_sub_duration; |
||
175 | SpecifierOpt *canvas_sizes; |
||
176 | int nb_canvas_sizes; |
||
177 | SpecifierOpt *pass; |
||
178 | int nb_pass; |
||
179 | SpecifierOpt *passlogfiles; |
||
180 | int nb_passlogfiles; |
||
181 | SpecifierOpt *guess_layout_max; |
||
182 | int nb_guess_layout_max; |
||
183 | SpecifierOpt *apad; |
||
184 | int nb_apad; |
||
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 | int reconfiguration; |
||
210 | |||
211 | InputFilter **inputs; |
||
212 | int nb_inputs; |
||
213 | OutputFilter **outputs; |
||
214 | int nb_outputs; |
||
215 | } FilterGraph; |
||
216 | |||
217 | typedef struct InputStream { |
||
218 | int file_index; |
||
219 | AVStream *st; |
||
220 | int discard; /* true if stream data should be discarded */ |
||
221 | int decoding_needed; /* true if the packets must be decoded in 'raw_fifo' */ |
||
222 | AVCodec *dec; |
||
223 | AVFrame *decoded_frame; |
||
224 | AVFrame *filter_frame; /* a ref of decoded_frame, to be sent to filters */ |
||
225 | |||
226 | int64_t start; /* time when read started */ |
||
227 | /* predicted dts of the next packet read for this stream or (when there are |
||
228 | * several frames in a packet) of the next frame in current packet (in AV_TIME_BASE units) */ |
||
229 | int64_t next_dts; |
||
230 | int64_t dts; ///< dts of the last packet read for this stream (in AV_TIME_BASE units) |
||
231 | |||
232 | int64_t next_pts; ///< synthetic pts for the next decode frame (in AV_TIME_BASE units) |
||
233 | int64_t pts; ///< current pts of the decoded frame (in AV_TIME_BASE units) |
||
234 | int wrap_correction_done; |
||
235 | |||
236 | int64_t filter_in_rescale_delta_last; |
||
237 | |||
238 | double ts_scale; |
||
239 | int is_start; /* is 1 at the start and after a discontinuity */ |
||
240 | int saw_first_ts; |
||
241 | int showed_multi_packet_warning; |
||
242 | AVDictionary *opts; |
||
243 | AVRational framerate; /* framerate forced with -r */ |
||
244 | int top_field_first; |
||
245 | int guess_layout_max; |
||
246 | |||
247 | int resample_height; |
||
248 | int resample_width; |
||
249 | int resample_pix_fmt; |
||
250 | |||
251 | int resample_sample_fmt; |
||
252 | int resample_sample_rate; |
||
253 | int resample_channels; |
||
254 | uint64_t resample_channel_layout; |
||
255 | |||
256 | int fix_sub_duration; |
||
257 | struct { /* previous decoded subtitle and related variables */ |
||
258 | int got_output; |
||
259 | int ret; |
||
260 | AVSubtitle subtitle; |
||
261 | } prev_sub; |
||
262 | |||
263 | struct sub2video { |
||
264 | int64_t last_pts; |
||
265 | int64_t end_pts; |
||
266 | AVFrame *frame; |
||
267 | int w, h; |
||
268 | } sub2video; |
||
269 | |||
270 | int dr1; |
||
271 | |||
272 | /* decoded data from this stream goes into all those filters |
||
273 | * currently video and audio only */ |
||
274 | InputFilter **filters; |
||
275 | int nb_filters; |
||
276 | |||
277 | int reinit_filters; |
||
278 | } InputStream; |
||
279 | |||
280 | typedef struct InputFile { |
||
281 | AVFormatContext *ctx; |
||
282 | int eof_reached; /* true if eof reached */ |
||
283 | int eagain; /* true if last read attempt returned EAGAIN */ |
||
284 | int ist_index; /* index of first stream in input_streams */ |
||
285 | int64_t input_ts_offset; |
||
286 | int64_t ts_offset; |
||
287 | int64_t last_ts; |
||
288 | int64_t start_time; /* user-specified start time in AV_TIME_BASE or AV_NOPTS_VALUE */ |
||
289 | int64_t recording_time; |
||
290 | int nb_streams; /* number of stream that ffmpeg is aware of; may be different |
||
291 | from ctx.nb_streams if new streams appear during av_read_frame() */ |
||
292 | int nb_streams_warn; /* number of streams that the user was warned of */ |
||
293 | int rate_emu; |
||
294 | int accurate_seek; |
||
295 | |||
296 | #if HAVE_PTHREADS |
||
297 | pthread_t thread; /* thread reading from this file */ |
||
298 | int finished; /* the thread has exited */ |
||
299 | int joined; /* the thread has been joined */ |
||
300 | pthread_mutex_t fifo_lock; /* lock for access to fifo */ |
||
301 | pthread_cond_t fifo_cond; /* the main thread will signal on this cond after reading from fifo */ |
||
302 | AVFifoBuffer *fifo; /* demuxed packets are stored here; freed by the main thread */ |
||
303 | #endif |
||
304 | } InputFile; |
||
305 | |||
306 | enum forced_keyframes_const { |
||
307 | FKF_N, |
||
308 | FKF_N_FORCED, |
||
309 | FKF_PREV_FORCED_N, |
||
310 | FKF_PREV_FORCED_T, |
||
311 | FKF_T, |
||
312 | FKF_NB |
||
313 | }; |
||
314 | |||
315 | extern const char *const forced_keyframes_const_names[]; |
||
316 | |||
317 | typedef struct OutputStream { |
||
318 | int file_index; /* file index */ |
||
319 | int index; /* stream index in the output file */ |
||
320 | int source_index; /* InputStream index */ |
||
321 | AVStream *st; /* stream in the output file */ |
||
322 | int encoding_needed; /* true if encoding needed for this stream */ |
||
323 | int frame_number; |
||
324 | /* input pts and corresponding output pts |
||
325 | for A/V sync */ |
||
326 | struct InputStream *sync_ist; /* input stream to sync against */ |
||
327 | int64_t sync_opts; /* output frame counter, could be changed to some true timestamp */ // FIXME look at frame_number |
||
328 | /* pts of the first frame encoded for this stream, used for limiting |
||
329 | * recording time */ |
||
330 | int64_t first_pts; |
||
331 | /* dts of the last packet sent to the muxer */ |
||
332 | int64_t last_mux_dts; |
||
333 | AVBitStreamFilterContext *bitstream_filters; |
||
334 | AVCodec *enc; |
||
335 | int64_t max_frames; |
||
336 | AVFrame *filtered_frame; |
||
337 | |||
338 | /* video only */ |
||
339 | AVRational frame_rate; |
||
340 | int force_fps; |
||
341 | int top_field_first; |
||
342 | |||
343 | AVRational frame_aspect_ratio; |
||
344 | |||
345 | /* forced key frames */ |
||
346 | int64_t *forced_kf_pts; |
||
347 | int forced_kf_count; |
||
348 | int forced_kf_index; |
||
349 | char *forced_keyframes; |
||
350 | AVExpr *forced_keyframes_pexpr; |
||
351 | double forced_keyframes_expr_const_values[FKF_NB]; |
||
352 | |||
353 | /* audio only */ |
||
354 | int audio_channels_map[SWR_CH_MAX]; /* list of the channels id to pick from the source stream */ |
||
355 | int audio_channels_mapped; /* number of channels in audio_channels_map */ |
||
356 | |||
357 | char *logfile_prefix; |
||
358 | FILE *logfile; |
||
359 | |||
360 | OutputFilter *filter; |
||
361 | char *avfilter; |
||
362 | |||
363 | int64_t sws_flags; |
||
364 | AVDictionary *opts; |
||
365 | AVDictionary *swr_opts; |
||
366 | AVDictionary *resample_opts; |
||
367 | char *apad; |
||
368 | int finished; /* no more packets should be written for this stream */ |
||
369 | int unavailable; /* true if the steram is unavailable (possibly temporarily) */ |
||
370 | int stream_copy; |
||
371 | const char *attachment_filename; |
||
372 | int copy_initial_nonkeyframes; |
||
373 | int copy_prior_start; |
||
374 | |||
375 | int keep_pix_fmt; |
||
376 | } OutputStream; |
||
377 | |||
378 | typedef struct OutputFile { |
||
379 | AVFormatContext *ctx; |
||
380 | AVDictionary *opts; |
||
381 | int ost_index; /* index of the first stream in output_streams */ |
||
382 | int64_t recording_time; ///< desired length of the resulting file in microseconds == AV_TIME_BASE units |
||
383 | int64_t start_time; ///< start time in microseconds == AV_TIME_BASE units |
||
384 | uint64_t limit_filesize; /* filesize limit expressed in bytes */ |
||
385 | |||
386 | int shortest; |
||
387 | } OutputFile; |
||
388 | |||
389 | extern InputStream **input_streams; |
||
390 | extern int nb_input_streams; |
||
391 | extern InputFile **input_files; |
||
392 | extern int nb_input_files; |
||
393 | |||
394 | extern OutputStream **output_streams; |
||
395 | extern int nb_output_streams; |
||
396 | extern OutputFile **output_files; |
||
397 | extern int nb_output_files; |
||
398 | |||
399 | extern FilterGraph **filtergraphs; |
||
400 | extern int nb_filtergraphs; |
||
401 | |||
402 | extern char *vstats_filename; |
||
403 | |||
404 | extern float audio_drift_threshold; |
||
405 | extern float dts_delta_threshold; |
||
406 | extern float dts_error_threshold; |
||
407 | |||
408 | extern int audio_volume; |
||
409 | extern int audio_sync_method; |
||
410 | extern int video_sync_method; |
||
411 | extern int do_benchmark; |
||
412 | extern int do_benchmark_all; |
||
413 | extern int do_deinterlace; |
||
414 | extern int do_hex_dump; |
||
415 | extern int do_pkt_dump; |
||
416 | extern int copy_ts; |
||
417 | extern int copy_tb; |
||
418 | extern int debug_ts; |
||
419 | extern int exit_on_error; |
||
420 | extern int print_stats; |
||
421 | extern int qp_hist; |
||
422 | extern int stdin_interaction; |
||
423 | extern int frame_bits_per_raw_sample; |
||
424 | extern AVIOContext *progress_avio; |
||
425 | extern float max_error_rate; |
||
426 | |||
427 | extern const AVIOInterruptCB int_cb; |
||
428 | |||
429 | extern const OptionDef options[]; |
||
430 | |||
431 | void term_init(void); |
||
432 | void term_exit(void); |
||
433 | |||
434 | void reset_options(OptionsContext *o, int is_input); |
||
435 | void show_usage(void); |
||
436 | |||
437 | void opt_output_file(void *optctx, const char *filename); |
||
438 | |||
439 | void assert_avoptions(AVDictionary *m); |
||
440 | |||
441 | int guess_input_channel_layout(InputStream *ist); |
||
442 | |||
443 | enum AVPixelFormat choose_pixel_fmt(AVStream *st, AVCodec *codec, enum AVPixelFormat target); |
||
444 | void choose_sample_fmt(AVStream *st, AVCodec *codec); |
||
445 | |||
446 | int configure_filtergraph(FilterGraph *fg); |
||
447 | int configure_output_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out); |
||
448 | int ist_in_filtergraph(FilterGraph *fg, InputStream *ist); |
||
449 | FilterGraph *init_simple_filtergraph(InputStream *ist, OutputStream *ost); |
||
450 | |||
451 | int ffmpeg_parse_options(int argc, char **argv); |
||
452 | |||
453 | #endif /* FFMPEG_H */>>>>> |