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.

206 lines
5.9KB

  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 Libav.
  8. *
  9. * Libav 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. * Libav 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 Libav; 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. #define MOV_FRAG_INFO_ALLOC_INCREMENT 64
  27. #define MOV_INDEX_CLUSTER_SIZE 1024
  28. #define MOV_TIMESCALE 1000
  29. #define RTP_MAX_PACKET_SIZE 1450
  30. #define MODE_MP4 0x01
  31. #define MODE_MOV 0x02
  32. #define MODE_3GP 0x04
  33. #define MODE_PSP 0x08 // example working PSP command line:
  34. // avconv -i testinput.avi -f psp -r 14.985 -s 320x240 -b 768 -ar 24000 -ab 32 M4V00001.MP4
  35. #define MODE_3G2 0x10
  36. #define MODE_IPOD 0x20
  37. #define MODE_ISM 0x40
  38. #define MODE_F4V 0x80
  39. typedef struct MOVIentry {
  40. uint64_t pos;
  41. int64_t dts;
  42. unsigned int size;
  43. unsigned int samples_in_chunk;
  44. unsigned int entries;
  45. int cts;
  46. #define MOV_SYNC_SAMPLE 0x0001
  47. #define MOV_PARTIAL_SYNC_SAMPLE 0x0002
  48. uint32_t flags;
  49. } MOVIentry;
  50. typedef struct HintSample {
  51. uint8_t *data;
  52. int size;
  53. int sample_number;
  54. int offset;
  55. int own_data;
  56. } HintSample;
  57. typedef struct HintSampleQueue {
  58. int size;
  59. int len;
  60. HintSample *samples;
  61. } HintSampleQueue;
  62. typedef struct MOVFragmentInfo {
  63. int64_t offset;
  64. int64_t time;
  65. int64_t duration;
  66. int64_t tfrf_offset;
  67. int size;
  68. } MOVFragmentInfo;
  69. typedef struct MOVTrack {
  70. int mode;
  71. int entry;
  72. unsigned timescale;
  73. uint64_t time;
  74. int64_t track_duration;
  75. long sample_count;
  76. long sample_size;
  77. int has_keyframes;
  78. #define MOV_TRACK_CTTS 0x0001
  79. #define MOV_TRACK_STPS 0x0002
  80. #define MOV_TRACK_ENABLED 0x0004
  81. uint32_t flags;
  82. int language;
  83. int track_id;
  84. int tag; ///< stsd fourcc
  85. AVStream *st;
  86. AVCodecContext *enc;
  87. int vos_len;
  88. uint8_t *vos_data;
  89. MOVIentry *cluster;
  90. unsigned cluster_capacity;
  91. int audio_vbr;
  92. int height; ///< active picture (w/o VBI) height for D-10/IMX
  93. uint32_t tref_tag;
  94. int tref_id; ///< trackID of the referenced track
  95. int64_t start_dts;
  96. int64_t start_cts;
  97. int64_t end_pts;
  98. int hint_track; ///< the track that hints this track, -1 if no hint track is set
  99. int src_track; ///< the track that this hint track describes
  100. AVFormatContext *rtp_ctx; ///< the format context for the hinting rtp muxer
  101. uint32_t prev_rtp_ts;
  102. int64_t cur_rtp_ts_unwrapped;
  103. uint32_t max_packet_size;
  104. int64_t default_duration;
  105. uint32_t default_sample_flags;
  106. uint32_t default_size;
  107. HintSampleQueue sample_queue;
  108. AVIOContext *mdat_buf;
  109. int64_t data_offset;
  110. int64_t frag_start;
  111. int frag_discont;
  112. int entries_flushed;
  113. int nb_frag_info;
  114. MOVFragmentInfo *frag_info;
  115. unsigned frag_info_capacity;
  116. struct {
  117. int first_packet_seq;
  118. int first_packet_entry;
  119. int first_packet_seen;
  120. int first_frag_written;
  121. int packet_seq;
  122. int packet_entry;
  123. int slices;
  124. } vc1_info;
  125. } MOVTrack;
  126. typedef struct MOVMuxContext {
  127. const AVClass *av_class;
  128. int mode;
  129. int64_t time;
  130. int nb_streams;
  131. int chapter_track; ///< qt chapter track number
  132. int64_t mdat_pos;
  133. uint64_t mdat_size;
  134. MOVTrack *tracks;
  135. int flags;
  136. int rtp_flags;
  137. int iods_skip;
  138. int iods_video_profile;
  139. int iods_audio_profile;
  140. int moov_written;
  141. int fragments;
  142. int max_fragment_duration;
  143. int min_fragment_duration;
  144. int max_fragment_size;
  145. int ism_lookahead;
  146. AVIOContext *mdat_buf;
  147. int first_trun;
  148. int64_t reserved_header_pos;
  149. char *major_brand;
  150. int per_stream_grouping;
  151. AVFormatContext *fc;
  152. int use_editlist;
  153. int frag_interleave;
  154. int missing_duration_warned;
  155. } MOVMuxContext;
  156. #define FF_MOV_FLAG_RTP_HINT (1 << 0)
  157. #define FF_MOV_FLAG_FRAGMENT (1 << 1)
  158. #define FF_MOV_FLAG_EMPTY_MOOV (1 << 2)
  159. #define FF_MOV_FLAG_FRAG_KEYFRAME (1 << 3)
  160. #define FF_MOV_FLAG_SEPARATE_MOOF (1 << 4)
  161. #define FF_MOV_FLAG_FRAG_CUSTOM (1 << 5)
  162. #define FF_MOV_FLAG_ISML (1 << 6)
  163. #define FF_MOV_FLAG_FASTSTART (1 << 7)
  164. #define FF_MOV_FLAG_OMIT_TFHD_OFFSET (1 << 8)
  165. #define FF_MOV_FLAG_DISABLE_CHPL (1 << 9)
  166. #define FF_MOV_FLAG_DEFAULT_BASE_MOOF (1 << 10)
  167. #define FF_MOV_FLAG_DASH (1 << 11)
  168. #define FF_MOV_FLAG_FRAG_DISCONT (1 << 12)
  169. #define FF_MOV_FLAG_DELAY_MOOV (1 << 13)
  170. #define FF_MOV_FLAG_GLOBAL_SIDX (1 << 14)
  171. int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt);
  172. int ff_mov_init_hinting(AVFormatContext *s, int index, int src_index);
  173. int ff_mov_add_hinted_packet(AVFormatContext *s, AVPacket *pkt,
  174. int track_index, int sample,
  175. uint8_t *sample_data, int sample_size);
  176. void ff_mov_close_hinting(MOVTrack *track);
  177. #endif /* AVFORMAT_MOVENC_H */