movenc.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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_INDEX_CLUSTER_SIZE 16384
  27. #define MOV_TIMESCALE 1000
  28. #define RTP_MAX_PACKET_SIZE 1450
  29. #define MODE_MP4 0x01
  30. #define MODE_MOV 0x02
  31. #define MODE_3GP 0x04
  32. #define MODE_PSP 0x08 // example working PSP command line:
  33. // ffmpeg -i testinput.avi -f psp -r 14.985 -s 320x240 -b 768 -ar 24000 -ab 32 M4V00001.MP4
  34. #define MODE_3G2 0x10
  35. #define MODE_IPOD 0x20
  36. #define MODE_ISM 0x40
  37. #define MODE_F4V 0x80
  38. typedef struct MOVIentry {
  39. uint64_t pos;
  40. int64_t dts;
  41. unsigned int size;
  42. unsigned int samples_in_chunk;
  43. unsigned int chunkNum; ///< Chunk number if the current entry is a chunk start otherwise 0
  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 {
  58. int size;
  59. int len;
  60. HintSample *samples;
  61. } HintSampleQueue;
  62. typedef struct {
  63. int64_t offset;
  64. int64_t time;
  65. int64_t duration;
  66. int64_t tfrf_offset;
  67. } MOVFragmentInfo;
  68. typedef struct MOVIndex {
  69. int mode;
  70. int entry;
  71. unsigned timescale;
  72. uint64_t time;
  73. int64_t track_duration;
  74. int last_sample_is_subtitle_end;
  75. long sample_count;
  76. long sample_size;
  77. long chunkCount;
  78. int has_keyframes;
  79. #define MOV_TRACK_CTTS 0x0001
  80. #define MOV_TRACK_STPS 0x0002
  81. uint32_t flags;
  82. #define MOV_TIMECODE_FLAG_DROPFRAME 0x0001
  83. #define MOV_TIMECODE_FLAG_24HOURSMAX 0x0002
  84. #define MOV_TIMECODE_FLAG_ALLOWNEGATIVE 0x0004
  85. uint32_t timecode_flags;
  86. int language;
  87. int track_id;
  88. int tag; ///< stsd fourcc
  89. AVCodecContext *enc;
  90. int vos_len;
  91. uint8_t *vos_data;
  92. MOVIentry *cluster;
  93. int audio_vbr;
  94. int height; ///< active picture (w/o VBI) height for D-10/IMX
  95. uint32_t tref_tag;
  96. int tref_id; ///< trackID of the referenced track
  97. int64_t start_dts;
  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 (or tmcd) 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 moof_size_offset;
  110. int64_t data_offset;
  111. int64_t frag_start;
  112. int64_t tfrf_offset;
  113. int nb_frag_info;
  114. MOVFragmentInfo *frag_info;
  115. struct {
  116. int64_t struct_offset;
  117. int first_packet_seq;
  118. int first_packet_entry;
  119. int packet_seq;
  120. int packet_entry;
  121. int slices;
  122. } vc1_info;
  123. } MOVTrack;
  124. typedef struct MOVMuxContext {
  125. const AVClass *av_class;
  126. int mode;
  127. int64_t time;
  128. int nb_streams;
  129. int nb_meta_tmcd; ///< number of new created tmcd track based on metadata (aka not data copy)
  130. int chapter_track; ///< qt chapter track number
  131. int64_t mdat_pos;
  132. uint64_t mdat_size;
  133. MOVTrack *tracks;
  134. int flags;
  135. int rtp_flags;
  136. int reserved_moov_size; ///< 0 for disabled, -1 for automatic, size otherwise
  137. int64_t reserved_moov_pos;
  138. int iods_skip;
  139. int iods_video_profile;
  140. int iods_audio_profile;
  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. } MOVMuxContext;
  148. #define FF_MOV_FLAG_RTP_HINT 1
  149. #define FF_MOV_FLAG_FRAGMENT 2
  150. #define FF_MOV_FLAG_EMPTY_MOOV 4
  151. #define FF_MOV_FLAG_FRAG_KEYFRAME 8
  152. #define FF_MOV_FLAG_SEPARATE_MOOF 16
  153. #define FF_MOV_FLAG_FRAG_CUSTOM 32
  154. #define FF_MOV_FLAG_ISML 64
  155. #define FF_MOV_FLAG_FASTSTART 128
  156. int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt);
  157. int ff_mov_init_hinting(AVFormatContext *s, int index, int src_index);
  158. int ff_mov_add_hinted_packet(AVFormatContext *s, AVPacket *pkt,
  159. int track_index, int sample,
  160. uint8_t *sample_data, int sample_size);
  161. void ff_mov_close_hinting(MOVTrack *track);
  162. #endif /* AVFORMAT_MOVENC_H */