annotate movenc.c @ 494:abc8a657a8dd libavformat

warn user if ms style codec tag is used remove " " codec tag
author michael
date Tue, 13 Jul 2004 20:59:29 +0000
parents 60f897e8dd2d
children e996e7da971c
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.
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
4 * Copyright (c) 2004 Gildas Bazin <gbazin at videolan dot org>.
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
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
30 #define MODE_MP4 0
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
31 #define MODE_MOV 1
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
32 #define MODE_3GP 2
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
33
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
34 typedef struct MOVIentry {
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
35 unsigned int flags, pos, size;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
36 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
37 char key_frame;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
38 unsigned int entries;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
39 } MOVIentry;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
40
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
41 typedef struct MOVIndex {
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
42 int mode;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
43 int entry;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
44 int mdat_size;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
45 int ents_allocated;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
46 long timescale;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
47 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
48 long trackDuration;
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
49 long sampleCount;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
50 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
51 int hasKeyframes;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
52 int trackID;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
53 AVCodecContext *enc;
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 int vosLen;
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
56 uint8_t *vosData;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
57 MOVIentry** cluster;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
58 } MOVTrack;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
59
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
60 typedef struct {
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
61 int mode;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
62 long time;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
63 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
64 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
65 offset_t mdat_pos;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
66 long timescale;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
67 MOVTrack tracks[MAX_STREAMS];
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
68 } MOVContext;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
69
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
70 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
71
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
72 //FIXME supprt 64bit varaint with wide placeholders
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
73 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
74 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
75 long curpos = url_ftell(pb);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
76 url_fseek(pb, pos, SEEK_SET);
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
77 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
78 url_fseek(pb, curpos, SEEK_SET);
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
79
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
80 return curpos - pos;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
81 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
82
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
83 /* Chunk offset atom */
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
84 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
85 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
86 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
87 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
88 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
89 put_tag(pb, "stco");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
90 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
91 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
92 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
93 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
94 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
95 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
96 }
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
97 return updateSize (pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
98 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
99
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
100 /* Sample size atom */
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
101 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
102 {
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
103 int equalChunks = 1;
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
104 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
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 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
107 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
108 put_tag(pb, "stsz");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
109 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
110
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
111 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
112 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
113 int id = i % MOV_INDEX_CLUSTER_SIZE;
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
114 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
115 if(oldtst != -1 && tst != oldtst) {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
116 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
117 }
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
118 oldtst = tst;
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
119 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
120 }
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
121 if (equalChunks) {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
122 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
123 put_be32(pb, sSize); // sample size
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
124 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
125 }
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
126 else {
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
127 put_be32(pb, 0); // sample size
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
128 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
129 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
130 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
131 int id = i % MOV_INDEX_CLUSTER_SIZE;
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
132 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
133 put_be32(pb, track->cluster[cl][id].size /
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
134 track->cluster[cl][id].entries);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
135 }
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
136 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
137 }
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
138 return updateSize (pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
139 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
140
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
141 /* Sample to chunk atom */
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
142 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
143 {
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
144 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
145
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
146 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
147 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
148 put_tag(pb, "stsc");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
149 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
150 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
151 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
152 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
153 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
154 int id = i % MOV_INDEX_CLUSTER_SIZE;
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
155 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
156 {
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
157 put_be32(pb, i+1); // first chunk
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
158 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
159 put_be32(pb, 0x1); // sample description index
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
160 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
161 index++;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
162 }
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 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
165 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
166 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
167 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
168
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
169 return updateSize (pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
170 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
171
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
172 /* 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
173 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
174 {
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
175 long curpos;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
176 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
177 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
178 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
179 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
180 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
181 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
182 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
183 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
184 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
185 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
186 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
187 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
188 index++;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
189 }
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
190 }
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
191 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
192 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
193 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
194 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
195 return updateSize (pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
196 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
197
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
198 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
199 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
200 put_be32(pb, 0x11); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
201 put_tag(pb, "damr");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
202 put_tag(pb, "FFMP");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
203 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
204
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
205 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
206 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
207 //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
208 //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
209 return 0x11;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
210 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
211
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
212 static int mov_write_wave_tag(ByteIOContext *pb, MOVTrack* track)
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
213 {
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
214 int pos = url_ftell(pb);
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
215
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
216 put_be32(pb, 0); /* size */
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
217 put_tag(pb, "wave");
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
218
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
219 put_be32(pb, 12); /* size */
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
220 put_tag(pb, "frma");
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
221 put_tag(pb, "mp4a");
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
222
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
223 put_be32(pb, 12); /* size */
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
224 put_tag(pb, "mp4a");
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
225 put_be32(pb, 0);
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
226
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
227 mov_write_esds_tag(pb, track);
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
228
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
229 put_be32(pb, 12); /* size */
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
230 put_tag(pb, "srcq");
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
231 put_be32(pb, 0x40);
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
232
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
233 put_be32(pb, 8); /* size */
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
234 put_be32(pb, 0); /* null tag */
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
235
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
236 return updateSize (pb, pos);
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
237 }
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
238
422
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
239 const CodecTag codec_movaudio_tags[] = {
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
240 { CODEC_ID_PCM_MULAW, MKTAG('u', 'l', 'a', 'w') },
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
241 { CODEC_ID_PCM_ALAW, MKTAG('a', 'l', 'a', 'w') },
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
242 { CODEC_ID_ADPCM_IMA_QT, MKTAG('i', 'm', 'a', '4') },
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
243 { CODEC_ID_MACE3, MKTAG('M', 'A', 'C', '3') },
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
244 { CODEC_ID_MACE6, MKTAG('M', 'A', 'C', '6') },
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
245 { CODEC_ID_AAC, MKTAG('m', 'p', '4', 'a') },
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
246 { CODEC_ID_AMR_NB, MKTAG('s', 'a', 'm', 'r') },
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
247 { CODEC_ID_PCM_S16BE, MKTAG('t', 'w', 'o', 's') },
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
248 { CODEC_ID_PCM_S16LE, MKTAG('s', 'o', 'w', 't') },
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
249 { CODEC_ID_MP3, MKTAG('.', 'm', 'p', '3') },
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
250 { 0, 0 },
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
251 };
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
252
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
253 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
254 {
494
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
255 int pos = url_ftell(pb);
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
256 int tag;
422
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
257
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
258 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
259
422
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
260 tag = codec_get_tag(codec_movaudio_tags, track->enc->codec_id);
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
261 // if no mac fcc found, try with Microsoft tags
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
262 if (!tag)
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
263 {
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
264 int tmp = codec_get_tag(codec_wav_tags, track->enc->codec_id);
494
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
265 tag = MKTAG('m', 's', ((tmp >> 8) & 0xff), (tmp & 0xff));
422
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
266 }
494
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
267 put_le32(pb, tag); // store it byteswapped
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
268
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
269 put_be32(pb, 0); /* Reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
270 put_be16(pb, 0); /* Reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
271 put_be16(pb, 1); /* Data-reference index, XXX == 1 */
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
272
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
273 /* SoundDescription */
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
274 if(track->mode == MODE_MOV && track->enc->codec_id == CODEC_ID_AAC)
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
275 put_be16(pb, 1); /* Version 1 */
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
276 else
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
277 put_be16(pb, 0); /* Version 0 */
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
278 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
279 put_be32(pb, 0); /* Reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
280
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
281 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
282 /* 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
283 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
284 put_be16(pb, 0x10); /* Reserved */
399
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
285 put_be16(pb, 0); /* compression ID (= 0) */
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
286 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
287 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
288 put_be16(pb, 0); /* Reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
289
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
290 if(track->mode == MODE_MOV && track->enc->codec_id == CODEC_ID_AAC)
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
291 {
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
292 /* SoundDescription V1 extended info */
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
293 put_be32(pb, track->enc->frame_size); /* Samples per packet */
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
294 put_be32(pb, 1536); /* Bytes per packet */
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
295 put_be32(pb, 2); /* Bytes per frame */
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
296 put_be32(pb, 2); /* Bytes per sample */
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
297 }
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
298
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
299 if(track->enc->codec_id == CODEC_ID_AAC) {
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
300 if( track->mode == MODE_MOV ) mov_write_wave_tag(pb, track);
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
301 else mov_write_esds_tag(pb, track);
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
302 }
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
303 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
304 mov_write_damr_tag(pb);
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
305 return updateSize (pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
306 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
307
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
308 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
309 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
310 put_be32(pb, 0xf); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
311 put_tag(pb, "d263");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
312 put_tag(pb, "FFMP");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
313 put_be16(pb, 0x0a);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
314 put_byte(pb, 0);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
315 return 0xf;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
316 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
317
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
318 /* 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
319 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
320 {
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
321 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
322 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
323 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
324 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
325 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
326 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
327 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
328 return 0x15;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
329 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
330
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
331 static unsigned int descrLength(unsigned int len)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
332 {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
333 if (len < 0x00000080)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
334 return 2 + len;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
335 else if (len < 0x00004000)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
336 return 3 + len;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
337 else if(len < 0x00200000)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
338 return 4 + len;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
339 else
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
340 return 5 + len;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
341 }
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
342
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
343 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
344 {
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
345 uint32_t len;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
346 uint8_t vals[4];
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
347
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
348 len = size;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
349 vals[3] = (uint8_t)(len & 0x7f);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
350 len >>= 7;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
351 vals[2] = (uint8_t)((len & 0x7f) | 0x80);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
352 len >>= 7;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
353 vals[1] = (uint8_t)((len & 0x7f) | 0x80);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
354 len >>= 7;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
355 vals[0] = (uint8_t)((len & 0x7f) | 0x80);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
356
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
357 put_byte(pb, tag); // DescriptorTag
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
358
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
359 if (size < 0x00000080)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
360 {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
361 put_byte(pb, vals[3]);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
362 }
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
363 else if (size < 0x00004000)
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 put_byte(pb, vals[2]);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
366 put_byte(pb, vals[3]);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
367 }
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
368 else if (size < 0x00200000)
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 put_byte(pb, vals[1]);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
371 put_byte(pb, vals[2]);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
372 put_byte(pb, vals[3]);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
373 }
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
374 else if (size < 0x10000000)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
375 {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
376 put_byte(pb, vals[0]);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
377 put_byte(pb, vals[1]);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
378 put_byte(pb, vals[2]);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
379 put_byte(pb, vals[3]);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
380 }
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
381 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
382
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
383 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
384 {
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
385 int decoderSpecificInfoLen = track->vosLen ? descrLength(track->vosLen):0;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
386 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
387
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
388 put_be32(pb, 0); // size
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
389 put_tag(pb, "esds");
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
390 put_be32(pb, 0); // Version
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
391
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
392 // ES descriptor
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
393 putDescr(pb, 0x03, 3 + descrLength(13 + decoderSpecificInfoLen) +
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
394 descrLength(1));
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
395 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
396 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
397
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
398 // DecoderConfig descriptor
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
399 putDescr(pb, 0x04, 13 + decoderSpecificInfoLen);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
400
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
401 if(track->enc->codec_id == CODEC_ID_AAC)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
402 put_byte(pb, 0x40); // Object type indication
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
403 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
404 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
405
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
406 if(track->enc->codec_type == CODEC_TYPE_AUDIO)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
407 put_byte(pb, 0x15); // flags (= Audiostream)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
408 else
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
409 put_byte(pb, 0x11); // flags (= Visualstream)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
410
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
411 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
412 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
413
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
414 // 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
415 put_be32(pb, 0x0002e918); // maxbitrate
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
416 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
417
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
418 if (track->vosLen)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
419 {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
420 // DecoderSpecific info descriptor
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
421 putDescr(pb, 0x05, track->vosLen);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
422 put_buffer(pb, track->vosData, track->vosLen);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
423 }
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
424
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
425 // SL descriptor
377
d58f2852730e 10l (1 vs. descrLength(1)) found by (Jean Le Feuvre - jeanlf)
michael
parents: 365
diff changeset
426 putDescr(pb, 0x06, 1);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
427 put_byte(pb, 0x02);
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
428 return updateSize (pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
429 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
430
422
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
431 const CodecTag codec_movvideo_tags[] = {
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
432 { CODEC_ID_SVQ1, MKTAG('S', 'V', 'Q', '1') },
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
433 { CODEC_ID_SVQ3, MKTAG('S', 'V', 'Q', '3') },
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
434 { CODEC_ID_MPEG4, MKTAG('m', 'p', '4', 'v') },
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
435 { CODEC_ID_H263, MKTAG('s', '2', '6', '3') },
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
436 { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'c', ' ') },
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
437 { 0, 0 },
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
438 };
2f30932cda1f support for wider range of codecs
alex
parents: 400
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 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
441 {
494
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
442 int pos = url_ftell(pb);
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
443 int tag;
422
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
444
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
445 put_be32(pb, 0); /* size */
422
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
446
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
447 tag = codec_get_tag(codec_movvideo_tags, track->enc->codec_id);
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
448 // if no mac fcc found, try with Microsoft tags
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
449 if (!tag)
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
450 tag = codec_get_tag(codec_bmp_tags, track->enc->codec_id);
494
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
451 put_le32(pb, tag); // store it byteswapped
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
452
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
453 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
454 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
455 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
456
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
457 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
458 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
459 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
460 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
461 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
462 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
463 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
464 put_be32(pb, 0x00480000); /* Reserved */
399
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
465 put_be32(pb, 0); /* Data size (= 0) */
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
466 put_be16(pb, 1); /* Frame count (= 1) */
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
467
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
468 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
469 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
470 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
471 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
472 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
473 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
474 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
475 put_be32(pb, 0); /* Reserved */
399
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
476
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
477 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
478 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
479 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
480 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
481 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
482 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
483 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
484 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
485
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
486 return updateSize (pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
487 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
488
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
489 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
490 {
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
491 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
492 put_be32(pb, 0); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
493 put_tag(pb, "stsd");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
494 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
495 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
496 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
497 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
498 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
499 mov_write_audio_tag(pb, track);
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
500 return updateSize(pb, pos);
201
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
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
503 /* 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
504 /* Time to sample atom */
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
505 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
506 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
507 put_be32(pb, 0x18); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
508 put_tag(pb, "stts");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
509 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
510 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
511
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
512 put_be32(pb, track->sampleCount); /* sample count */
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
513 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
514 return 0x18;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
515 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
516
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
517 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
518 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
519 put_be32(pb, 28); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
520 put_tag(pb, "dref");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
521 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
522 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
523
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
524 put_be32(pb, 0xc); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
525 put_tag(pb, "url ");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
526 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
527
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
528 return 28;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
529 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
530
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
531 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
532 {
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
533 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
534 put_be32(pb, 0); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
535 put_tag(pb, "stbl");
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
536 mov_write_stsd_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
537 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
538 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
539 track->hasKeyframes)
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
540 mov_write_stss_tag(pb, track);
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
541 mov_write_stsc_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
542 mov_write_stsz_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
543 mov_write_stco_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
544 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
545 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
546
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
547 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
548 {
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
549 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
550 put_be32(pb, 0); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
551 put_tag(pb, "dinf");
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
552 mov_write_dref_tag(pb);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
553 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
554 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
555
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
556 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
557 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
558 put_be32(pb, 16); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
559 put_tag(pb, "smhd");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
560 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
561 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
562 put_be16(pb, 0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
563 return 16;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
564 }
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 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
567 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
568 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
569 put_tag(pb, "vmhd");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
570 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
571 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
572 return 0x14;
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
399
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
575 static int mov_write_hdlr_tag(ByteIOContext *pb, MOVTrack* track)
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
576 {
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
577 char *descr, *hdlr, *hdlr_type;
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
578 int pos = url_ftell(pb);
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
579
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
580 if (!track) { /* no media --> data handler */
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
581 hdlr = "dhlr";
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
582 hdlr_type = "url ";
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
583 descr = "DataHandler";
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
584 } else {
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
585 hdlr = (track->mode == MODE_MOV) ? "mhlr" : "\0\0\0\0";
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
586 if (track->enc->codec_type == CODEC_TYPE_VIDEO) {
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
587 hdlr_type = "vide";
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
588 descr = "VideoHandler";
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
589 } else {
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
590 hdlr_type = "soun";
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
591 descr = "SoundHandler";
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
592 }
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
593 }
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
594
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
595 put_be32(pb, 0); /* size */
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
596 put_tag(pb, "hdlr");
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
597 put_be32(pb, 0); /* Version & flags */
400
62e4ea840c52 * fixing 10l in movenc.c + updating regression patterns.
romansh
parents: 399
diff changeset
598 put_buffer(pb, hdlr, 4); /* handler */
399
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
599 put_tag(pb, hdlr_type); /* handler type */
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
600 put_be32(pb ,0); /* reserved */
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
601 put_be32(pb ,0); /* reserved */
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
602 put_be32(pb ,0); /* reserved */
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
603 put_byte(pb, strlen(descr)); /* string counter */
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
604 put_buffer(pb, descr, strlen(descr)); /* handler description */
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
605 return updateSize(pb, pos);
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
606 }
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
607
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
608 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
609 {
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
610 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
611 put_be32(pb, 0); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
612 put_tag(pb, "minf");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
613 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
614 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
615 else
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
616 mov_write_smhd_tag(pb);
399
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
617 if (track->mode == MODE_MOV) /* FIXME: Why do it for MODE_MOV only ? */
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
618 mov_write_hdlr_tag(pb, NULL);
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
619 mov_write_dinf_tag(pb);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
620 mov_write_stbl_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
621 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
622 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
623
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
624 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
625 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
626 put_be32(pb, 32); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
627 put_tag(pb, "mdhd");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
628 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
629 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
630 put_be32(pb, track->time); /* modification time */
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
631 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
632 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
633 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
634 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
635 return 32;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
636 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
637
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
638 static int mov_write_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
639 {
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
640 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
641 put_be32(pb, 0); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
642 put_tag(pb, "mdia");
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
643 mov_write_mdhd_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
644 mov_write_hdlr_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
645 mov_write_minf_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
646 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
647 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
648
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
649 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
650 {
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
651 int64_t maxTrackLenTemp;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
652 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
653 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
654 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
655 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
656 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
657 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
658 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
659 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
660 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
661
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
662 put_be32(pb, 0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
663 put_be32(pb, 0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
664 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
665 /* Volume, only for audio */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
666 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
667 put_be16(pb, 0x0100);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
668 else
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
669 put_be16(pb, 0);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
670 put_be16(pb, 0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
671
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
672 /* Matrix structure */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
673 put_be32(pb, 0x00010000); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
674 put_be32(pb, 0x0); /* 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, 0x00010000); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
678 put_be32(pb, 0x0); /* 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, 0x40000000); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
682
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
683 /* 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
684 if(track->enc->codec_type == CODEC_TYPE_VIDEO) {
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
685 double sample_aspect_ratio = av_q2d(track->enc->sample_aspect_ratio);
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
686 if( !sample_aspect_ratio ) sample_aspect_ratio = 1;
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
687 put_be32(pb, sample_aspect_ratio * track->enc->width*0x10000);
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
688 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
689 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
690 else {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
691 put_be32(pb, 0);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
692 put_be32(pb, 0);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
693 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
694 return 0x5c;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
695 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
696
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
697 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
698 {
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
699 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
700 put_be32(pb, 0); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
701 put_tag(pb, "trak");
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
702 mov_write_tkhd_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
703 mov_write_mdia_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
704 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
705 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
706
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
707 /* 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
708 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
709 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
710 put_be32(pb, 0x15); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
711 put_tag(pb, "iods");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
712 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
713 put_be16(pb, 0x1007);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
714 put_byte(pb, 0);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
715 put_be16(pb, 0x4fff);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
716 put_be16(pb, 0xfffe);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
717 put_be16(pb, 0x01ff);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
718 return 0x15;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
719 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
720
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
721 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
722 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
723 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
724 int64_t maxTrackLenTemp;
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 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
727 put_tag(pb, "mvhd");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
728 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
729 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
730 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
731 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
732 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
733 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
734 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
735 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
736 maxTrackLen = maxTrackLenTemp;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
737 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
738 maxTrackID = mov->tracks[i].trackID;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
739 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
740 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
741 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
742
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
743 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
744 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
745 put_be16(pb, 0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
746 put_be32(pb, 0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
747 put_be32(pb, 0); /* reserved */
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 /* Matrix structure */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
750 put_be32(pb, 0x00010000); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
751 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
752 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
753 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
754 put_be32(pb, 0x00010000); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
755 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
756 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
757 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
758 put_be32(pb, 0x40000000); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
759
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
760 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
761 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
762 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
763 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
764 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
765 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
766 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
767 return 0x6c;
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
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
770 static int mov_write_udta_tag(ByteIOContext *pb, MOVContext* mov,
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
771 AVFormatContext *s)
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
772 {
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
773 int pos = url_ftell(pb);
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
774 int i;
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
775
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
776 put_be32(pb, 0); /* size */
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
777 put_tag(pb, "udta");
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
778
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
779 /* Requirements */
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
780 for (i=0; i<MAX_STREAMS; i++) {
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
781 if(mov->tracks[i].entry <= 0) continue;
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
782 if (mov->tracks[i].enc->codec_id == CODEC_ID_AAC ||
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
783 mov->tracks[i].enc->codec_id == CODEC_ID_MPEG4) {
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
784 int pos = url_ftell(pb);
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
785 put_be32(pb, 0); /* size */
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
786 put_tag(pb, "\251req");
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
787 put_be16(pb, sizeof("QuickTime 6.0 or greater") - 1);
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
788 put_be16(pb, 0);
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
789 put_buffer(pb, "QuickTime 6.0 or greater",
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
790 sizeof("QuickTime 6.0 or greater") - 1);
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
791 updateSize(pb, pos);
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
792 break;
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
793 }
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
794 }
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
795
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
796 /* Encoder */
441
6635c1e75087 bit-exact
michael
parents: 424
diff changeset
797 if(!(mov->tracks[0].enc->flags & CODEC_FLAG_BITEXACT))
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
798 {
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
799 int pos = url_ftell(pb);
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
800 put_be32(pb, 0); /* size */
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
801 put_tag(pb, "\251enc");
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
802 put_be16(pb, sizeof(LIBAVFORMAT_IDENT) - 1); /* string length */
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
803 put_be16(pb, 0);
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
804 put_buffer(pb, LIBAVFORMAT_IDENT, sizeof(LIBAVFORMAT_IDENT) - 1);
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
805 updateSize(pb, pos);
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
806 }
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
807
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
808 if( s->title[0] )
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
809 {
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
810 int pos = url_ftell(pb);
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
811 put_be32(pb, 0); /* size */
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
812 put_tag(pb, "\251nam");
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
813 put_be16(pb, strlen(s->title)); /* string length */
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
814 put_be16(pb, 0);
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
815 put_buffer(pb, s->title, strlen(s->title));
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
816 updateSize(pb, pos);
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
817 }
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
818
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
819 if( s->author[0] )
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
820 {
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
821 int pos = url_ftell(pb);
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
822 put_be32(pb, 0); /* size */
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
823 put_tag(pb, /*"\251aut"*/ "\251day" );
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
824 put_be16(pb, strlen(s->author)); /* string length */
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
825 put_be16(pb, 0);
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
826 put_buffer(pb, s->author, strlen(s->author));
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
827 updateSize(pb, pos);
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
828 }
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
829
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
830 if( s->comment[0] )
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
831 {
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
832 int pos = url_ftell(pb);
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
833 put_be32(pb, 0); /* size */
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
834 put_tag(pb, "\251des");
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
835 put_be16(pb, strlen(s->comment)); /* string length */
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
836 put_be16(pb, 0);
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
837 put_buffer(pb, s->comment, strlen(s->comment));
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
838 updateSize(pb, pos);
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
839 }
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
840
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
841 return updateSize(pb, pos);
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
842 }
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
843
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
844 static int mov_write_moov_tag(ByteIOContext *pb, MOVContext *mov,
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
845 AVFormatContext *s)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
846 {
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
847 int pos, i;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
848 pos = url_ftell(pb);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
849 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
850 put_tag(pb, "moov");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
851 mov->timescale = globalTimescale;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
852
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
853 for (i=0; i<MAX_STREAMS; i++) {
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
854 if(mov->tracks[i].entry <= 0) continue;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
855
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
856 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
857 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
858 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
859 }
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
860 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
861 /* If AMR, track timescale = 8000, AMR_WB = 16000 */
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
862 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
863 mov->tracks[i].sampleDuration = 160; // Bytes per chunk
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
864 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
865 }
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
866 else {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
867 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
868 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
869 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
870 }
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
871
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
872 mov->tracks[i].trackDuration =
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
873 mov->tracks[i].sampleCount * mov->tracks[i].sampleDuration;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
874 mov->tracks[i].time = mov->time;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
875 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
876 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
877
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
878 mov_write_mvhd_tag(pb, mov);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
879 //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
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].entry > 0) {
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
882 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
883 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
884 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
885
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
886 mov_write_udta_tag(pb, mov, s);
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
887
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
888 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
889 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
890
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
891 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
892 {
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
893 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
894 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
895 put_tag(pb, "mdat");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
896 return 0;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
897 }
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 /* TODO: This needs to be more general */
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
900 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
901 {
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
902 MOVContext *mov = s->priv_data;
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
903
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
904 put_be32(pb, 0x14 ); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
905 put_tag(pb, "ftyp");
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
906
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
907 if ( mov->mode == MODE_3GP )
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
908 put_tag(pb, "3gp4");
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
909 else
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
910 put_tag(pb, "isom");
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
911
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
912 put_be32(pb, 0x200 );
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
913
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
914 if ( mov->mode == MODE_3GP )
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
915 put_tag(pb, "3gp4");
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
916 else
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
917 put_tag(pb, "mp41");
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
918
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
919 return 0x14;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
920 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
921
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
922 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
923 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
924 ByteIOContext *pb = &s->pb;
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
925 MOVContext *mov = s->priv_data;
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
926 int i;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
927
494
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
928 for(i=0; i<s->nb_streams; i++){
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
929 AVCodecContext *c= &s->streams[i]->codec;
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
930
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
931 if (c->codec_type == CODEC_TYPE_VIDEO){
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
932 if (!codec_get_tag(codec_movvideo_tags, c->codec_id)){
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
933 if(!codec_get_tag(codec_bmp_tags, c->codec_id))
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
934 return -1;
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
935 else
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
936 av_log(s, AV_LOG_INFO, "Warning, using MS style video codec tag, the file may be unplayable!\n");
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
937 }
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
938 }else if(c->codec_type == CODEC_TYPE_AUDIO){
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
939 if (!codec_get_tag(codec_movaudio_tags, c->codec_id)){
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
940 if(!codec_get_tag(codec_wav_tags, c->codec_id))
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
941 return -1;
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
942 else
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
943 av_log(s, AV_LOG_INFO, "Warning, using MS style audio codec tag, the file may be unplayable!\n");
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
944 }
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
945 }
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
946 }
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
947
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
948 /* Default mode == MP4 */
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
949 mov->mode = MODE_MP4;
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
950
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
951 if (s->oformat != NULL) {
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
952 if (!strcmp("3gp", s->oformat->name)) mov->mode = MODE_3GP;
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
953 else if (!strcmp("mov", s->oformat->name)) mov->mode = MODE_MOV;
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
954
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
955 if ( mov->mode == MODE_3GP || mov->mode == MODE_MP4 )
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
956 mov_write_ftyp_tag(pb,s);
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
957 }
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
958
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
959 for (i=0; i<MAX_STREAMS; i++) {
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
960 mov->tracks[i].mode = mov->mode;
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
961 }
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
962
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
963 put_flush_packet(pb);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
964
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
965 return 0;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
966 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
967
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 441
diff changeset
968 static int mov_write_packet(AVFormatContext *s, AVPacket *pkt)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
969 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
970 MOVContext *mov = s->priv_data;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
971 ByteIOContext *pb = &s->pb;
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 441
diff changeset
972 AVCodecContext *enc = &s->streams[pkt->stream_index]->codec;
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 441
diff changeset
973 MOVTrack* trk = &mov->tracks[pkt->stream_index];
202
d755254e8797 naughty, forbidden variable declarations
tmmm
parents: 201
diff changeset
974 int cl, id;
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
975 unsigned int samplesInChunk = 0;
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 441
diff changeset
976 int size= pkt->size;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
977
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
978 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
979 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
980
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
981 if (enc->codec_type == CODEC_TYPE_VIDEO ) {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
982 samplesInChunk = 1;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
983 }
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
984 else if (enc->codec_type == CODEC_TYPE_AUDIO ) {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
985 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
986 /* 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
987 static uint16_t packed_size[16] =
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
988 {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
989 int len = 0;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
990
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
991 while (len < size && samplesInChunk < 100) {
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 441
diff changeset
992 len += packed_size[(pkt->data[len] >> 3) & 0x0F];
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
993 samplesInChunk++;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
994 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
995 }
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
996 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
997 samplesInChunk = size/enc->channels;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
998 }
399
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
999 else if(enc->codec_id == CODEC_ID_PCM_S16BE || enc->codec_id == CODEC_ID_PCM_S16LE) {
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
1000 samplesInChunk = size/(2*enc->channels);
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
1001 }
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1002 else {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1003 samplesInChunk = 1;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1004 }
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1005 }
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1006
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1007 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
1008 && trk->vosLen == 0) {
424
dc59cb26955c support for -timestamp
alex
parents: 422
diff changeset
1009 // assert(enc->extradata_size);
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1010
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1011 trk->vosLen = enc->extradata_size;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1012 trk->vosData = av_malloc(trk->vosLen);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1013 memcpy(trk->vosData, enc->extradata, trk->vosLen);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1014 }
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1015
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1016 cl = trk->entry / MOV_INDEX_CLUSTER_SIZE;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1017 id = trk->entry % MOV_INDEX_CLUSTER_SIZE;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1018
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1019 if (trk->ents_allocated <= trk->entry) {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1020 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
1021 if (!trk->cluster)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1022 return -1;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1023 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
1024 if (!trk->cluster[cl])
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1025 return -1;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1026 trk->ents_allocated += MOV_INDEX_CLUSTER_SIZE;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1027 }
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1028 if (mov->mdat_written == 0) {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1029 mov_write_mdat_tag(pb, mov);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1030 mov->mdat_written = 1;
424
dc59cb26955c support for -timestamp
alex
parents: 422
diff changeset
1031 mov->time = s->timestamp;
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1032 }
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1033
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
1034 trk->cluster[cl][id].pos = url_ftell(pb);
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1035 trk->cluster[cl][id].samplesInChunk = samplesInChunk;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1036 trk->cluster[cl][id].size = size;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1037 trk->cluster[cl][id].entries = samplesInChunk;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1038 if(enc->codec_type == CODEC_TYPE_VIDEO) {
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 441
diff changeset
1039 trk->cluster[cl][id].key_frame = !!(pkt->flags & PKT_FLAG_KEY);
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 441
diff changeset
1040 if(trk->cluster[cl][id].key_frame)
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
1041 trk->hasKeyframes = 1;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1042 }
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1043 trk->enc = enc;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1044 trk->entry++;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1045 trk->sampleCount += samplesInChunk;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1046 trk->mdat_size += size;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1047
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 441
diff changeset
1048 put_buffer(pb, pkt->data, size);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1049
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1050 put_flush_packet(pb);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1051 return 0;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1052 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1053
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1054 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
1055 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1056 MOVContext *mov = s->priv_data;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1057 ByteIOContext *pb = &s->pb;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1058 int res = 0;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1059 int i, j;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1060
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
1061 offset_t moov_pos = url_ftell(pb);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1062
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1063 /* Write size of mdat tag */
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
1064 for (i=0, j=0; i<MAX_STREAMS; i++) {
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1065 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
1066 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
1067 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1068 }
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
1069 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
1070 put_be32(pb, j+8);
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
1071 url_fseek(pb, moov_pos, SEEK_SET);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1072
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
1073 mov_write_moov_tag(pb, mov, s);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1074
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1075 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
1076 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
1077 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
1078 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1079 av_free(mov->tracks[i].cluster);
342
0c1b489c96bf memleak patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 299
diff changeset
1080 if( mov->tracks[i].vosLen ) av_free( mov->tracks[i].vosData );
0c1b489c96bf memleak patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 299
diff changeset
1081
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1082 mov->tracks[i].cluster = NULL;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1083 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
1084 }
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
1085
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1086 put_flush_packet(pb);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1087
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1088 return res;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1089 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1090
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1091 static AVOutputFormat mov_oformat = {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1092 "mov",
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1093 "mov format",
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1094 NULL,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1095 "mov",
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1096 sizeof(MOVContext),
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
1097 CODEC_ID_AAC,
239
48c3134e93c3 theres no SVQ1 encoder -> it cant be default
michaelni
parents: 238
diff changeset
1098 CODEC_ID_MPEG4,
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1099 mov_write_header,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1100 mov_write_packet,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1101 mov_write_trailer,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1102 };
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1103
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1104 static AVOutputFormat _3gp_oformat = {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1105 "3gp",
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1106 "3gp format",
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1107 NULL,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1108 "3gp",
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1109 sizeof(MOVContext),
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1110 CODEC_ID_AMR_NB,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1111 CODEC_ID_H263,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1112 mov_write_header,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1113 mov_write_packet,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1114 mov_write_trailer,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1115 };
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1116
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1117 static AVOutputFormat mp4_oformat = {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1118 "mp4",
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1119 "mp4 format",
286
eccf0c3e3289 Using the extension m4a for audio only MPEG-4 files is increasingly
michael
parents: 259
diff changeset
1120 "application/mp4",
eccf0c3e3289 Using the extension m4a for audio only MPEG-4 files is increasingly
michael
parents: 259
diff changeset
1121 "mp4,m4a",
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1122 sizeof(MOVContext),
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1123 CODEC_ID_AAC,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1124 CODEC_ID_MPEG4,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1125 mov_write_header,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1126 mov_write_packet,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1127 mov_write_trailer,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1128 };
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1129
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1130 int movenc_init(void)
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1131 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1132 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
1133 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
1134 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
1135 return 0;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1136 }