annotate movenc.c @ 299:5ee1aa8cc0ea libavformat

removing borderline spyware
author michael
date Tue, 04 Nov 2003 12:55:26 +0000
parents 0b2eed7b1210
children 0c1b489c96bf
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.
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
4 * Enhancements by Gildas Bazin <gbazin@netcourrier.com>
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
5 *
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
6 * 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
7 * 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
8 * 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
9 * 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
10 *
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
11 * 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
12 * 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
13 * 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
14 * 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
15 *
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
16 * 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
17 * 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
18 * 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
19 */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
20 #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
21 #include "avi.h"
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
22 #include "avio.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 {
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
31 unsigned int flags, pos, size;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
32 unsigned int samplesInChunk;
259
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 mdat_size;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
40 int ents_allocated;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
41 long timescale;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
42 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
43 long trackDuration;
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
44 long sampleCount;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
45 long sampleDuration;
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
46 int hasKeyframes;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
47 int trackID;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
48 AVCodecContext *enc;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
49
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
50 int vosLen;
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
51 uint8_t *vosData;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
52 MOVIentry** cluster;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
53 } MOVTrack;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
54
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
55 typedef struct {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
56 long time;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
57 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
58 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
59 offset_t mdat_pos;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
60 offset_t movi_list;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
61 long timescale;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
62 MOVTrack tracks[MAX_STREAMS];
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
63 } MOVContext;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
64
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
65 static int mov_write_esds_tag(ByteIOContext *pb, MOVTrack* track);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
66
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
67 //FIXME supprt 64bit varaint with wide placeholders
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
68 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
69 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
70 long curpos = url_ftell(pb);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
71 url_fseek(pb, pos, SEEK_SET);
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
72 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
73 url_fseek(pb, curpos, SEEK_SET);
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
74
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
75 return curpos - pos;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
76 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
77
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
78 /* Chunk offset atom */
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
79 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
80 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
81 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
82 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
83 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
84 put_tag(pb, "stco");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
85 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
86 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
87 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
88 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
89 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
90 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
91 }
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
92 return updateSize (pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
93 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
94
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
95 /* Sample size atom */
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
96 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
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 equalChunks = 1;
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
99 int i, j, entries = 0, tst = -1, oldtst = -1;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
100
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
101 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
102 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
103 put_tag(pb, "stsz");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
104 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
105
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
106 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
107 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
108 int id = i % MOV_INDEX_CLUSTER_SIZE;
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
109 tst = track->cluster[cl][id].size/track->cluster[cl][id].entries;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
110 if(oldtst != -1 && tst != oldtst) {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
111 equalChunks = 0;
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
112 }
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
113 oldtst = tst;
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
114 entries += track->cluster[cl][id].entries;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
115 }
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
116 if (equalChunks) {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
117 int sSize = track->cluster[0][0].size/track->cluster[0][0].entries;
259
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, sSize); // sample size
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
119 put_be32(pb, entries); // sample count
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
120 }
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
121 else {
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, 0); // sample size
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
123 put_be32(pb, entries); // sample count
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
124 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
125 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
126 int id = i % MOV_INDEX_CLUSTER_SIZE;
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
127 for ( j=0; j<track->cluster[cl][id].entries; j++) {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
128 put_be32(pb, track->cluster[cl][id].size /
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
129 track->cluster[cl][id].entries);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
130 }
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
131 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
132 }
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
133 return updateSize (pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
134 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
135
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
136 /* Sample to chunk atom */
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
137 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
138 {
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
139 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
140
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
141 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
142 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
143 put_tag(pb, "stsc");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
144 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
145 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
146 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
147 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
148 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
149 int id = i % MOV_INDEX_CLUSTER_SIZE;
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
150 if(oldval != track->cluster[cl][id].samplesInChunk)
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
151 {
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
152 put_be32(pb, i+1); // first chunk
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
153 put_be32(pb, track->cluster[cl][id].samplesInChunk); // samples per chunk
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
154 put_be32(pb, 0x1); // sample description index
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
155 oldval = track->cluster[cl][id].samplesInChunk;
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
156 index++;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
157 }
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 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
160 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
161 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
162 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
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 return updateSize (pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
165 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
166
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
167 /* Sync sample atom */
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
168 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
169 {
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
170 long curpos;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
171 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
172 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
173 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
174 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
175 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
176 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
177 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
178 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
179 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
180 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
181 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
182 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
183 index++;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
184 }
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
185 }
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
186 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
187 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
188 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
189 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
190 return updateSize (pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
191 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
192
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
193 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
194 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
195 put_be32(pb, 0x11); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
196 put_tag(pb, "damr");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
197 put_tag(pb, "FFMP");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
198 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
199
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
200 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
201 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
202 //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
203 //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
204 return 0x11;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
205 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
206
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
207 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
208 {
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
209 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
210 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
211
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
212 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
213 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
214 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
215 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
216 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
217 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
218 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
219 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
220 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
221 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
222 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
223 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
224 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
225 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
226 else
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
227 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
228
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
229 put_be32(pb, 0); /* Reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
230 put_be16(pb, 0); /* Reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
231 put_be16(pb, 1); /* Data-reference index, XXX == 1 */
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
232 /* SoundDescription */
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
233 put_be16(pb, 0); /* Version */
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
234 put_be16(pb, 0); /* Revision level */
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
235 put_be32(pb, 0); /* Reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
236
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
237 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
238 /* TODO: Currently hard-coded to 16-bit, there doesn't seem
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
239 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
240 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
241 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
242 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
243 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
244 put_be16(pb, 0); /* Reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
245
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
246 if(track->enc->codec_id == CODEC_ID_AAC)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
247 mov_write_esds_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
248 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
249 mov_write_damr_tag(pb);
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
250 return updateSize (pb, pos);
201
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
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
253 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
254 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
255 put_be32(pb, 0xf); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
256 put_tag(pb, "d263");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
257 put_tag(pb, "FFMP");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
258 put_be16(pb, 0x0a);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
259 put_byte(pb, 0);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
260 return 0xf;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
261 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
262
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
263 /* 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
264 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
265 {
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
266 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
267 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
268 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
269 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
270 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
271 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
272 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
273 return 0x15;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
274 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
275
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
276 static unsigned int descrLength(unsigned int len)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
277 {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
278 if (len < 0x00000080)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
279 return 2 + len;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
280 else if (len < 0x00004000)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
281 return 3 + len;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
282 else if(len < 0x00200000)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
283 return 4 + len;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
284 else
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
285 return 5 + len;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
286 }
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
287
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
288 static void putDescr(ByteIOContext *pb, int tag, int size)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
289 {
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
290 uint32_t len;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
291 uint8_t vals[4];
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
292
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
293 len = size;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
294 vals[3] = (uint8_t)(len & 0x7f);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
295 len >>= 7;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
296 vals[2] = (uint8_t)((len & 0x7f) | 0x80);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
297 len >>= 7;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
298 vals[1] = (uint8_t)((len & 0x7f) | 0x80);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
299 len >>= 7;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
300 vals[0] = (uint8_t)((len & 0x7f) | 0x80);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
301
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
302 put_byte(pb, tag); // DescriptorTag
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
303
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
304 if (size < 0x00000080)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
305 {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
306 put_byte(pb, vals[3]);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
307 }
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
308 else if (size < 0x00004000)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
309 {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
310 put_byte(pb, vals[2]);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
311 put_byte(pb, vals[3]);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
312 }
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
313 else if (size < 0x00200000)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
314 {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
315 put_byte(pb, vals[1]);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
316 put_byte(pb, vals[2]);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
317 put_byte(pb, vals[3]);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
318 }
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
319 else if (size < 0x10000000)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
320 {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
321 put_byte(pb, vals[0]);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
322 put_byte(pb, vals[1]);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
323 put_byte(pb, vals[2]);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
324 put_byte(pb, vals[3]);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
325 }
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
326 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
327
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
328 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
329 {
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
330 int decoderSpecificInfoLen = track->vosLen ? descrLength(track->vosLen):0;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
331 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
332
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
333 put_be32(pb, 0); // size
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
334 put_tag(pb, "esds");
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
335 put_be32(pb, 0); // Version
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
336
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
337 // ES descriptor
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
338 putDescr(pb, 0x03, 3 + descrLength(13 + decoderSpecificInfoLen) +
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
339 descrLength(1));
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
340 put_be16(pb, 0x0001); // ID (= 1)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
341 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
342
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
343 // DecoderConfig descriptor
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
344 putDescr(pb, 0x04, 13 + decoderSpecificInfoLen);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
345
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
346 if(track->enc->codec_id == CODEC_ID_AAC)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
347 put_byte(pb, 0x40); // Object type indication
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
348 else if(track->enc->codec_id == CODEC_ID_MPEG4)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
349 put_byte(pb, 0x20); // Object type indication (Visual 14496-2)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
350
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
351 if(track->enc->codec_type == CODEC_TYPE_AUDIO)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
352 put_byte(pb, 0x15); // flags (= Audiostream)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
353 else
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
354 put_byte(pb, 0x11); // flags (= Visualstream)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
355
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
356 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
357 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
358
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
359 // 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
360 put_be32(pb, 0x0002e918); // maxbitrate
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
361 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
362
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
363 if (track->vosLen)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
364 {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
365 // DecoderSpecific info descriptor
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
366 putDescr(pb, 0x05, track->vosLen);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
367 put_buffer(pb, track->vosData, track->vosLen);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
368 }
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
369
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
370 // SL descriptor
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
371 putDescr(pb, 0x06, descrLength(1));
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
372 put_byte(pb, 0x02);
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
373 return updateSize (pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
374 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
375
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
376 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
377 {
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
378 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
379 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
380 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
381 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
382 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
383 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
384 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
385 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
386 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
387 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
388 else
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
389 put_tag(pb, " "); /* Unknown tag */
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
390
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
391 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
392 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
393 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
394
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
395 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
396 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
397 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
398 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
399 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
400 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
401 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
402 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
403 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
404 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
405 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
406 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
407 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
408 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
409
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
410 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
411 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
412 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
413 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
414 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
415 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
416 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
417 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
418 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
419 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
420 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
421 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
422
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
423 return updateSize (pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
424 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
425
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
426 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
427 {
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
428 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
429 put_be32(pb, 0); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
430 put_tag(pb, "stsd");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
431 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
432 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
433 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
434 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
435 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
436 mov_write_audio_tag(pb, track);
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
437 return updateSize(pb, pos);
201
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
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
440 /* TODO?: Currently all samples/frames seem to have same duration */
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
441 /* Time to sample atom */
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
442 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
443 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
444 put_be32(pb, 0x18); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
445 put_tag(pb, "stts");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
446 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
447 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
448
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
449 put_be32(pb, track->sampleCount); /* sample count */
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
450 put_be32(pb, track->sampleDuration); /* sample duration */
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
451 return 0x18;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
452 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
453
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
454 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
455 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
456 put_be32(pb, 28); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
457 put_tag(pb, "dref");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
458 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
459 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
460
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
461 put_be32(pb, 0xc); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
462 put_tag(pb, "url ");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
463 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
464
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
465 return 28;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
466 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
467
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
468 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
469 {
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
470 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
471 put_be32(pb, 0); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
472 put_tag(pb, "stbl");
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
473 mov_write_stsd_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
474 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
475 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
476 track->hasKeyframes)
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
477 mov_write_stss_tag(pb, track);
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
478 mov_write_stsc_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
479 mov_write_stsz_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
480 mov_write_stco_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
481 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
482 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
483
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
484 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
485 {
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
486 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
487 put_be32(pb, 0); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
488 put_tag(pb, "dinf");
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
489 mov_write_dref_tag(pb);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
490 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
491 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
492
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
493 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
494 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
495 put_be32(pb, 16); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
496 put_tag(pb, "smhd");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
497 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
498 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
499 put_be16(pb, 0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
500 return 16;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
501 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
502
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
503 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
504 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
505 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
506 put_tag(pb, "vmhd");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
507 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
508 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
509 return 0x14;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
510 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
511
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
512 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
513 {
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
514 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
515 put_be32(pb, 0); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
516 put_tag(pb, "minf");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
517 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
518 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
519 else
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
520 mov_write_smhd_tag(pb);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
521 mov_write_dinf_tag(pb);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
522 mov_write_stbl_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
523 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
524 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
525
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
526 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
527 {
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
528 char *str;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
529 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
530 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
531 put_tag(pb, "hdlr");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
532 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
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 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
535 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
536 else
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
537 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
538 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
539 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
540 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
541 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
542 str = "VideoHandler";
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
543 else
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
544 str = "SoundHandler";
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
545 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
546 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
547 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
548 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
549
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
550 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
551 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
552 put_be32(pb, 32); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
553 put_tag(pb, "mdhd");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
554 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
555 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
556 put_be32(pb, track->time); /* modification time */
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
557 put_be32(pb, track->timescale); /* time scale (sample rate for audio) */
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
558 put_be32(pb, track->trackDuration); /* duration */
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
559 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
560 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
561 return 32;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
562 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
563
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
564 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
565 {
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
566 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
567 put_be32(pb, 0); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
568 put_tag(pb, "mdia");
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
569 mov_write_mdhd_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
570 mov_write_hdlr_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
571 mov_write_minf_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
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
575 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
576 {
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
577 int64_t maxTrackLenTemp;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
578 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
579 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
580 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
581 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
582 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
583 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
584 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
585 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
586 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
587
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
588 put_be32(pb, 0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
589 put_be32(pb, 0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
590 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
591 /* Volume, only for audio */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
592 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
593 put_be16(pb, 0x0100);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
594 else
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
595 put_be16(pb, 0);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
596 put_be16(pb, 0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
597
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
598 /* Matrix structure */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
599 put_be32(pb, 0x00010000); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
600 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
601 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
602 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
603 put_be32(pb, 0x00010000); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
604 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
605 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
606 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
607 put_be32(pb, 0x40000000); /* reserved */
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 /* 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
610 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
611 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
612 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
613 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
614 else {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
615 put_be32(pb, 0);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
616 put_be32(pb, 0);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
617 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
618 return 0x5c;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
619 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
620
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
621 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
622 {
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
623 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
624 put_be32(pb, 0); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
625 put_tag(pb, "trak");
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
626 mov_write_tkhd_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
627 mov_write_mdia_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
628 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
629 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
630
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
631 /* 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
632 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
633 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
634 put_be32(pb, 0x15); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
635 put_tag(pb, "iods");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
636 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
637 put_be16(pb, 0x1007);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
638 put_byte(pb, 0);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
639 put_be16(pb, 0x4fff);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
640 put_be16(pb, 0xfffe);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
641 put_be16(pb, 0x01ff);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
642 return 0x15;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
643 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
644
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
645 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
646 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
647 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
648 int64_t maxTrackLenTemp;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
649
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
650 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
651 put_tag(pb, "mvhd");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
652 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
653 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
654 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
655 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
656 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
657 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
658 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
659 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
660 maxTrackLen = maxTrackLenTemp;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
661 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
662 maxTrackID = mov->tracks[i].trackID;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
663 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
664 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
665 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
666
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
667 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
668 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
669 put_be16(pb, 0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
670 put_be32(pb, 0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
671 put_be32(pb, 0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
672
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
673 /* Matrix structure */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
674 put_be32(pb, 0x00010000); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
675 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
676 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
677 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
678 put_be32(pb, 0x00010000); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
679 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
680 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
681 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
682 put_be32(pb, 0x40000000); /* reserved */
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 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
685 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
686 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
687 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
688 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
689 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
690 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
691 return 0x6c;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
692 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
693
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
694 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
695 {
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
696 int pos, i;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
697 pos = url_ftell(pb);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
698 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
699 put_tag(pb, "moov");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
700 mov->timescale = globalTimescale;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
701
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
702 for (i=0; i<MAX_STREAMS; i++) {
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
703 if(mov->tracks[i].entry <= 0) continue;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
704
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
705 if(mov->tracks[i].enc->codec_type == CODEC_TYPE_VIDEO) {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
706 mov->tracks[i].timescale = mov->tracks[i].enc->frame_rate;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
707 mov->tracks[i].sampleDuration = mov->tracks[i].enc->frame_rate_base;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
708 }
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
709 else if(mov->tracks[i].enc->codec_type == CODEC_TYPE_AUDIO) {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
710 /* If AMR, track timescale = 8000, AMR_WB = 16000 */
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
711 if(mov->tracks[i].enc->codec_id == CODEC_ID_AMR_NB) {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
712 mov->tracks[i].sampleDuration = 160; // Bytes per chunk
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
713 mov->tracks[i].timescale = 8000;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
714 }
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
715 else {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
716 mov->tracks[i].timescale = mov->tracks[i].enc->sample_rate;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
717 mov->tracks[i].sampleDuration = mov->tracks[i].enc->frame_size;
201
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 }
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
720
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
721 mov->tracks[i].trackDuration =
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
722 mov->tracks[i].sampleCount * mov->tracks[i].sampleDuration;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
723 mov->tracks[i].time = mov->time;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
724 mov->tracks[i].trackID = i+1;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
725 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
726
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
727 mov_write_mvhd_tag(pb, mov);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
728 //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
729 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
730 if(mov->tracks[i].entry > 0) {
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
731 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
732 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
733 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
734
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
735 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
736 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
737
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
738 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
739 {
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
740 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
741 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
742 put_tag(pb, "mdat");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
743 return 0;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
744 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
745
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
746 /* TODO: This needs to be more general */
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
747 int mov_write_ftyp_tag(ByteIOContext *pb, AVFormatContext *s)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
748 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
749 put_be32(pb, 0x14 ); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
750 put_tag(pb, "ftyp");
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
751
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
752 if (!strcmp("3gp", s->oformat->name))
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
753 put_tag(pb, "3gp4");
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
754 else
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
755 put_tag(pb, "isom");
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
756
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
757 put_be32(pb, 0x200 );
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
758
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
759 if (!strcmp("3gp", s->oformat->name))
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
760 put_tag(pb, "3gp4");
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
761 else
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
762 put_tag(pb, "mp41");
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
763
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
764 return 0x14;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
765 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
766
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
767 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
768 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
769 ByteIOContext *pb = &s->pb;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
770
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
771 if(s->oformat != NULL) {
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
772 if(!strcmp("3gp", s->oformat->name) || !strcmp("mp4", s->oformat->name))
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
773 mov_write_ftyp_tag(pb,s);
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
774 }
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
775
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
776 put_flush_packet(pb);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
777
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
778 return 0;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
779 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
780
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
781 static int Timestamp() {
299
5ee1aa8cc0ea removing borderline spyware
michael
parents: 298
diff changeset
782 return 1067949799U+(24107*86400); //its the modification time of this line :)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
783 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
784
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
785 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
786 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
787 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
788 MOVContext *mov = s->priv_data;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
789 ByteIOContext *pb = &s->pb;
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
790 AVCodecContext *enc = &s->streams[stream_index]->codec;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
791 MOVTrack* trk = &mov->tracks[stream_index];
202
d755254e8797 naughty, forbidden variable declarations
tmmm
parents: 201
diff changeset
792 int cl, id;
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
793 unsigned int samplesInChunk = 0;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
794
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
795 if (url_is_streamed(&s->pb)) return 0; /* Can't handle that */
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
796 if (!size) return 0; /* Discard 0 sized packets */
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
797
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
798 if (enc->codec_type == CODEC_TYPE_VIDEO ) {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
799 samplesInChunk = 1;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
800 }
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
801 else if (enc->codec_type == CODEC_TYPE_AUDIO ) {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
802 if( 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
803 /* We must find out how many AMR blocks there are in one packet */
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
804 static uint16_t packed_size[16] =
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
805 {13, 14, 16, 18, 20, 21, 27, 32, 6, 0, 0, 0, 0, 0, 0, 0};
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
806 int len = 0;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
807
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
808 while (len < size && samplesInChunk < 100) {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
809 len += packed_size[(buf[len] >> 3) & 0x0F];
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
810 samplesInChunk++;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
811 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
812 }
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
813 else if(enc->codec_id == CODEC_ID_PCM_ALAW) {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
814 samplesInChunk = size/enc->channels;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
815 }
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
816 else {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
817 samplesInChunk = 1;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
818 }
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
819 }
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
820
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
821 if ((enc->codec_id == CODEC_ID_MPEG4 || enc->codec_id == CODEC_ID_AAC)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
822 && trk->vosLen == 0) {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
823 assert(enc->extradata_size);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
824
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
825 trk->vosLen = enc->extradata_size;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
826 trk->vosData = av_malloc(trk->vosLen);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
827 memcpy(trk->vosData, enc->extradata, trk->vosLen);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
828 }
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
829
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
830 cl = trk->entry / MOV_INDEX_CLUSTER_SIZE;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
831 id = trk->entry % MOV_INDEX_CLUSTER_SIZE;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
832
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
833 if (trk->ents_allocated <= trk->entry) {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
834 trk->cluster = av_realloc(trk->cluster, (cl+1)*sizeof(void*));
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
835 if (!trk->cluster)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
836 return -1;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
837 trk->cluster[cl] = av_malloc(MOV_INDEX_CLUSTER_SIZE*sizeof(MOVIentry));
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
838 if (!trk->cluster[cl])
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
839 return -1;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
840 trk->ents_allocated += MOV_INDEX_CLUSTER_SIZE;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
841 }
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
842 if (mov->mdat_written == 0) {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
843 mov_write_mdat_tag(pb, mov);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
844 mov->mdat_written = 1;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
845 mov->time = Timestamp();
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
846 }
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
847
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
848 trk->cluster[cl][id].pos = url_ftell(pb) - mov->movi_list;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
849 trk->cluster[cl][id].samplesInChunk = samplesInChunk;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
850 trk->cluster[cl][id].size = size;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
851 trk->cluster[cl][id].entries = samplesInChunk;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
852 if(enc->codec_type == CODEC_TYPE_VIDEO) {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
853 trk->cluster[cl][id].key_frame = enc->coded_frame->key_frame;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
854 if(enc->coded_frame->pict_type == FF_I_TYPE)
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
855 trk->hasKeyframes = 1;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
856 }
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
857 trk->enc = enc;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
858 trk->entry++;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
859 trk->sampleCount += samplesInChunk;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
860 trk->mdat_size += size;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
861
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
862 put_buffer(pb, buf, size);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
863
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
864 put_flush_packet(pb);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
865 return 0;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
866 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
867
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
868 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
869 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
870 MOVContext *mov = s->priv_data;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
871 ByteIOContext *pb = &s->pb;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
872 int res = 0;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
873 int i, j;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
874 offset_t file_size;
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 file_size = url_ftell(pb);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
877 j = 0;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
878
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
879 /* Write size of mdat tag */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
880 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
881 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
882 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
883 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
884 }
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
885 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
886 put_be32(pb, j+8);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
887 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
888
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
889 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
890
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
891 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
892 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
893 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
894 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
895 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
896 mov->tracks[i].cluster = NULL;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
897 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
898 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
899 put_flush_packet(pb);
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 return res;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
902 }
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 static AVOutputFormat mov_oformat = {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
905 "mov",
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
906 "mov format",
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
907 NULL,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
908 "mov",
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
909 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
910 CODEC_ID_PCM_ALAW,
239
48c3134e93c3 theres no SVQ1 encoder -> it cant be default
michaelni
parents: 238
diff changeset
911 CODEC_ID_MPEG4,
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
912 mov_write_header,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
913 mov_write_packet,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
914 mov_write_trailer,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
915 };
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
916
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
917 static AVOutputFormat _3gp_oformat = {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
918 "3gp",
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
919 "3gp format",
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
920 NULL,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
921 "3gp",
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
922 sizeof(MOVContext),
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
923 CODEC_ID_AMR_NB,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
924 CODEC_ID_H263,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
925 mov_write_header,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
926 mov_write_packet,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
927 mov_write_trailer,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
928 };
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
929
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
930 static AVOutputFormat mp4_oformat = {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
931 "mp4",
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
932 "mp4 format",
286
eccf0c3e3289 Using the extension m4a for audio only MPEG-4 files is increasingly
michael
parents: 259
diff changeset
933 "application/mp4",
eccf0c3e3289 Using the extension m4a for audio only MPEG-4 files is increasingly
michael
parents: 259
diff changeset
934 "mp4,m4a",
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
935 sizeof(MOVContext),
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
936 CODEC_ID_AAC,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
937 CODEC_ID_MPEG4,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
938 mov_write_header,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
939 mov_write_packet,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
940 mov_write_trailer,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
941 };
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
942
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
943 int movenc_init(void)
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
944 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
945 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
946 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
947 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
948 return 0;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
949 }