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.

205 lines
5.8KB

  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. #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. // ffmpeg -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 chunkNum; ///< Chunk number if the current entry is a chunk start otherwise 0
  45. unsigned int entries;
  46. int cts;
  47. #define MOV_SYNC_SAMPLE 0x0001
  48. #define MOV_PARTIAL_SYNC_SAMPLE 0x0002
  49. uint32_t flags;
  50. } MOVIentry;
  51. typedef struct HintSample {
  52. uint8_t *data;
  53. int size;
  54. int sample_number;
  55. int offset;
  56. int own_data;
  57. } HintSample;
  58. typedef struct HintSampleQueue {
  59. int size;
  60. int len;
  61. HintSample *samples;
  62. } HintSampleQueue;
  63. typedef struct MOVFragmentInfo {
  64. int64_t offset;
  65. int64_t time;
  66. int64_t duration;
  67. int64_t tfrf_offset;
  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. int last_sample_is_subtitle_end;
  76. long sample_count;
  77. long sample_size;
  78. long chunkCount;
  79. int has_keyframes;
  80. #define MOV_TRACK_CTTS 0x0001
  81. #define MOV_TRACK_STPS 0x0002
  82. #define MOV_TRACK_ENABLED 0x0004
  83. uint32_t flags;
  84. #define MOV_TIMECODE_FLAG_DROPFRAME 0x0001
  85. #define MOV_TIMECODE_FLAG_24HOURSMAX 0x0002
  86. #define MOV_TIMECODE_FLAG_ALLOWNEGATIVE 0x0004
  87. uint32_t timecode_flags;
  88. int language;
  89. int track_id;
  90. int tag; ///< stsd fourcc
  91. AVStream *st;
  92. AVCodecContext *enc;
  93. int multichannel_as_mono;
  94. int vos_len;
  95. uint8_t *vos_data;
  96. MOVIentry *cluster;
  97. unsigned cluster_capacity;
  98. int audio_vbr;
  99. int height; ///< active picture (w/o VBI) height for D-10/IMX
  100. uint32_t tref_tag;
  101. int tref_id; ///< trackID of the referenced track
  102. int64_t start_dts;
  103. int hint_track; ///< the track that hints this track, -1 if no hint track is set
  104. int src_track; ///< the track that this hint (or tmcd) track describes
  105. AVFormatContext *rtp_ctx; ///< the format context for the hinting rtp muxer
  106. uint32_t prev_rtp_ts;
  107. int64_t cur_rtp_ts_unwrapped;
  108. uint32_t max_packet_size;
  109. int64_t default_duration;
  110. uint32_t default_sample_flags;
  111. uint32_t default_size;
  112. HintSampleQueue sample_queue;
  113. AVIOContext *mdat_buf;
  114. int64_t data_offset;
  115. int64_t frag_start;
  116. int64_t tfrf_offset;
  117. int nb_frag_info;
  118. MOVFragmentInfo *frag_info;
  119. unsigned frag_info_capacity;
  120. struct {
  121. int64_t struct_offset;
  122. int first_packet_seq;
  123. int first_packet_entry;
  124. int packet_seq;
  125. int packet_entry;
  126. int slices;
  127. } vc1_info;
  128. } MOVTrack;
  129. typedef struct MOVMuxContext {
  130. const AVClass *av_class;
  131. int mode;
  132. int64_t time;
  133. int nb_streams;
  134. int nb_meta_tmcd; ///< number of new created tmcd track based on metadata (aka not data copy)
  135. int chapter_track; ///< qt chapter track number
  136. int64_t mdat_pos;
  137. uint64_t mdat_size;
  138. MOVTrack *tracks;
  139. int flags;
  140. int rtp_flags;
  141. int exact;
  142. int iods_skip;
  143. int iods_video_profile;
  144. int iods_audio_profile;
  145. int fragments;
  146. int max_fragment_duration;
  147. int min_fragment_duration;
  148. int max_fragment_size;
  149. int ism_lookahead;
  150. AVIOContext *mdat_buf;
  151. int use_editlist;
  152. int video_track_timescale;
  153. int reserved_moov_size; ///< 0 for disabled, -1 for automatic, size otherwise
  154. int64_t reserved_moov_pos;
  155. char *major_brand;
  156. int per_stream_grouping;
  157. AVFormatContext *fc;
  158. } MOVMuxContext;
  159. #define FF_MOV_FLAG_RTP_HINT 1
  160. #define FF_MOV_FLAG_FRAGMENT 2
  161. #define FF_MOV_FLAG_EMPTY_MOOV 4
  162. #define FF_MOV_FLAG_FRAG_KEYFRAME 8
  163. #define FF_MOV_FLAG_SEPARATE_MOOF 16
  164. #define FF_MOV_FLAG_FRAG_CUSTOM 32
  165. #define FF_MOV_FLAG_ISML 64
  166. #define FF_MOV_FLAG_FASTSTART 128
  167. #define FF_MOV_FLAG_OMIT_TFHD_OFFSET 256
  168. #define FF_MOV_FLAG_DISABLE_CHPL 512
  169. int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt);
  170. int ff_mov_init_hinting(AVFormatContext *s, int index, int src_index);
  171. int ff_mov_add_hinted_packet(AVFormatContext *s, AVPacket *pkt,
  172. int track_index, int sample,
  173. uint8_t *sample_data, int sample_size);
  174. void ff_mov_close_hinting(MOVTrack *track);
  175. #endif /* AVFORMAT_MOVENC_H */