movenc.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /*
  2. * MOV, 3GP, MP4 muxer
  3. * Copyright (c) 2003 Thomas Raivio
  4. * Copyright (c) 2004 Gildas Bazin <gbazin at videolan dot org>
  5. * Copyright (c) 2009 Baptiste Coudurier <baptiste dot coudurier at gmail dot com>
  6. *
  7. * This file is part of FFmpeg.
  8. *
  9. * FFmpeg is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2.1 of the License, or (at your option) any later version.
  13. *
  14. * FFmpeg is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with FFmpeg; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. */
  23. #ifndef AVFORMAT_MOVENC_H
  24. #define AVFORMAT_MOVENC_H
  25. #include "avformat.h"
  26. #include "movenccenc.h"
  27. #define MOV_FRAG_INFO_ALLOC_INCREMENT 64
  28. #define MOV_INDEX_CLUSTER_SIZE 1024
  29. #define MOV_TIMESCALE 1000
  30. #define RTP_MAX_PACKET_SIZE 1450
  31. #define MODE_MP4 0x01
  32. #define MODE_MOV 0x02
  33. #define MODE_3GP 0x04
  34. #define MODE_PSP 0x08 // example working PSP command line:
  35. // ffmpeg -i testinput.avi -f psp -r 14.985 -s 320x240 -b 768 -ar 24000 -ab 32 M4V00001.MP4
  36. #define MODE_3G2 0x10
  37. #define MODE_IPOD 0x20
  38. #define MODE_ISM 0x40
  39. #define MODE_F4V 0x80
  40. typedef struct MOVIentry {
  41. uint64_t pos;
  42. int64_t dts;
  43. int64_t pts;
  44. unsigned int size;
  45. unsigned int samples_in_chunk;
  46. unsigned int chunkNum; ///< Chunk number if the current entry is a chunk start otherwise 0
  47. unsigned int entries;
  48. int cts;
  49. #define MOV_SYNC_SAMPLE 0x0001
  50. #define MOV_PARTIAL_SYNC_SAMPLE 0x0002
  51. #define MOV_DISPOSABLE_SAMPLE 0x0004
  52. uint32_t flags;
  53. AVProducerReferenceTime prft;
  54. } MOVIentry;
  55. typedef struct HintSample {
  56. uint8_t *data;
  57. int size;
  58. int sample_number;
  59. int offset;
  60. int own_data;
  61. } HintSample;
  62. typedef struct HintSampleQueue {
  63. int size;
  64. int len;
  65. HintSample *samples;
  66. } HintSampleQueue;
  67. typedef struct MOVFragmentInfo {
  68. int64_t offset;
  69. int64_t time;
  70. int64_t duration;
  71. int64_t tfrf_offset;
  72. int size;
  73. } MOVFragmentInfo;
  74. typedef struct MOVTrack {
  75. int mode;
  76. int entry;
  77. unsigned timescale;
  78. uint64_t time;
  79. int64_t track_duration;
  80. int last_sample_is_subtitle_end;
  81. long sample_count;
  82. long sample_size;
  83. long chunkCount;
  84. int has_keyframes;
  85. int has_disposable;
  86. #define MOV_TRACK_CTTS 0x0001
  87. #define MOV_TRACK_STPS 0x0002
  88. #define MOV_TRACK_ENABLED 0x0004
  89. uint32_t flags;
  90. #define MOV_TIMECODE_FLAG_DROPFRAME 0x0001
  91. #define MOV_TIMECODE_FLAG_24HOURSMAX 0x0002
  92. #define MOV_TIMECODE_FLAG_ALLOWNEGATIVE 0x0004
  93. uint32_t timecode_flags;
  94. int language;
  95. int track_id;
  96. int tag; ///< stsd fourcc
  97. AVStream *st;
  98. AVCodecParameters *par;
  99. int multichannel_as_mono;
  100. int vos_len;
  101. uint8_t *vos_data;
  102. MOVIentry *cluster;
  103. unsigned cluster_capacity;
  104. int audio_vbr;
  105. int height; ///< active picture (w/o VBI) height for D-10/IMX
  106. uint32_t tref_tag;
  107. int tref_id; ///< trackID of the referenced track
  108. int64_t start_dts;
  109. int64_t start_cts;
  110. int64_t end_pts;
  111. int end_reliable;
  112. int64_t dts_shift;
  113. int hint_track; ///< the track that hints this track, -1 if no hint track is set
  114. int src_track; ///< the track that this hint (or tmcd) track describes
  115. AVFormatContext *rtp_ctx; ///< the format context for the hinting rtp muxer
  116. uint32_t prev_rtp_ts;
  117. int64_t cur_rtp_ts_unwrapped;
  118. uint32_t max_packet_size;
  119. int64_t default_duration;
  120. uint32_t default_sample_flags;
  121. uint32_t default_size;
  122. HintSampleQueue sample_queue;
  123. AVPacket cover_image;
  124. AVIOContext *mdat_buf;
  125. int64_t data_offset;
  126. int64_t frag_start;
  127. int frag_discont;
  128. int entries_flushed;
  129. int nb_frag_info;
  130. MOVFragmentInfo *frag_info;
  131. unsigned frag_info_capacity;
  132. struct {
  133. int first_packet_seq;
  134. int first_packet_entry;
  135. int first_packet_seen;
  136. int first_frag_written;
  137. int packet_seq;
  138. int packet_entry;
  139. int slices;
  140. } vc1_info;
  141. void *eac3_priv;
  142. MOVMuxCencContext cenc;
  143. uint32_t palette[AVPALETTE_COUNT];
  144. int pal_done;
  145. int is_unaligned_qt_rgb;
  146. } MOVTrack;
  147. typedef enum {
  148. MOV_ENC_NONE = 0,
  149. MOV_ENC_CENC_AES_CTR,
  150. } MOVEncryptionScheme;
  151. typedef enum {
  152. MOV_PRFT_NONE = 0,
  153. MOV_PRFT_SRC_WALLCLOCK,
  154. MOV_PRFT_SRC_PTS,
  155. MOV_PRFT_NB
  156. } MOVPrftBox;
  157. typedef struct MOVMuxContext {
  158. const AVClass *av_class;
  159. int mode;
  160. int64_t time;
  161. int nb_streams;
  162. int nb_meta_tmcd; ///< number of new created tmcd track based on metadata (aka not data copy)
  163. int chapter_track; ///< qt chapter track number
  164. int64_t mdat_pos;
  165. uint64_t mdat_size;
  166. MOVTrack *tracks;
  167. int flags;
  168. int rtp_flags;
  169. int iods_skip;
  170. int iods_video_profile;
  171. int iods_audio_profile;
  172. int moov_written;
  173. int fragments;
  174. int max_fragment_duration;
  175. int min_fragment_duration;
  176. int max_fragment_size;
  177. int ism_lookahead;
  178. AVIOContext *mdat_buf;
  179. int first_trun;
  180. int video_track_timescale;
  181. int reserved_moov_size; ///< 0 for disabled, -1 for automatic, size otherwise
  182. int64_t reserved_header_pos;
  183. char *major_brand;
  184. int per_stream_grouping;
  185. AVFormatContext *fc;
  186. int use_editlist;
  187. float gamma;
  188. int frag_interleave;
  189. int missing_duration_warned;
  190. char *encryption_scheme_str;
  191. MOVEncryptionScheme encryption_scheme;
  192. uint8_t *encryption_key;
  193. int encryption_key_len;
  194. uint8_t *encryption_kid;
  195. int encryption_kid_len;
  196. int need_rewrite_extradata;
  197. int use_stream_ids_as_track_ids;
  198. int track_ids_ok;
  199. int write_tmcd;
  200. MOVPrftBox write_prft;
  201. int empty_hdlr_name;
  202. } MOVMuxContext;
  203. #define FF_MOV_FLAG_RTP_HINT (1 << 0)
  204. #define FF_MOV_FLAG_FRAGMENT (1 << 1)
  205. #define FF_MOV_FLAG_EMPTY_MOOV (1 << 2)
  206. #define FF_MOV_FLAG_FRAG_KEYFRAME (1 << 3)
  207. #define FF_MOV_FLAG_SEPARATE_MOOF (1 << 4)
  208. #define FF_MOV_FLAG_FRAG_CUSTOM (1 << 5)
  209. #define FF_MOV_FLAG_ISML (1 << 6)
  210. #define FF_MOV_FLAG_FASTSTART (1 << 7)
  211. #define FF_MOV_FLAG_OMIT_TFHD_OFFSET (1 << 8)
  212. #define FF_MOV_FLAG_DISABLE_CHPL (1 << 9)
  213. #define FF_MOV_FLAG_DEFAULT_BASE_MOOF (1 << 10)
  214. #define FF_MOV_FLAG_DASH (1 << 11)
  215. #define FF_MOV_FLAG_FRAG_DISCONT (1 << 12)
  216. #define FF_MOV_FLAG_DELAY_MOOV (1 << 13)
  217. #define FF_MOV_FLAG_GLOBAL_SIDX (1 << 14)
  218. #define FF_MOV_FLAG_WRITE_COLR (1 << 15)
  219. #define FF_MOV_FLAG_WRITE_GAMA (1 << 16)
  220. #define FF_MOV_FLAG_USE_MDTA (1 << 17)
  221. #define FF_MOV_FLAG_SKIP_TRAILER (1 << 18)
  222. #define FF_MOV_FLAG_NEGATIVE_CTS_OFFSETS (1 << 19)
  223. #define FF_MOV_FLAG_FRAG_EVERY_FRAME (1 << 20)
  224. #define FF_MOV_FLAG_SKIP_SIDX (1 << 21)
  225. #define FF_MOV_FLAG_CMAF (1 << 22)
  226. #define FF_MOV_FLAG_PREFER_ICC (1 << 23)
  227. int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt);
  228. int ff_mov_init_hinting(AVFormatContext *s, int index, int src_index);
  229. int ff_mov_add_hinted_packet(AVFormatContext *s, AVPacket *pkt,
  230. int track_index, int sample,
  231. uint8_t *sample_data, int sample_size);
  232. void ff_mov_close_hinting(MOVTrack *track);
  233. #endif /* AVFORMAT_MOVENC_H */