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.

266 lines
8.6KB

  1. /*
  2. * ISO Media common code
  3. * copyright (c) 2001 Fabrice Bellard
  4. * copyright (c) 2002 Francois Revol <revol@free.fr>
  5. * copyright (c) 2006 Baptiste Coudurier <baptiste.coudurier@free.fr>
  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_ISOM_H
  24. #define AVFORMAT_ISOM_H
  25. #include "avio.h"
  26. #include "internal.h"
  27. #include "dv.h"
  28. /* isom.c */
  29. extern const AVCodecTag ff_mp4_obj_type[];
  30. extern const AVCodecTag ff_codec_movvideo_tags[];
  31. extern const AVCodecTag ff_codec_movaudio_tags[];
  32. extern const AVCodecTag ff_codec_movsubtitle_tags[];
  33. int ff_mov_iso639_to_lang(const char lang[4], int mp4);
  34. int ff_mov_lang_to_iso639(unsigned code, char to[4]);
  35. /* the QuickTime file format is quite convoluted...
  36. * it has lots of index tables, each indexing something in another one...
  37. * Here we just use what is needed to read the chunks
  38. */
  39. typedef struct MOVStts {
  40. int count;
  41. int duration;
  42. } MOVStts;
  43. typedef struct MOVStsc {
  44. int first;
  45. int count;
  46. int id;
  47. } MOVStsc;
  48. typedef struct MOVDref {
  49. uint32_t type;
  50. char *path;
  51. char *dir;
  52. char volume[28];
  53. char filename[64];
  54. int16_t nlvl_to, nlvl_from;
  55. } MOVDref;
  56. typedef struct MOVAtom {
  57. uint32_t type;
  58. int64_t size; /* total size (excluding the size and type fields) */
  59. } MOVAtom;
  60. struct MOVParseTableEntry;
  61. typedef struct MOVFragment {
  62. unsigned track_id;
  63. uint64_t base_data_offset;
  64. uint64_t moof_offset;
  65. uint64_t implicit_offset;
  66. unsigned stsd_id;
  67. unsigned duration;
  68. unsigned size;
  69. unsigned flags;
  70. int64_t time;
  71. } MOVFragment;
  72. typedef struct MOVTrackExt {
  73. unsigned track_id;
  74. unsigned stsd_id;
  75. unsigned duration;
  76. unsigned size;
  77. unsigned flags;
  78. } MOVTrackExt;
  79. typedef struct MOVSbgp {
  80. unsigned int count;
  81. unsigned int index;
  82. } MOVSbgp;
  83. typedef struct MOVFragmentIndexItem {
  84. int64_t moof_offset;
  85. int64_t time;
  86. } MOVFragmentIndexItem;
  87. typedef struct MOVFragmentIndex {
  88. unsigned track_id;
  89. unsigned item_count;
  90. unsigned current_item;
  91. MOVFragmentIndexItem *items;
  92. } MOVFragmentIndex;
  93. typedef struct MOVStreamContext {
  94. AVIOContext *pb;
  95. int pb_is_copied;
  96. int ffindex; ///< AVStream index
  97. int next_chunk;
  98. unsigned int chunk_count;
  99. int64_t *chunk_offsets;
  100. unsigned int stts_count;
  101. MOVStts *stts_data;
  102. unsigned int ctts_count;
  103. MOVStts *ctts_data;
  104. unsigned int stsc_count;
  105. MOVStsc *stsc_data;
  106. unsigned int stps_count;
  107. unsigned *stps_data; ///< partial sync sample for mpeg-2 open gop
  108. int ctts_index;
  109. int ctts_sample;
  110. unsigned int sample_size; ///< may contain value calculated from stsd or value from stsz atom
  111. unsigned int stsz_sample_size; ///< always contains sample size from stsz atom
  112. unsigned int sample_count;
  113. int *sample_sizes;
  114. int keyframe_absent;
  115. unsigned int keyframe_count;
  116. int *keyframes;
  117. int time_scale;
  118. int64_t empty_duration; ///< empty duration of the first edit list entry
  119. int64_t start_time; ///< start time of the media
  120. int64_t time_offset; ///< time offset of the edit list entries
  121. int current_sample;
  122. unsigned int bytes_per_frame;
  123. unsigned int samples_per_frame;
  124. int dv_audio_container;
  125. int pseudo_stream_id; ///< -1 means demux all ids
  126. int16_t audio_cid; ///< stsd audio compression id
  127. unsigned drefs_count;
  128. MOVDref *drefs;
  129. int dref_id;
  130. int timecode_track;
  131. int wrong_dts; ///< dts are wrong due to huge ctts offset (iMovie files)
  132. int width; ///< tkhd width
  133. int height; ///< tkhd height
  134. int dts_shift; ///< dts shift when ctts is negative
  135. uint32_t palette[256];
  136. int has_palette;
  137. int64_t data_size;
  138. uint32_t tmcd_flags; ///< tmcd track flags
  139. int64_t track_end; ///< used for dts generation in fragmented movie files
  140. int start_pad; ///< amount of samples to skip due to enc-dec delay
  141. unsigned int rap_group_count;
  142. MOVSbgp *rap_group;
  143. int nb_frames_for_fps;
  144. int64_t duration_for_fps;
  145. int32_t *display_matrix;
  146. } MOVStreamContext;
  147. typedef struct MOVContext {
  148. const AVClass *class; ///< class for private options
  149. AVFormatContext *fc;
  150. int time_scale;
  151. int64_t duration; ///< duration of the longest track
  152. int found_moov; ///< 'moov' atom has been found
  153. int found_mdat; ///< 'mdat' atom has been found
  154. DVDemuxContext *dv_demux;
  155. AVFormatContext *dv_fctx;
  156. int isom; ///< 1 if file is ISO Media (mp4/3gp)
  157. MOVFragment fragment; ///< current fragment in moof atom
  158. MOVTrackExt *trex_data;
  159. unsigned trex_count;
  160. int itunes_metadata; ///< metadata are itunes style
  161. int chapter_track;
  162. int use_absolute_path;
  163. int ignore_editlist;
  164. int64_t next_root_atom; ///< offset of the next root atom
  165. int export_all;
  166. int export_xmp;
  167. int *bitrates; ///< bitrates read before streams creation
  168. int bitrates_count;
  169. int moov_retry;
  170. int use_mfra_for;
  171. int has_looked_for_mfra;
  172. MOVFragmentIndex** fragment_index_data;
  173. unsigned fragment_index_count;
  174. int atom_depth;
  175. } MOVContext;
  176. int ff_mp4_read_descr_len(AVIOContext *pb);
  177. int ff_mp4_read_descr(AVFormatContext *fc, AVIOContext *pb, int *tag);
  178. int ff_mp4_read_dec_config_descr(AVFormatContext *fc, AVStream *st, AVIOContext *pb);
  179. void ff_mp4_parse_es_descr(AVIOContext *pb, int *es_id);
  180. #define MP4ODescrTag 0x01
  181. #define MP4IODescrTag 0x02
  182. #define MP4ESDescrTag 0x03
  183. #define MP4DecConfigDescrTag 0x04
  184. #define MP4DecSpecificDescrTag 0x05
  185. #define MP4SLDescrTag 0x06
  186. #define MOV_TFHD_BASE_DATA_OFFSET 0x01
  187. #define MOV_TFHD_STSD_ID 0x02
  188. #define MOV_TFHD_DEFAULT_DURATION 0x08
  189. #define MOV_TFHD_DEFAULT_SIZE 0x10
  190. #define MOV_TFHD_DEFAULT_FLAGS 0x20
  191. #define MOV_TFHD_DURATION_IS_EMPTY 0x010000
  192. #define MOV_TFHD_DEFAULT_BASE_IS_MOOF 0x020000
  193. #define MOV_TRUN_DATA_OFFSET 0x01
  194. #define MOV_TRUN_FIRST_SAMPLE_FLAGS 0x04
  195. #define MOV_TRUN_SAMPLE_DURATION 0x100
  196. #define MOV_TRUN_SAMPLE_SIZE 0x200
  197. #define MOV_TRUN_SAMPLE_FLAGS 0x400
  198. #define MOV_TRUN_SAMPLE_CTS 0x800
  199. #define MOV_FRAG_SAMPLE_FLAG_DEGRADATION_PRIORITY_MASK 0x0000ffff
  200. #define MOV_FRAG_SAMPLE_FLAG_IS_NON_SYNC 0x00010000
  201. #define MOV_FRAG_SAMPLE_FLAG_PADDING_MASK 0x000e0000
  202. #define MOV_FRAG_SAMPLE_FLAG_REDUNDANCY_MASK 0x00300000
  203. #define MOV_FRAG_SAMPLE_FLAG_DEPENDED_MASK 0x00c00000
  204. #define MOV_FRAG_SAMPLE_FLAG_DEPENDS_MASK 0x03000000
  205. #define MOV_FRAG_SAMPLE_FLAG_DEPENDS_NO 0x02000000
  206. #define MOV_FRAG_SAMPLE_FLAG_DEPENDS_YES 0x01000000
  207. #define MOV_TKHD_FLAG_ENABLED 0x0001
  208. #define MOV_TKHD_FLAG_IN_MOVIE 0x0002
  209. #define MOV_TKHD_FLAG_IN_PREVIEW 0x0004
  210. #define MOV_TKHD_FLAG_IN_POSTER 0x0008
  211. #define TAG_IS_AVCI(tag) \
  212. ((tag) == MKTAG('a', 'i', '5', 'p') || \
  213. (tag) == MKTAG('a', 'i', '5', 'q') || \
  214. (tag) == MKTAG('a', 'i', '5', '2') || \
  215. (tag) == MKTAG('a', 'i', '5', '3') || \
  216. (tag) == MKTAG('a', 'i', '5', '5') || \
  217. (tag) == MKTAG('a', 'i', '5', '6') || \
  218. (tag) == MKTAG('a', 'i', '1', 'p') || \
  219. (tag) == MKTAG('a', 'i', '1', 'q') || \
  220. (tag) == MKTAG('a', 'i', '1', '2') || \
  221. (tag) == MKTAG('a', 'i', '1', '3') || \
  222. (tag) == MKTAG('a', 'i', '1', '5') || \
  223. (tag) == MKTAG('a', 'i', '1', '6') || \
  224. (tag) == MKTAG('a', 'i', 'v', 'x') || \
  225. (tag) == MKTAG('A', 'V', 'i', 'n'))
  226. int ff_mov_read_esds(AVFormatContext *fc, AVIOContext *pb);
  227. enum AVCodecID ff_mov_get_lpcm_codec_id(int bps, int flags);
  228. int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries);
  229. void ff_mov_write_chan(AVIOContext *pb, int64_t channel_layout);
  230. #define FF_MOV_FLAG_MFRA_AUTO -1
  231. #define FF_MOV_FLAG_MFRA_DTS 1
  232. #define FF_MOV_FLAG_MFRA_PTS 2
  233. #endif /* AVFORMAT_ISOM_H */