You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

369 lines
11KB

  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. #ifndef AVCONV_H
  19. #define AVCONV_H
  20. #include "config.h"
  21. #include <stdint.h>
  22. #include <stdio.h>
  23. #if HAVE_PTHREADS
  24. #include <pthread.h>
  25. #endif
  26. #include "cmdutils.h"
  27. #include "libavformat/avformat.h"
  28. #include "libavformat/avio.h"
  29. #include "libavcodec/avcodec.h"
  30. #include "libavfilter/avfilter.h"
  31. #include "libavfilter/avfiltergraph.h"
  32. #include "libavutil/avutil.h"
  33. #include "libavutil/dict.h"
  34. #include "libavutil/fifo.h"
  35. #include "libavutil/pixfmt.h"
  36. #include "libavutil/rational.h"
  37. #define VSYNC_AUTO -1
  38. #define VSYNC_PASSTHROUGH 0
  39. #define VSYNC_CFR 1
  40. #define VSYNC_VFR 2
  41. /* select an input stream for an output stream */
  42. typedef struct StreamMap {
  43. int disabled; /* 1 is this mapping is disabled by a negative map */
  44. int file_index;
  45. int stream_index;
  46. int sync_file_index;
  47. int sync_stream_index;
  48. char *linklabel; /* name of an output link, for mapping lavfi outputs */
  49. } StreamMap;
  50. /* select an input file for an output file */
  51. typedef struct MetadataMap {
  52. int file; // file index
  53. char type; // type of metadata to copy -- (g)lobal, (s)tream, (c)hapter or (p)rogram
  54. int index; // stream/chapter/program number
  55. } MetadataMap;
  56. typedef struct OptionsContext {
  57. OptionGroup *g;
  58. /* input/output options */
  59. int64_t start_time;
  60. const char *format;
  61. SpecifierOpt *codec_names;
  62. int nb_codec_names;
  63. SpecifierOpt *audio_channels;
  64. int nb_audio_channels;
  65. SpecifierOpt *audio_sample_rate;
  66. int nb_audio_sample_rate;
  67. SpecifierOpt *frame_rates;
  68. int nb_frame_rates;
  69. SpecifierOpt *frame_sizes;
  70. int nb_frame_sizes;
  71. SpecifierOpt *frame_pix_fmts;
  72. int nb_frame_pix_fmts;
  73. /* input options */
  74. int64_t input_ts_offset;
  75. int rate_emu;
  76. SpecifierOpt *ts_scale;
  77. int nb_ts_scale;
  78. SpecifierOpt *dump_attachment;
  79. int nb_dump_attachment;
  80. /* output options */
  81. StreamMap *stream_maps;
  82. int nb_stream_maps;
  83. /* first item specifies output metadata, second is input */
  84. MetadataMap (*meta_data_maps)[2];
  85. int nb_meta_data_maps;
  86. int metadata_global_manual;
  87. int metadata_streams_manual;
  88. int metadata_chapters_manual;
  89. const char **attachments;
  90. int nb_attachments;
  91. int chapters_input_file;
  92. int64_t recording_time;
  93. uint64_t limit_filesize;
  94. float mux_preload;
  95. float mux_max_delay;
  96. int shortest;
  97. int video_disable;
  98. int audio_disable;
  99. int subtitle_disable;
  100. int data_disable;
  101. /* indexed by output file stream index */
  102. int *streamid_map;
  103. int nb_streamid_map;
  104. SpecifierOpt *metadata;
  105. int nb_metadata;
  106. SpecifierOpt *max_frames;
  107. int nb_max_frames;
  108. SpecifierOpt *bitstream_filters;
  109. int nb_bitstream_filters;
  110. SpecifierOpt *codec_tags;
  111. int nb_codec_tags;
  112. SpecifierOpt *sample_fmts;
  113. int nb_sample_fmts;
  114. SpecifierOpt *qscale;
  115. int nb_qscale;
  116. SpecifierOpt *forced_key_frames;
  117. int nb_forced_key_frames;
  118. SpecifierOpt *force_fps;
  119. int nb_force_fps;
  120. SpecifierOpt *frame_aspect_ratios;
  121. int nb_frame_aspect_ratios;
  122. SpecifierOpt *rc_overrides;
  123. int nb_rc_overrides;
  124. SpecifierOpt *intra_matrices;
  125. int nb_intra_matrices;
  126. SpecifierOpt *inter_matrices;
  127. int nb_inter_matrices;
  128. SpecifierOpt *top_field_first;
  129. int nb_top_field_first;
  130. SpecifierOpt *metadata_map;
  131. int nb_metadata_map;
  132. SpecifierOpt *presets;
  133. int nb_presets;
  134. SpecifierOpt *copy_initial_nonkeyframes;
  135. int nb_copy_initial_nonkeyframes;
  136. SpecifierOpt *filters;
  137. int nb_filters;
  138. SpecifierOpt *pass;
  139. int nb_pass;
  140. SpecifierOpt *passlogfiles;
  141. int nb_passlogfiles;
  142. } OptionsContext;
  143. typedef struct InputFilter {
  144. AVFilterContext *filter;
  145. struct InputStream *ist;
  146. struct FilterGraph *graph;
  147. uint8_t *name;
  148. } InputFilter;
  149. typedef struct OutputFilter {
  150. AVFilterContext *filter;
  151. struct OutputStream *ost;
  152. struct FilterGraph *graph;
  153. uint8_t *name;
  154. /* temporary storage until stream maps are processed */
  155. AVFilterInOut *out_tmp;
  156. } OutputFilter;
  157. typedef struct FilterGraph {
  158. int index;
  159. const char *graph_desc;
  160. AVFilterGraph *graph;
  161. InputFilter **inputs;
  162. int nb_inputs;
  163. OutputFilter **outputs;
  164. int nb_outputs;
  165. } FilterGraph;
  166. typedef struct InputStream {
  167. int file_index;
  168. AVStream *st;
  169. int discard; /* true if stream data should be discarded */
  170. int decoding_needed; /* true if the packets must be decoded in 'raw_fifo' */
  171. AVCodec *dec;
  172. AVFrame *decoded_frame;
  173. int64_t start; /* time when read started */
  174. /* predicted dts of the next packet read for this stream or (when there are
  175. * several frames in a packet) of the next frame in current packet */
  176. int64_t next_dts;
  177. /* dts of the last packet read for this stream */
  178. int64_t last_dts;
  179. PtsCorrectionContext pts_ctx;
  180. double ts_scale;
  181. int is_start; /* is 1 at the start and after a discontinuity */
  182. int showed_multi_packet_warning;
  183. AVDictionary *opts;
  184. AVRational framerate; /* framerate forced with -r */
  185. int resample_height;
  186. int resample_width;
  187. int resample_pix_fmt;
  188. int resample_sample_fmt;
  189. int resample_sample_rate;
  190. int resample_channels;
  191. uint64_t resample_channel_layout;
  192. /* a pool of free buffers for decoded data */
  193. FrameBuffer *buffer_pool;
  194. /* decoded data from this stream goes into all those filters
  195. * currently video and audio only */
  196. InputFilter **filters;
  197. int nb_filters;
  198. } InputStream;
  199. typedef struct InputFile {
  200. AVFormatContext *ctx;
  201. int eof_reached; /* true if eof reached */
  202. int eagain; /* true if last read attempt returned EAGAIN */
  203. int ist_index; /* index of first stream in ist_table */
  204. int64_t ts_offset;
  205. int nb_streams; /* number of stream that avconv is aware of; may be different
  206. from ctx.nb_streams if new streams appear during av_read_frame() */
  207. int rate_emu;
  208. #if HAVE_PTHREADS
  209. pthread_t thread; /* thread reading from this file */
  210. int finished; /* the thread has exited */
  211. int joined; /* the thread has been joined */
  212. pthread_mutex_t fifo_lock; /* lock for access to fifo */
  213. pthread_cond_t fifo_cond; /* the main thread will signal on this cond after reading from fifo */
  214. AVFifoBuffer *fifo; /* demuxed packets are stored here; freed by the main thread */
  215. #endif
  216. } InputFile;
  217. typedef struct OutputStream {
  218. int file_index; /* file index */
  219. int index; /* stream index in the output file */
  220. int source_index; /* InputStream index */
  221. AVStream *st; /* stream in the output file */
  222. int encoding_needed; /* true if encoding needed for this stream */
  223. int frame_number;
  224. /* input pts and corresponding output pts
  225. for A/V sync */
  226. // double sync_ipts; /* dts from the AVPacket of the demuxer in second units */
  227. struct InputStream *sync_ist; /* input stream to sync against */
  228. int64_t sync_opts; /* output frame counter, could be changed to some true timestamp */ // FIXME look at frame_number
  229. /* pts of the first frame encoded for this stream, used for limiting
  230. * recording time */
  231. int64_t first_pts;
  232. AVBitStreamFilterContext *bitstream_filters;
  233. AVCodec *enc;
  234. int64_t max_frames;
  235. AVFrame *filtered_frame;
  236. /* video only */
  237. AVRational frame_rate;
  238. int force_fps;
  239. int top_field_first;
  240. float frame_aspect_ratio;
  241. /* forced key frames */
  242. int64_t *forced_kf_pts;
  243. int forced_kf_count;
  244. int forced_kf_index;
  245. char *forced_keyframes;
  246. char *logfile_prefix;
  247. FILE *logfile;
  248. OutputFilter *filter;
  249. char *avfilter;
  250. int64_t sws_flags;
  251. AVDictionary *opts;
  252. int finished; /* no more packets should be written for this stream */
  253. int stream_copy;
  254. const char *attachment_filename;
  255. int copy_initial_nonkeyframes;
  256. enum AVPixelFormat pix_fmts[2];
  257. } OutputStream;
  258. typedef struct OutputFile {
  259. AVFormatContext *ctx;
  260. AVDictionary *opts;
  261. int ost_index; /* index of the first stream in output_streams */
  262. int64_t recording_time; /* desired length of the resulting file in microseconds */
  263. int64_t start_time; /* start time in microseconds */
  264. uint64_t limit_filesize;
  265. int shortest;
  266. } OutputFile;
  267. extern InputStream **input_streams;
  268. extern int nb_input_streams;
  269. extern InputFile **input_files;
  270. extern int nb_input_files;
  271. extern OutputStream **output_streams;
  272. extern int nb_output_streams;
  273. extern OutputFile **output_files;
  274. extern int nb_output_files;
  275. extern FilterGraph **filtergraphs;
  276. extern int nb_filtergraphs;
  277. extern char *vstats_filename;
  278. extern float audio_drift_threshold;
  279. extern float dts_delta_threshold;
  280. extern int audio_volume;
  281. extern int audio_sync_method;
  282. extern int video_sync_method;
  283. extern int do_benchmark;
  284. extern int do_deinterlace;
  285. extern int do_hex_dump;
  286. extern int do_pkt_dump;
  287. extern int copy_ts;
  288. extern int copy_tb;
  289. extern int exit_on_error;
  290. extern int print_stats;
  291. extern int qp_hist;
  292. extern const AVIOInterruptCB int_cb;
  293. extern const OptionDef options[];
  294. void reset_options(OptionsContext *o);
  295. void show_usage(void);
  296. int opt_cpuflags(void *optctx, const char *opt, const char *arg);
  297. void opt_output_file(void *optctx, const char *filename);
  298. void assert_avoptions(AVDictionary *m);
  299. int guess_input_channel_layout(InputStream *ist);
  300. int configure_filtergraph(FilterGraph *fg);
  301. int configure_output_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out);
  302. int ist_in_filtergraph(FilterGraph *fg, InputStream *ist);
  303. FilterGraph *init_simple_filtergraph(InputStream *ist, OutputStream *ost);
  304. int avconv_parse_options(int argc, char **argv);
  305. #endif /* AVCONV_H */