annotate movenc.c @ 286:eccf0c3e3289 libavformat

Using the extension m4a for audio only MPEG-4 files is increasingly common, especially since Apple iTunes treats files with the two extensions differently. Without the patch, FFmpeg won't know that m4a is for MPEG-4 files patch by (Dan Christiansen <danchr at daimi dot au dot dk>)
author michael
date Sun, 19 Oct 2003 20:57:47 +0000
parents e091218eccd2
children 0b2eed7b1210
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1 /*
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
2 * MOV, 3GP, MP4 encoder.
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
3 * Copyright (c) 2003 Thomas Raivio.
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
4 *
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
9 *
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
13 * Lesser General Public License for more details.
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
14 *
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
18 */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
19 #include "avformat.h"
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
20 #include "avi.h"
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
21 #include "avio.h"
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
22 #include <time.h>
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
23
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
24 #undef NDEBUG
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
25 #include <assert.h>
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
26
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
27 #define MOV_INDEX_CLUSTER_SIZE 16384
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
28 #define globalTimescale 1000
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
29
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
30 typedef struct MOVIentry {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
31 unsigned int flags, pos, len;
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
32 unsigned int chunkSize;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
33 char key_frame;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
34 unsigned int entries;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
35 } MOVIentry;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
36
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
37 typedef struct MOVIndex {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
38 int entry;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
39 int samples;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
40 int mdat_size;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
41 int ents_allocated;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
42 long timescale;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
43 long time;
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
44 long frameCount;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
45 long trackDuration;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
46 long sampleDelta;
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
47 int hasKeyframes;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
48 int trackID;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
49 AVCodecContext *enc;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
50
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
51 int vosLen;
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
52 uint8_t *vosData;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
53 MOVIentry** cluster;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
54 } MOVTrack;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
55
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
56 typedef struct {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
57 long time;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
58 int nb_streams;
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
59 int mdat_written;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
60 offset_t mdat_pos;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
61 offset_t movi_list;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
62 long timescale;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
63 MOVTrack tracks[MAX_STREAMS];
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
64 } MOVContext;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
65
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
66 //FIXME supprt 64bit varaint with wide placeholders
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
67 static int updateSize (ByteIOContext *pb, int pos)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
68 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
69 long curpos = url_ftell(pb);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
70 url_fseek(pb, pos, SEEK_SET);
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
71 put_be32(pb, curpos - pos); /* rewrite size */
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
72 url_fseek(pb, curpos, SEEK_SET);
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
73
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
74 return curpos - pos;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
75 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
76
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
77 static int mov_write_stco_tag(ByteIOContext *pb, MOVTrack* track)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
78 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
79 int i;
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
80 int pos = url_ftell(pb);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
81 put_be32(pb, 0); /* size */
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
82 put_tag(pb, "stco");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
83 put_be32(pb, 0); /* version & flags */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
84 put_be32(pb, track->entry); /* entry count */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
85 for (i=0; i<track->entry; i++) {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
86 int cl = i / MOV_INDEX_CLUSTER_SIZE;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
87 int id = i % MOV_INDEX_CLUSTER_SIZE;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
88 put_be32(pb, track->cluster[cl][id].pos);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
89 }
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
90 return updateSize (pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
91 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
92
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
93 static int mov_write_stsz_tag(ByteIOContext *pb, MOVTrack* track)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
94 {
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
95 int equalChunks = 1;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
96 int i, tst = -1, oldtst = -1;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
97
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
98 int pos = url_ftell(pb);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
99 put_be32(pb, 0); /* size */
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
100 put_tag(pb, "stsz");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
101 put_be32(pb, 0); /* version & flags */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
102
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
103 for (i=0; i<track->entry; i++) {
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
104 int cl = i / MOV_INDEX_CLUSTER_SIZE;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
105 int id = i % MOV_INDEX_CLUSTER_SIZE;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
106 tst = track->cluster[cl][id].len;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
107 if(oldtst != -1 && tst != oldtst) {
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
108 equalChunks = 0;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
109 break;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
110 }
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
111 oldtst = tst;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
112 }
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
113 if(equalChunks ||
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
114 track->enc->codec_type == CODEC_TYPE_AUDIO) {
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
115 //int sSize = track->cluster[0][0].len/track->cluster[0][0].entries;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
116 int sSize = track->cluster[0][0].len;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
117 put_be32(pb, sSize); // sample size
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
118 put_be32(pb, track->samples/track->enc->channels); // sample count
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
119 }
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
120 else {
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
121 put_be32(pb, 0); // sample size
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
122 put_be32(pb, track->entry); // sample count
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
123 for (i=0; i<track->entry; i++) {
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
124 int cl = i / MOV_INDEX_CLUSTER_SIZE;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
125 int id = i % MOV_INDEX_CLUSTER_SIZE;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
126 put_be32(pb, track->cluster[cl][id].len);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
127 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
128 }
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
129 return updateSize (pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
130 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
131
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
132 static int mov_write_stsc_tag(ByteIOContext *pb, MOVTrack* track)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
133 {
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
134 int index = 0, oldval = -1, i, entryPos, curpos;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
135
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
136 int pos = url_ftell(pb);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
137 put_be32(pb, 0); /* size */
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
138 put_tag(pb, "stsc");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
139 put_be32(pb, 0); // version & flags
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
140 entryPos = url_ftell(pb);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
141 put_be32(pb, track->entry); // entry count
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
142 for (i=0; i<track->entry; i++) {
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
143 int cl = i / MOV_INDEX_CLUSTER_SIZE;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
144 int id = i % MOV_INDEX_CLUSTER_SIZE;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
145 if(oldval != track->cluster[cl][id].chunkSize)
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
146 {
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
147 put_be32(pb, i+1); // first chunk
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
148 put_be32(pb, track->cluster[cl][id].chunkSize);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
149 put_be32(pb, 0x1); // sample description index
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
150 oldval = track->cluster[cl][id].chunkSize;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
151 index++;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
152 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
153 }
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
154 curpos = url_ftell(pb);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
155 url_fseek(pb, entryPos, SEEK_SET);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
156 put_be32(pb, index); // rewrite size
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
157 url_fseek(pb, curpos, SEEK_SET);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
158
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
159 return updateSize (pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
160 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
161
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
162 static int mov_write_stss_tag(ByteIOContext *pb, MOVTrack* track)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
163 {
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
164 long curpos;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
165 int i, index = 0, entryPos;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
166 int pos = url_ftell(pb);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
167 put_be32(pb, 0); // size
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
168 put_tag(pb, "stss");
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
169 put_be32(pb, 0); // version & flags
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
170 entryPos = url_ftell(pb);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
171 put_be32(pb, track->entry); // entry count
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
172 for (i=0; i<track->entry; i++) {
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
173 int cl = i / MOV_INDEX_CLUSTER_SIZE;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
174 int id = i % MOV_INDEX_CLUSTER_SIZE;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
175 if(track->cluster[cl][id].key_frame == 1) {
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
176 put_be32(pb, i+1);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
177 index++;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
178 }
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
179 }
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
180 curpos = url_ftell(pb);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
181 url_fseek(pb, entryPos, SEEK_SET);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
182 put_be32(pb, index); // rewrite size
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
183 url_fseek(pb, curpos, SEEK_SET);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
184 return updateSize (pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
185 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
186
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
187 static int mov_write_damr_tag(ByteIOContext *pb)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
188 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
189 put_be32(pb, 0x11); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
190 put_tag(pb, "damr");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
191 put_tag(pb, "FFMP");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
192 put_byte(pb, 0);
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
193
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
194 put_be16(pb, 0x80); /* Mode set (all modes for AMR_NB) */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
195 put_be16(pb, 0xa); /* Mode change period (no restriction) */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
196 //put_be16(pb, 0x81ff); /* Mode set (all modes for AMR_NB) */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
197 //put_be16(pb, 1); /* Mode change period (no restriction) */
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
198 return 0x11;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
199 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
200
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
201 static int mov_write_audio_tag(ByteIOContext *pb, MOVTrack* track)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
202 {
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
203 int pos = url_ftell(pb);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
204 put_be32(pb, 0); /* size */
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
205
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
206 if(track->enc->codec_id == CODEC_ID_PCM_MULAW)
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
207 put_tag(pb, "ulaw");
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
208 else if(track->enc->codec_id == CODEC_ID_PCM_ALAW)
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
209 put_tag(pb, "alaw");
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
210 else if(track->enc->codec_id == CODEC_ID_ADPCM_IMA_QT)
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
211 put_tag(pb, "ima4");
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
212 else if(track->enc->codec_id == CODEC_ID_MACE3)
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
213 put_tag(pb, "MAC3");
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
214 else if(track->enc->codec_id == CODEC_ID_MACE6)
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
215 put_tag(pb, "MAC6");
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
216 else if(track->enc->codec_id == CODEC_ID_AAC)
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
217 put_tag(pb, "mp4a");
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
218 else if(track->enc->codec_id == CODEC_ID_AMR_NB)
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
219 put_tag(pb, "samr");
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
220 else
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
221 put_tag(pb, " ");
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
222
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
223 put_be32(pb, 0); /* Reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
224 put_be16(pb, 0); /* Reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
225 put_be16(pb, 1); /* Data-reference index, XXX == 1 */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
226 put_be32(pb, 0); /* Reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
227 put_be32(pb, 0); /* Reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
228
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
229 put_be16(pb, track->enc->channels); /* Number of channels */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
230 /* TODO: Currently hard-coded to 16-bit, there doesn't seem
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
231 to be a good way to get number of bits of audio */
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
232 put_be16(pb, 0x10); /* Reserved */
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
233 put_be16(pb, 0); /* compression ID (= 0) */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
234 put_be16(pb, 0); /* packet size (= 0) */
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
235 put_be16(pb, track->timescale); /* Time scale */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
236 put_be16(pb, 0); /* Reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
237
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
238 if(track->enc->codec_id == CODEC_ID_AMR_NB)
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
239 mov_write_damr_tag(pb);
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
240 return updateSize (pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
241 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
242
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
243 static int mov_write_d263_tag(ByteIOContext *pb)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
244 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
245 put_be32(pb, 0xf); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
246 put_tag(pb, "d263");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
247 put_tag(pb, "FFMP");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
248 put_be16(pb, 0x0a);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
249 put_byte(pb, 0);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
250 return 0xf;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
251 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
252
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
253 /* TODO: No idea about these values */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
254 static int mov_write_svq3_tag(ByteIOContext *pb)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
255 {
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
256 put_be32(pb, 0x15);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
257 put_tag(pb, "SMI ");
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
258 put_tag(pb, "SEQH");
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
259 put_be32(pb, 0x5);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
260 put_be32(pb, 0xe2c0211d);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
261 put_be32(pb, 0xc0000000);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
262 put_byte(pb, 0);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
263 return 0x15;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
264 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
265
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
266 static unsigned int esdsLength(unsigned int len)
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
267 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
268 unsigned int result = 0;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
269 unsigned char b = len & 0x7f;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
270 result += b;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
271 b = (len >> 8) & 0x7f;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
272 result += (b + 0x80) << 8;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
273 b = (len >> 16) & 0x7f;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
274 result += (b + 0x80) << 16;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
275 b = (len >> 24) & 0x7f;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
276 result += (b + 0x80) << 24;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
277 return result;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
278 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
279
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
280 static int mov_write_esds_tag(ByteIOContext *pb, MOVTrack* track) // Basic
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
281 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
282 put_be32(pb, track->vosLen+18+14+17);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
283 put_tag(pb, "esds");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
284 put_be32(pb, 0); // Version
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
285
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
286 put_byte(pb, 0x03); // tag = ES_DescriptorTag
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
287 put_be32(pb, esdsLength(track->vosLen+18+14)); // Length
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
288 put_be16(pb, 0x0001); // ID (= 1)
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
289 put_byte(pb, 0x00); // flags (= no flags)
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
290
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
291 // Decoderconfigdescriptor = 4
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
292 put_byte(pb, 0x04); // tag = DecoderConfigDescriptor
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
293 put_be32(pb, esdsLength(track->vosLen+18)); // Length
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
294 put_byte(pb, 0x20); // Object type indication (Visual 14496-2)
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
295 put_byte(pb, 0x11); // flags (= Visualstream)
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
296 put_byte(pb, 0x0); // Buffersize DB (24 bits)
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
297 put_be16(pb, 0x0dd2); // Buffersize DB
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
298
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
299 // TODO: find real values for these
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
300 put_be32(pb, 0x0002e918); // maxbitrate
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
301 put_be32(pb, 0x00017e6b); // avg bitrate
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
302
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
303 // Decoderspecific info Tag = 5
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
304 put_byte(pb, 0x05); // tag = Decoderspecific info
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
305 put_be32(pb, esdsLength(track->vosLen)); // length
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
306 put_buffer(pb, track->vosData, track->vosLen);
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
307
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
308 put_byte(pb, 0x06);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
309 put_be32(pb, esdsLength(1)); // length
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
310 put_byte(pb, 0x02);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
311 return track->vosLen+18+14+17;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
312 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
313
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
314 static int mov_write_video_tag(ByteIOContext *pb, MOVTrack* track)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
315 {
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
316 int pos = url_ftell(pb);
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
317 put_be32(pb, 0); /* size */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
318 if(track->enc->codec_id == CODEC_ID_SVQ1)
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
319 put_tag(pb, "SVQ1");
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
320 else if(track->enc->codec_id == CODEC_ID_SVQ3)
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
321 put_tag(pb, "SVQ3");
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
322 else if(track->enc->codec_id == CODEC_ID_MPEG4)
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
323 put_tag(pb, "mp4v");
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
324 else if(track->enc->codec_id == CODEC_ID_H263)
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
325 put_tag(pb, "s263");
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
326 else
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
327 put_tag(pb, " "); /* Unknown tag */
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
328
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
329 put_be32(pb, 0); /* Reserved */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
330 put_be16(pb, 0); /* Reserved */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
331 put_be16(pb, 1); /* Data-reference index */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
332
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
333 put_be32(pb, 0); /* Reserved (= 02000c) */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
334 put_be32(pb, 0); /* Reserved ("SVis")*/
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
335 put_be32(pb, 0); /* Reserved */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
336 put_be32(pb, 0); /* Reserved (400)*/
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
337 put_be16(pb, track->enc->width); /* Video width */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
338 put_be16(pb, track->enc->height); /* Video height */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
339 put_be32(pb, 0x00480000); /* Reserved */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
340 put_be32(pb, 0x00480000); /* Reserved */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
341 put_be32(pb, 0); /* Reserved */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
342 put_be32(pb, 0); /* Reserved */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
343 put_be32(pb, 0); /* Reserved */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
344 put_be32(pb, 0); /* Reserved */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
345 put_be32(pb, 0); /* Reserved */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
346 put_be32(pb, 0); /* Reserved */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
347
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
348 put_be16(pb, 0); /* Reserved */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
349 put_be32(pb, 0); /* Reserved */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
350 put_be32(pb, 0); /* Reserved */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
351 put_be32(pb, 0); /* Reserved */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
352 put_be16(pb, 0x18); /* Reserved */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
353 put_be16(pb, 0xffff); /* Reserved */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
354 if(track->enc->codec_id == CODEC_ID_MPEG4)
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
355 mov_write_esds_tag(pb, track);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
356 else if(track->enc->codec_id == CODEC_ID_H263)
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
357 mov_write_d263_tag(pb);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
358 else if(track->enc->codec_id == CODEC_ID_SVQ3)
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
359 mov_write_svq3_tag(pb);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
360
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
361 return updateSize (pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
362 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
363
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
364 static int mov_write_stsd_tag(ByteIOContext *pb, MOVTrack* track)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
365 {
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
366 int pos = url_ftell(pb);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
367 put_be32(pb, 0); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
368 put_tag(pb, "stsd");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
369 put_be32(pb, 0); /* version & flags */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
370 put_be32(pb, 1); /* entry count */
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
371 if (track->enc->codec_type == CODEC_TYPE_VIDEO)
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
372 mov_write_video_tag(pb, track);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
373 else if (track->enc->codec_type == CODEC_TYPE_AUDIO)
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
374 mov_write_audio_tag(pb, track);
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
375 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
376 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
377
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
378 /* TODO?: Currently all samples/frames seem to have same duration */
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
379 static int mov_write_stts_tag(ByteIOContext *pb, MOVTrack* track)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
380 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
381 put_be32(pb, 0x18); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
382 put_tag(pb, "stts");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
383 put_be32(pb, 0); /* version & flags */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
384 put_be32(pb, 1); /* entry count */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
385
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
386 put_be32(pb, track->frameCount); /* sample count */
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
387 put_be32(pb, track->sampleDelta); /* sample delta */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
388 return 0x18;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
389 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
390
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
391 static int mov_write_dref_tag(ByteIOContext *pb)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
392 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
393 put_be32(pb, 28); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
394 put_tag(pb, "dref");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
395 put_be32(pb, 0); /* version & flags */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
396 put_be32(pb, 1); /* entry count */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
397
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
398 put_be32(pb, 0xc); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
399 put_tag(pb, "url ");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
400 put_be32(pb, 1); /* version & flags */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
401
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
402 return 28;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
403 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
404
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
405 static int mov_write_stbl_tag(ByteIOContext *pb, MOVTrack* track)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
406 {
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
407 int pos = url_ftell(pb);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
408 put_be32(pb, 0); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
409 put_tag(pb, "stbl");
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
410 mov_write_stsd_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
411 mov_write_stts_tag(pb, track);
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
412 if (track->enc->codec_type == CODEC_TYPE_VIDEO &&
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
413 track->hasKeyframes)
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
414 mov_write_stss_tag(pb, track);
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
415 mov_write_stsc_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
416 mov_write_stsz_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
417 mov_write_stco_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
418 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
419 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
420
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
421 static int mov_write_dinf_tag(ByteIOContext *pb)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
422 {
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
423 int pos = url_ftell(pb);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
424 put_be32(pb, 0); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
425 put_tag(pb, "dinf");
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
426 mov_write_dref_tag(pb);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
427 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
428 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
429
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
430 static int mov_write_smhd_tag(ByteIOContext *pb)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
431 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
432 put_be32(pb, 16); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
433 put_tag(pb, "smhd");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
434 put_be32(pb, 0); /* version & flags */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
435 put_be16(pb, 0); /* reserved (balance, normally = 0) */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
436 put_be16(pb, 0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
437 return 16;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
438 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
439
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
440 static int mov_write_vmhd_tag(ByteIOContext *pb)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
441 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
442 put_be32(pb, 0x14); /* size (always 0x14) */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
443 put_tag(pb, "vmhd");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
444 put_be32(pb, 0x01); /* version & flags */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
445 put_be64(pb, 0); /* reserved (graphics mode = copy) */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
446 return 0x14;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
447 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
448
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
449 static int mov_write_minf_tag(ByteIOContext *pb, MOVTrack* track)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
450 {
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
451 int pos = url_ftell(pb);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
452 put_be32(pb, 0); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
453 put_tag(pb, "minf");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
454 if(track->enc->codec_type == CODEC_TYPE_VIDEO)
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
455 mov_write_vmhd_tag(pb);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
456 else
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
457 mov_write_smhd_tag(pb);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
458 mov_write_dinf_tag(pb);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
459 mov_write_stbl_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
460 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
461 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
462
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
463 static int mov_write_hdlr_tag(ByteIOContext *pb, MOVTrack* track)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
464 {
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
465 char *str;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
466 int pos = url_ftell(pb);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
467 put_be32(pb, 0); /* size */
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
468 put_tag(pb, "hdlr");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
469 put_be32(pb, 0); /* Version & flags */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
470 put_be32(pb, 0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
471 if(track->enc->codec_type == CODEC_TYPE_VIDEO)
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
472 put_tag(pb, "vide"); /* handler type */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
473 else
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
474 put_tag(pb, "soun"); /* handler type */
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
475 put_be32(pb ,0); /* reserved */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
476 put_be32(pb ,0); /* reserved */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
477 put_be32(pb ,0); /* reserved */
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
478 if(track->enc->codec_type == CODEC_TYPE_VIDEO)
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
479 str = "VideoHandler";
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
480 else
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
481 str = "SoundHandler";
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
482 put_byte(pb, strlen(str)); /* string counter */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
483 put_buffer(pb, str, strlen(str));
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
484 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
485 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
486
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
487 static int mov_write_mdhd_tag(ByteIOContext *pb, MOVTrack* track)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
488 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
489 put_be32(pb, 32); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
490 put_tag(pb, "mdhd");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
491 put_be32(pb, 0); /* Version & flags */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
492 put_be32(pb, track->time); /* creation time */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
493 put_be32(pb, track->time); /* modification time */
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
494 if(track->enc->codec_type == CODEC_TYPE_VIDEO) {
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
495 int64_t rate = track->enc->frame_rate;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
496 put_be32(pb, rate);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
497 put_be32(pb, rate*(int64_t)track->trackDuration/(int64_t)globalTimescale); // duration
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
498 }
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
499 else {
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
500 put_be32(pb, track->timescale); /* time scale (sample rate for audio) */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
501 put_be32(pb, track->trackDuration); /* duration */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
502 }
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
503 put_be16(pb, 0); /* language, 0 = english */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
504 put_be16(pb, 0); /* reserved (quality) */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
505 return 32;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
506 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
507
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
508 static int mov_write_mdia_tag(ByteIOContext *pb, MOVTrack* track)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
509 {
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
510 int pos = url_ftell(pb);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
511 put_be32(pb, 0); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
512 put_tag(pb, "mdia");
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
513 mov_write_mdhd_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
514 mov_write_hdlr_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
515 mov_write_minf_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
516 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
517 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
518
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
519 static int mov_write_tkhd_tag(ByteIOContext *pb, MOVTrack* track)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
520 {
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
521 int64_t maxTrackLenTemp;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
522 put_be32(pb, 0x5c); /* size (always 0x5c) */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
523 put_tag(pb, "tkhd");
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
524 put_be32(pb, 0xf); /* version & flags (track enabled) */
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
525 put_be32(pb, track->time); /* creation time */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
526 put_be32(pb, track->time); /* modification time */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
527 put_be32(pb, track->trackID); /* track-id */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
528 put_be32(pb, 0); /* reserved */
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
529 maxTrackLenTemp = ((int64_t)globalTimescale*(int64_t)track->trackDuration)/(int64_t)track->timescale;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
530 put_be32(pb, (long)maxTrackLenTemp); /* duration */
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
531
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
532 put_be32(pb, 0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
533 put_be32(pb, 0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
534 put_be32(pb, 0x0); /* reserved (Layer & Alternate group) */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
535 /* Volume, only for audio */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
536 if(track->enc->codec_type == CODEC_TYPE_AUDIO)
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
537 put_be16(pb, 0x0100);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
538 else
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
539 put_be16(pb, 0);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
540 put_be16(pb, 0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
541
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
542 /* Matrix structure */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
543 put_be32(pb, 0x00010000); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
544 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
545 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
546 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
547 put_be32(pb, 0x00010000); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
548 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
549 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
550 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
551 put_be32(pb, 0x40000000); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
552
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
553 /* Track width and height, for visual only */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
554 if(track->enc->codec_type == CODEC_TYPE_VIDEO) {
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
555 put_be32(pb, track->enc->width*0x10000);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
556 put_be32(pb, track->enc->height*0x10000);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
557 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
558 else {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
559 put_be32(pb, 0);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
560 put_be32(pb, 0);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
561 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
562 return 0x5c;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
563 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
564
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
565 static int mov_write_trak_tag(ByteIOContext *pb, MOVTrack* track)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
566 {
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
567 int pos = url_ftell(pb);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
568 put_be32(pb, 0); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
569 put_tag(pb, "trak");
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
570 mov_write_tkhd_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
571 mov_write_mdia_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
572 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
573 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
574
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
575 /* TODO: Not sorted out, but not necessary either */
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
576 static int mov_write_iods_tag(ByteIOContext *pb, MOVContext *mov)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
577 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
578 put_be32(pb, 0x15); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
579 put_tag(pb, "iods");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
580 put_be32(pb, 0); /* version & flags */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
581 put_be16(pb, 0x1007);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
582 put_byte(pb, 0);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
583 put_be16(pb, 0x4fff);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
584 put_be16(pb, 0xfffe);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
585 put_be16(pb, 0x01ff);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
586 return 0x15;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
587 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
588
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
589 static int mov_write_mvhd_tag(ByteIOContext *pb, MOVContext *mov)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
590 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
591 int maxTrackID = 1, maxTrackLen = 0, i;
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
592 int64_t maxTrackLenTemp;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
593
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
594 put_be32(pb, 0x6c); /* size (always 0x6c) */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
595 put_tag(pb, "mvhd");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
596 put_be32(pb, 0); /* version & flags */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
597 put_be32(pb, mov->time); /* creation time */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
598 put_be32(pb, mov->time); /* modification time */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
599 put_be32(pb, mov->timescale); /* timescale */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
600 for (i=0; i<MAX_STREAMS; i++) {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
601 if(mov->tracks[i].entry > 0) {
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
602 maxTrackLenTemp = ((int64_t)globalTimescale*(int64_t)mov->tracks[i].trackDuration)/(int64_t)mov->tracks[i].timescale;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
603 if(maxTrackLen < maxTrackLenTemp)
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
604 maxTrackLen = maxTrackLenTemp;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
605 if(maxTrackID < mov->tracks[i].trackID)
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
606 maxTrackID = mov->tracks[i].trackID;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
607 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
608 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
609 put_be32(pb, maxTrackLen); /* duration of longest track */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
610
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
611 put_be32(pb, 0x00010000); /* reserved (preferred rate) 1.0 = normal */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
612 put_be16(pb, 0x0100); /* reserved (preferred volume) 1.0 = normal */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
613 put_be16(pb, 0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
614 put_be32(pb, 0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
615 put_be32(pb, 0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
616
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
617 /* Matrix structure */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
618 put_be32(pb, 0x00010000); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
619 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
620 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
621 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
622 put_be32(pb, 0x00010000); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
623 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
624 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
625 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
626 put_be32(pb, 0x40000000); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
627
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
628 put_be32(pb, 0); /* reserved (preview time) */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
629 put_be32(pb, 0); /* reserved (preview duration) */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
630 put_be32(pb, 0); /* reserved (poster time) */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
631 put_be32(pb, 0); /* reserved (selection time) */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
632 put_be32(pb, 0); /* reserved (selection duration) */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
633 put_be32(pb, 0); /* reserved (current time) */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
634 put_be32(pb, maxTrackID+1); /* Next track id */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
635 return 0x6c;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
636 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
637
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
638 static int mov_write_moov_tag(ByteIOContext *pb, MOVContext *mov)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
639 {
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
640 int pos, i;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
641 pos = url_ftell(pb);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
642 put_be32(pb, 0); /* size placeholder*/
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
643 put_tag(pb, "moov");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
644 mov->timescale = globalTimescale;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
645
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
646 for (i=0; i<MAX_STREAMS; i++) {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
647 if(mov->tracks[i].entry > 0) {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
648 if(mov->tracks[i].enc->codec_type == CODEC_TYPE_VIDEO) {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
649 mov->tracks[i].timescale = globalTimescale;
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
650 mov->tracks[i].sampleDelta = mov->tracks[i].enc->frame_rate_base;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
651 mov->tracks[i].frameCount = mov->tracks[i].samples;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
652 mov->tracks[i].trackDuration = (int64_t)((int64_t)mov->tracks[i].entry*
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
653 (int64_t)globalTimescale*(int64_t)mov->tracks[i].enc->frame_rate_base)/(int64_t)mov->tracks[i].enc->frame_rate;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
654 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
655 else if(mov->tracks[i].enc->codec_type == CODEC_TYPE_AUDIO) {
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
656 long trackDuration = 0;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
657 /* If AMR, track timescale = 8000, AMR_WB = 16000 */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
658 if(mov->tracks[i].enc->codec_id == CODEC_ID_AMR_NB) {
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
659 int j;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
660 for (j=0; j<mov->tracks[i].samples; j++) {
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
661 int cl = j / MOV_INDEX_CLUSTER_SIZE;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
662 int id = j % MOV_INDEX_CLUSTER_SIZE;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
663 trackDuration += mov->tracks[i].cluster[cl][id].entries;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
664 }
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
665 mov->tracks[i].sampleDelta = 160; // Bytes per chunk
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
666 mov->tracks[i].frameCount = mov->tracks[i].samples;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
667 mov->tracks[i].trackDuration =
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
668 mov->tracks[i].samples * mov->tracks[i].sampleDelta; //trackDuration
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
669 mov->tracks[i].timescale = 8000;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
670 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
671 else {
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
672 int j;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
673 for (j=0; j<=mov->tracks[i].entry; j++) {
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
674 int cl = j / MOV_INDEX_CLUSTER_SIZE;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
675 int id = j % MOV_INDEX_CLUSTER_SIZE;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
676 trackDuration += mov->tracks[i].cluster[cl][id].len;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
677 }
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
678 mov->tracks[i].frameCount = trackDuration;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
679 mov->tracks[i].timescale = mov->tracks[i].enc->sample_rate;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
680 mov->tracks[i].sampleDelta = 1;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
681 mov->tracks[i].trackDuration = trackDuration;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
682 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
683 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
684 mov->tracks[i].time = mov->time;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
685 mov->tracks[i].trackID = i+1;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
686 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
687 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
688
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
689 mov_write_mvhd_tag(pb, mov);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
690 //mov_write_iods_tag(pb, mov);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
691 for (i=0; i<MAX_STREAMS; i++) {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
692 if(mov->tracks[i].entry > 0) {
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
693 mov_write_trak_tag(pb, &(mov->tracks[i]));
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
694 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
695 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
696
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
697 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
698 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
699
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
700 int mov_write_mdat_tag(ByteIOContext *pb, MOVContext* mov)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
701 {
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
702 mov->mdat_pos = url_ftell(pb);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
703 put_be32(pb, 0); /* size placeholder*/
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
704 put_tag(pb, "mdat");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
705 return 0;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
706 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
707
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
708 /* TODO: This needs to be more general */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
709 int mov_write_ftyp_tag(ByteIOContext *pb)
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
710 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
711 put_be32(pb, 0x14 ); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
712 put_tag(pb, "ftyp");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
713 put_tag(pb, "3gp4");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
714 put_be32(pb, 0x200 );
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
715 put_tag(pb, "3gp4");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
716 return 0x14;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
717 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
718
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
719 static int mov_write_header(AVFormatContext *s)
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
720 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
721 ByteIOContext *pb = &s->pb;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
722
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
723 if(s->oformat != NULL) {
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
724 if(!strcmp("3gp", s->oformat->name))
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
725 mov_write_ftyp_tag(pb);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
726 }
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
727
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
728 put_flush_packet(pb);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
729
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
730 return 0;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
731 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
732
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
733 static int Timestamp() {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
734 time_t ltime;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
735 time ( &ltime );
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
736 return ltime+(24107*86400);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
737 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
738
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
739 static int mov_write_packet(AVFormatContext *s, int stream_index,
241
3d92f793fd67 64 bit pts for writing - more const usage
bellard
parents: 239
diff changeset
740 const uint8_t *buf, int size, int64_t pts)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
741 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
742 MOVContext *mov = s->priv_data;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
743 ByteIOContext *pb = &s->pb;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
744 AVCodecContext *enc;
202
d755254e8797 naughty, forbidden variable declarations
tmmm
parents: 201
diff changeset
745 int cl, id;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
746
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
747 enc = &s->streams[stream_index]->codec;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
748 if (!url_is_streamed(&s->pb)) {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
749 MOVTrack* trk = &mov->tracks[stream_index];
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
750 int sampleCount = 0;
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
751 unsigned int chunkSize = 0;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
752
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
753 if(enc->codec_type == CODEC_TYPE_AUDIO) {
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
754 /* We must find out how many AMR blocks there are in one packet */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
755 if(enc->codec_id == CODEC_ID_AMR_NB) {
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
756 static uint16_t packed_size[16] = {13, 14, 16, 18, 20, 21, 27, 32, 6, 0, 0, 0, 0, 0, 0, 0};
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
757 int len = 0;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
758
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
759 while(len < size && sampleCount < 100) {
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
760 len += packed_size[(buf[len] >> 3) & 0x0F];
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
761 sampleCount++;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
762 }
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
763 chunkSize = 1;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
764 }
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
765 else {
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
766 sampleCount = size;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
767 chunkSize = size/enc->channels;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
768 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
769 }
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
770 else if(enc->codec_type == CODEC_TYPE_VIDEO) {
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
771 if(enc->codec_id == CODEC_ID_MPEG4 &&
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
772 trk->vosLen == 0)
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
773 {
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
774 assert(enc->extradata_size);
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
775
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
776 trk->vosLen = enc->extradata_size;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
777 trk->vosData = av_malloc(trk->vosLen);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
778 memcpy(trk->vosData, enc->extradata, trk->vosLen);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
779 }
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
780 chunkSize = 1;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
781 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
782
202
d755254e8797 naughty, forbidden variable declarations
tmmm
parents: 201
diff changeset
783 cl = trk->entry / MOV_INDEX_CLUSTER_SIZE;
d755254e8797 naughty, forbidden variable declarations
tmmm
parents: 201
diff changeset
784 id = trk->entry % MOV_INDEX_CLUSTER_SIZE;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
785
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
786 if (trk->ents_allocated <= trk->entry) {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
787 trk->cluster = av_realloc(trk->cluster, (cl+1)*sizeof(void*));
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
788 if (!trk->cluster)
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
789 return -1;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
790 trk->cluster[cl] = av_malloc(MOV_INDEX_CLUSTER_SIZE*sizeof(MOVIentry));
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
791 if (!trk->cluster[cl])
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
792 return -1;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
793 trk->ents_allocated += MOV_INDEX_CLUSTER_SIZE;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
794 }
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
795 if(mov->mdat_written == 0) {
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
796 mov_write_mdat_tag(pb, mov);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
797 mov->mdat_written = 1;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
798 mov->time = Timestamp();
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
799 }
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
800
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
801 trk->cluster[cl][id].pos = url_ftell(pb) - mov->movi_list;
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
802 trk->cluster[cl][id].chunkSize = chunkSize;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
803 if(enc->channels > 1)
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
804 trk->cluster[cl][id].len = size/enc->channels;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
805 else
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
806 trk->cluster[cl][id].len = size;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
807 trk->cluster[cl][id].entries = sampleCount;
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
808 if(enc->codec_type == CODEC_TYPE_VIDEO) {
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
809 trk->cluster[cl][id].key_frame = enc->coded_frame->key_frame;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
810 if(enc->coded_frame->pict_type == FF_I_TYPE)
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
811 trk->hasKeyframes = 1;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
812 }
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
813 trk->enc = enc;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
814 trk->entry++;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
815 if(sampleCount == 0)
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
816 trk->samples++;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
817 else
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
818 trk->samples += sampleCount;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
819 trk->mdat_size += size;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
820 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
821 put_buffer(pb, buf, size);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
822
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
823 put_flush_packet(pb);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
824 return 0;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
825 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
826
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
827 static int mov_write_trailer(AVFormatContext *s)
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
828 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
829 MOVContext *mov = s->priv_data;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
830 ByteIOContext *pb = &s->pb;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
831 int res = 0;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
832 int i, j;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
833 offset_t file_size;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
834
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
835 file_size = url_ftell(pb);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
836 j = 0;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
837
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
838 /* Write size of mdat tag */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
839 for (i=0; i<MAX_STREAMS; i++) {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
840 if(mov->tracks[i].ents_allocated > 0) {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
841 j += mov->tracks[i].mdat_size;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
842 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
843 }
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
844 url_fseek(pb, mov->mdat_pos, SEEK_SET);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
845 put_be32(pb, j+8);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
846 url_fseek(pb, file_size, SEEK_SET);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
847
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
848 mov_write_moov_tag(pb, mov);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
849
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
850 for (i=0; i<MAX_STREAMS; i++) {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
851 for (j=0; j<mov->tracks[i].ents_allocated/MOV_INDEX_CLUSTER_SIZE; j++) {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
852 av_free(mov->tracks[i].cluster[j]);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
853 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
854 av_free(mov->tracks[i].cluster);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
855 mov->tracks[i].cluster = NULL;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
856 mov->tracks[i].ents_allocated = mov->tracks[i].entry = 0;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
857 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
858 put_flush_packet(pb);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
859
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
860 return res;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
861 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
862
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
863 static AVOutputFormat mov_oformat = {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
864 "mov",
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
865 "mov format",
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
866 NULL,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
867 "mov",
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
868 sizeof(MOVContext),
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
869 CODEC_ID_PCM_ALAW,
239
48c3134e93c3 theres no SVQ1 encoder -> it cant be default
michaelni
parents: 238
diff changeset
870 CODEC_ID_MPEG4,
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
871 mov_write_header,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
872 mov_write_packet,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
873 mov_write_trailer,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
874 };
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
875
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
876 static AVOutputFormat _3gp_oformat = {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
877 "3gp",
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
878 "3gp format",
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
879 NULL,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
880 "3gp",
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
881 sizeof(MOVContext),
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
882 CODEC_ID_AMR_NB,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
883 CODEC_ID_H263,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
884 mov_write_header,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
885 mov_write_packet,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
886 mov_write_trailer,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
887 };
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
888
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
889 static AVOutputFormat mp4_oformat = {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
890 "mp4",
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
891 "mp4 format",
286
eccf0c3e3289 Using the extension m4a for audio only MPEG-4 files is increasingly
michael
parents: 259
diff changeset
892 "application/mp4",
eccf0c3e3289 Using the extension m4a for audio only MPEG-4 files is increasingly
michael
parents: 259
diff changeset
893 "mp4,m4a",
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
894 sizeof(MOVContext),
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
895 CODEC_ID_AAC,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
896 CODEC_ID_MPEG4,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
897 mov_write_header,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
898 mov_write_packet,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
899 mov_write_trailer,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
900 };
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
901
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
902 int movenc_init(void)
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
903 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
904 av_register_output_format(&mov_oformat);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
905 av_register_output_format(&_3gp_oformat);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
906 av_register_output_format(&mp4_oformat);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
907 return 0;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
908 }