annotate movenc.c @ 657:5b9575f5b6e8 libavformat

mov header field and compressor name patch by Roine Gustafsson <roine AT users DOT sourceforge DOT net>
author mmu_man
date Wed, 26 Jan 2005 09:31:49 +0000
parents 7d50b0a324ea
children 6d7c0e6d929e
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
619
7d50b0a324ea add -vtag and-atag support to mov patch by (Roine Gustafsson <roine at users sourceforge net>)
michael
parents: 513
diff changeset
260 tag = track->enc->codec_tag;
7d50b0a324ea add -vtag and-atag support to mov patch by (Roine Gustafsson <roine at users sourceforge net>)
michael
parents: 513
diff changeset
261 if (!tag)
422
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
262 tag = codec_get_tag(codec_movaudio_tags, track->enc->codec_id);
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
263 // if no mac fcc found, try with Microsoft tags
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
264 if (!tag)
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
265 {
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
266 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
267 tag = MKTAG('m', 's', ((tmp >> 8) & 0xff), (tmp & 0xff));
422
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
268 }
494
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
269 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
270
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
271 put_be32(pb, 0); /* Reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
272 put_be16(pb, 0); /* Reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
273 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
274
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
275 /* 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
276 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
277 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
278 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
279 put_be16(pb, 0); /* Version 0 */
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
280 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
281 put_be32(pb, 0); /* Reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
282
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
283 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
284 /* 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
285 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
286 put_be16(pb, 0x10); /* Reserved */
505
e996e7da971c AAC in mov/mp4 patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 494
diff changeset
287
e996e7da971c AAC in mov/mp4 patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 494
diff changeset
288 if(track->enc->codec_id == CODEC_ID_AAC ||
e996e7da971c AAC in mov/mp4 patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 494
diff changeset
289 track->enc->codec_id == CODEC_ID_MP3)
e996e7da971c AAC in mov/mp4 patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 494
diff changeset
290 {
e996e7da971c AAC in mov/mp4 patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 494
diff changeset
291 put_be16(pb, 0xfffe); /* compression ID (vbr)*/
e996e7da971c AAC in mov/mp4 patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 494
diff changeset
292 }
e996e7da971c AAC in mov/mp4 patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 494
diff changeset
293 else
e996e7da971c AAC in mov/mp4 patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 494
diff changeset
294 {
e996e7da971c AAC in mov/mp4 patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 494
diff changeset
295 put_be16(pb, 0); /* compression ID (= 0) */
e996e7da971c AAC in mov/mp4 patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 494
diff changeset
296 }
399
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
297 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
298 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
299 put_be16(pb, 0); /* Reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
300
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
301 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
302 {
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
303 /* 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
304 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
305 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
306 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
307 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
308 }
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
309
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
310 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
311 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
312 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
313 }
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
314 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
315 mov_write_damr_tag(pb);
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
316 return updateSize (pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
317 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
318
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
319 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
320 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
321 put_be32(pb, 0xf); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
322 put_tag(pb, "d263");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
323 put_tag(pb, "FFMP");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
324 put_be16(pb, 0x0a);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
325 put_byte(pb, 0);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
326 return 0xf;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
327 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
328
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
329 /* 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
330 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
331 {
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
332 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
333 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
334 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
335 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
336 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
337 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
338 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
339 return 0x15;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
340 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
341
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
342 static unsigned int descrLength(unsigned int len)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
343 {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
344 if (len < 0x00000080)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
345 return 2 + len;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
346 else if (len < 0x00004000)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
347 return 3 + len;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
348 else if(len < 0x00200000)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
349 return 4 + len;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
350 else
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
351 return 5 + len;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
352 }
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
353
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
354 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
355 {
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
356 uint32_t len;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
357 uint8_t vals[4];
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 len = size;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
360 vals[3] = (uint8_t)(len & 0x7f);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
361 len >>= 7;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
362 vals[2] = (uint8_t)((len & 0x7f) | 0x80);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
363 len >>= 7;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
364 vals[1] = (uint8_t)((len & 0x7f) | 0x80);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
365 len >>= 7;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
366 vals[0] = (uint8_t)((len & 0x7f) | 0x80);
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 put_byte(pb, tag); // DescriptorTag
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 if (size < 0x00000080)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
371 {
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 < 0x00004000)
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[2]);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
377 put_byte(pb, vals[3]);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
378 }
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
379 else if (size < 0x00200000)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
380 {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
381 put_byte(pb, vals[1]);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
382 put_byte(pb, vals[2]);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
383 put_byte(pb, vals[3]);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
384 }
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
385 else if (size < 0x10000000)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
386 {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
387 put_byte(pb, vals[0]);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
388 put_byte(pb, vals[1]);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
389 put_byte(pb, vals[2]);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
390 put_byte(pb, vals[3]);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
391 }
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
392 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
393
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
394 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
395 {
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
396 int decoderSpecificInfoLen = track->vosLen ? descrLength(track->vosLen):0;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
397 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
398
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
399 put_be32(pb, 0); // size
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
400 put_tag(pb, "esds");
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
401 put_be32(pb, 0); // Version
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
402
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
403 // ES descriptor
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
404 putDescr(pb, 0x03, 3 + descrLength(13 + decoderSpecificInfoLen) +
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
405 descrLength(1));
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
406 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
407 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
408
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
409 // DecoderConfig descriptor
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
410 putDescr(pb, 0x04, 13 + decoderSpecificInfoLen);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
411
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
412 if(track->enc->codec_id == CODEC_ID_AAC)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
413 put_byte(pb, 0x40); // Object type indication
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
414 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
415 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
416
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
417 if(track->enc->codec_type == CODEC_TYPE_AUDIO)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
418 put_byte(pb, 0x15); // flags (= Audiostream)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
419 else
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
420 put_byte(pb, 0x11); // flags (= Visualstream)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
421
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
422 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
423 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
424
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
425 // 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
426 put_be32(pb, 0x0002e918); // maxbitrate
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
427 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
428
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
429 if (track->vosLen)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
430 {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
431 // DecoderSpecific info descriptor
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
432 putDescr(pb, 0x05, track->vosLen);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
433 put_buffer(pb, track->vosData, track->vosLen);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
434 }
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
435
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
436 // SL descriptor
377
d58f2852730e 10l (1 vs. descrLength(1)) found by (Jean Le Feuvre - jeanlf)
michael
parents: 365
diff changeset
437 putDescr(pb, 0x06, 1);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
438 put_byte(pb, 0x02);
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
439 return updateSize (pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
440 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
441
422
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
442 const CodecTag codec_movvideo_tags[] = {
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
443 { CODEC_ID_SVQ1, MKTAG('S', 'V', 'Q', '1') },
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
444 { CODEC_ID_SVQ3, MKTAG('S', 'V', 'Q', '3') },
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
445 { CODEC_ID_MPEG4, MKTAG('m', 'p', '4', 'v') },
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
446 { CODEC_ID_H263, MKTAG('s', '2', '6', '3') },
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
447 { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'c', ' ') },
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
448 { 0, 0 },
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
449 };
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
450
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
451 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
452 {
494
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
453 int pos = url_ftell(pb);
657
5b9575f5b6e8 mov header field and compressor name patch by Roine Gustafsson <roine AT users DOT sourceforge DOT net>
mmu_man
parents: 619
diff changeset
454 char compressor_name[32];
494
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
455 int tag;
422
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
456
259
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); /* size */
422
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
458
619
7d50b0a324ea add -vtag and-atag support to mov patch by (Roine Gustafsson <roine at users sourceforge net>)
michael
parents: 513
diff changeset
459 tag = track->enc->codec_tag;
7d50b0a324ea add -vtag and-atag support to mov patch by (Roine Gustafsson <roine at users sourceforge net>)
michael
parents: 513
diff changeset
460 if (!tag)
422
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
461 tag = codec_get_tag(codec_movvideo_tags, track->enc->codec_id);
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
462 // if no mac fcc found, try with Microsoft tags
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
463 if (!tag)
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
464 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
465 put_le32(pb, tag); // store it byteswapped
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
466
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
467 put_be32(pb, 0); /* Reserved */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
468 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
469 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
470
657
5b9575f5b6e8 mov header field and compressor name patch by Roine Gustafsson <roine AT users DOT sourceforge DOT net>
mmu_man
parents: 619
diff changeset
471 put_be16(pb, 0); /* Codec stream version */
5b9575f5b6e8 mov header field and compressor name patch by Roine Gustafsson <roine AT users DOT sourceforge DOT net>
mmu_man
parents: 619
diff changeset
472 put_be16(pb, 0); /* Codec stream revision (=0) */
5b9575f5b6e8 mov header field and compressor name patch by Roine Gustafsson <roine AT users DOT sourceforge DOT net>
mmu_man
parents: 619
diff changeset
473 put_tag(pb, "FFMP"); /* Vendor */
5b9575f5b6e8 mov header field and compressor name patch by Roine Gustafsson <roine AT users DOT sourceforge DOT net>
mmu_man
parents: 619
diff changeset
474 if(track->enc->codec_id == CODEC_ID_RAWVIDEO) {
5b9575f5b6e8 mov header field and compressor name patch by Roine Gustafsson <roine AT users DOT sourceforge DOT net>
mmu_man
parents: 619
diff changeset
475 put_be32(pb, 0); /* Temporal Quality */
5b9575f5b6e8 mov header field and compressor name patch by Roine Gustafsson <roine AT users DOT sourceforge DOT net>
mmu_man
parents: 619
diff changeset
476 put_be32(pb, 0x400); /* Spatial Quality = lossless*/
5b9575f5b6e8 mov header field and compressor name patch by Roine Gustafsson <roine AT users DOT sourceforge DOT net>
mmu_man
parents: 619
diff changeset
477 } else {
5b9575f5b6e8 mov header field and compressor name patch by Roine Gustafsson <roine AT users DOT sourceforge DOT net>
mmu_man
parents: 619
diff changeset
478 put_be32(pb, 0x200); /* Temporal Quality = normal */
5b9575f5b6e8 mov header field and compressor name patch by Roine Gustafsson <roine AT users DOT sourceforge DOT net>
mmu_man
parents: 619
diff changeset
479 put_be32(pb, 0x200); /* Spatial Quality = normal */
5b9575f5b6e8 mov header field and compressor name patch by Roine Gustafsson <roine AT users DOT sourceforge DOT net>
mmu_man
parents: 619
diff changeset
480 }
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
481 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
482 put_be16(pb, track->enc->height); /* Video height */
657
5b9575f5b6e8 mov header field and compressor name patch by Roine Gustafsson <roine AT users DOT sourceforge DOT net>
mmu_man
parents: 619
diff changeset
483 put_be32(pb, 0x00480000); /* Horizontal resolution 72dpi */
5b9575f5b6e8 mov header field and compressor name patch by Roine Gustafsson <roine AT users DOT sourceforge DOT net>
mmu_man
parents: 619
diff changeset
484 put_be32(pb, 0x00480000); /* Vertical resolution 72dpi */
399
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
485 put_be32(pb, 0); /* Data size (= 0) */
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
486 put_be16(pb, 1); /* Frame count (= 1) */
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
487
657
5b9575f5b6e8 mov header field and compressor name patch by Roine Gustafsson <roine AT users DOT sourceforge DOT net>
mmu_man
parents: 619
diff changeset
488 memset(compressor_name,0,32);
5b9575f5b6e8 mov header field and compressor name patch by Roine Gustafsson <roine AT users DOT sourceforge DOT net>
mmu_man
parents: 619
diff changeset
489 if (track->enc->codec->name)
5b9575f5b6e8 mov header field and compressor name patch by Roine Gustafsson <roine AT users DOT sourceforge DOT net>
mmu_man
parents: 619
diff changeset
490 strncpy(compressor_name,track->enc->codec->name,31);
5b9575f5b6e8 mov header field and compressor name patch by Roine Gustafsson <roine AT users DOT sourceforge DOT net>
mmu_man
parents: 619
diff changeset
491 put_byte(pb, FFMAX(strlen(compressor_name),32) );
5b9575f5b6e8 mov header field and compressor name patch by Roine Gustafsson <roine AT users DOT sourceforge DOT net>
mmu_man
parents: 619
diff changeset
492 put_buffer(pb, compressor_name, 31);
399
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
493
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
494 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
495 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
496 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
497 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
498 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
499 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
500 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
501 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
502
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
503 return updateSize (pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
504 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
505
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
506 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
507 {
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
508 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
509 put_be32(pb, 0); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
510 put_tag(pb, "stsd");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
511 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
512 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
513 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
514 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
515 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
516 mov_write_audio_tag(pb, track);
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
517 return updateSize(pb, pos);
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
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
520 /* 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
521 /* Time to sample atom */
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
522 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
523 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
524 put_be32(pb, 0x18); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
525 put_tag(pb, "stts");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
526 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
527 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
528
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
529 put_be32(pb, track->sampleCount); /* sample count */
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
530 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
531 return 0x18;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
532 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
533
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
534 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
535 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
536 put_be32(pb, 28); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
537 put_tag(pb, "dref");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
538 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
539 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
540
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
541 put_be32(pb, 0xc); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
542 put_tag(pb, "url ");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
543 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
544
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
545 return 28;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
546 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
547
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
548 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
549 {
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
550 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
551 put_be32(pb, 0); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
552 put_tag(pb, "stbl");
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
553 mov_write_stsd_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
554 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
555 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
556 track->hasKeyframes)
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
557 mov_write_stss_tag(pb, track);
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
558 mov_write_stsc_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
559 mov_write_stsz_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
560 mov_write_stco_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
561 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
562 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
563
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
564 static int mov_write_dinf_tag(ByteIOContext *pb)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
565 {
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
566 int pos = url_ftell(pb);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
567 put_be32(pb, 0); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
568 put_tag(pb, "dinf");
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
569 mov_write_dref_tag(pb);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
570 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
571 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
572
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
573 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
574 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
575 put_be32(pb, 16); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
576 put_tag(pb, "smhd");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
577 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
578 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
579 put_be16(pb, 0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
580 return 16;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
581 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
582
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
583 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
584 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
585 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
586 put_tag(pb, "vmhd");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
587 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
588 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
589 return 0x14;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
590 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
591
399
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
592 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
593 {
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
594 char *descr, *hdlr, *hdlr_type;
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
595 int pos = url_ftell(pb);
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
596
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
597 if (!track) { /* no media --> data handler */
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
598 hdlr = "dhlr";
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
599 hdlr_type = "url ";
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
600 descr = "DataHandler";
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
601 } else {
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
602 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
603 if (track->enc->codec_type == CODEC_TYPE_VIDEO) {
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
604 hdlr_type = "vide";
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
605 descr = "VideoHandler";
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
606 } else {
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
607 hdlr_type = "soun";
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
608 descr = "SoundHandler";
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
609 }
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
610 }
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
611
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
612 put_be32(pb, 0); /* size */
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
613 put_tag(pb, "hdlr");
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
614 put_be32(pb, 0); /* Version & flags */
400
62e4ea840c52 * fixing 10l in movenc.c + updating regression patterns.
romansh
parents: 399
diff changeset
615 put_buffer(pb, hdlr, 4); /* handler */
399
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
616 put_tag(pb, hdlr_type); /* handler type */
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
617 put_be32(pb ,0); /* reserved */
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
618 put_be32(pb ,0); /* reserved */
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
619 put_be32(pb ,0); /* reserved */
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
620 put_byte(pb, strlen(descr)); /* string counter */
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
621 put_buffer(pb, descr, strlen(descr)); /* handler description */
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
622 return updateSize(pb, pos);
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
623 }
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
624
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
625 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
626 {
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
627 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
628 put_be32(pb, 0); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
629 put_tag(pb, "minf");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
630 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
631 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
632 else
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
633 mov_write_smhd_tag(pb);
399
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
634 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
635 mov_write_hdlr_tag(pb, NULL);
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
636 mov_write_dinf_tag(pb);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
637 mov_write_stbl_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
638 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
639 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
640
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
641 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
642 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
643 put_be32(pb, 32); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
644 put_tag(pb, "mdhd");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
645 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
646 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
647 put_be32(pb, track->time); /* modification time */
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
648 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
649 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
650 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
651 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
652 return 32;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
653 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
654
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
655 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
656 {
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
657 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
658 put_be32(pb, 0); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
659 put_tag(pb, "mdia");
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
660 mov_write_mdhd_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
661 mov_write_hdlr_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
662 mov_write_minf_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
663 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
664 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
665
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
666 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
667 {
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
668 int64_t maxTrackLenTemp;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
669 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
670 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
671 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
672 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
673 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
674 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
675 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
676 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
677 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
678
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
679 put_be32(pb, 0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
680 put_be32(pb, 0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
681 put_be32(pb, 0x0); /* reserved (Layer & Alternate group) */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
682 /* Volume, only for audio */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
683 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
684 put_be16(pb, 0x0100);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
685 else
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
686 put_be16(pb, 0);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
687 put_be16(pb, 0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
688
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
689 /* Matrix structure */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
690 put_be32(pb, 0x00010000); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
691 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
692 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
693 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
694 put_be32(pb, 0x00010000); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
695 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
696 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
697 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
698 put_be32(pb, 0x40000000); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
699
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
700 /* 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
701 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
702 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
703 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
704 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
705 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
706 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
707 else {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
708 put_be32(pb, 0);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
709 put_be32(pb, 0);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
710 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
711 return 0x5c;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
712 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
713
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
714 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
715 {
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
716 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
717 put_be32(pb, 0); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
718 put_tag(pb, "trak");
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
719 mov_write_tkhd_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
720 mov_write_mdia_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
721 return updateSize(pb, pos);
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
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
724 /* 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
725 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
726 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
727 put_be32(pb, 0x15); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
728 put_tag(pb, "iods");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
729 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
730 put_be16(pb, 0x1007);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
731 put_byte(pb, 0);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
732 put_be16(pb, 0x4fff);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
733 put_be16(pb, 0xfffe);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
734 put_be16(pb, 0x01ff);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
735 return 0x15;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
736 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
737
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
738 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
739 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
740 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
741 int64_t maxTrackLenTemp;
201
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, 0x6c); /* size (always 0x6c) */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
744 put_tag(pb, "mvhd");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
745 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
746 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
747 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
748 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
749 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
750 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
751 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
752 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
753 maxTrackLen = maxTrackLenTemp;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
754 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
755 maxTrackID = mov->tracks[i].trackID;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
756 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
757 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
758 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
759
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
760 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
761 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
762 put_be16(pb, 0); /* reserved */
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 */
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 */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
765
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
766 /* Matrix structure */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
767 put_be32(pb, 0x00010000); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
768 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
769 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
770 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
771 put_be32(pb, 0x00010000); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
772 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
773 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
774 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
775 put_be32(pb, 0x40000000); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
776
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
777 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
778 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
779 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
780 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
781 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
782 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
783 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
784 return 0x6c;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
785 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
786
513
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
787 static int mov_write_itunes_hdlr_tag(ByteIOContext *pb, MOVContext* mov,
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
788 AVFormatContext *s)
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
789 {
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
790 int pos = url_ftell(pb);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
791 put_be32(pb, 0); /* size */
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
792 put_tag(pb, "hdlr");
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
793 put_be32(pb, 0);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
794 put_be32(pb, 0);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
795 put_tag(pb, "mdir");
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
796 put_tag(pb, "appl");
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
797 put_be32(pb, 0);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
798 put_be32(pb, 0);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
799 put_be16(pb, 0);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
800 return updateSize(pb, pos);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
801 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
802
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
803 /* helper function to write a data tag with the specified string as data */
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
804 static int mov_write_string_data_tag(ByteIOContext *pb, MOVContext* mov,
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
805 AVFormatContext *s, const char *data)
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
806 {
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
807 int pos = url_ftell(pb);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
808 put_be32(pb, 0); /* size */
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
809 put_tag(pb, "data");
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
810 put_be32(pb, 1);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
811 put_be32(pb, 0);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
812 put_buffer(pb, data, strlen(data));
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
813 return updateSize(pb, pos);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
814 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
815
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
816 /* iTunes name of the song/movie */
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
817 static int mov_write_nam_tag(ByteIOContext *pb, MOVContext* mov,
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
818 AVFormatContext *s)
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
819 {
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
820 int size = 0;
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
821 if ( s->title[0] ) {
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
822 int pos = url_ftell(pb);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
823 put_be32(pb, 0); /* size */
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
824 put_tag(pb, "\251nam");
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
825 mov_write_string_data_tag(pb, mov, s, s->title);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
826 size = updateSize(pb, pos);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
827 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
828 return size;
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
829 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
830
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
831 /* iTunes name of the artist/performer */
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
832 static int mov_write_ART_tag(ByteIOContext *pb, MOVContext* mov,
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
833 AVFormatContext *s)
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
834 {
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
835 int size = 0;
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
836 if ( s->author[0] ) {
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
837 int pos = url_ftell(pb);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
838 put_be32(pb, 0); /* size */
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
839 put_tag(pb, "\251ART");
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
840 // we use the author here as this is the only thing that we have...
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
841 mov_write_string_data_tag(pb, mov, s, s->author);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
842 size = updateSize(pb, pos);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
843 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
844 return size;
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
845 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
846
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
847 /* iTunes name of the writer */
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
848 static int mov_write_wrt_tag(ByteIOContext *pb, MOVContext* mov,
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
849 AVFormatContext *s)
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
850 {
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
851 int size = 0;
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
852 if ( s->author[0] ) {
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
853 int pos = url_ftell(pb);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
854 put_be32(pb, 0); /* size */
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
855 put_tag(pb, "\251wrt");
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
856 mov_write_string_data_tag(pb, mov, s, s->author);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
857 size = updateSize(pb, pos);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
858 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
859 return size;
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
860 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
861
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
862 /* iTunes name of the album */
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
863 static int mov_write_alb_tag(ByteIOContext *pb, MOVContext* mov,
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
864 AVFormatContext *s)
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
865 {
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
866 int size = 0;
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
867 if ( s->album[0] ) {
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
868 int pos = url_ftell(pb);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
869 put_be32(pb, 0); /* size */
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
870 put_tag(pb, "\251alb");
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
871 mov_write_string_data_tag(pb, mov, s, s->album);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
872 size = updateSize(pb, pos);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
873 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
874 return size;
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
875 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
876
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
877 /* iTunes year */
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
878 static int mov_write_day_tag(ByteIOContext *pb, MOVContext* mov,
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
879 AVFormatContext *s)
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
880 {
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
881 char year[5];
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
882 int size = 0;
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
883 if ( s->year ) {
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
884 int pos = url_ftell(pb);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
885 put_be32(pb, 0); /* size */
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
886 put_tag(pb, "\251day");
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
887 snprintf(year, 5, "%04d", s->year);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
888 mov_write_string_data_tag(pb, mov, s, year);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
889 size = updateSize(pb, pos);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
890 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
891 return size;
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
892 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
893
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
894 /* iTunes tool used to create the file */
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
895 static int mov_write_too_tag(ByteIOContext *pb, MOVContext* mov,
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
896 AVFormatContext *s)
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
897 {
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
898 int pos = url_ftell(pb);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
899 put_be32(pb, 0); /* size */
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
900 put_tag(pb, "\251too");
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
901 mov_write_string_data_tag(pb, mov, s, LIBAVFORMAT_IDENT);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
902 return updateSize(pb, pos);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
903 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
904
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
905 /* iTunes comment */
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
906 static int mov_write_cmt_tag(ByteIOContext *pb, MOVContext* mov,
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
907 AVFormatContext *s)
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
908 {
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
909 int size = 0;
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
910 if ( s->comment[0] ) {
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
911 int pos = url_ftell(pb);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
912 put_be32(pb, 0); /* size */
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
913 put_tag(pb, "\251cmt");
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
914 mov_write_string_data_tag(pb, mov, s, s->comment);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
915 size = updateSize(pb, pos);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
916 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
917 return size;
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
918 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
919
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
920 /* iTunes custom genre */
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
921 static int mov_write_gen_tag(ByteIOContext *pb, MOVContext* mov,
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
922 AVFormatContext *s)
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
923 {
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
924 int size = 0;
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
925 if ( s->genre[0] ) {
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
926 int pos = url_ftell(pb);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
927 put_be32(pb, 0); /* size */
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
928 put_tag(pb, "\251gen");
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
929 mov_write_string_data_tag(pb, mov, s, s->genre);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
930 size = updateSize(pb, pos);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
931 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
932 return size;
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
933 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
934
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
935 /* iTunes track number */
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
936 static int mov_write_trkn_tag(ByteIOContext *pb, MOVContext* mov,
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
937 AVFormatContext *s)
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
938 {
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
939 int size = 0;
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
940 if ( s->track ) {
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
941 int pos = url_ftell(pb);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
942 put_be32(pb, 0); /* size */
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
943 put_tag(pb, "trkn");
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
944 {
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
945 int pos = url_ftell(pb);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
946 put_be32(pb, 0); /* size */
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
947 put_tag(pb, "data");
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
948 put_be32(pb, 0); // 8 bytes empty
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
949 put_be32(pb, 0);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
950 put_be16(pb, 0); // empty
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
951 put_be16(pb, s->track); // track number
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
952 put_be16(pb, 0); // total track number
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
953 put_be16(pb, 0); // empty
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
954 updateSize(pb, pos);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
955 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
956 size = updateSize(pb, pos);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
957 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
958 return size;
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
959 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
960
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
961 /* iTunes meta data list */
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
962 static int mov_write_ilst_tag(ByteIOContext *pb, MOVContext* mov,
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
963 AVFormatContext *s)
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
964 {
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
965 int pos = url_ftell(pb);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
966 put_be32(pb, 0); /* size */
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
967 put_tag(pb, "ilst");
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
968 mov_write_nam_tag(pb, mov, s);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
969 mov_write_ART_tag(pb, mov, s);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
970 mov_write_wrt_tag(pb, mov, s);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
971 mov_write_alb_tag(pb, mov, s);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
972 mov_write_day_tag(pb, mov, s);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
973 mov_write_too_tag(pb, mov, s);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
974 mov_write_cmt_tag(pb, mov, s);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
975 mov_write_gen_tag(pb, mov, s);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
976 mov_write_trkn_tag(pb, mov, s);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
977 return updateSize(pb, pos);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
978 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
979
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
980 /* iTunes meta data tag */
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
981 static int mov_write_meta_tag(ByteIOContext *pb, MOVContext* mov,
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
982 AVFormatContext *s)
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
983 {
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
984 int size = 0;
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
985
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
986 // only save meta tag if required
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
987 if ( s->title[0] || s->author[0] || s->album[0] || s->year ||
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
988 s->comment[0] || s->genre[0] || s->track ) {
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
989 int pos = url_ftell(pb);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
990 put_be32(pb, 0); /* size */
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
991 put_tag(pb, "meta");
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
992 put_be32(pb, 0);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
993 mov_write_itunes_hdlr_tag(pb, mov, s);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
994 mov_write_ilst_tag(pb, mov, s);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
995 size = updateSize(pb, pos);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
996 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
997 return size;
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
998 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
999
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
1000 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
1001 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
1002 {
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
1003 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
1004 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
1005
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
1006 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
1007 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
1008
513
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1009 /* iTunes meta data */
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1010 mov_write_meta_tag(pb, mov, s);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1011
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
1012 /* 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
1013 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
1014 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
1015 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
1016 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
1017 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
1018 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
1019 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
1020 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
1021 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
1022 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
1023 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
1024 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
1025 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
1026 }
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
1027 }
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
1028
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
1029 /* Encoder */
441
6635c1e75087 bit-exact
michael
parents: 424
diff changeset
1030 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
1031 {
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
1032 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
1033 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
1034 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
1035 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
1036 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
1037 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
1038 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
1039 }
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
1040
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
1041 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
1042 {
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
1043 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
1044 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
1045 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
1046 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
1047 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
1048 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
1049 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
1050 }
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
1051
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
1052 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
1053 {
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
1054 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
1055 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
1056 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
1057 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
1058 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
1059 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
1060 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
1061 }
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
1062
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
1063 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
1064 {
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
1065 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
1066 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
1067 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
1068 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
1069 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
1070 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
1071 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
1072 }
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
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
1074 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
1075 }
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
1076
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
1077 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
1078 AVFormatContext *s)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1079 {
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
1080 int pos, i;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1081 pos = url_ftell(pb);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1082 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
1083 put_tag(pb, "moov");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1084 mov->timescale = globalTimescale;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1085
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1086 for (i=0; i<MAX_STREAMS; i++) {
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1087 if(mov->tracks[i].entry <= 0) continue;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1088
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1089 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
1090 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
1091 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
1092 }
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1093 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
1094 /* If AMR, track timescale = 8000, AMR_WB = 16000 */
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1095 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
1096 mov->tracks[i].sampleDuration = 160; // Bytes per chunk
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1097 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
1098 }
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1099 else {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1100 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
1101 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
1102 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1103 }
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1104
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1105 mov->tracks[i].trackDuration =
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1106 mov->tracks[i].sampleCount * mov->tracks[i].sampleDuration;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1107 mov->tracks[i].time = mov->time;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1108 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
1109 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1110
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
1111 mov_write_mvhd_tag(pb, mov);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
1112 //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
1113 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
1114 if(mov->tracks[i].entry > 0) {
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
1115 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
1116 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1117 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1118
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
1119 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
1120
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
1121 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1122 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1123
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
1124 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
1125 {
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
1126 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
1127 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
1128 put_tag(pb, "mdat");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1129 return 0;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1130 }
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 /* TODO: This needs to be more general */
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1133 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
1134 {
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
1135 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
1136
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1137 put_be32(pb, 0x14 ); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1138 put_tag(pb, "ftyp");
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1139
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
1140 if ( mov->mode == MODE_3GP )
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1141 put_tag(pb, "3gp4");
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1142 else
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1143 put_tag(pb, "isom");
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1144
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1145 put_be32(pb, 0x200 );
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1146
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
1147 if ( mov->mode == MODE_3GP )
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1148 put_tag(pb, "3gp4");
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1149 else
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1150 put_tag(pb, "mp41");
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1151
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1152 return 0x14;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1153 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1154
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1155 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
1156 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1157 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
1158 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
1159 int i;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1160
494
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
1161 for(i=0; i<s->nb_streams; i++){
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
1162 AVCodecContext *c= &s->streams[i]->codec;
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
1163
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
1164 if (c->codec_type == CODEC_TYPE_VIDEO){
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
1165 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
1166 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
1167 return -1;
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
1168 else
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
1169 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
1170 }
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
1171 }else if(c->codec_type == CODEC_TYPE_AUDIO){
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
1172 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
1173 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
1174 return -1;
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
1175 else
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
1176 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
1177 }
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
1178 }
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
1179 }
abc8a657a8dd warn user if ms style codec tag is used
michael
parents: 468
diff changeset
1180
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
1181 /* 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
1182 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
1183
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
1184 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
1185 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
1186 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
1187
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
1188 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
1189 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
1190 }
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
1191
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
1192 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
1193 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
1194 }
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
1195
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1196 put_flush_packet(pb);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1197
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1198 return 0;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1199 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1200
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 441
diff changeset
1201 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
1202 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1203 MOVContext *mov = s->priv_data;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1204 ByteIOContext *pb = &s->pb;
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 441
diff changeset
1205 AVCodecContext *enc = &s->streams[pkt->stream_index]->codec;
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 441
diff changeset
1206 MOVTrack* trk = &mov->tracks[pkt->stream_index];
202
d755254e8797 naughty, forbidden variable declarations
tmmm
parents: 201
diff changeset
1207 int cl, id;
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1208 unsigned int samplesInChunk = 0;
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 441
diff changeset
1209 int size= pkt->size;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1210
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1211 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
1212 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
1213
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1214 if (enc->codec_type == CODEC_TYPE_VIDEO ) {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1215 samplesInChunk = 1;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1216 }
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1217 else if (enc->codec_type == CODEC_TYPE_AUDIO ) {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1218 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
1219 /* 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
1220 static uint16_t packed_size[16] =
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1221 {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
1222 int len = 0;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1223
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1224 while (len < size && samplesInChunk < 100) {
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 441
diff changeset
1225 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
1226 samplesInChunk++;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1227 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1228 }
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1229 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
1230 samplesInChunk = size/enc->channels;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1231 }
399
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
1232 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
1233 samplesInChunk = size/(2*enc->channels);
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
1234 }
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1235 else {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1236 samplesInChunk = 1;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1237 }
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1238 }
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1239
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1240 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
1241 && trk->vosLen == 0) {
424
dc59cb26955c support for -timestamp
alex
parents: 422
diff changeset
1242 // assert(enc->extradata_size);
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1243
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1244 trk->vosLen = enc->extradata_size;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1245 trk->vosData = av_malloc(trk->vosLen);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1246 memcpy(trk->vosData, enc->extradata, trk->vosLen);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1247 }
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1248
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1249 cl = trk->entry / MOV_INDEX_CLUSTER_SIZE;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1250 id = trk->entry % MOV_INDEX_CLUSTER_SIZE;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1251
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1252 if (trk->ents_allocated <= trk->entry) {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1253 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
1254 if (!trk->cluster)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1255 return -1;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1256 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
1257 if (!trk->cluster[cl])
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1258 return -1;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1259 trk->ents_allocated += MOV_INDEX_CLUSTER_SIZE;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1260 }
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1261 if (mov->mdat_written == 0) {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1262 mov_write_mdat_tag(pb, mov);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1263 mov->mdat_written = 1;
424
dc59cb26955c support for -timestamp
alex
parents: 422
diff changeset
1264 mov->time = s->timestamp;
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1265 }
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1266
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
1267 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
1268 trk->cluster[cl][id].samplesInChunk = samplesInChunk;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1269 trk->cluster[cl][id].size = size;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1270 trk->cluster[cl][id].entries = samplesInChunk;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1271 if(enc->codec_type == CODEC_TYPE_VIDEO) {
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 441
diff changeset
1272 trk->cluster[cl][id].key_frame = !!(pkt->flags & PKT_FLAG_KEY);
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 441
diff changeset
1273 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
1274 trk->hasKeyframes = 1;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1275 }
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1276 trk->enc = enc;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1277 trk->entry++;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1278 trk->sampleCount += samplesInChunk;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1279 trk->mdat_size += size;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1280
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 441
diff changeset
1281 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
1282
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1283 put_flush_packet(pb);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1284 return 0;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1285 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1286
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1287 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
1288 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1289 MOVContext *mov = s->priv_data;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1290 ByteIOContext *pb = &s->pb;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1291 int res = 0;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1292 int i, j;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1293
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
1294 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
1295
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1296 /* 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
1297 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
1298 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
1299 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
1300 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1301 }
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
1302 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
1303 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
1304 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
1305
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
1306 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
1307
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1308 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
1309 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
1310 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
1311 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1312 av_free(mov->tracks[i].cluster);
342
0c1b489c96bf memleak patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 299
diff changeset
1313 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
1314
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1315 mov->tracks[i].cluster = NULL;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1316 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
1317 }
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
1318
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1319 put_flush_packet(pb);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1320
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1321 return res;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1322 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1323
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1324 static AVOutputFormat mov_oformat = {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1325 "mov",
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1326 "mov format",
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1327 NULL,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1328 "mov",
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1329 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
1330 CODEC_ID_AAC,
239
48c3134e93c3 theres no SVQ1 encoder -> it cant be default
michaelni
parents: 238
diff changeset
1331 CODEC_ID_MPEG4,
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1332 mov_write_header,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1333 mov_write_packet,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1334 mov_write_trailer,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1335 };
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1336
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1337 static AVOutputFormat _3gp_oformat = {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1338 "3gp",
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1339 "3gp format",
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1340 NULL,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1341 "3gp",
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1342 sizeof(MOVContext),
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1343 CODEC_ID_AMR_NB,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1344 CODEC_ID_H263,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1345 mov_write_header,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1346 mov_write_packet,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1347 mov_write_trailer,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1348 };
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1349
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1350 static AVOutputFormat mp4_oformat = {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1351 "mp4",
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1352 "mp4 format",
286
eccf0c3e3289 Using the extension m4a for audio only MPEG-4 files is increasingly
michael
parents: 259
diff changeset
1353 "application/mp4",
eccf0c3e3289 Using the extension m4a for audio only MPEG-4 files is increasingly
michael
parents: 259
diff changeset
1354 "mp4,m4a",
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1355 sizeof(MOVContext),
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1356 CODEC_ID_AAC,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1357 CODEC_ID_MPEG4,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1358 mov_write_header,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1359 mov_write_packet,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1360 mov_write_trailer,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1361 };
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1362
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1363 int movenc_init(void)
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1364 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1365 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
1366 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
1367 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
1368 return 0;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1369 }