2 * MOV, 3GP, MP4 encoder.
3 * Copyright (c) 2003 Thomas Raivio.
4 * Copyright (c) 2004 Gildas Bazin <gbazin at videolan dot org>.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #define MOV_INDEX_CLUSTER_SIZE 16384
28 #define globalTimescale 1000
33 #define MODE_PSP 3 // 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
37 typedef struct MOVIentry {
38 unsigned int flags, pos, size;
39 unsigned int samplesInChunk;
44 typedef struct MOVIndex {
63 typedef struct MOVContext {
70 MOVTrack tracks[MAX_STREAMS];
73 static int mov_write_esds_tag(ByteIOContext *pb, MOVTrack* track);
75 const CodecTag ff_mov_obj_type[] = {
76 { CODEC_ID_MPEG4 , 32 },
77 { CODEC_ID_AAC , 64 },
78 { CODEC_ID_MPEG1VIDEO, 106 },
79 { CODEC_ID_MPEG2VIDEO, 96 },//mpeg2 profiles
80 { CODEC_ID_MP2 , 107 },//FIXME mpeg2 mpeg audio -> 105
81 { CODEC_ID_MP3 , 107 },//FIXME mpeg2 mpeg audio -> 105
82 { CODEC_ID_H264 , 241 },
83 { CODEC_ID_H263 , 242 },
84 { CODEC_ID_H261 , 243 },
85 { CODEC_ID_MJPEG , 108 },
86 { CODEC_ID_PCM_S16LE , 224 },
87 { CODEC_ID_VORBIS , 225 },
88 { CODEC_ID_AC3 , 226 },
89 { CODEC_ID_PCM_ALAW , 227 },
90 { CODEC_ID_PCM_MULAW , 228 },
91 { CODEC_ID_PCM_S16BE , 230 },
95 //FIXME supprt 64bit varaint with wide placeholders
96 static int updateSize (ByteIOContext *pb, int pos)
98 long curpos = url_ftell(pb);
99 url_fseek(pb, pos, SEEK_SET);
100 put_be32(pb, curpos - pos); /* rewrite size */
101 url_fseek(pb, curpos, SEEK_SET);
106 /* Chunk offset atom */
107 static int mov_write_stco_tag(ByteIOContext *pb, MOVTrack* track)
110 int pos = url_ftell(pb);
111 put_be32(pb, 0); /* size */
113 put_be32(pb, 0); /* version & flags */
114 put_be32(pb, track->entry); /* entry count */
115 for (i=0; i<track->entry; i++) {
116 int cl = i / MOV_INDEX_CLUSTER_SIZE;
117 int id = i % MOV_INDEX_CLUSTER_SIZE;
118 put_be32(pb, track->cluster[cl][id].pos);
120 return updateSize (pb, pos);
123 /* Sample size atom */
124 static int mov_write_stsz_tag(ByteIOContext *pb, MOVTrack* track)
127 int i, j, entries = 0, tst = -1, oldtst = -1;
129 int pos = url_ftell(pb);
130 put_be32(pb, 0); /* size */
132 put_be32(pb, 0); /* version & flags */
134 for (i=0; i<track->entry; i++) {
135 int cl = i / MOV_INDEX_CLUSTER_SIZE;
136 int id = i % MOV_INDEX_CLUSTER_SIZE;
137 tst = track->cluster[cl][id].size/track->cluster[cl][id].entries;
138 if(oldtst != -1 && tst != oldtst) {
142 entries += track->cluster[cl][id].entries;
145 int sSize = track->cluster[0][0].size/track->cluster[0][0].entries;
146 put_be32(pb, sSize); // sample size
147 put_be32(pb, entries); // sample count
150 put_be32(pb, 0); // sample size
151 put_be32(pb, entries); // sample count
152 for (i=0; i<track->entry; i++) {
153 int cl = i / MOV_INDEX_CLUSTER_SIZE;
154 int id = i % MOV_INDEX_CLUSTER_SIZE;
155 for ( j=0; j<track->cluster[cl][id].entries; j++) {
156 put_be32(pb, track->cluster[cl][id].size /
157 track->cluster[cl][id].entries);
161 return updateSize (pb, pos);
164 /* Sample to chunk atom */
165 static int mov_write_stsc_tag(ByteIOContext *pb, MOVTrack* track)
167 int index = 0, oldval = -1, i, entryPos, curpos;
169 int pos = url_ftell(pb);
170 put_be32(pb, 0); /* size */
172 put_be32(pb, 0); // version & flags
173 entryPos = url_ftell(pb);
174 put_be32(pb, track->entry); // entry count
175 for (i=0; i<track->entry; i++) {
176 int cl = i / MOV_INDEX_CLUSTER_SIZE;
177 int id = i % MOV_INDEX_CLUSTER_SIZE;
178 if(oldval != track->cluster[cl][id].samplesInChunk)
180 put_be32(pb, i+1); // first chunk
181 put_be32(pb, track->cluster[cl][id].samplesInChunk); // samples per chunk
182 put_be32(pb, 0x1); // sample description index
183 oldval = track->cluster[cl][id].samplesInChunk;
187 curpos = url_ftell(pb);
188 url_fseek(pb, entryPos, SEEK_SET);
189 put_be32(pb, index); // rewrite size
190 url_fseek(pb, curpos, SEEK_SET);
192 return updateSize (pb, pos);
195 /* Sync sample atom */
196 static int mov_write_stss_tag(ByteIOContext *pb, MOVTrack* track)
199 int i, index = 0, entryPos;
200 int pos = url_ftell(pb);
201 put_be32(pb, 0); // size
203 put_be32(pb, 0); // version & flags
204 entryPos = url_ftell(pb);
205 put_be32(pb, track->entry); // entry count
206 for (i=0; i<track->entry; i++) {
207 int cl = i / MOV_INDEX_CLUSTER_SIZE;
208 int id = i % MOV_INDEX_CLUSTER_SIZE;
209 if(track->cluster[cl][id].key_frame == 1) {
214 curpos = url_ftell(pb);
215 url_fseek(pb, entryPos, SEEK_SET);
216 put_be32(pb, index); // rewrite size
217 url_fseek(pb, curpos, SEEK_SET);
218 return updateSize (pb, pos);
221 static int mov_write_damr_tag(ByteIOContext *pb)
223 put_be32(pb, 0x11); /* size */
228 put_be16(pb, 0x80); /* Mode set (all modes for AMR_NB) */
229 put_be16(pb, 0xa); /* Mode change period (no restriction) */
230 //put_be16(pb, 0x81ff); /* Mode set (all modes for AMR_NB) */
231 //put_be16(pb, 1); /* Mode change period (no restriction) */
235 static int mov_write_wave_tag(ByteIOContext *pb, MOVTrack* track)
237 int pos = url_ftell(pb);
239 put_be32(pb, 0); /* size */
242 put_be32(pb, 12); /* size */
246 put_be32(pb, 12); /* size */
250 mov_write_esds_tag(pb, track);
252 put_be32(pb, 12); /* size */
256 put_be32(pb, 8); /* size */
257 put_be32(pb, 0); /* null tag */
259 return updateSize (pb, pos);
262 const CodecTag codec_movaudio_tags[] = {
263 { CODEC_ID_PCM_MULAW, MKTAG('u', 'l', 'a', 'w') },
264 { CODEC_ID_PCM_ALAW, MKTAG('a', 'l', 'a', 'w') },
265 { CODEC_ID_ADPCM_IMA_QT, MKTAG('i', 'm', 'a', '4') },
266 { CODEC_ID_MACE3, MKTAG('M', 'A', 'C', '3') },
267 { CODEC_ID_MACE6, MKTAG('M', 'A', 'C', '6') },
268 { CODEC_ID_AAC, MKTAG('m', 'p', '4', 'a') },
269 { CODEC_ID_AMR_NB, MKTAG('s', 'a', 'm', 'r') },
270 { CODEC_ID_PCM_S16BE, MKTAG('t', 'w', 'o', 's') },
271 { CODEC_ID_PCM_S16LE, MKTAG('s', 'o', 'w', 't') },
272 { CODEC_ID_MP3, MKTAG('.', 'm', 'p', '3') },
276 static int mov_write_audio_tag(ByteIOContext *pb, MOVTrack* track)
278 int pos = url_ftell(pb);
281 put_be32(pb, 0); /* size */
283 tag = track->enc->codec_tag;
285 tag = codec_get_tag(codec_movaudio_tags, track->enc->codec_id);
286 // if no mac fcc found, try with Microsoft tags
289 int tmp = codec_get_tag(codec_wav_tags, track->enc->codec_id);
290 tag = MKTAG('m', 's', ((tmp >> 8) & 0xff), (tmp & 0xff));
292 put_le32(pb, tag); // store it byteswapped
294 put_be32(pb, 0); /* Reserved */
295 put_be16(pb, 0); /* Reserved */
296 put_be16(pb, 1); /* Data-reference index, XXX == 1 */
298 /* SoundDescription */
299 if(track->mode == MODE_MOV && track->enc->codec_id == CODEC_ID_AAC)
300 put_be16(pb, 1); /* Version 1 */
302 put_be16(pb, 0); /* Version 0 */
303 put_be16(pb, 0); /* Revision level */
304 put_be32(pb, 0); /* Reserved */
306 put_be16(pb, track->enc->channels); /* Number of channels */
307 /* TODO: Currently hard-coded to 16-bit, there doesn't seem
308 to be a good way to get number of bits of audio */
309 put_be16(pb, 0x10); /* Reserved */
311 if(track->enc->codec_id == CODEC_ID_AAC ||
312 track->enc->codec_id == CODEC_ID_MP3)
314 put_be16(pb, 0xfffe); /* compression ID (vbr)*/
318 put_be16(pb, 0); /* compression ID (= 0) */
320 put_be16(pb, 0); /* packet size (= 0) */
321 put_be16(pb, track->timescale); /* Time scale */
322 put_be16(pb, 0); /* Reserved */
324 if(track->mode == MODE_MOV && track->enc->codec_id == CODEC_ID_AAC)
326 /* SoundDescription V1 extended info */
327 put_be32(pb, track->enc->frame_size); /* Samples per packet */
328 put_be32(pb, 1536); /* Bytes per packet */
329 put_be32(pb, 2); /* Bytes per frame */
330 put_be32(pb, 2); /* Bytes per sample */
333 if(track->enc->codec_id == CODEC_ID_AAC) {
334 if( track->mode == MODE_MOV ) mov_write_wave_tag(pb, track);
335 else mov_write_esds_tag(pb, track);
337 if(track->enc->codec_id == CODEC_ID_AMR_NB)
338 mov_write_damr_tag(pb);
339 return updateSize (pb, pos);
342 static int mov_write_d263_tag(ByteIOContext *pb)
344 put_be32(pb, 0xf); /* size */
352 /* TODO: No idea about these values */
353 static int mov_write_svq3_tag(ByteIOContext *pb)
359 put_be32(pb, 0xe2c0211d);
360 put_be32(pb, 0xc0000000);
365 static unsigned int descrLength(unsigned int len)
367 if (len < 0x00000080)
369 else if (len < 0x00004000)
371 else if(len < 0x00200000)
377 static void putDescr(ByteIOContext *pb, int tag, int size)
383 vals[3] = (uint8_t)(len & 0x7f);
385 vals[2] = (uint8_t)((len & 0x7f) | 0x80);
387 vals[1] = (uint8_t)((len & 0x7f) | 0x80);
389 vals[0] = (uint8_t)((len & 0x7f) | 0x80);
391 put_byte(pb, tag); // DescriptorTag
393 if (size < 0x00000080)
395 put_byte(pb, vals[3]);
397 else if (size < 0x00004000)
399 put_byte(pb, vals[2]);
400 put_byte(pb, vals[3]);
402 else if (size < 0x00200000)
404 put_byte(pb, vals[1]);
405 put_byte(pb, vals[2]);
406 put_byte(pb, vals[3]);
408 else if (size < 0x10000000)
410 put_byte(pb, vals[0]);
411 put_byte(pb, vals[1]);
412 put_byte(pb, vals[2]);
413 put_byte(pb, vals[3]);
417 static int mov_write_esds_tag(ByteIOContext *pb, MOVTrack* track) // Basic
419 int decoderSpecificInfoLen;
420 int pos = url_ftell(pb);
421 void *vosDataBackup=track->vosData;
422 int vosLenBackup=track->vosLen;
424 // we should be able to have these passed in, via vosData, then we wouldn't need to attack this routine at all
425 static const char PSPAACData[]={0x13,0x10};
426 static const char PSPMP4Data[]={0x00,0x00,0x01,0xB0,0x03,0x00,0x00,0x01,0xB5,0x09,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x20,0x00,0x84,0x5D,0x4C,0x28,0x50,0x20,0xF0,0xA3,0x1F };
429 if (track->mode == MODE_PSP) // fails on psp if this is not here
431 if (track->enc->codec_id == CODEC_ID_AAC)
434 track->vosData = PSPAACData;
437 if (track->enc->codec_id == CODEC_ID_MPEG4)
440 track->vosData = PSPMP4Data;
444 decoderSpecificInfoLen = track->vosLen ? descrLength(track->vosLen):0;
446 put_be32(pb, 0); // size
448 put_be32(pb, 0); // Version
451 putDescr(pb, 0x03, 3 + descrLength(13 + decoderSpecificInfoLen) +
453 put_be16(pb, track->trackID);
454 put_byte(pb, 0x00); // flags (= no flags)
456 // DecoderConfig descriptor
457 putDescr(pb, 0x04, 13 + decoderSpecificInfoLen);
459 // Object type indication
460 put_byte(pb, codec_get_tag(ff_mov_obj_type, track->enc->codec_id));
462 if(track->enc->codec_type == CODEC_TYPE_AUDIO)
463 put_byte(pb, 0x15); // flags (= Audiostream)
465 put_byte(pb, 0x11); // flags (= Visualstream)
467 put_byte(pb, track->enc->rc_buffer_size>>(3+16)); // Buffersize DB (24 bits)
468 put_be16(pb, (track->enc->rc_buffer_size>>3)&0xFFFF); // Buffersize DB
470 put_be32(pb, FFMAX(track->enc->bit_rate, track->enc->rc_max_rate)); // maxbitrate (FIXME should be max rate in any 1 sec window)
471 if(track->enc->rc_max_rate != track->enc->rc_min_rate || track->enc->rc_min_rate==0)
472 put_be32(pb, 0); // vbr
474 put_be32(pb, track->enc->rc_max_rate); // avg bitrate
478 // DecoderSpecific info descriptor
479 putDescr(pb, 0x05, track->vosLen);
480 put_buffer(pb, track->vosData, track->vosLen);
483 track->vosData = vosDataBackup;
484 track->vosLen = vosLenBackup;
487 putDescr(pb, 0x06, 1);
489 return updateSize (pb, pos);
492 const CodecTag codec_movvideo_tags[] = {
493 { CODEC_ID_SVQ1, MKTAG('S', 'V', 'Q', '1') },
494 { CODEC_ID_SVQ3, MKTAG('S', 'V', 'Q', '3') },
495 { CODEC_ID_MPEG4, MKTAG('m', 'p', '4', 'v') },
496 { CODEC_ID_H263, MKTAG('s', '2', '6', '3') },
497 { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'c', ' ') },
501 static int mov_write_video_tag(ByteIOContext *pb, MOVTrack* track)
503 int pos = url_ftell(pb);
504 char compressor_name[32];
507 put_be32(pb, 0); /* size */
509 tag = track->enc->codec_tag;
511 tag = codec_get_tag(codec_movvideo_tags, track->enc->codec_id);
512 // if no mac fcc found, try with Microsoft tags
514 tag = codec_get_tag(codec_bmp_tags, track->enc->codec_id);
515 put_le32(pb, tag); // store it byteswapped
517 put_be32(pb, 0); /* Reserved */
518 put_be16(pb, 0); /* Reserved */
519 put_be16(pb, 1); /* Data-reference index */
521 put_be16(pb, 0); /* Codec stream version */
522 put_be16(pb, 0); /* Codec stream revision (=0) */
523 put_tag(pb, "FFMP"); /* Vendor */
524 if(track->enc->codec_id == CODEC_ID_RAWVIDEO) {
525 put_be32(pb, 0); /* Temporal Quality */
526 put_be32(pb, 0x400); /* Spatial Quality = lossless*/
528 put_be32(pb, 0x200); /* Temporal Quality = normal */
529 put_be32(pb, 0x200); /* Spatial Quality = normal */
531 put_be16(pb, track->enc->width); /* Video width */
532 put_be16(pb, track->enc->height); /* Video height */
533 put_be32(pb, 0x00480000); /* Horizontal resolution 72dpi */
534 put_be32(pb, 0x00480000); /* Vertical resolution 72dpi */
535 put_be32(pb, 0); /* Data size (= 0) */
536 put_be16(pb, 1); /* Frame count (= 1) */
538 memset(compressor_name,0,32);
539 if (track->enc->codec && track->enc->codec->name)
540 strncpy(compressor_name,track->enc->codec->name,31);
541 put_byte(pb, strlen(compressor_name));
542 put_buffer(pb, compressor_name, 31);
544 put_be16(pb, 0x18); /* Reserved */
545 put_be16(pb, 0xffff); /* Reserved */
546 if(track->enc->codec_id == CODEC_ID_MPEG4)
547 mov_write_esds_tag(pb, track);
548 else if(track->enc->codec_id == CODEC_ID_H263)
549 mov_write_d263_tag(pb);
550 else if(track->enc->codec_id == CODEC_ID_SVQ3)
551 mov_write_svq3_tag(pb);
553 return updateSize (pb, pos);
556 static int mov_write_stsd_tag(ByteIOContext *pb, MOVTrack* track)
558 int pos = url_ftell(pb);
559 put_be32(pb, 0); /* size */
561 put_be32(pb, 0); /* version & flags */
562 put_be32(pb, 1); /* entry count */
563 if (track->enc->codec_type == CODEC_TYPE_VIDEO)
564 mov_write_video_tag(pb, track);
565 else if (track->enc->codec_type == CODEC_TYPE_AUDIO)
566 mov_write_audio_tag(pb, track);
567 return updateSize(pb, pos);
571 /* Time to sample atom */
572 static int mov_write_stts_tag(ByteIOContext *pb, MOVTrack* track)
574 put_be32(pb, 0x18); /* size */
576 put_be32(pb, 0); /* version & flags */
577 put_be32(pb, 1); /* entry count */
579 put_be32(pb, track->sampleCount); /* sample count */
580 put_be32(pb, track->sampleDuration); /* sample duration */
584 static int mov_write_dref_tag(ByteIOContext *pb)
586 put_be32(pb, 28); /* size */
588 put_be32(pb, 0); /* version & flags */
589 put_be32(pb, 1); /* entry count */
591 put_be32(pb, 0xc); /* size */
593 put_be32(pb, 1); /* version & flags */
598 static int mov_write_stbl_tag(ByteIOContext *pb, MOVTrack* track)
600 int pos = url_ftell(pb);
601 put_be32(pb, 0); /* size */
603 mov_write_stsd_tag(pb, track);
604 mov_write_stts_tag(pb, track);
605 if (track->enc->codec_type == CODEC_TYPE_VIDEO &&
607 mov_write_stss_tag(pb, track);
608 mov_write_stsc_tag(pb, track);
609 mov_write_stsz_tag(pb, track);
610 mov_write_stco_tag(pb, track);
611 return updateSize(pb, pos);
614 static int mov_write_dinf_tag(ByteIOContext *pb)
616 int pos = url_ftell(pb);
617 put_be32(pb, 0); /* size */
619 mov_write_dref_tag(pb);
620 return updateSize(pb, pos);
623 static int mov_write_smhd_tag(ByteIOContext *pb)
625 put_be32(pb, 16); /* size */
627 put_be32(pb, 0); /* version & flags */
628 put_be16(pb, 0); /* reserved (balance, normally = 0) */
629 put_be16(pb, 0); /* reserved */
633 static int mov_write_vmhd_tag(ByteIOContext *pb)
635 put_be32(pb, 0x14); /* size (always 0x14) */
637 put_be32(pb, 0x01); /* version & flags */
638 put_be64(pb, 0); /* reserved (graphics mode = copy) */
642 static int mov_write_hdlr_tag(ByteIOContext *pb, MOVTrack* track)
644 char *descr, *hdlr, *hdlr_type;
645 int pos = url_ftell(pb);
647 if (!track) { /* no media --> data handler */
650 descr = "DataHandler";
652 hdlr = (track->mode == MODE_MOV) ? "mhlr" : "\0\0\0\0";
653 if (track->enc->codec_type == CODEC_TYPE_VIDEO) {
655 descr = "VideoHandler";
658 descr = "SoundHandler";
662 put_be32(pb, 0); /* size */
664 put_be32(pb, 0); /* Version & flags */
665 put_buffer(pb, hdlr, 4); /* handler */
666 put_tag(pb, hdlr_type); /* handler type */
667 put_be32(pb ,0); /* reserved */
668 put_be32(pb ,0); /* reserved */
669 put_be32(pb ,0); /* reserved */
670 put_byte(pb, strlen(descr)); /* string counter */
671 put_buffer(pb, descr, strlen(descr)); /* handler description */
672 return updateSize(pb, pos);
675 static int mov_write_minf_tag(ByteIOContext *pb, MOVTrack* track)
677 int pos = url_ftell(pb);
678 put_be32(pb, 0); /* size */
680 if(track->enc->codec_type == CODEC_TYPE_VIDEO)
681 mov_write_vmhd_tag(pb);
683 mov_write_smhd_tag(pb);
684 if (track->mode == MODE_MOV) /* FIXME: Why do it for MODE_MOV only ? */
685 mov_write_hdlr_tag(pb, NULL);
686 mov_write_dinf_tag(pb);
687 mov_write_stbl_tag(pb, track);
688 return updateSize(pb, pos);
691 static int mov_write_mdhd_tag(ByteIOContext *pb, MOVTrack* track)
693 put_be32(pb, 32); /* size */
695 put_be32(pb, 0); /* Version & flags */
696 put_be32(pb, track->time); /* creation time */
697 put_be32(pb, track->time); /* modification time */
698 put_be32(pb, track->timescale); /* time scale (sample rate for audio) */
699 put_be32(pb, track->trackDuration); /* duration */
700 put_be16(pb, 0); /* language, 0 = english */
701 put_be16(pb, 0); /* reserved (quality) */
705 static int mov_write_mdia_tag(ByteIOContext *pb, MOVTrack* track)
707 int pos = url_ftell(pb);
708 put_be32(pb, 0); /* size */
710 mov_write_mdhd_tag(pb, track);
711 mov_write_hdlr_tag(pb, track);
712 mov_write_minf_tag(pb, track);
713 return updateSize(pb, pos);
716 static int mov_write_tkhd_tag(ByteIOContext *pb, MOVTrack* track)
718 int64_t maxTrackLenTemp;
719 put_be32(pb, 0x5c); /* size (always 0x5c) */
721 put_be32(pb, 0xf); /* version & flags (track enabled) */
722 put_be32(pb, track->time); /* creation time */
723 put_be32(pb, track->time); /* modification time */
724 put_be32(pb, track->trackID); /* track-id */
725 put_be32(pb, 0); /* reserved */
726 maxTrackLenTemp = ((int64_t)globalTimescale*(int64_t)track->trackDuration)/(int64_t)track->timescale;
727 put_be32(pb, (long)maxTrackLenTemp); /* duration */
729 put_be32(pb, 0); /* reserved */
730 put_be32(pb, 0); /* reserved */
731 put_be32(pb, 0x0); /* reserved (Layer & Alternate group) */
732 /* Volume, only for audio */
733 if(track->enc->codec_type == CODEC_TYPE_AUDIO)
734 put_be16(pb, 0x0100);
737 put_be16(pb, 0); /* reserved */
739 /* Matrix structure */
740 put_be32(pb, 0x00010000); /* reserved */
741 put_be32(pb, 0x0); /* reserved */
742 put_be32(pb, 0x0); /* reserved */
743 put_be32(pb, 0x0); /* reserved */
744 put_be32(pb, 0x00010000); /* reserved */
745 put_be32(pb, 0x0); /* reserved */
746 put_be32(pb, 0x0); /* reserved */
747 put_be32(pb, 0x0); /* reserved */
748 put_be32(pb, 0x40000000); /* reserved */
750 /* Track width and height, for visual only */
751 if(track->enc->codec_type == CODEC_TYPE_VIDEO) {
752 double sample_aspect_ratio = av_q2d(track->enc->sample_aspect_ratio);
753 if( !sample_aspect_ratio ) sample_aspect_ratio = 1;
754 put_be32(pb, sample_aspect_ratio * track->enc->width*0x10000);
755 put_be32(pb, track->enc->height*0x10000);
764 // This box seems important for the psp playback ... without it the movie seems to hang
765 static int mov_write_edts_tag(ByteIOContext *pb, MOVTrack *track)
767 int64_t maxTrackLenTemp;
768 put_be32(pb, 0x24); /* size */
770 put_be32(pb, 0x1c); /* size */
775 maxTrackLenTemp = ((int64_t)globalTimescale*(int64_t)track->trackDuration)/(int64_t)track->timescale;
776 put_be32(pb, (long)maxTrackLenTemp); /* duration ... doesn't seem to effect psp */
779 put_be32(pb, 0x00010000);
783 // goes at the end of each track! ... Critical for PSP playback ("Incompatible data" without it)
784 static int mov_write_uuid_tag_psp(ByteIOContext *pb, MOVTrack *mov)
786 put_be32(pb, 0x34); /* size ... reports as 28 in mp4box! */
789 put_be32(pb, 0x21d24fce);
790 put_be32(pb, 0xbb88695c);
791 put_be32(pb, 0xfac9c740);
792 put_be32(pb, 0x1c); // another size here!
794 put_be32(pb, 0x00010012);
796 put_be32(pb, 0x55c40000);
802 static int mov_write_trak_tag(ByteIOContext *pb, MOVTrack* track)
804 int pos = url_ftell(pb);
805 put_be32(pb, 0); /* size */
807 mov_write_tkhd_tag(pb, track);
808 if (track->mode == MODE_PSP)
809 mov_write_edts_tag(pb, track); // PSP Movies require edts box
810 mov_write_mdia_tag(pb, track);
811 if (track->mode == MODE_PSP)
812 mov_write_uuid_tag_psp(pb,track); // PSP Movies require this uuid box
813 return updateSize(pb, pos);
817 /* TODO: Not sorted out, but not necessary either */
818 static int mov_write_iods_tag(ByteIOContext *pb, MOVContext *mov)
820 put_be32(pb, 0x15); /* size */
822 put_be32(pb, 0); /* version & flags */
823 put_be16(pb, 0x1007);
825 put_be16(pb, 0x4fff);
826 put_be16(pb, 0xfffe);
827 put_be16(pb, 0x01ff);
832 static int mov_write_mvhd_tag(ByteIOContext *pb, MOVContext *mov)
834 int maxTrackID = 1, maxTrackLen = 0, i;
835 int64_t maxTrackLenTemp;
837 put_be32(pb, 0x6c); /* size (always 0x6c) */
839 put_be32(pb, 0); /* version & flags */
840 put_be32(pb, mov->time); /* creation time */
841 put_be32(pb, mov->time); /* modification time */
842 put_be32(pb, mov->timescale); /* timescale */
843 for (i=0; i<MAX_STREAMS; i++) {
844 if(mov->tracks[i].entry > 0) {
845 maxTrackLenTemp = ((int64_t)globalTimescale*(int64_t)mov->tracks[i].trackDuration)/(int64_t)mov->tracks[i].timescale;
846 if(maxTrackLen < maxTrackLenTemp)
847 maxTrackLen = maxTrackLenTemp;
848 if(maxTrackID < mov->tracks[i].trackID)
849 maxTrackID = mov->tracks[i].trackID;
852 put_be32(pb, maxTrackLen); /* duration of longest track */
854 put_be32(pb, 0x00010000); /* reserved (preferred rate) 1.0 = normal */
855 put_be16(pb, 0x0100); /* reserved (preferred volume) 1.0 = normal */
856 put_be16(pb, 0); /* reserved */
857 put_be32(pb, 0); /* reserved */
858 put_be32(pb, 0); /* reserved */
860 /* Matrix structure */
861 put_be32(pb, 0x00010000); /* reserved */
862 put_be32(pb, 0x0); /* reserved */
863 put_be32(pb, 0x0); /* reserved */
864 put_be32(pb, 0x0); /* reserved */
865 put_be32(pb, 0x00010000); /* reserved */
866 put_be32(pb, 0x0); /* reserved */
867 put_be32(pb, 0x0); /* reserved */
868 put_be32(pb, 0x0); /* reserved */
869 put_be32(pb, 0x40000000); /* reserved */
871 put_be32(pb, 0); /* reserved (preview time) */
872 put_be32(pb, 0); /* reserved (preview duration) */
873 put_be32(pb, 0); /* reserved (poster time) */
874 put_be32(pb, 0); /* reserved (selection time) */
875 put_be32(pb, 0); /* reserved (selection duration) */
876 put_be32(pb, 0); /* reserved (current time) */
877 put_be32(pb, maxTrackID+1); /* Next track id */
881 static int mov_write_itunes_hdlr_tag(ByteIOContext *pb, MOVContext* mov,
884 int pos = url_ftell(pb);
885 put_be32(pb, 0); /* size */
894 return updateSize(pb, pos);
897 /* helper function to write a data tag with the specified string as data */
898 static int mov_write_string_data_tag(ByteIOContext *pb, MOVContext* mov,
899 AVFormatContext *s, const char *data)
901 int pos = url_ftell(pb);
902 put_be32(pb, 0); /* size */
906 put_buffer(pb, data, strlen(data));
907 return updateSize(pb, pos);
910 /* iTunes name of the song/movie */
911 static int mov_write_nam_tag(ByteIOContext *pb, MOVContext* mov,
916 int pos = url_ftell(pb);
917 put_be32(pb, 0); /* size */
918 put_tag(pb, "\251nam");
919 mov_write_string_data_tag(pb, mov, s, s->title);
920 size = updateSize(pb, pos);
925 /* iTunes name of the artist/performer */
926 static int mov_write_ART_tag(ByteIOContext *pb, MOVContext* mov,
930 if ( s->author[0] ) {
931 int pos = url_ftell(pb);
932 put_be32(pb, 0); /* size */
933 put_tag(pb, "\251ART");
934 // we use the author here as this is the only thing that we have...
935 mov_write_string_data_tag(pb, mov, s, s->author);
936 size = updateSize(pb, pos);
941 /* iTunes name of the writer */
942 static int mov_write_wrt_tag(ByteIOContext *pb, MOVContext* mov,
946 if ( s->author[0] ) {
947 int pos = url_ftell(pb);
948 put_be32(pb, 0); /* size */
949 put_tag(pb, "\251wrt");
950 mov_write_string_data_tag(pb, mov, s, s->author);
951 size = updateSize(pb, pos);
956 /* iTunes name of the album */
957 static int mov_write_alb_tag(ByteIOContext *pb, MOVContext* mov,
962 int pos = url_ftell(pb);
963 put_be32(pb, 0); /* size */
964 put_tag(pb, "\251alb");
965 mov_write_string_data_tag(pb, mov, s, s->album);
966 size = updateSize(pb, pos);
972 static int mov_write_day_tag(ByteIOContext *pb, MOVContext* mov,
978 int pos = url_ftell(pb);
979 put_be32(pb, 0); /* size */
980 put_tag(pb, "\251day");
981 snprintf(year, 5, "%04d", s->year);
982 mov_write_string_data_tag(pb, mov, s, year);
983 size = updateSize(pb, pos);
988 /* iTunes tool used to create the file */
989 static int mov_write_too_tag(ByteIOContext *pb, MOVContext* mov,
992 int pos = url_ftell(pb);
993 put_be32(pb, 0); /* size */
994 put_tag(pb, "\251too");
995 mov_write_string_data_tag(pb, mov, s, LIBAVFORMAT_IDENT);
996 return updateSize(pb, pos);
1000 static int mov_write_cmt_tag(ByteIOContext *pb, MOVContext* mov,
1004 if ( s->comment[0] ) {
1005 int pos = url_ftell(pb);
1006 put_be32(pb, 0); /* size */
1007 put_tag(pb, "\251cmt");
1008 mov_write_string_data_tag(pb, mov, s, s->comment);
1009 size = updateSize(pb, pos);
1014 /* iTunes custom genre */
1015 static int mov_write_gen_tag(ByteIOContext *pb, MOVContext* mov,
1019 if ( s->genre[0] ) {
1020 int pos = url_ftell(pb);
1021 put_be32(pb, 0); /* size */
1022 put_tag(pb, "\251gen");
1023 mov_write_string_data_tag(pb, mov, s, s->genre);
1024 size = updateSize(pb, pos);
1029 /* iTunes track number */
1030 static int mov_write_trkn_tag(ByteIOContext *pb, MOVContext* mov,
1035 int pos = url_ftell(pb);
1036 put_be32(pb, 0); /* size */
1037 put_tag(pb, "trkn");
1039 int pos = url_ftell(pb);
1040 put_be32(pb, 0); /* size */
1041 put_tag(pb, "data");
1042 put_be32(pb, 0); // 8 bytes empty
1044 put_be16(pb, 0); // empty
1045 put_be16(pb, s->track); // track number
1046 put_be16(pb, 0); // total track number
1047 put_be16(pb, 0); // empty
1048 updateSize(pb, pos);
1050 size = updateSize(pb, pos);
1055 /* iTunes meta data list */
1056 static int mov_write_ilst_tag(ByteIOContext *pb, MOVContext* mov,
1059 int pos = url_ftell(pb);
1060 put_be32(pb, 0); /* size */
1061 put_tag(pb, "ilst");
1062 mov_write_nam_tag(pb, mov, s);
1063 mov_write_ART_tag(pb, mov, s);
1064 mov_write_wrt_tag(pb, mov, s);
1065 mov_write_alb_tag(pb, mov, s);
1066 mov_write_day_tag(pb, mov, s);
1067 mov_write_too_tag(pb, mov, s);
1068 mov_write_cmt_tag(pb, mov, s);
1069 mov_write_gen_tag(pb, mov, s);
1070 mov_write_trkn_tag(pb, mov, s);
1071 return updateSize(pb, pos);
1074 /* iTunes meta data tag */
1075 static int mov_write_meta_tag(ByteIOContext *pb, MOVContext* mov,
1080 // only save meta tag if required
1081 if ( s->title[0] || s->author[0] || s->album[0] || s->year ||
1082 s->comment[0] || s->genre[0] || s->track ) {
1083 int pos = url_ftell(pb);
1084 put_be32(pb, 0); /* size */
1085 put_tag(pb, "meta");
1087 mov_write_itunes_hdlr_tag(pb, mov, s);
1088 mov_write_ilst_tag(pb, mov, s);
1089 size = updateSize(pb, pos);
1094 static int mov_write_udta_tag(ByteIOContext *pb, MOVContext* mov,
1097 int pos = url_ftell(pb);
1100 put_be32(pb, 0); /* size */
1101 put_tag(pb, "udta");
1103 /* iTunes meta data */
1104 mov_write_meta_tag(pb, mov, s);
1107 for (i=0; i<MAX_STREAMS; i++) {
1108 if(mov->tracks[i].entry <= 0) continue;
1109 if (mov->tracks[i].enc->codec_id == CODEC_ID_AAC ||
1110 mov->tracks[i].enc->codec_id == CODEC_ID_MPEG4) {
1111 int pos = url_ftell(pb);
1112 put_be32(pb, 0); /* size */
1113 put_tag(pb, "\251req");
1114 put_be16(pb, sizeof("QuickTime 6.0 or greater") - 1);
1116 put_buffer(pb, "QuickTime 6.0 or greater",
1117 sizeof("QuickTime 6.0 or greater") - 1);
1118 updateSize(pb, pos);
1124 if(mov->tracks[0].enc && !(mov->tracks[0].enc->flags & CODEC_FLAG_BITEXACT))
1126 int pos = url_ftell(pb);
1127 put_be32(pb, 0); /* size */
1128 put_tag(pb, "\251enc");
1129 put_be16(pb, sizeof(LIBAVFORMAT_IDENT) - 1); /* string length */
1131 put_buffer(pb, LIBAVFORMAT_IDENT, sizeof(LIBAVFORMAT_IDENT) - 1);
1132 updateSize(pb, pos);
1137 int pos = url_ftell(pb);
1138 put_be32(pb, 0); /* size */
1139 put_tag(pb, "\251nam");
1140 put_be16(pb, strlen(s->title)); /* string length */
1142 put_buffer(pb, s->title, strlen(s->title));
1143 updateSize(pb, pos);
1148 int pos = url_ftell(pb);
1149 put_be32(pb, 0); /* size */
1150 put_tag(pb, /*"\251aut"*/ "\251day" );
1151 put_be16(pb, strlen(s->author)); /* string length */
1153 put_buffer(pb, s->author, strlen(s->author));
1154 updateSize(pb, pos);
1159 int pos = url_ftell(pb);
1160 put_be32(pb, 0); /* size */
1161 put_tag(pb, "\251des");
1162 put_be16(pb, strlen(s->comment)); /* string length */
1164 put_buffer(pb, s->comment, strlen(s->comment));
1165 updateSize(pb, pos);
1168 return updateSize(pb, pos);
1171 static int mov_write_moov_tag(ByteIOContext *pb, MOVContext *mov,
1175 pos = url_ftell(pb);
1176 put_be32(pb, 0); /* size placeholder*/
1177 put_tag(pb, "moov");
1178 mov->timescale = globalTimescale;
1180 for (i=0; i<MAX_STREAMS; i++) {
1181 if(mov->tracks[i].entry <= 0) continue;
1183 if(mov->tracks[i].enc->codec_type == CODEC_TYPE_VIDEO) {
1184 mov->tracks[i].timescale = mov->tracks[i].enc->frame_rate;
1185 mov->tracks[i].sampleDuration = mov->tracks[i].enc->frame_rate_base;
1187 else if(mov->tracks[i].enc->codec_type == CODEC_TYPE_AUDIO) {
1188 /* If AMR, track timescale = 8000, AMR_WB = 16000 */
1189 if(mov->tracks[i].enc->codec_id == CODEC_ID_AMR_NB) {
1190 mov->tracks[i].sampleDuration = 160; // Bytes per chunk
1191 mov->tracks[i].timescale = 8000;
1194 mov->tracks[i].timescale = mov->tracks[i].enc->sample_rate;
1195 mov->tracks[i].sampleDuration = mov->tracks[i].enc->frame_size;
1199 mov->tracks[i].trackDuration =
1200 mov->tracks[i].sampleCount * mov->tracks[i].sampleDuration;
1201 mov->tracks[i].time = mov->time;
1202 mov->tracks[i].trackID = i+1;
1205 mov_write_mvhd_tag(pb, mov);
1206 //mov_write_iods_tag(pb, mov);
1207 for (i=0; i<MAX_STREAMS; i++) {
1208 if(mov->tracks[i].entry > 0) {
1209 mov_write_trak_tag(pb, &(mov->tracks[i]));
1213 mov_write_udta_tag(pb, mov, s);
1215 return updateSize(pb, pos);
1218 int mov_write_mdat_tag(ByteIOContext *pb, MOVContext* mov)
1220 mov->mdat_pos = url_ftell(pb);
1221 put_be32(pb, 0); /* size placeholder*/
1222 put_tag(pb, "mdat");
1226 /* TODO: This needs to be more general */
1227 int mov_write_ftyp_tag(ByteIOContext *pb, AVFormatContext *s)
1229 MOVContext *mov = s->priv_data;
1231 put_be32(pb, 0x14 ); /* size */
1232 put_tag(pb, "ftyp");
1234 if ( mov->mode == MODE_3GP )
1235 put_tag(pb, "3gp4");
1236 else if ( mov->mode == MODE_3G2 )
1237 put_tag(pb, "3g2a");
1238 else if ( mov->mode == MODE_PSP )
1239 put_tag(pb, "MSNV");
1241 put_tag(pb, "isom");
1243 put_be32(pb, 0x200 );
1245 if ( mov->mode == MODE_3GP )
1246 put_tag(pb, "3gp4");
1247 else if ( mov->mode == MODE_3G2 )
1248 put_tag(pb, "3g2a");
1249 else if ( mov->mode == MODE_PSP )
1250 put_tag(pb, "MSNV");
1252 put_tag(pb, "mp41");
1257 static void mov_write_uuidprof_tag(ByteIOContext *pb, AVFormatContext *s)
1259 int AudioRate = s->streams[1]->codec.sample_rate;
1260 int FrameRate = ((s->streams[0]->codec.frame_rate) * (0x10000))/ (s->streams[0]->codec.frame_rate_base);
1262 //printf("audiorate = %d\n",AudioRate);
1263 //printf("framerate = %d / %d = 0x%x\n",s->streams[0]->codec.frame_rate,s->streams[0]->codec.frame_rate_base,FrameRate);
1265 put_be32(pb, 0x94 ); /* size */
1266 put_tag(pb, "uuid");
1267 put_tag(pb, "PROF");
1269 put_be32(pb, 0x21d24fce ); /* 96 bit UUID */
1270 put_be32(pb, 0xbb88695c );
1271 put_be32(pb, 0xfac9c740 );
1273 put_be32(pb, 0x0 ); /* ? */
1274 put_be32(pb, 0x3 ); /* 3 sections ? */
1276 put_be32(pb, 0x14 ); /* size */
1277 put_tag(pb, "FPRF");
1278 put_be32(pb, 0x0 ); /* ? */
1279 put_be32(pb, 0x0 ); /* ? */
1280 put_be32(pb, 0x0 ); /* ? */
1282 put_be32(pb, 0x2c ); /* size */
1283 put_tag(pb, "APRF"); /* audio */
1286 put_tag(pb, "mp4a");
1287 put_be32(pb, 0x20f );
1289 put_be32(pb, 0x40 );
1290 put_be32(pb, 0x40 );
1291 put_be32(pb, AudioRate ); //24000 ... audio rate?
1294 put_be32(pb, 0x34 ); /* size */
1295 put_tag(pb, "VPRF"); /* video */
1298 put_tag(pb, "mp4v");
1299 put_be32(pb, 0x103 );
1301 put_be32(pb, 0xc0 );
1302 put_be32(pb, 0xc0 );
1303 put_be32(pb, FrameRate); // was 0xefc29
1304 put_be32(pb, FrameRate ); // was 0xefc29
1305 put_be16(pb, s->streams[0]->codec.width);
1306 put_be16(pb, s->streams[0]->codec.height);
1307 put_be32(pb, 0x010001 );
1310 static int mov_write_header(AVFormatContext *s)
1312 ByteIOContext *pb = &s->pb;
1313 MOVContext *mov = s->priv_data;
1316 for(i=0; i<s->nb_streams; i++){
1317 AVCodecContext *c= &s->streams[i]->codec;
1319 if (c->codec_type == CODEC_TYPE_VIDEO){
1320 if (!codec_get_tag(codec_movvideo_tags, c->codec_id)){
1321 if(!codec_get_tag(codec_bmp_tags, c->codec_id))
1324 av_log(s, AV_LOG_INFO, "Warning, using MS style video codec tag, the file may be unplayable!\n");
1326 }else if(c->codec_type == CODEC_TYPE_AUDIO){
1327 if (!codec_get_tag(codec_movaudio_tags, c->codec_id)){
1328 if(!codec_get_tag(codec_wav_tags, c->codec_id))
1331 av_log(s, AV_LOG_INFO, "Warning, using MS style audio codec tag, the file may be unplayable!\n");
1336 /* Default mode == MP4 */
1337 mov->mode = MODE_MP4;
1339 if (s->oformat != NULL) {
1340 if (!strcmp("3gp", s->oformat->name)) mov->mode = MODE_3GP;
1341 else if (!strcmp("3g2", s->oformat->name)) mov->mode = MODE_3G2;
1342 else if (!strcmp("mov", s->oformat->name)) mov->mode = MODE_MOV;
1343 else if (!strcmp("psp", s->oformat->name)) mov->mode = MODE_PSP;
1345 if ( mov->mode == MODE_3GP || mov->mode == MODE_3G2 ||
1346 mov->mode == MODE_MP4 || mov->mode == MODE_PSP )
1347 mov_write_ftyp_tag(pb,s);
1348 if ( mov->mode == MODE_PSP ) {
1349 if ( s->nb_streams != 2 ) {
1350 av_log(s, AV_LOG_ERROR, "PSP mode need one video and one audio stream\n");
1353 mov_write_uuidprof_tag(pb,s);
1357 for (i=0; i<MAX_STREAMS; i++) {
1358 mov->tracks[i].mode = mov->mode;
1361 put_flush_packet(pb);
1366 static int mov_write_packet(AVFormatContext *s, AVPacket *pkt)
1368 MOVContext *mov = s->priv_data;
1369 ByteIOContext *pb = &s->pb;
1370 AVCodecContext *enc = &s->streams[pkt->stream_index]->codec;
1371 MOVTrack* trk = &mov->tracks[pkt->stream_index];
1373 unsigned int samplesInChunk = 0;
1374 int size= pkt->size;
1376 if (url_is_streamed(&s->pb)) return 0; /* Can't handle that */
1377 if (!size) return 0; /* Discard 0 sized packets */
1379 if (enc->codec_type == CODEC_TYPE_VIDEO ) {
1382 else if (enc->codec_type == CODEC_TYPE_AUDIO ) {
1383 if( enc->codec_id == CODEC_ID_AMR_NB) {
1384 /* We must find out how many AMR blocks there are in one packet */
1385 static uint16_t packed_size[16] =
1386 {13, 14, 16, 18, 20, 21, 27, 32, 6, 0, 0, 0, 0, 0, 0, 0};
1389 while (len < size && samplesInChunk < 100) {
1390 len += packed_size[(pkt->data[len] >> 3) & 0x0F];
1394 else if(enc->codec_id == CODEC_ID_PCM_ALAW) {
1395 samplesInChunk = size/enc->channels;
1397 else if(enc->codec_id == CODEC_ID_PCM_S16BE || enc->codec_id == CODEC_ID_PCM_S16LE) {
1398 samplesInChunk = size/(2*enc->channels);
1405 if ((enc->codec_id == CODEC_ID_MPEG4 || enc->codec_id == CODEC_ID_AAC)
1406 && trk->vosLen == 0) {
1407 // assert(enc->extradata_size);
1409 trk->vosLen = enc->extradata_size;
1410 trk->vosData = av_malloc(trk->vosLen);
1411 memcpy(trk->vosData, enc->extradata, trk->vosLen);
1414 cl = trk->entry / MOV_INDEX_CLUSTER_SIZE;
1415 id = trk->entry % MOV_INDEX_CLUSTER_SIZE;
1417 if (trk->ents_allocated <= trk->entry) {
1418 trk->cluster = av_realloc(trk->cluster, (cl+1)*sizeof(void*));
1421 trk->cluster[cl] = av_malloc(MOV_INDEX_CLUSTER_SIZE*sizeof(MOVIentry));
1422 if (!trk->cluster[cl])
1424 trk->ents_allocated += MOV_INDEX_CLUSTER_SIZE;
1426 if (mov->mdat_written == 0) {
1427 mov_write_mdat_tag(pb, mov);
1428 mov->mdat_written = 1;
1429 mov->time = s->timestamp + 0x7C25B080; //1970 based -> 1904 based
1432 trk->cluster[cl][id].pos = url_ftell(pb);
1433 trk->cluster[cl][id].samplesInChunk = samplesInChunk;
1434 trk->cluster[cl][id].size = size;
1435 trk->cluster[cl][id].entries = samplesInChunk;
1436 if(enc->codec_type == CODEC_TYPE_VIDEO) {
1437 trk->cluster[cl][id].key_frame = !!(pkt->flags & PKT_FLAG_KEY);
1438 if(trk->cluster[cl][id].key_frame)
1439 trk->hasKeyframes = 1;
1443 trk->sampleCount += samplesInChunk;
1444 trk->mdat_size += size;
1446 put_buffer(pb, pkt->data, size);
1448 put_flush_packet(pb);
1452 static int mov_write_trailer(AVFormatContext *s)
1454 MOVContext *mov = s->priv_data;
1455 ByteIOContext *pb = &s->pb;
1459 offset_t moov_pos = url_ftell(pb);
1461 /* Write size of mdat tag */
1462 for (i=0, j=0; i<MAX_STREAMS; i++) {
1463 if(mov->tracks[i].ents_allocated > 0) {
1464 j += mov->tracks[i].mdat_size;
1467 url_fseek(pb, mov->mdat_pos, SEEK_SET);
1469 url_fseek(pb, moov_pos, SEEK_SET);
1471 mov_write_moov_tag(pb, mov, s);
1473 for (i=0; i<MAX_STREAMS; i++) {
1474 for (j=0; j<mov->tracks[i].ents_allocated/MOV_INDEX_CLUSTER_SIZE; j++) {
1475 av_free(mov->tracks[i].cluster[j]);
1477 av_free(mov->tracks[i].cluster);
1478 if( mov->tracks[i].vosLen ) av_free( mov->tracks[i].vosData );
1480 mov->tracks[i].cluster = NULL;
1481 mov->tracks[i].ents_allocated = mov->tracks[i].entry = 0;
1484 put_flush_packet(pb);
1489 static AVOutputFormat mov_oformat = {
1500 .flags = AVFMT_GLOBALHEADER,
1503 static AVOutputFormat _3gp_oformat = {
1514 .flags = AVFMT_GLOBALHEADER,
1517 static AVOutputFormat mp4_oformat = {
1528 .flags = AVFMT_GLOBALHEADER,
1531 static AVOutputFormat psp_oformat = {
1542 .flags = AVFMT_GLOBALHEADER,
1545 static AVOutputFormat _3g2_oformat = {
1556 .flags = AVFMT_GLOBALHEADER,
1559 int movenc_init(void)
1561 av_register_output_format(&mov_oformat);
1562 av_register_output_format(&_3gp_oformat);
1563 av_register_output_format(&mp4_oformat);
1564 av_register_output_format(&psp_oformat);
1565 av_register_output_format(&_3g2_oformat);