FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ffmpeg.h
Go to the documentation of this file.
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"
48 
50 
51 #define VSYNC_AUTO -1
52 #define VSYNC_PASSTHROUGH 0
53 #define VSYNC_CFR 1
54 #define VSYNC_VFR 2
55 #define VSYNC_VSCFR 0xfe
56 #define VSYNC_DROP 0xff
57 
58 #define MAX_STREAMS 1024 /* arbitrary sanity check value */
59 
60 enum HWAccelID {
66 };
67 
68 typedef struct HWAccel {
69  const char *name;
70  int (*init)(AVCodecContext *s);
71  enum HWAccelID id;
73 } HWAccel;
74 
75 /* select an input stream for an output stream */
76 typedef struct StreamMap {
77  int disabled; /* 1 is this mapping is disabled by a negative map */
82  char *linklabel; /* name of an output link, for mapping lavfi outputs */
83 } StreamMap;
84 
85 typedef struct {
86  int file_idx, stream_idx, channel_idx; // input
87  int ofile_idx, ostream_idx; // output
89 
90 typedef struct OptionsContext {
92 
93  /* input/output options */
94  int64_t start_time;
95  const char *format;
96 
109 
110  /* input options */
112  int rate_emu;
114 
123 
124  /* output options */
127  AudioChannelMap *audio_channel_maps; /* one info entry per -map_channel */
128  int nb_audio_channel_maps; /* number of (valid) -map_channel settings */
132  const char **attachments;
134 
136 
137  int64_t recording_time;
138  int64_t stop_time;
139  uint64_t limit_filesize;
140  float mux_preload;
142  int shortest;
143 
148 
149  /* indexed by output file stream index */
152 
200  int nb_pass;
206  int nb_apad;
210 
211 typedef struct InputFilter {
213  struct InputStream *ist;
216 } InputFilter;
217 
218 typedef struct OutputFilter {
220  struct OutputStream *ost;
223 
224  /* temporary storage until stream maps are processed */
226 } OutputFilter;
227 
228 typedef struct FilterGraph {
229  int index;
230  const char *graph_desc;
231 
234 
239 } FilterGraph;
240 
241 typedef struct InputStream {
244  int discard; /* true if stream data should be discarded */
246  int decoding_needed; /* non zero if the packets must be decoded in 'raw_fifo', see DECODING_FOR_* */
247 #define DECODING_FOR_OST 1
248 #define DECODING_FOR_FILTER 2
249 
253  AVFrame *filter_frame; /* a ref of decoded_frame, to be sent to filters */
254 
255  int64_t start; /* time when read started */
256  /* predicted dts of the next packet read for this stream or (when there are
257  * several frames in a packet) of the next frame in current packet (in AV_TIME_BASE units) */
258  int64_t next_dts;
259  int64_t dts; ///< dts of the last packet read for this stream (in AV_TIME_BASE units)
260 
261  int64_t next_pts; ///< synthetic pts for the next decode frame (in AV_TIME_BASE units)
262  int64_t pts; ///< current pts of the decoded frame (in AV_TIME_BASE units)
264 
266 
267  double ts_scale;
271  AVRational framerate; /* framerate forced with -r */
274 
278 
283 
285  struct { /* previous decoded subtitle and related variables */
287  int ret;
289  } prev_sub;
290 
291  struct sub2video {
292  int64_t last_pts;
293  int64_t end_pts;
295  int w, h;
296  } sub2video;
297 
298  int dr1;
299 
300  /* decoded data from this stream goes into all those filters
301  * currently video and audio only */
304 
306 
307  /* hwaccel options */
310 
311  /* hwaccel context */
313  void *hwaccel_ctx;
319 
320  /* stats */
321  // combined size of all the packets read
322  uint64_t data_size;
323  /* number of packets successfully read for this stream */
324  uint64_t nb_packets;
325  // number of frames/samples retrieved from the decoder
326  uint64_t frames_decoded;
327  uint64_t samples_decoded;
328 } InputStream;
329 
330 typedef struct InputFile {
332  int eof_reached; /* true if eof reached */
333  int eagain; /* true if last read attempt returned EAGAIN */
334  int ist_index; /* index of first stream in input_streams */
336  int64_t ts_offset;
337  int64_t last_ts;
338  int64_t start_time; /* user-specified start time in AV_TIME_BASE or AV_NOPTS_VALUE */
339  int64_t recording_time;
340  int nb_streams; /* number of stream that ffmpeg is aware of; may be different
341  from ctx.nb_streams if new streams appear during av_read_frame() */
342  int nb_streams_warn; /* number of streams that the user was warned of */
343  int rate_emu;
345 
346 #if HAVE_PTHREADS
347  AVThreadMessageQueue *in_thread_queue;
348  pthread_t thread; /* thread reading from this file */
349  int non_blocking; /* reading packets from the thread should not block */
350  int joined; /* the thread has been joined */
351 #endif
352 } InputFile;
353 
361 };
362 
363 extern const char *const forced_keyframes_const_names[];
364 
365 typedef enum {
368 } OSTFinished ;
369 
370 typedef struct OutputStream {
371  int file_index; /* file index */
372  int index; /* stream index in the output file */
373  int source_index; /* InputStream index */
374  AVStream *st; /* stream in the output file */
375  int encoding_needed; /* true if encoding needed for this stream */
377  /* input pts and corresponding output pts
378  for A/V sync */
379  struct InputStream *sync_ist; /* input stream to sync against */
380  int64_t sync_opts; /* output frame counter, could be changed to some true timestamp */ // FIXME look at frame_number
381  /* pts of the first frame encoded for this stream, used for limiting
382  * recording time */
383  int64_t first_pts;
384  /* dts of the last packet sent to the muxer */
385  int64_t last_mux_dts;
389  int64_t max_frames;
393 
394  /* video only */
398 
400 
401  /* forced key frames */
402  int64_t *forced_kf_pts;
408 
409  /* audio only */
410  int *audio_channels_map; /* list of the channels id to pick from the source stream */
411  int audio_channels_mapped; /* number of channels in audio_channels_map */
412 
414  FILE *logfile;
415 
417  char *avfilter;
418  char *filters; ///< filtergraph associated to the -filter option
419  char *filters_script; ///< filtergraph script associated to the -filter_script option
420 
421  int64_t sws_flags;
425  char *apad;
426  OSTFinished finished; /* no more packets should be written for this stream */
427  int unavailable; /* true if the steram is unavailable (possibly temporarily) */
429  const char *attachment_filename;
432 
434 
436 
437  /* stats */
438  // combined size of all the packets written
439  uint64_t data_size;
440  // number of packets send to the muxer
441  uint64_t packets_written;
442  // number of frames/samples sent to the encoder
443  uint64_t frames_encoded;
444  uint64_t samples_encoded;
445 } OutputStream;
446 
447 typedef struct OutputFile {
450  int ost_index; /* index of the first stream in output_streams */
451  int64_t recording_time; ///< desired length of the resulting file in microseconds == AV_TIME_BASE units
452  int64_t start_time; ///< start time in microseconds == AV_TIME_BASE units
453  uint64_t limit_filesize; /* filesize limit expressed in bytes */
454 
455  int shortest;
456 } OutputFile;
457 
458 extern InputStream **input_streams;
459 extern int nb_input_streams;
460 extern InputFile **input_files;
461 extern int nb_input_files;
462 
464 extern int nb_output_streams;
465 extern OutputFile **output_files;
466 extern int nb_output_files;
467 
468 extern FilterGraph **filtergraphs;
469 extern int nb_filtergraphs;
470 
471 extern char *vstats_filename;
472 
473 extern float audio_drift_threshold;
474 extern float dts_delta_threshold;
475 extern float dts_error_threshold;
476 
477 extern int audio_volume;
478 extern int audio_sync_method;
479 extern int video_sync_method;
480 extern int do_benchmark;
481 extern int do_benchmark_all;
482 extern int do_deinterlace;
483 extern int do_hex_dump;
484 extern int do_pkt_dump;
485 extern int copy_ts;
486 extern int start_at_zero;
487 extern int copy_tb;
488 extern int debug_ts;
489 extern int exit_on_error;
490 extern int print_stats;
491 extern int qp_hist;
492 extern int stdin_interaction;
493 extern int frame_bits_per_raw_sample;
494 extern AVIOContext *progress_avio;
495 extern float max_error_rate;
496 extern int vdpau_api_ver;
497 
498 extern const AVIOInterruptCB int_cb;
499 
500 extern const OptionDef options[];
501 extern const HWAccel hwaccels[];
502 
503 
504 void term_init(void);
505 void term_exit(void);
506 
507 void reset_options(OptionsContext *o, int is_input);
508 void show_usage(void);
509 
510 void opt_output_file(void *optctx, const char *filename);
511 
514 
516 
517 enum AVPixelFormat choose_pixel_fmt(AVStream *st, AVCodecContext *avctx, AVCodec *codec, enum AVPixelFormat target);
518 void choose_sample_fmt(AVStream *st, AVCodec *codec);
519 
524 
525 int ffmpeg_parse_options(int argc, char **argv);
526 
530 
531 #endif /* FFMPEG_H */