00001 /* 00002 * MOV, 3GP, MP4 muxer 00003 * Copyright (c) 2003 Thomas Raivio 00004 * Copyright (c) 2004 Gildas Bazin <gbazin at videolan dot org> 00005 * Copyright (c) 2009 Baptiste Coudurier <baptiste dot coudurier at gmail dot com> 00006 * 00007 * This file is part of FFmpeg. 00008 * 00009 * FFmpeg is free software; you can redistribute it and/or 00010 * modify it under the terms of the GNU Lesser General Public 00011 * License as published by the Free Software Foundation; either 00012 * version 2.1 of the License, or (at your option) any later version. 00013 * 00014 * FFmpeg is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 * Lesser General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU Lesser General Public 00020 * License along with FFmpeg; if not, write to the Free Software 00021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00022 */ 00023 00024 #ifndef AVFORMAT_MOVENC_H 00025 #define AVFORMAT_MOVENC_H 00026 00027 #include "avformat.h" 00028 00029 #define MOV_INDEX_CLUSTER_SIZE 16384 00030 #define MOV_TIMESCALE 1000 00031 00032 #define RTP_MAX_PACKET_SIZE 1450 00033 00034 #define MODE_MP4 0x01 00035 #define MODE_MOV 0x02 00036 #define MODE_3GP 0x04 00037 #define MODE_PSP 0x08 // example working PSP command line: 00038 // ffmpeg -i testinput.avi -f psp -r 14.985 -s 320x240 -b 768 -ar 24000 -ab 32 M4V00001.MP4 00039 #define MODE_3G2 0x10 00040 #define MODE_IPOD 0x20 00041 #define MODE_ISM 0x40 00042 #define MODE_F4V 0x80 00043 00044 typedef struct MOVIentry { 00045 uint64_t pos; 00046 int64_t dts; 00047 unsigned int size; 00048 unsigned int samples_in_chunk; 00049 unsigned int chunkNum; 00050 unsigned int entries; 00051 int cts; 00052 #define MOV_SYNC_SAMPLE 0x0001 00053 #define MOV_PARTIAL_SYNC_SAMPLE 0x0002 00054 uint32_t flags; 00055 } MOVIentry; 00056 00057 typedef struct HintSample { 00058 uint8_t *data; 00059 int size; 00060 int sample_number; 00061 int offset; 00062 int own_data; 00063 } HintSample; 00064 00065 typedef struct { 00066 int size; 00067 int len; 00068 HintSample *samples; 00069 } HintSampleQueue; 00070 00071 typedef struct { 00072 int64_t offset; 00073 int64_t time; 00074 int64_t duration; 00075 int64_t tfrf_offset; 00076 } MOVFragmentInfo; 00077 00078 typedef struct MOVIndex { 00079 int mode; 00080 int entry; 00081 unsigned timescale; 00082 uint64_t time; 00083 int64_t track_duration; 00084 int last_sample_is_subtitle_end; 00085 long sample_count; 00086 long sample_size; 00087 long chunkCount; 00088 int has_keyframes; 00089 #define MOV_TRACK_CTTS 0x0001 00090 #define MOV_TRACK_STPS 0x0002 00091 uint32_t flags; 00092 #define MOV_TIMECODE_FLAG_DROPFRAME 0x0001 00093 #define MOV_TIMECODE_FLAG_24HOURSMAX 0x0002 00094 #define MOV_TIMECODE_FLAG_ALLOWNEGATIVE 0x0004 00095 uint32_t timecode_flags; 00096 int language; 00097 int track_id; 00098 int tag; 00099 AVCodecContext *enc; 00100 00101 int vos_len; 00102 uint8_t *vos_data; 00103 MOVIentry *cluster; 00104 int audio_vbr; 00105 int height; 00106 uint32_t tref_tag; 00107 int tref_id; 00108 int64_t start_dts; 00109 00110 int hint_track; 00111 int src_track; 00112 AVFormatContext *rtp_ctx; 00113 uint32_t prev_rtp_ts; 00114 int64_t cur_rtp_ts_unwrapped; 00115 uint32_t max_packet_size; 00116 00117 int64_t default_duration; 00118 uint32_t default_sample_flags; 00119 uint32_t default_size; 00120 00121 HintSampleQueue sample_queue; 00122 00123 AVIOContext *mdat_buf; 00124 int64_t moof_size_offset; 00125 int64_t data_offset; 00126 int64_t frag_start; 00127 int64_t tfrf_offset; 00128 00129 int nb_frag_info; 00130 MOVFragmentInfo *frag_info; 00131 00132 struct { 00133 int64_t struct_offset; 00134 int first_packet_seq; 00135 int first_packet_entry; 00136 int packet_seq; 00137 int packet_entry; 00138 int slices; 00139 } vc1_info; 00140 } MOVTrack; 00141 00142 typedef struct MOVMuxContext { 00143 const AVClass *av_class; 00144 int mode; 00145 int64_t time; 00146 int nb_streams; 00147 int nb_meta_tmcd; 00148 int chapter_track; 00149 int64_t mdat_pos; 00150 uint64_t mdat_size; 00151 MOVTrack *tracks; 00152 00153 int flags; 00154 int rtp_flags; 00155 int reserved_moov_size; 00156 int64_t reserved_moov_pos; 00157 00158 int iods_skip; 00159 int iods_video_profile; 00160 int iods_audio_profile; 00161 00162 int fragments; 00163 int max_fragment_duration; 00164 int min_fragment_duration; 00165 int max_fragment_size; 00166 int ism_lookahead; 00167 AVIOContext *mdat_buf; 00168 } MOVMuxContext; 00169 00170 #define FF_MOV_FLAG_RTP_HINT 1 00171 #define FF_MOV_FLAG_FRAGMENT 2 00172 #define FF_MOV_FLAG_EMPTY_MOOV 4 00173 #define FF_MOV_FLAG_FRAG_KEYFRAME 8 00174 #define FF_MOV_FLAG_SEPARATE_MOOF 16 00175 #define FF_MOV_FLAG_FRAG_CUSTOM 32 00176 #define FF_MOV_FLAG_ISML 64 00177 #define FF_MOV_FLAG_FASTSTART 128 00178 00179 int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt); 00180 00181 int ff_mov_init_hinting(AVFormatContext *s, int index, int src_index); 00182 int ff_mov_add_hinted_packet(AVFormatContext *s, AVPacket *pkt, 00183 int track_index, int sample, 00184 uint8_t *sample_data, int sample_size); 00185 void ff_mov_close_hinting(MOVTrack *track); 00186 00187 #endif /* AVFORMAT_MOVENC_H */