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 00043 typedef struct MOVIentry { 00044 uint64_t pos; 00045 int64_t dts; 00046 unsigned int size; 00047 unsigned int samples_in_chunk; 00048 unsigned int chunkNum; 00049 unsigned int entries; 00050 int cts; 00051 #define MOV_SYNC_SAMPLE 0x0001 00052 #define MOV_PARTIAL_SYNC_SAMPLE 0x0002 00053 uint32_t flags; 00054 } MOVIentry; 00055 00056 typedef struct HintSample { 00057 uint8_t *data; 00058 int size; 00059 int sample_number; 00060 int offset; 00061 int own_data; 00062 } HintSample; 00063 00064 typedef struct { 00065 int size; 00066 int len; 00067 HintSample *samples; 00068 } HintSampleQueue; 00069 00070 typedef struct { 00071 int64_t offset; 00072 int64_t time; 00073 int64_t duration; 00074 int64_t tfrf_offset; 00075 } MOVFragmentInfo; 00076 00077 typedef struct MOVIndex { 00078 int mode; 00079 int entry; 00080 unsigned timescale; 00081 uint64_t time; 00082 int64_t track_duration; 00083 long sample_count; 00084 long sample_size; 00085 long chunkCount; 00086 int has_keyframes; 00087 #define MOV_TRACK_CTTS 0x0001 00088 #define MOV_TRACK_STPS 0x0002 00089 uint32_t flags; 00090 int language; 00091 int track_id; 00092 int tag; 00093 AVCodecContext *enc; 00094 00095 int vos_len; 00096 uint8_t *vos_data; 00097 MOVIentry *cluster; 00098 int audio_vbr; 00099 int height; 00100 uint32_t tref_tag; 00101 int tref_id; 00102 int64_t start_dts; 00103 00104 int hint_track; 00105 int src_track; 00106 AVFormatContext *rtp_ctx; 00107 uint32_t prev_rtp_ts; 00108 int64_t cur_rtp_ts_unwrapped; 00109 uint32_t max_packet_size; 00110 00111 int64_t default_duration; 00112 uint32_t default_sample_flags; 00113 uint32_t default_size; 00114 00115 HintSampleQueue sample_queue; 00116 00117 AVIOContext *mdat_buf; 00118 int64_t moof_size_offset; 00119 int64_t data_offset; 00120 int64_t frag_start; 00121 int64_t tfrf_offset; 00122 00123 int nb_frag_info; 00124 MOVFragmentInfo *frag_info; 00125 00126 struct { 00127 int64_t struct_offset; 00128 int first_packet_seq; 00129 int first_packet_entry; 00130 int packet_seq; 00131 int packet_entry; 00132 int slices; 00133 } vc1_info; 00134 } MOVTrack; 00135 00136 typedef struct MOVMuxContext { 00137 const AVClass *av_class; 00138 int mode; 00139 int64_t time; 00140 int nb_streams; 00141 int chapter_track; 00142 int64_t mdat_pos; 00143 uint64_t mdat_size; 00144 MOVTrack *tracks; 00145 00146 int flags; 00147 int rtp_flags; 00148 int reserved_moov_size; 00149 int64_t reserved_moov_pos; 00150 00151 int iods_skip; 00152 int iods_video_profile; 00153 int iods_audio_profile; 00154 00155 int fragments; 00156 int max_fragment_duration; 00157 int min_fragment_duration; 00158 int max_fragment_size; 00159 int ism_lookahead; 00160 AVIOContext *mdat_buf; 00161 } MOVMuxContext; 00162 00163 #define FF_MOV_FLAG_RTP_HINT 1 00164 #define FF_MOV_FLAG_FRAGMENT 2 00165 #define FF_MOV_FLAG_EMPTY_MOOV 4 00166 #define FF_MOV_FLAG_FRAG_KEYFRAME 8 00167 #define FF_MOV_FLAG_SEPARATE_MOOF 16 00168 #define FF_MOV_FLAG_FRAG_CUSTOM 32 00169 #define FF_MOV_FLAG_ISML 64 00170 00171 int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt); 00172 00173 int ff_mov_init_hinting(AVFormatContext *s, int index, int src_index); 00174 int ff_mov_add_hinted_packet(AVFormatContext *s, AVPacket *pkt, 00175 int track_index, int sample, 00176 uint8_t *sample_data, int sample_size); 00177 void ff_mov_close_hinting(MOVTrack *track); 00178 00179 #endif /* AVFORMAT_MOVENC_H */