Ticket #3014: ffmpeg.h

File ffmpeg.h, 13.7 KB (added by cyril, 13 years ago)

JpegTest.cpp converted to C (1/2)

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