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.

259 lines
7.5KB

  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. unsigned int size;
  44. unsigned int samples_in_chunk;
  45. unsigned int chunkNum; ///< Chunk number if the current entry is a chunk start otherwise 0
  46. unsigned int entries;
  47. int cts;
  48. #define MOV_SYNC_SAMPLE 0x0001
  49. #define MOV_PARTIAL_SYNC_SAMPLE 0x0002
  50. #define MOV_DISPOSABLE_SAMPLE 0x0004
  51. uint32_t flags;
  52. } MOVIentry;
  53. typedef struct HintSample {
  54. uint8_t *data;
  55. int size;
  56. int sample_number;
  57. int offset;
  58. int own_data;
  59. } HintSample;
  60. typedef struct HintSampleQueue {
  61. int size;
  62. int len;
  63. HintSample *samples;
  64. } HintSampleQueue;
  65. typedef struct MOVFragmentInfo {
  66. int64_t offset;
  67. int64_t time;
  68. int64_t duration;
  69. int64_t tfrf_offset;
  70. int size;
  71. } MOVFragmentInfo;
  72. typedef struct MOVTrack {
  73. int mode;
  74. int entry;
  75. unsigned timescale;
  76. uint64_t time;
  77. int64_t track_duration;
  78. int last_sample_is_subtitle_end;
  79. long sample_count;
  80. long sample_size;
  81. long chunkCount;
  82. int has_keyframes;
  83. int has_disposable;
  84. #define MOV_TRACK_CTTS 0x0001
  85. #define MOV_TRACK_STPS 0x0002
  86. #define MOV_TRACK_ENABLED 0x0004
  87. uint32_t flags;
  88. #define MOV_TIMECODE_FLAG_DROPFRAME 0x0001
  89. #define MOV_TIMECODE_FLAG_24HOURSMAX 0x0002
  90. #define MOV_TIMECODE_FLAG_ALLOWNEGATIVE 0x0004
  91. uint32_t timecode_flags;
  92. int language;
  93. int track_id;
  94. int tag; ///< stsd fourcc
  95. AVStream *st;
  96. AVCodecParameters *par;
  97. int multichannel_as_mono;
  98. int vos_len;
  99. uint8_t *vos_data;
  100. MOVIentry *cluster;
  101. unsigned cluster_capacity;
  102. int audio_vbr;
  103. int height; ///< active picture (w/o VBI) height for D-10/IMX
  104. uint32_t tref_tag;
  105. int tref_id; ///< trackID of the referenced track
  106. int64_t start_dts;
  107. int64_t start_cts;
  108. int64_t end_pts;
  109. int end_reliable;
  110. int64_t dts_shift;
  111. int hint_track; ///< the track that hints this track, -1 if no hint track is set
  112. int src_track; ///< the track that this hint (or tmcd) track describes
  113. AVFormatContext *rtp_ctx; ///< the format context for the hinting rtp muxer
  114. uint32_t prev_rtp_ts;
  115. int64_t cur_rtp_ts_unwrapped;
  116. uint32_t max_packet_size;
  117. int64_t default_duration;
  118. uint32_t default_sample_flags;
  119. uint32_t default_size;
  120. HintSampleQueue sample_queue;
  121. AVIOContext *mdat_buf;
  122. int64_t data_offset;
  123. int64_t frag_start;
  124. int frag_discont;
  125. int entries_flushed;
  126. int nb_frag_info;
  127. MOVFragmentInfo *frag_info;
  128. unsigned frag_info_capacity;
  129. struct {
  130. int first_packet_seq;
  131. int first_packet_entry;
  132. int first_packet_seen;
  133. int first_frag_written;
  134. int packet_seq;
  135. int packet_entry;
  136. int slices;
  137. } vc1_info;
  138. void *eac3_priv;
  139. MOVMuxCencContext cenc;
  140. uint32_t palette[AVPALETTE_COUNT];
  141. int pal_done;
  142. int is_unaligned_qt_rgb;
  143. } MOVTrack;
  144. typedef enum {
  145. MOV_ENC_NONE = 0,
  146. MOV_ENC_CENC_AES_CTR,
  147. } MOVEncryptionScheme;
  148. typedef struct MOVMuxContext {
  149. const AVClass *av_class;
  150. int mode;
  151. int64_t time;
  152. int nb_streams;
  153. int nb_meta_tmcd; ///< number of new created tmcd track based on metadata (aka not data copy)
  154. int chapter_track; ///< qt chapter track number
  155. int64_t mdat_pos;
  156. uint64_t mdat_size;
  157. MOVTrack *tracks;
  158. int flags;
  159. int rtp_flags;
  160. int iods_skip;
  161. int iods_video_profile;
  162. int iods_audio_profile;
  163. int moov_written;
  164. int fragments;
  165. int max_fragment_duration;
  166. int min_fragment_duration;
  167. int max_fragment_size;
  168. int ism_lookahead;
  169. AVIOContext *mdat_buf;
  170. int first_trun;
  171. int video_track_timescale;
  172. int reserved_moov_size; ///< 0 for disabled, -1 for automatic, size otherwise
  173. int64_t reserved_header_pos;
  174. char *major_brand;
  175. int per_stream_grouping;
  176. AVFormatContext *fc;
  177. int use_editlist;
  178. float gamma;
  179. int frag_interleave;
  180. int missing_duration_warned;
  181. char *encryption_scheme_str;
  182. MOVEncryptionScheme encryption_scheme;
  183. uint8_t *encryption_key;
  184. int encryption_key_len;
  185. uint8_t *encryption_kid;
  186. int encryption_kid_len;
  187. int need_rewrite_extradata;
  188. int use_stream_ids_as_track_ids;
  189. int track_ids_ok;
  190. int write_tmcd;
  191. } MOVMuxContext;
  192. #define FF_MOV_FLAG_RTP_HINT (1 << 0)
  193. #define FF_MOV_FLAG_FRAGMENT (1 << 1)
  194. #define FF_MOV_FLAG_EMPTY_MOOV (1 << 2)
  195. #define FF_MOV_FLAG_FRAG_KEYFRAME (1 << 3)
  196. #define FF_MOV_FLAG_SEPARATE_MOOF (1 << 4)
  197. #define FF_MOV_FLAG_FRAG_CUSTOM (1 << 5)
  198. #define FF_MOV_FLAG_ISML (1 << 6)
  199. #define FF_MOV_FLAG_FASTSTART (1 << 7)
  200. #define FF_MOV_FLAG_OMIT_TFHD_OFFSET (1 << 8)
  201. #define FF_MOV_FLAG_DISABLE_CHPL (1 << 9)
  202. #define FF_MOV_FLAG_DEFAULT_BASE_MOOF (1 << 10)
  203. #define FF_MOV_FLAG_DASH (1 << 11)
  204. #define FF_MOV_FLAG_FRAG_DISCONT (1 << 12)
  205. #define FF_MOV_FLAG_DELAY_MOOV (1 << 13)
  206. #define FF_MOV_FLAG_GLOBAL_SIDX (1 << 14)
  207. #define FF_MOV_FLAG_WRITE_COLR (1 << 15)
  208. #define FF_MOV_FLAG_WRITE_GAMA (1 << 16)
  209. #define FF_MOV_FLAG_USE_MDTA (1 << 17)
  210. #define FF_MOV_FLAG_SKIP_TRAILER (1 << 18)
  211. #define FF_MOV_FLAG_NEGATIVE_CTS_OFFSETS (1 << 19)
  212. #define FF_MOV_FLAG_FRAG_EVERY_FRAME (1 << 20)
  213. int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt);
  214. int ff_mov_init_hinting(AVFormatContext *s, int index, int src_index);
  215. int ff_mov_add_hinted_packet(AVFormatContext *s, AVPacket *pkt,
  216. int track_index, int sample,
  217. uint8_t *sample_data, int sample_size);
  218. void ff_mov_close_hinting(MOVTrack *track);
  219. #endif /* AVFORMAT_MOVENC_H */