annotate movenc.c @ 238:3519903c6c2a libavformat

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