annotate movenc.c @ 6262:7b8b71ff9a76 libavformat

Move SPACE_CHARS back to libavformat/internal.h It will be used by other parts of lavf now. This reverts svn rev 23846.
author mstorsjo
date Fri, 16 Jul 2010 14:12:52 +0000
parents 40f3dc7e5fcb
children f2ad554b2464
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 /*
1415
3b00fb8ef8e4 replace coder/decoder file description in libavformat by muxer/demuxer
aurel
parents: 1358
diff changeset
2 * MOV, 3GP, MP4 muxer
4251
77e0c7511d41 cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents: 4225
diff changeset
3 * Copyright (c) 2003 Thomas Raivio
77e0c7511d41 cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents: 4225
diff changeset
4 * Copyright (c) 2004 Gildas Bazin <gbazin at videolan dot org>
4722
639c428c8b23 typo in the mail, the 4am commit is always the worst
bcoudurier
parents: 4721
diff changeset
5 * Copyright (c) 2009 Baptiste Coudurier <baptiste dot coudurier at gmail dot com>
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
6 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1292
diff changeset
7 * This file is part of FFmpeg.
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1292
diff changeset
8 *
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1292
diff changeset
9 * FFmpeg is free software; you can redistribute it and/or
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
10 * 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
11 * License as published by the Free Software Foundation; either
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1292
diff changeset
12 * version 2.1 of the License, or (at your option) any later version.
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
13 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1292
diff changeset
14 * FFmpeg is distributed in the hope that it will be useful,
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
15 * 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
16 * 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
17 * 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
18 *
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
19 * You should have received a copy of the GNU Lesser General Public
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1292
diff changeset
20 * License along with FFmpeg; if not, write to the Free Software
896
edbe5c3717f9 Update licensing information: The FSF changed postal address.
diego
parents: 890
diff changeset
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
22 */
4721
69e6e5008eb8 cosmetics
bcoudurier
parents: 4720
diff changeset
23
6011
97fdefab56cd Move the mov muxer structures to a separate header
mstorsjo
parents: 5993
diff changeset
24 #include "movenc.h"
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
25 #include "avformat.h"
1172
6a5e58d2114b move common stuff from avienc.c and wav.c to new file riff.c
mru
parents: 1169
diff changeset
26 #include "riff.h"
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
27 #include "avio.h"
1216
fec0a3d5408f move common code from mov.c and movenc.c to isom.c
bcoudurier
parents: 1172
diff changeset
28 #include "isom.h"
2922
dcd599833abc Move isom_write_avcc() and related functions into a separate file.
aurel
parents: 2921
diff changeset
29 #include "avc.h"
4872
304a0ea063f0 Rename bitstream.h to get_bits.h.
stefano
parents: 4864
diff changeset
30 #include "libavcodec/get_bits.h"
4864
7aa7c5853bb6 Split bitstream.h, put the bitstream writer stuff in the new file
stefano
parents: 4832
diff changeset
31 #include "libavcodec/put_bits.h"
6013
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
32 #include "internal.h"
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
33 #include "libavutil/avstring.h"
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
34
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
35 #undef NDEBUG
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
36 #include <assert.h>
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
37
2165
eac986610f47 misc typo fixes
diego
parents: 2164
diff changeset
38 //FIXME support 64 bit variant with wide placeholders
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3909
diff changeset
39 static int64_t updateSize(ByteIOContext *pb, int64_t pos)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
40 {
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3909
diff changeset
41 int64_t curpos = url_ftell(pb);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
42 url_fseek(pb, pos, SEEK_SET);
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
43 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
44 url_fseek(pb, curpos, SEEK_SET);
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
45
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
46 return curpos - pos;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
47 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
48
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
49 /* Chunk offset atom */
3446
7d73c4a64714 cosmetics
bcoudurier
parents: 3424
diff changeset
50 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
51 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
52 int i;
910
d92e6d673ef5 gcc 2.95 fix
banan
parents: 909
diff changeset
53 int mode64 = 0; // use 32 bit size variant if possible
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3909
diff changeset
54 int64_t pos = url_ftell(pb);
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
55 put_be32(pb, 0); /* size */
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
56 if (pos > UINT32_MAX) {
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
57 mode64 = 1;
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
58 put_tag(pb, "co64");
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
59 } else
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
60 put_tag(pb, "stco");
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
61 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
62 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
63 for (i=0; i<track->entry; i++) {
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
64 if(mode64 == 1)
1129
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
65 put_be64(pb, track->cluster[i].pos);
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
66 else
1129
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
67 put_be32(pb, track->cluster[i].pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
68 }
3455
aefb1cbf9479 cosmetics
bcoudurier
parents: 3454
diff changeset
69 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
70 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
71
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
72 /* Sample size atom */
3446
7d73c4a64714 cosmetics
bcoudurier
parents: 3424
diff changeset
73 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
74 {
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
75 int equalChunks = 1;
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
76 int i, j, entries = 0, tst = -1, oldtst = -1;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
77
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3909
diff changeset
78 int64_t pos = url_ftell(pb);
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
79 put_be32(pb, 0); /* size */
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
80 put_tag(pb, "stsz");
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
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
83 for (i=0; i<track->entry; i++) {
1129
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
84 tst = track->cluster[i].size/track->cluster[i].entries;
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
85 if(oldtst != -1 && tst != oldtst) {
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
86 equalChunks = 0;
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
87 }
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
88 oldtst = tst;
1129
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
89 entries += track->cluster[i].entries;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
90 }
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
91 if (equalChunks) {
1129
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
92 int sSize = track->cluster[0].size/track->cluster[0].entries;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
93 put_be32(pb, sSize); // sample size
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
94 put_be32(pb, entries); // sample count
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
95 }
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
96 else {
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
97 put_be32(pb, 0); // sample size
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
98 put_be32(pb, entries); // sample count
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
99 for (i=0; i<track->entry; i++) {
3024
19de43025f0f cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents: 3010
diff changeset
100 for (j=0; j<track->cluster[i].entries; j++) {
1129
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
101 put_be32(pb, track->cluster[i].size /
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
102 track->cluster[i].entries);
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
103 }
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
104 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
105 }
3455
aefb1cbf9479 cosmetics
bcoudurier
parents: 3454
diff changeset
106 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
107 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
108
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
109 /* Sample to chunk atom */
3446
7d73c4a64714 cosmetics
bcoudurier
parents: 3424
diff changeset
110 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
111 {
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
112 int index = 0, oldval = -1, i;
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3909
diff changeset
113 int64_t entryPos, curpos;
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
114
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3909
diff changeset
115 int64_t pos = url_ftell(pb);
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
116 put_be32(pb, 0); /* size */
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
117 put_tag(pb, "stsc");
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
118 put_be32(pb, 0); // version & flags
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
119 entryPos = url_ftell(pb);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
120 put_be32(pb, track->entry); // entry count
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
121 for (i=0; i<track->entry; i++) {
1129
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
122 if(oldval != track->cluster[i].samplesInChunk)
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
123 {
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
124 put_be32(pb, i+1); // first chunk
1129
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
125 put_be32(pb, track->cluster[i].samplesInChunk); // samples per chunk
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
126 put_be32(pb, 0x1); // sample description index
1129
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
127 oldval = track->cluster[i].samplesInChunk;
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
128 index++;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
129 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
130 }
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
131 curpos = url_ftell(pb);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
132 url_fseek(pb, entryPos, SEEK_SET);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
133 put_be32(pb, index); // rewrite size
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
134 url_fseek(pb, curpos, SEEK_SET);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
135
3455
aefb1cbf9479 cosmetics
bcoudurier
parents: 3454
diff changeset
136 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
137 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
138
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
139 /* Sync sample atom */
4941
45a08facad6f write 'stps' for mpeg-2 open gop in .mov
bcoudurier
parents: 4937
diff changeset
140 static int mov_write_stss_tag(ByteIOContext *pb, MOVTrack *track, uint32_t flag)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
141 {
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3909
diff changeset
142 int64_t curpos, entryPos;
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
143 int i, index = 0;
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3909
diff changeset
144 int64_t pos = url_ftell(pb);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
145 put_be32(pb, 0); // size
4941
45a08facad6f write 'stps' for mpeg-2 open gop in .mov
bcoudurier
parents: 4937
diff changeset
146 put_tag(pb, flag == MOV_SYNC_SAMPLE ? "stss" : "stps");
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
147 put_be32(pb, 0); // version & flags
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
148 entryPos = url_ftell(pb);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
149 put_be32(pb, track->entry); // entry count
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
150 for (i=0; i<track->entry; i++) {
4941
45a08facad6f write 'stps' for mpeg-2 open gop in .mov
bcoudurier
parents: 4937
diff changeset
151 if (track->cluster[i].flags & flag) {
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
152 put_be32(pb, i+1);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
153 index++;
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
154 }
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
155 }
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
156 curpos = url_ftell(pb);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
157 url_fseek(pb, entryPos, SEEK_SET);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
158 put_be32(pb, index); // rewrite size
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
159 url_fseek(pb, curpos, SEEK_SET);
3455
aefb1cbf9479 cosmetics
bcoudurier
parents: 3454
diff changeset
160 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
161 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
162
1152
c7cf3d1f9bd7 simplify and write correct values conforming to specs
bcoudurier
parents: 1151
diff changeset
163 static int mov_write_amr_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
164 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
165 put_be32(pb, 0x11); /* size */
1152
c7cf3d1f9bd7 simplify and write correct values conforming to specs
bcoudurier
parents: 1151
diff changeset
166 if (track->mode == MODE_MOV) put_tag(pb, "samr");
c7cf3d1f9bd7 simplify and write correct values conforming to specs
bcoudurier
parents: 1151
diff changeset
167 else put_tag(pb, "damr");
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
168 put_tag(pb, "FFMP");
1152
c7cf3d1f9bd7 simplify and write correct values conforming to specs
bcoudurier
parents: 1151
diff changeset
169 put_byte(pb, 0); /* decoder version */
1083
96283b259b1a fix AMR muxing in mov
bcoudurier
parents: 1082
diff changeset
170
1153
6cb1c11cc363 10l, all modes is 0x81FF
bcoudurier
parents: 1152
diff changeset
171 put_be16(pb, 0x81FF); /* Mode set (all modes for AMR_NB) */
1152
c7cf3d1f9bd7 simplify and write correct values conforming to specs
bcoudurier
parents: 1151
diff changeset
172 put_byte(pb, 0x00); /* Mode change period (no restriction) */
c7cf3d1f9bd7 simplify and write correct values conforming to specs
bcoudurier
parents: 1151
diff changeset
173 put_byte(pb, 0x01); /* Frames per sample */
1083
96283b259b1a fix AMR muxing in mov
bcoudurier
parents: 1082
diff changeset
174 return 0x11;
96283b259b1a fix AMR muxing in mov
bcoudurier
parents: 1082
diff changeset
175 }
96283b259b1a fix AMR muxing in mov
bcoudurier
parents: 1082
diff changeset
176
3881
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
177 static int mov_write_ac3_tag(ByteIOContext *pb, MOVTrack *track)
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
178 {
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
179 GetBitContext gbc;
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
180 PutBitContext pbc;
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
181 uint8_t buf[3];
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
182 int fscod, bsid, bsmod, acmod, lfeon, frmsizecod;
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
183
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
184 if (track->vosLen < 7)
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
185 return -1;
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
186
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
187 put_be32(pb, 11);
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
188 put_tag(pb, "dac3");
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
189
3888
0244f7383b70 skip 2 bytes more when parsing ac3 frame, syncword 16bits + crc 16bits,
bcoudurier
parents: 3887
diff changeset
190 init_get_bits(&gbc, track->vosData+4, track->vosLen-4);
3881
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
191 fscod = get_bits(&gbc, 2);
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
192 frmsizecod = get_bits(&gbc, 6);
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
193 bsid = get_bits(&gbc, 5);
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
194 bsmod = get_bits(&gbc, 3);
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
195 acmod = get_bits(&gbc, 3);
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
196 if (acmod == 2) {
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
197 skip_bits(&gbc, 2); // dsurmod
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
198 } else {
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
199 if ((acmod & 1) && acmod != 1)
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
200 skip_bits(&gbc, 2); // cmixlev
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
201 if (acmod & 4)
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
202 skip_bits(&gbc, 2); // surmixlev
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
203 }
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
204 lfeon = get_bits1(&gbc);
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
205
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
206 init_put_bits(&pbc, buf, sizeof(buf));
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
207 put_bits(&pbc, 2, fscod);
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
208 put_bits(&pbc, 5, bsid);
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
209 put_bits(&pbc, 3, bsmod);
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
210 put_bits(&pbc, 3, acmod);
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
211 put_bits(&pbc, 1, lfeon);
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
212 put_bits(&pbc, 5, frmsizecod>>1); // bit_rate_code
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
213 put_bits(&pbc, 5, 0); // reserved
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
214
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
215 flush_put_bits(&pbc);
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
216 put_buffer(pb, buf, sizeof(buf));
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
217
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
218 return 11;
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
219 }
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
220
3243
355683c241dd support for alac in .mov
bcoudurier
parents: 3203
diff changeset
221 /**
355683c241dd support for alac in .mov
bcoudurier
parents: 3203
diff changeset
222 * This function writes extradata "as is".
355683c241dd support for alac in .mov
bcoudurier
parents: 3203
diff changeset
223 * Extradata must be formated like a valid atom (with size and tag)
355683c241dd support for alac in .mov
bcoudurier
parents: 3203
diff changeset
224 */
355683c241dd support for alac in .mov
bcoudurier
parents: 3203
diff changeset
225 static int mov_write_extradata_tag(ByteIOContext *pb, MOVTrack *track)
355683c241dd support for alac in .mov
bcoudurier
parents: 3203
diff changeset
226 {
355683c241dd support for alac in .mov
bcoudurier
parents: 3203
diff changeset
227 put_buffer(pb, track->enc->extradata, track->enc->extradata_size);
355683c241dd support for alac in .mov
bcoudurier
parents: 3203
diff changeset
228 return track->enc->extradata_size;
355683c241dd support for alac in .mov
bcoudurier
parents: 3203
diff changeset
229 }
355683c241dd support for alac in .mov
bcoudurier
parents: 3203
diff changeset
230
1082
4239bc0dc05e add pcm 24/32 le/be support
bcoudurier
parents: 1081
diff changeset
231 static int mov_write_enda_tag(ByteIOContext *pb)
4239bc0dc05e add pcm 24/32 le/be support
bcoudurier
parents: 1081
diff changeset
232 {
4239bc0dc05e add pcm 24/32 le/be support
bcoudurier
parents: 1081
diff changeset
233 put_be32(pb, 10);
4239bc0dc05e add pcm 24/32 le/be support
bcoudurier
parents: 1081
diff changeset
234 put_tag(pb, "enda");
4239bc0dc05e add pcm 24/32 le/be support
bcoudurier
parents: 1081
diff changeset
235 put_be16(pb, 1); /* little endian */
4239bc0dc05e add pcm 24/32 le/be support
bcoudurier
parents: 1081
diff changeset
236 return 10;
4239bc0dc05e add pcm 24/32 le/be support
bcoudurier
parents: 1081
diff changeset
237 }
4239bc0dc05e add pcm 24/32 le/be support
bcoudurier
parents: 1081
diff changeset
238
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
239 static unsigned int descrLength(unsigned int len)
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
240 {
1081
ee5aac70a7dc simplify
michael
parents: 1080
diff changeset
241 int i;
ee5aac70a7dc simplify
michael
parents: 1080
diff changeset
242 for(i=1; len>>(7*i); i++);
ee5aac70a7dc simplify
michael
parents: 1080
diff changeset
243 return len + 1 + i;
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
244 }
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
245
1081
ee5aac70a7dc simplify
michael
parents: 1080
diff changeset
246 static void putDescr(ByteIOContext *pb, int tag, unsigned int size)
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
247 {
1081
ee5aac70a7dc simplify
michael
parents: 1080
diff changeset
248 int i= descrLength(size) - size - 2;
ee5aac70a7dc simplify
michael
parents: 1080
diff changeset
249 put_byte(pb, tag);
ee5aac70a7dc simplify
michael
parents: 1080
diff changeset
250 for(; i>0; i--)
ee5aac70a7dc simplify
michael
parents: 1080
diff changeset
251 put_byte(pb, (size>>(7*i)) | 0x80);
ee5aac70a7dc simplify
michael
parents: 1080
diff changeset
252 put_byte(pb, size & 0x7F);
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
253 }
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
254
3446
7d73c4a64714 cosmetics
bcoudurier
parents: 3424
diff changeset
255 static int mov_write_esds_tag(ByteIOContext *pb, MOVTrack *track) // Basic
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
256 {
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3909
diff changeset
257 int64_t pos = url_ftell(pb);
1082
4239bc0dc05e add pcm 24/32 le/be support
bcoudurier
parents: 1081
diff changeset
258 int decoderSpecificInfoLen = track->vosLen ? descrLength(track->vosLen):0;
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
259
3246
a6a78c1cbf33 cosmetics: remove useless whitespaces and put braces correctly
bcoudurier
parents: 3243
diff changeset
260 put_be32(pb, 0); // size
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
261 put_tag(pb, "esds");
3246
a6a78c1cbf33 cosmetics: remove useless whitespaces and put braces correctly
bcoudurier
parents: 3243
diff changeset
262 put_be32(pb, 0); // Version
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
263
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
264 // ES descriptor
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
265 putDescr(pb, 0x03, 3 + descrLength(13 + decoderSpecificInfoLen) +
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
266 descrLength(1));
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
267 put_be16(pb, track->trackID);
3246
a6a78c1cbf33 cosmetics: remove useless whitespaces and put braces correctly
bcoudurier
parents: 3243
diff changeset
268 put_byte(pb, 0x00); // flags (= no flags)
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
269
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
270 // DecoderConfig descriptor
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
271 putDescr(pb, 0x04, 13 + decoderSpecificInfoLen);
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
272
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
273 // Object type indication
3869
9288b207a184 correctly mux mpeg2 audio 13818-3 in mp4
bcoudurier
parents: 3858
diff changeset
274 if ((track->enc->codec_id == CODEC_ID_MP2 ||
9288b207a184 correctly mux mpeg2 audio 13818-3 in mp4
bcoudurier
parents: 3858
diff changeset
275 track->enc->codec_id == CODEC_ID_MP3) &&
3887
c8ab0676bba6 change the logic to mux 13818-3 and 11172-3 in mp4, less code
bcoudurier
parents: 3886
diff changeset
276 track->enc->sample_rate > 24000)
c8ab0676bba6 change the logic to mux 13818-3 and 11172-3 in mp4, less code
bcoudurier
parents: 3886
diff changeset
277 put_byte(pb, 0x6B); // 11172-3
3869
9288b207a184 correctly mux mpeg2 audio 13818-3 in mp4
bcoudurier
parents: 3858
diff changeset
278 else
5058
33a244b7ca65 Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents: 4996
diff changeset
279 put_byte(pb, ff_codec_get_tag(ff_mp4_obj_type, track->enc->codec_id));
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
280
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
281 // the following fields is made of 6 bits to identify the streamtype (4 for video, 5 for audio)
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
282 // plus 1 bit to indicate upstream and 1 bit set to 1 (reserved)
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5792
diff changeset
283 if(track->enc->codec_type == AVMEDIA_TYPE_AUDIO)
3246
a6a78c1cbf33 cosmetics: remove useless whitespaces and put braces correctly
bcoudurier
parents: 3243
diff changeset
284 put_byte(pb, 0x15); // flags (= Audiostream)
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
285 else
3246
a6a78c1cbf33 cosmetics: remove useless whitespaces and put braces correctly
bcoudurier
parents: 3243
diff changeset
286 put_byte(pb, 0x11); // flags (= Visualstream)
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
287
3246
a6a78c1cbf33 cosmetics: remove useless whitespaces and put braces correctly
bcoudurier
parents: 3243
diff changeset
288 put_byte(pb, track->enc->rc_buffer_size>>(3+16)); // Buffersize DB (24 bits)
a6a78c1cbf33 cosmetics: remove useless whitespaces and put braces correctly
bcoudurier
parents: 3243
diff changeset
289 put_be16(pb, (track->enc->rc_buffer_size>>3)&0xFFFF); // Buffersize DB
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
290
3246
a6a78c1cbf33 cosmetics: remove useless whitespaces and put braces correctly
bcoudurier
parents: 3243
diff changeset
291 put_be32(pb, FFMAX(track->enc->bit_rate, track->enc->rc_max_rate)); // maxbitrate (FIXME should be max rate in any 1 sec window)
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
292 if(track->enc->rc_max_rate != track->enc->rc_min_rate || track->enc->rc_min_rate==0)
3246
a6a78c1cbf33 cosmetics: remove useless whitespaces and put braces correctly
bcoudurier
parents: 3243
diff changeset
293 put_be32(pb, 0); // vbr
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
294 else
3246
a6a78c1cbf33 cosmetics: remove useless whitespaces and put braces correctly
bcoudurier
parents: 3243
diff changeset
295 put_be32(pb, track->enc->rc_max_rate); // avg bitrate
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
296
3246
a6a78c1cbf33 cosmetics: remove useless whitespaces and put braces correctly
bcoudurier
parents: 3243
diff changeset
297 if (track->vosLen) {
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
298 // DecoderSpecific info descriptor
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
299 putDescr(pb, 0x05, track->vosLen);
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
300 put_buffer(pb, track->vosData, track->vosLen);
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
301 }
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
302
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
303 // SL descriptor
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
304 putDescr(pb, 0x06, 1);
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
305 put_byte(pb, 0x02);
3455
aefb1cbf9479 cosmetics
bcoudurier
parents: 3454
diff changeset
306 return updateSize(pb, pos);
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
307 }
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
308
5390
9bf0eaa769dc support pcm_f32/64le in mov
bcoudurier
parents: 5389
diff changeset
309 static int mov_pcm_le_gt16(enum CodecID codec_id)
9bf0eaa769dc support pcm_f32/64le in mov
bcoudurier
parents: 5389
diff changeset
310 {
9bf0eaa769dc support pcm_f32/64le in mov
bcoudurier
parents: 5389
diff changeset
311 return codec_id == CODEC_ID_PCM_S24LE ||
9bf0eaa769dc support pcm_f32/64le in mov
bcoudurier
parents: 5389
diff changeset
312 codec_id == CODEC_ID_PCM_S32LE ||
9bf0eaa769dc support pcm_f32/64le in mov
bcoudurier
parents: 5389
diff changeset
313 codec_id == CODEC_ID_PCM_F32LE ||
9bf0eaa769dc support pcm_f32/64le in mov
bcoudurier
parents: 5389
diff changeset
314 codec_id == CODEC_ID_PCM_F64LE;
9bf0eaa769dc support pcm_f32/64le in mov
bcoudurier
parents: 5389
diff changeset
315 }
9bf0eaa769dc support pcm_f32/64le in mov
bcoudurier
parents: 5389
diff changeset
316
3446
7d73c4a64714 cosmetics
bcoudurier
parents: 3424
diff changeset
317 static int mov_write_wave_tag(ByteIOContext *pb, MOVTrack *track)
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
318 {
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3909
diff changeset
319 int64_t pos = url_ftell(pb);
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
320
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
321 put_be32(pb, 0); /* size */
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
322 put_tag(pb, "wave");
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
323
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
324 put_be32(pb, 12); /* size */
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
325 put_tag(pb, "frma");
1082
4239bc0dc05e add pcm 24/32 le/be support
bcoudurier
parents: 1081
diff changeset
326 put_le32(pb, track->tag);
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
327
1082
4239bc0dc05e add pcm 24/32 le/be support
bcoudurier
parents: 1081
diff changeset
328 if (track->enc->codec_id == CODEC_ID_AAC) {
1125
6380964c7623 fix aac in mov for ipod
bcoudurier
parents: 1124
diff changeset
329 /* useless atom needed by mplayer, ipod, not needed by quicktime */
6380964c7623 fix aac in mov for ipod
bcoudurier
parents: 1124
diff changeset
330 put_be32(pb, 12); /* size */
6380964c7623 fix aac in mov for ipod
bcoudurier
parents: 1124
diff changeset
331 put_tag(pb, "mp4a");
6380964c7623 fix aac in mov for ipod
bcoudurier
parents: 1124
diff changeset
332 put_be32(pb, 0);
1082
4239bc0dc05e add pcm 24/32 le/be support
bcoudurier
parents: 1081
diff changeset
333 mov_write_esds_tag(pb, track);
5390
9bf0eaa769dc support pcm_f32/64le in mov
bcoudurier
parents: 5389
diff changeset
334 } else if (mov_pcm_le_gt16(track->enc->codec_id)) {
1082
4239bc0dc05e add pcm 24/32 le/be support
bcoudurier
parents: 1081
diff changeset
335 mov_write_enda_tag(pb);
1083
96283b259b1a fix AMR muxing in mov
bcoudurier
parents: 1082
diff changeset
336 } else if (track->enc->codec_id == CODEC_ID_AMR_NB) {
1152
c7cf3d1f9bd7 simplify and write correct values conforming to specs
bcoudurier
parents: 1151
diff changeset
337 mov_write_amr_tag(pb, track);
3881
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
338 } else if (track->enc->codec_id == CODEC_ID_AC3) {
ab65a52ca544 ac3 muxing support in mov/mp4/m4v
bcoudurier
parents: 3869
diff changeset
339 mov_write_ac3_tag(pb, track);
3243
355683c241dd support for alac in .mov
bcoudurier
parents: 3203
diff changeset
340 } else if (track->enc->codec_id == CODEC_ID_ALAC) {
355683c241dd support for alac in .mov
bcoudurier
parents: 3203
diff changeset
341 mov_write_extradata_tag(pb, track);
1082
4239bc0dc05e add pcm 24/32 le/be support
bcoudurier
parents: 1081
diff changeset
342 }
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
343
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
344 put_be32(pb, 8); /* size */
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
345 put_be32(pb, 0); /* null tag */
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
346
3455
aefb1cbf9479 cosmetics
bcoudurier
parents: 3454
diff changeset
347 return updateSize(pb, pos);
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
348 }
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
349
3446
7d73c4a64714 cosmetics
bcoudurier
parents: 3424
diff changeset
350 static int mov_write_glbl_tag(ByteIOContext *pb, MOVTrack *track)
2838
6bea49ef18b1 use generic 'glbl' atom if extradata is present but no specific method is known
bcoudurier
parents: 2802
diff changeset
351 {
6bea49ef18b1 use generic 'glbl' atom if extradata is present but no specific method is known
bcoudurier
parents: 2802
diff changeset
352 put_be32(pb, track->vosLen+8);
6bea49ef18b1 use generic 'glbl' atom if extradata is present but no specific method is known
bcoudurier
parents: 2802
diff changeset
353 put_tag(pb, "glbl");
6bea49ef18b1 use generic 'glbl' atom if extradata is present but no specific method is known
bcoudurier
parents: 2802
diff changeset
354 put_buffer(pb, track->vosData, track->vosLen);
6bea49ef18b1 use generic 'glbl' atom if extradata is present but no specific method is known
bcoudurier
parents: 2802
diff changeset
355 return 8+track->vosLen;
6bea49ef18b1 use generic 'glbl' atom if extradata is present but no specific method is known
bcoudurier
parents: 2802
diff changeset
356 }
6bea49ef18b1 use generic 'glbl' atom if extradata is present but no specific method is known
bcoudurier
parents: 2802
diff changeset
357
5388
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
358 /**
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
359 * Compute flags for 'lpcm' tag.
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
360 * See CoreAudioTypes and AudioStreamBasicDescription at Apple.
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
361 */
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
362 static int mov_get_lpcm_flags(enum CodecID codec_id)
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
363 {
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
364 switch (codec_id) {
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
365 case CODEC_ID_PCM_F32BE:
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
366 case CODEC_ID_PCM_F64BE:
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
367 return 11;
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
368 case CODEC_ID_PCM_F32LE:
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
369 case CODEC_ID_PCM_F64LE:
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
370 return 9;
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
371 case CODEC_ID_PCM_U8:
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
372 return 10;
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
373 case CODEC_ID_PCM_S16BE:
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
374 case CODEC_ID_PCM_S24BE:
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
375 case CODEC_ID_PCM_S32BE:
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
376 return 14;
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
377 case CODEC_ID_PCM_S8:
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
378 case CODEC_ID_PCM_S16LE:
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
379 case CODEC_ID_PCM_S24LE:
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
380 case CODEC_ID_PCM_S32LE:
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
381 return 12;
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
382 default:
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
383 return 0;
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
384 }
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
385 }
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
386
3446
7d73c4a64714 cosmetics
bcoudurier
parents: 3424
diff changeset
387 static int mov_write_audio_tag(ByteIOContext *pb, MOVTrack *track)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
388 {
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3909
diff changeset
389 int64_t pos = url_ftell(pb);
5388
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
390 int version = 0;
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
391 uint32_t tag = track->tag;
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
392
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
393 if (track->mode == MODE_MOV) {
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
394 if (track->timescale > UINT16_MAX) {
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
395 if (mov_get_lpcm_flags(track->enc->codec_id))
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
396 tag = AV_RL32("lpcm");
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
397 version = 2;
5390
9bf0eaa769dc support pcm_f32/64le in mov
bcoudurier
parents: 5389
diff changeset
398 } else if (track->audio_vbr || mov_pcm_le_gt16(track->enc->codec_id)) {
5388
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
399 version = 1;
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
400 }
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
401 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
402
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
403 put_be32(pb, 0); /* size */
5388
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
404 put_le32(pb, tag); // store it byteswapped
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
405 put_be32(pb, 0); /* Reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
406 put_be16(pb, 0); /* Reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
407 put_be16(pb, 1); /* Data-reference index, XXX == 1 */
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
408
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
409 /* SoundDescription */
1082
4239bc0dc05e add pcm 24/32 le/be support
bcoudurier
parents: 1081
diff changeset
410 put_be16(pb, version); /* Version */
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
411 put_be16(pb, 0); /* Revision level */
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
412 put_be32(pb, 0); /* Reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
413
5388
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
414 if (version == 2) {
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
415 put_be16(pb, 3);
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
416 put_be16(pb, 16);
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
417 put_be16(pb, 0xfffe);
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
418 put_be16(pb, 0);
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
419 put_be32(pb, 0x00010000);
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
420 put_be32(pb, 72);
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
421 put_be64(pb, av_dbl2int(track->timescale));
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
422 put_be32(pb, track->enc->channels);
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
423 put_be32(pb, 0x7F000000);
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
424 put_be32(pb, av_get_bits_per_sample(track->enc->codec_id));
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
425 put_be32(pb, mov_get_lpcm_flags(track->enc->codec_id));
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
426 put_be32(pb, track->sampleSize);
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
427 put_be32(pb, track->enc->frame_size);
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
428 } else {
5389
f5959bd99afd cosmetics, reindent after last commit
bcoudurier
parents: 5388
diff changeset
429 if (track->mode == MODE_MOV) {
f5959bd99afd cosmetics, reindent after last commit
bcoudurier
parents: 5388
diff changeset
430 put_be16(pb, track->enc->channels);
f5959bd99afd cosmetics, reindent after last commit
bcoudurier
parents: 5388
diff changeset
431 if (track->enc->codec_id == CODEC_ID_PCM_U8 ||
f5959bd99afd cosmetics, reindent after last commit
bcoudurier
parents: 5388
diff changeset
432 track->enc->codec_id == CODEC_ID_PCM_S8)
f5959bd99afd cosmetics, reindent after last commit
bcoudurier
parents: 5388
diff changeset
433 put_be16(pb, 8); /* bits per sample */
f5959bd99afd cosmetics, reindent after last commit
bcoudurier
parents: 5388
diff changeset
434 else
f5959bd99afd cosmetics, reindent after last commit
bcoudurier
parents: 5388
diff changeset
435 put_be16(pb, 16);
f5959bd99afd cosmetics, reindent after last commit
bcoudurier
parents: 5388
diff changeset
436 put_be16(pb, track->audio_vbr ? -2 : 0); /* compression ID */
f5959bd99afd cosmetics, reindent after last commit
bcoudurier
parents: 5388
diff changeset
437 } else { /* reserved for mp4/3gp */
f5959bd99afd cosmetics, reindent after last commit
bcoudurier
parents: 5388
diff changeset
438 put_be16(pb, 2);
1850
4d4e0ab8c667 fix pcm u/s8 muxing
bcoudurier
parents: 1849
diff changeset
439 put_be16(pb, 16);
5389
f5959bd99afd cosmetics, reindent after last commit
bcoudurier
parents: 5388
diff changeset
440 put_be16(pb, 0);
f5959bd99afd cosmetics, reindent after last commit
bcoudurier
parents: 5388
diff changeset
441 }
505
e996e7da971c AAC in mov/mp4 patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 494
diff changeset
442
5389
f5959bd99afd cosmetics, reindent after last commit
bcoudurier
parents: 5388
diff changeset
443 put_be16(pb, 0); /* packet size (= 0) */
f5959bd99afd cosmetics, reindent after last commit
bcoudurier
parents: 5388
diff changeset
444 put_be16(pb, track->timescale); /* Time scale */
f5959bd99afd cosmetics, reindent after last commit
bcoudurier
parents: 5388
diff changeset
445 put_be16(pb, 0); /* Reserved */
5388
5d5c1dc09223 support sample rates > INT16_MAX in mov using stsd v2
bcoudurier
parents: 5382
diff changeset
446 }
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
447
1147
5cac4246a84a write exact values for audio stsd v1
bcoudurier
parents: 1131
diff changeset
448 if(version == 1) { /* SoundDescription V1 extended info */
5cac4246a84a write exact values for audio stsd v1
bcoudurier
parents: 1131
diff changeset
449 put_be32(pb, track->enc->frame_size); /* Samples per packet */
1150
c8edab114cc3 vbr requires version=1 and samplesize=0 per QT spec
michael
parents: 1147
diff changeset
450 put_be32(pb, track->sampleSize / track->enc->channels); /* Bytes per packet */
1147
5cac4246a84a write exact values for audio stsd v1
bcoudurier
parents: 1131
diff changeset
451 put_be32(pb, track->sampleSize); /* Bytes per frame */
1125
6380964c7623 fix aac in mov for ipod
bcoudurier
parents: 1124
diff changeset
452 put_be32(pb, 2); /* Bytes per sample */
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
453 }
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
454
1084
9db2ed540c30 do not write wave if not needed
bcoudurier
parents: 1083
diff changeset
455 if(track->mode == MODE_MOV &&
9db2ed540c30 do not write wave if not needed
bcoudurier
parents: 1083
diff changeset
456 (track->enc->codec_id == CODEC_ID_AAC ||
3889
94ba4a17d03f actually write dac3 atom, patch by Kurtnoise, kurtnoise at free dot fr
bcoudurier
parents: 3888
diff changeset
457 track->enc->codec_id == CODEC_ID_AC3 ||
1084
9db2ed540c30 do not write wave if not needed
bcoudurier
parents: 1083
diff changeset
458 track->enc->codec_id == CODEC_ID_AMR_NB ||
5390
9bf0eaa769dc support pcm_f32/64le in mov
bcoudurier
parents: 5389
diff changeset
459 track->enc->codec_id == CODEC_ID_ALAC ||
9bf0eaa769dc support pcm_f32/64le in mov
bcoudurier
parents: 5389
diff changeset
460 mov_pcm_le_gt16(track->enc->codec_id)))
1083
96283b259b1a fix AMR muxing in mov
bcoudurier
parents: 1082
diff changeset
461 mov_write_wave_tag(pb, track);
2977
b5ad3169a579 write esds atom when mpeg-4 systems tags are used
bcoudurier
parents: 2975
diff changeset
462 else if(track->tag == MKTAG('m','p','4','a'))
1083
96283b259b1a fix AMR muxing in mov
bcoudurier
parents: 1082
diff changeset
463 mov_write_esds_tag(pb, track);
96283b259b1a fix AMR muxing in mov
bcoudurier
parents: 1082
diff changeset
464 else if(track->enc->codec_id == CODEC_ID_AMR_NB)
1152
c7cf3d1f9bd7 simplify and write correct values conforming to specs
bcoudurier
parents: 1151
diff changeset
465 mov_write_amr_tag(pb, track);
3889
94ba4a17d03f actually write dac3 atom, patch by Kurtnoise, kurtnoise at free dot fr
bcoudurier
parents: 3888
diff changeset
466 else if(track->enc->codec_id == CODEC_ID_AC3)
94ba4a17d03f actually write dac3 atom, patch by Kurtnoise, kurtnoise at free dot fr
bcoudurier
parents: 3888
diff changeset
467 mov_write_ac3_tag(pb, track);
3890
76e7b6822fa6 cosmetics, remove whitespace
bcoudurier
parents: 3889
diff changeset
468 else if(track->enc->codec_id == CODEC_ID_ALAC)
3453
3046c8e6ba4f support alac in ipod m4a format, tested on quicktime
bcoudurier
parents: 3452
diff changeset
469 mov_write_extradata_tag(pb, track);
2838
6bea49ef18b1 use generic 'glbl' atom if extradata is present but no specific method is known
bcoudurier
parents: 2802
diff changeset
470 else if(track->vosLen > 0)
6bea49ef18b1 use generic 'glbl' atom if extradata is present but no specific method is known
bcoudurier
parents: 2802
diff changeset
471 mov_write_glbl_tag(pb, track);
1083
96283b259b1a fix AMR muxing in mov
bcoudurier
parents: 1082
diff changeset
472
3455
aefb1cbf9479 cosmetics
bcoudurier
parents: 3454
diff changeset
473 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
474 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
475
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
476 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
477 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
478 put_be32(pb, 0xf); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
479 put_tag(pb, "d263");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
480 put_tag(pb, "FFMP");
1240
504be467b795 detailed infos about d263 atom
bcoudurier
parents: 1239
diff changeset
481 put_byte(pb, 0); /* decoder version */
504be467b795 detailed infos about d263 atom
bcoudurier
parents: 1239
diff changeset
482 /* FIXME use AVCodecContext level/profile, when encoder will set values */
504be467b795 detailed infos about d263 atom
bcoudurier
parents: 1239
diff changeset
483 put_byte(pb, 0xa); /* level */
504be467b795 detailed infos about d263 atom
bcoudurier
parents: 1239
diff changeset
484 put_byte(pb, 0); /* profile */
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
485 return 0xf;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
486 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
487
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
488 /* TODO: No idea about these values */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
489 static int mov_write_svq3_tag(ByteIOContext *pb)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
490 {
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
491 put_be32(pb, 0x15);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
492 put_tag(pb, "SMI ");
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
493 put_tag(pb, "SEQH");
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
494 put_be32(pb, 0x5);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
495 put_be32(pb, 0xe2c0211d);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
496 put_be32(pb, 0xc0000000);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
497 put_byte(pb, 0);
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
498 return 0x15;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
499 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
500
2921
dab2aecebb97 extract isom_write_avcc into a function
aurel
parents: 2920
diff changeset
501 static int mov_write_avcc_tag(ByteIOContext *pb, MOVTrack *track)
dab2aecebb97 extract isom_write_avcc into a function
aurel
parents: 2920
diff changeset
502 {
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3909
diff changeset
503 int64_t pos = url_ftell(pb);
2921
dab2aecebb97 extract isom_write_avcc into a function
aurel
parents: 2920
diff changeset
504
dab2aecebb97 extract isom_write_avcc into a function
aurel
parents: 2920
diff changeset
505 put_be32(pb, 0);
dab2aecebb97 extract isom_write_avcc into a function
aurel
parents: 2920
diff changeset
506 put_tag(pb, "avcC");
2927
b75a49790f31 add a ff_ prefix to newly exported functions from avc.c
aurel
parents: 2922
diff changeset
507 ff_isom_write_avcc(pb, track->vosData, track->vosLen);
1006
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
508 return updateSize(pb, pos);
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
509 }
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
510
2588
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
511 /* also used by all avid codecs (dv, imx, meridien) and their variants */
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
512 static int mov_write_avid_tag(ByteIOContext *pb, MOVTrack *track)
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
513 {
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
514 int i;
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
515 put_be32(pb, 24); /* size */
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
516 put_tag(pb, "ACLR");
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
517 put_tag(pb, "ACLR");
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
518 put_tag(pb, "0001");
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
519 put_be32(pb, 1); /* yuv 1 / rgb 2 ? */
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
520 put_be32(pb, 0); /* unknown */
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
521
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
522 put_be32(pb, 24); /* size */
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
523 put_tag(pb, "APRG");
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
524 put_tag(pb, "APRG");
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
525 put_tag(pb, "0001");
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
526 put_be32(pb, 1); /* unknown */
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
527 put_be32(pb, 0); /* unknown */
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
528
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
529 put_be32(pb, 120); /* size */
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
530 put_tag(pb, "ARES");
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
531 put_tag(pb, "ARES");
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
532 put_tag(pb, "0001");
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
533 put_be32(pb, AV_RB32(track->vosData + 0x28)); /* dnxhd cid, some id ? */
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
534 put_be32(pb, track->enc->width);
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
535 /* values below are based on samples created with quicktime and avid codecs */
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
536 if (track->vosData[5] & 2) { // interlaced
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
537 put_be32(pb, track->enc->height/2);
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
538 put_be32(pb, 2); /* unknown */
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
539 put_be32(pb, 0); /* unknown */
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
540 put_be32(pb, 4); /* unknown */
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
541 } else {
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
542 put_be32(pb, track->enc->height);
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
543 put_be32(pb, 1); /* unknown */
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
544 put_be32(pb, 0); /* unknown */
2802
ef333b18b760 fix dnxhd 720p in mov for quicktime player
bcoudurier
parents: 2771
diff changeset
545 if (track->enc->height == 1080)
ef333b18b760 fix dnxhd 720p in mov for quicktime player
bcoudurier
parents: 2771
diff changeset
546 put_be32(pb, 5); /* unknown */
ef333b18b760 fix dnxhd 720p in mov for quicktime player
bcoudurier
parents: 2771
diff changeset
547 else
ef333b18b760 fix dnxhd 720p in mov for quicktime player
bcoudurier
parents: 2771
diff changeset
548 put_be32(pb, 6); /* unknown */
2588
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
549 }
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
550 /* padding */
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
551 for (i = 0; i < 10; i++)
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
552 put_be64(pb, 0);
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
553
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
554 /* extra padding for stsd needed */
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
555 put_be32(pb, 0);
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
556 return 0;
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
557 }
577c8b1dafcc DNxHD (SMPTE VC-3) encoder
bcoudurier
parents: 2546
diff changeset
558
4824
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
559 static int mp4_get_codec_tag(AVFormatContext *s, MOVTrack *track)
1000
508ab1067ed9 correct computing of DV fourcc in mov muxer
corey
parents: 990
diff changeset
560 {
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
561 int tag = track->enc->codec_tag;
4825
b2eef653b7e4 cosmetics, reindent, add empty lines
bcoudurier
parents: 4824
diff changeset
562
5058
33a244b7ca65 Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents: 4996
diff changeset
563 if (!ff_codec_get_tag(ff_mp4_obj_type, track->enc->codec_id))
4825
b2eef653b7e4 cosmetics, reindent, add empty lines
bcoudurier
parents: 4824
diff changeset
564 return 0;
b2eef653b7e4 cosmetics, reindent, add empty lines
bcoudurier
parents: 4824
diff changeset
565
b2eef653b7e4 cosmetics, reindent, add empty lines
bcoudurier
parents: 4824
diff changeset
566 if (track->enc->codec_id == CODEC_ID_H264) tag = MKTAG('a','v','c','1');
b2eef653b7e4 cosmetics, reindent, add empty lines
bcoudurier
parents: 4824
diff changeset
567 else if (track->enc->codec_id == CODEC_ID_AC3) tag = MKTAG('a','c','-','3');
b2eef653b7e4 cosmetics, reindent, add empty lines
bcoudurier
parents: 4824
diff changeset
568 else if (track->enc->codec_id == CODEC_ID_DIRAC) tag = MKTAG('d','r','a','c');
b2eef653b7e4 cosmetics, reindent, add empty lines
bcoudurier
parents: 4824
diff changeset
569 else if (track->enc->codec_id == CODEC_ID_MOV_TEXT) tag = MKTAG('t','x','3','g');
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5792
diff changeset
570 else if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO) tag = MKTAG('m','p','4','v');
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5792
diff changeset
571 else if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO) tag = MKTAG('m','p','4','a');
4824
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
572
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
573 return tag;
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
574 }
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
575
4832
b367d80986b3 move codec tag tables near corresponding code
bcoudurier
parents: 4831
diff changeset
576 static const AVCodecTag codec_ipod_tags[] = {
b367d80986b3 move codec tag tables near corresponding code
bcoudurier
parents: 4831
diff changeset
577 { CODEC_ID_H264, MKTAG('a','v','c','1') },
b367d80986b3 move codec tag tables near corresponding code
bcoudurier
parents: 4831
diff changeset
578 { CODEC_ID_MPEG4, MKTAG('m','p','4','v') },
b367d80986b3 move codec tag tables near corresponding code
bcoudurier
parents: 4831
diff changeset
579 { CODEC_ID_AAC, MKTAG('m','p','4','a') },
b367d80986b3 move codec tag tables near corresponding code
bcoudurier
parents: 4831
diff changeset
580 { CODEC_ID_ALAC, MKTAG('a','l','a','c') },
b367d80986b3 move codec tag tables near corresponding code
bcoudurier
parents: 4831
diff changeset
581 { CODEC_ID_AC3, MKTAG('a','c','-','3') },
b367d80986b3 move codec tag tables near corresponding code
bcoudurier
parents: 4831
diff changeset
582 { CODEC_ID_MOV_TEXT, MKTAG('t','x','3','g') },
b367d80986b3 move codec tag tables near corresponding code
bcoudurier
parents: 4831
diff changeset
583 { CODEC_ID_MOV_TEXT, MKTAG('t','e','x','t') },
b367d80986b3 move codec tag tables near corresponding code
bcoudurier
parents: 4831
diff changeset
584 { CODEC_ID_NONE, 0 },
b367d80986b3 move codec tag tables near corresponding code
bcoudurier
parents: 4831
diff changeset
585 };
b367d80986b3 move codec tag tables near corresponding code
bcoudurier
parents: 4831
diff changeset
586
4824
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
587 static int ipod_get_codec_tag(AVFormatContext *s, MOVTrack *track)
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
588 {
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
589 int tag = track->enc->codec_tag;
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
590
4828
762254cf3be9 comment the ipod subtitle check
bcoudurier
parents: 4827
diff changeset
591 // keep original tag for subs, ipod supports both formats
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5792
diff changeset
592 if (!(track->enc->codec_type == AVMEDIA_TYPE_SUBTITLE &&
4825
b2eef653b7e4 cosmetics, reindent, add empty lines
bcoudurier
parents: 4824
diff changeset
593 (tag == MKTAG('t','x','3','g') ||
4829
e3d1c92193a7 fix compilation, add missing parenthesis
bcoudurier
parents: 4828
diff changeset
594 tag == MKTAG('t','e','x','t'))))
5058
33a244b7ca65 Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents: 4996
diff changeset
595 tag = ff_codec_get_tag(codec_ipod_tags, track->enc->codec_id);
4830
8fcb2c0d6362 cosmetics, add empty line and remove useless braces
bcoudurier
parents: 4829
diff changeset
596
5556
c35e1d2373c7 Use av_match_ext() rather than the deprecated match_ext(), fix
stefano
parents: 5492
diff changeset
597 if (!av_match_ext(s->filename, "m4a") && !av_match_ext(s->filename, "m4v"))
4825
b2eef653b7e4 cosmetics, reindent, add empty lines
bcoudurier
parents: 4824
diff changeset
598 av_log(s, AV_LOG_WARNING, "Warning, extension is not .m4a nor .m4v "
b2eef653b7e4 cosmetics, reindent, add empty lines
bcoudurier
parents: 4824
diff changeset
599 "Quicktime/Ipod might not play the file\n");
4824
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
600
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
601 return tag;
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
602 }
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
603
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
604 static int mov_get_dv_codec_tag(AVFormatContext *s, MOVTrack *track)
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
605 {
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
606 int tag;
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
607
4825
b2eef653b7e4 cosmetics, reindent, add empty lines
bcoudurier
parents: 4824
diff changeset
608 if (track->enc->height == 480) /* NTSC */
b2eef653b7e4 cosmetics, reindent, add empty lines
bcoudurier
parents: 4824
diff changeset
609 if (track->enc->pix_fmt == PIX_FMT_YUV422P) tag = MKTAG('d','v','5','n');
b2eef653b7e4 cosmetics, reindent, add empty lines
bcoudurier
parents: 4824
diff changeset
610 else tag = MKTAG('d','v','c',' ');
b2eef653b7e4 cosmetics, reindent, add empty lines
bcoudurier
parents: 4824
diff changeset
611 else if (track->enc->pix_fmt == PIX_FMT_YUV422P) tag = MKTAG('d','v','5','p');
b2eef653b7e4 cosmetics, reindent, add empty lines
bcoudurier
parents: 4824
diff changeset
612 else if (track->enc->pix_fmt == PIX_FMT_YUV420P) tag = MKTAG('d','v','c','p');
b2eef653b7e4 cosmetics, reindent, add empty lines
bcoudurier
parents: 4824
diff changeset
613 else tag = MKTAG('d','v','p','p');
4824
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
614
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
615 return tag;
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
616 }
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
617
4832
b367d80986b3 move codec tag tables near corresponding code
bcoudurier
parents: 4831
diff changeset
618 static const struct {
b367d80986b3 move codec tag tables near corresponding code
bcoudurier
parents: 4831
diff changeset
619 enum PixelFormat pix_fmt;
b367d80986b3 move codec tag tables near corresponding code
bcoudurier
parents: 4831
diff changeset
620 uint32_t tag;
b367d80986b3 move codec tag tables near corresponding code
bcoudurier
parents: 4831
diff changeset
621 unsigned bps;
b367d80986b3 move codec tag tables near corresponding code
bcoudurier
parents: 4831
diff changeset
622 } mov_pix_fmt_tags[] = {
b367d80986b3 move codec tag tables near corresponding code
bcoudurier
parents: 4831
diff changeset
623 { PIX_FMT_YUYV422, MKTAG('y','u','v','s'), 0 },
b367d80986b3 move codec tag tables near corresponding code
bcoudurier
parents: 4831
diff changeset
624 { PIX_FMT_UYVY422, MKTAG('2','v','u','y'), 0 },
6091
9c8c96356051 fix raw 555 pixel format, add abgr fourcc
bcoudurier
parents: 6042
diff changeset
625 { PIX_FMT_RGB555BE,MKTAG('r','a','w',' '), 16 },
4920
7d8344d28ab9 rgb555le, rgb565le, rgb565be, bgr24 in .mov muxing
bcoudurier
parents: 4919
diff changeset
626 { PIX_FMT_RGB555LE,MKTAG('L','5','5','5'), 16 },
7d8344d28ab9 rgb555le, rgb565le, rgb565be, bgr24 in .mov muxing
bcoudurier
parents: 4919
diff changeset
627 { PIX_FMT_RGB565LE,MKTAG('L','5','6','5'), 16 },
7d8344d28ab9 rgb555le, rgb565le, rgb565be, bgr24 in .mov muxing
bcoudurier
parents: 4919
diff changeset
628 { PIX_FMT_RGB565BE,MKTAG('B','5','6','5'), 16 },
6132
a2c4863f9199 Support gray16be and rgb48be in mov
bcoudurier
parents: 6091
diff changeset
629 { PIX_FMT_GRAY16BE,MKTAG('b','1','6','g'), 16 },
4832
b367d80986b3 move codec tag tables near corresponding code
bcoudurier
parents: 4831
diff changeset
630 { PIX_FMT_RGB24, MKTAG('r','a','w',' '), 24 },
4920
7d8344d28ab9 rgb555le, rgb565le, rgb565be, bgr24 in .mov muxing
bcoudurier
parents: 4919
diff changeset
631 { PIX_FMT_BGR24, MKTAG('2','4','B','G'), 24 },
4918
16e41aadb1ca correct pixfmt for argb
bcoudurier
parents: 4917
diff changeset
632 { PIX_FMT_ARGB, MKTAG('r','a','w',' '), 32 },
4919
ba278ab96c31 bgra in .mov muxing
bcoudurier
parents: 4918
diff changeset
633 { PIX_FMT_BGRA, MKTAG('B','G','R','A'), 32 },
4917
8896469dbb49 rgba in .mov muxing
bcoudurier
parents: 4872
diff changeset
634 { PIX_FMT_RGBA, MKTAG('R','G','B','A'), 32 },
6091
9c8c96356051 fix raw 555 pixel format, add abgr fourcc
bcoudurier
parents: 6042
diff changeset
635 { PIX_FMT_ABGR, MKTAG('A','B','G','R'), 32 },
6132
a2c4863f9199 Support gray16be and rgb48be in mov
bcoudurier
parents: 6091
diff changeset
636 { PIX_FMT_RGB48BE, MKTAG('b','4','8','r'), 48 },
4832
b367d80986b3 move codec tag tables near corresponding code
bcoudurier
parents: 4831
diff changeset
637 };
b367d80986b3 move codec tag tables near corresponding code
bcoudurier
parents: 4831
diff changeset
638
4824
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
639 static int mov_get_rawvideo_codec_tag(AVFormatContext *s, MOVTrack *track)
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
640 {
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
641 int tag = track->enc->codec_tag;
4825
b2eef653b7e4 cosmetics, reindent, add empty lines
bcoudurier
parents: 4824
diff changeset
642 int i;
b2eef653b7e4 cosmetics, reindent, add empty lines
bcoudurier
parents: 4824
diff changeset
643
b2eef653b7e4 cosmetics, reindent, add empty lines
bcoudurier
parents: 4824
diff changeset
644 for (i = 0; i < FF_ARRAY_ELEMS(mov_pix_fmt_tags); i++) {
b2eef653b7e4 cosmetics, reindent, add empty lines
bcoudurier
parents: 4824
diff changeset
645 if (track->enc->pix_fmt == mov_pix_fmt_tags[i].pix_fmt) {
b2eef653b7e4 cosmetics, reindent, add empty lines
bcoudurier
parents: 4824
diff changeset
646 tag = mov_pix_fmt_tags[i].tag;
b2eef653b7e4 cosmetics, reindent, add empty lines
bcoudurier
parents: 4824
diff changeset
647 track->enc->bits_per_coded_sample = mov_pix_fmt_tags[i].bps;
b2eef653b7e4 cosmetics, reindent, add empty lines
bcoudurier
parents: 4824
diff changeset
648 break;
b2eef653b7e4 cosmetics, reindent, add empty lines
bcoudurier
parents: 4824
diff changeset
649 }
b2eef653b7e4 cosmetics, reindent, add empty lines
bcoudurier
parents: 4824
diff changeset
650 }
4824
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
651
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
652 return tag;
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
653 }
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
654
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
655 static int mov_get_codec_tag(AVFormatContext *s, MOVTrack *track)
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
656 {
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
657 int tag = track->enc->codec_tag;
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
658
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
659 if (!tag || (track->enc->strict_std_compliance >= FF_COMPLIANCE_NORMAL &&
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
660 (tag == MKTAG('d','v','c','p') ||
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
661 track->enc->codec_id == CODEC_ID_RAWVIDEO ||
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
662 av_get_bits_per_sample(track->enc->codec_id)))) { // pcm audio
4830
8fcb2c0d6362 cosmetics, add empty line and remove useless braces
bcoudurier
parents: 4829
diff changeset
663 if (track->enc->codec_id == CODEC_ID_DVVIDEO)
4824
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
664 tag = mov_get_dv_codec_tag(s, track);
4830
8fcb2c0d6362 cosmetics, add empty line and remove useless braces
bcoudurier
parents: 4829
diff changeset
665 else if (track->enc->codec_id == CODEC_ID_RAWVIDEO)
4824
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
666 tag = mov_get_rawvideo_codec_tag(s, track);
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5792
diff changeset
667 else if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO) {
5058
33a244b7ca65 Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents: 4996
diff changeset
668 tag = ff_codec_get_tag(codec_movvideo_tags, track->enc->codec_id);
4831
1c7db935f752 cosmetics, reindent
bcoudurier
parents: 4830
diff changeset
669 if (!tag) { // if no mac fcc found, try with Microsoft tags
5058
33a244b7ca65 Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents: 4996
diff changeset
670 tag = ff_codec_get_tag(ff_codec_bmp_tags, track->enc->codec_id);
4831
1c7db935f752 cosmetics, reindent
bcoudurier
parents: 4830
diff changeset
671 if (tag)
1c7db935f752 cosmetics, reindent
bcoudurier
parents: 4830
diff changeset
672 av_log(s, AV_LOG_INFO, "Warning, using MS style video codec tag, "
1c7db935f752 cosmetics, reindent
bcoudurier
parents: 4830
diff changeset
673 "the file may be unplayable!\n");
1c7db935f752 cosmetics, reindent
bcoudurier
parents: 4830
diff changeset
674 }
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5792
diff changeset
675 } else if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO) {
5058
33a244b7ca65 Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents: 4996
diff changeset
676 tag = ff_codec_get_tag(codec_movaudio_tags, track->enc->codec_id);
4831
1c7db935f752 cosmetics, reindent
bcoudurier
parents: 4830
diff changeset
677 if (!tag) { // if no mac fcc found, try with Microsoft tags
5058
33a244b7ca65 Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents: 4996
diff changeset
678 int ms_tag = ff_codec_get_tag(ff_codec_wav_tags, track->enc->codec_id);
4831
1c7db935f752 cosmetics, reindent
bcoudurier
parents: 4830
diff changeset
679 if (ms_tag) {
1c7db935f752 cosmetics, reindent
bcoudurier
parents: 4830
diff changeset
680 tag = MKTAG('m', 's', ((ms_tag >> 8) & 0xff), (ms_tag & 0xff));
1c7db935f752 cosmetics, reindent
bcoudurier
parents: 4830
diff changeset
681 av_log(s, AV_LOG_INFO, "Warning, using MS style audio codec tag, "
1c7db935f752 cosmetics, reindent
bcoudurier
parents: 4830
diff changeset
682 "the file may be unplayable!\n");
2979
1bc4c9ca1b04 indentation
bcoudurier
parents: 2978
diff changeset
683 }
4831
1c7db935f752 cosmetics, reindent
bcoudurier
parents: 4830
diff changeset
684 }
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5792
diff changeset
685 } else if (track->enc->codec_type == AVMEDIA_TYPE_SUBTITLE)
5058
33a244b7ca65 Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents: 4996
diff changeset
686 tag = ff_codec_get_tag(ff_codec_movsubtitle_tags, track->enc->codec_id);
2978
8dcdecbbf7e6 correctly and only set standard stsd fourcc for mp4/3gp
bcoudurier
parents: 2977
diff changeset
687 }
4825
b2eef653b7e4 cosmetics, reindent, add empty lines
bcoudurier
parents: 4824
diff changeset
688
1000
508ab1067ed9 correct computing of DV fourcc in mov muxer
corey
parents: 990
diff changeset
689 return tag;
508ab1067ed9 correct computing of DV fourcc in mov muxer
corey
parents: 990
diff changeset
690 }
508ab1067ed9 correct computing of DV fourcc in mov muxer
corey
parents: 990
diff changeset
691
4832
b367d80986b3 move codec tag tables near corresponding code
bcoudurier
parents: 4831
diff changeset
692 static const AVCodecTag codec_3gp_tags[] = {
b367d80986b3 move codec tag tables near corresponding code
bcoudurier
parents: 4831
diff changeset
693 { CODEC_ID_H263, MKTAG('s','2','6','3') },
b367d80986b3 move codec tag tables near corresponding code
bcoudurier
parents: 4831
diff changeset
694 { CODEC_ID_H264, MKTAG('a','v','c','1') },
b367d80986b3 move codec tag tables near corresponding code
bcoudurier
parents: 4831
diff changeset
695 { CODEC_ID_MPEG4, MKTAG('m','p','4','v') },
b367d80986b3 move codec tag tables near corresponding code
bcoudurier
parents: 4831
diff changeset
696 { CODEC_ID_AAC, MKTAG('m','p','4','a') },
b367d80986b3 move codec tag tables near corresponding code
bcoudurier
parents: 4831
diff changeset
697 { CODEC_ID_AMR_NB, MKTAG('s','a','m','r') },
b367d80986b3 move codec tag tables near corresponding code
bcoudurier
parents: 4831
diff changeset
698 { CODEC_ID_AMR_WB, MKTAG('s','a','w','b') },
b367d80986b3 move codec tag tables near corresponding code
bcoudurier
parents: 4831
diff changeset
699 { CODEC_ID_MOV_TEXT, MKTAG('t','x','3','g') },
b367d80986b3 move codec tag tables near corresponding code
bcoudurier
parents: 4831
diff changeset
700 { CODEC_ID_NONE, 0 },
b367d80986b3 move codec tag tables near corresponding code
bcoudurier
parents: 4831
diff changeset
701 };
b367d80986b3 move codec tag tables near corresponding code
bcoudurier
parents: 4831
diff changeset
702
4824
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
703 static int mov_find_codec_tag(AVFormatContext *s, MOVTrack *track)
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
704 {
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
705 int tag = track->enc->codec_tag;
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
706
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
707 if (track->mode == MODE_MP4 || track->mode == MODE_PSP)
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
708 tag = mp4_get_codec_tag(s, track);
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
709 else if (track->mode == MODE_IPOD)
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
710 tag = ipod_get_codec_tag(s, track);
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
711 else if (track->mode & MODE_3GP)
5058
33a244b7ca65 Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents: 4996
diff changeset
712 tag = ff_codec_get_tag(codec_3gp_tags, track->enc->codec_id);
4824
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
713 else
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
714 tag = mov_get_codec_tag(s, track);
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
715
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
716 return tag;
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
717 }
ef55a8830c20 split mov_find_codec_tag in separate per format functions
bcoudurier
parents: 4819
diff changeset
718
3143
7f0f50bbfe23 ipod/iphone compatible mp4 muxer
bcoudurier
parents: 3024
diff changeset
719 /** Write uuid atom.
7f0f50bbfe23 ipod/iphone compatible mp4 muxer
bcoudurier
parents: 3024
diff changeset
720 * Needed to make file play in iPods running newest firmware
7f0f50bbfe23 ipod/iphone compatible mp4 muxer
bcoudurier
parents: 3024
diff changeset
721 * goes after avcC atom in moov.trak.mdia.minf.stbl.stsd.avc1
7f0f50bbfe23 ipod/iphone compatible mp4 muxer
bcoudurier
parents: 3024
diff changeset
722 */
7f0f50bbfe23 ipod/iphone compatible mp4 muxer
bcoudurier
parents: 3024
diff changeset
723 static int mov_write_uuid_tag_ipod(ByteIOContext *pb)
7f0f50bbfe23 ipod/iphone compatible mp4 muxer
bcoudurier
parents: 3024
diff changeset
724 {
7f0f50bbfe23 ipod/iphone compatible mp4 muxer
bcoudurier
parents: 3024
diff changeset
725 put_be32(pb, 28);
7f0f50bbfe23 ipod/iphone compatible mp4 muxer
bcoudurier
parents: 3024
diff changeset
726 put_tag(pb, "uuid");
7f0f50bbfe23 ipod/iphone compatible mp4 muxer
bcoudurier
parents: 3024
diff changeset
727 put_be32(pb, 0x6b6840f2);
7f0f50bbfe23 ipod/iphone compatible mp4 muxer
bcoudurier
parents: 3024
diff changeset
728 put_be32(pb, 0x5f244fc5);
7f0f50bbfe23 ipod/iphone compatible mp4 muxer
bcoudurier
parents: 3024
diff changeset
729 put_be32(pb, 0xba39a51b);
7f0f50bbfe23 ipod/iphone compatible mp4 muxer
bcoudurier
parents: 3024
diff changeset
730 put_be32(pb, 0xcf0323f3);
7f0f50bbfe23 ipod/iphone compatible mp4 muxer
bcoudurier
parents: 3024
diff changeset
731 put_be32(pb, 0x0);
7f0f50bbfe23 ipod/iphone compatible mp4 muxer
bcoudurier
parents: 3024
diff changeset
732 return 28;
7f0f50bbfe23 ipod/iphone compatible mp4 muxer
bcoudurier
parents: 3024
diff changeset
733 }
7f0f50bbfe23 ipod/iphone compatible mp4 muxer
bcoudurier
parents: 3024
diff changeset
734
4193
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
735 static int mov_write_subtitle_tag(ByteIOContext *pb, MOVTrack *track)
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
736 {
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
737 int64_t pos = url_ftell(pb);
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
738 put_be32(pb, 0); /* size */
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
739 put_le32(pb, track->tag); // store it byteswapped
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
740 put_be32(pb, 0); /* Reserved */
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
741 put_be16(pb, 0); /* Reserved */
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
742 put_be16(pb, 1); /* Data-reference index */
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
743
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
744 if (track->enc->extradata_size)
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
745 put_buffer(pb, track->enc->extradata, track->enc->extradata_size);
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
746
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
747 return updateSize(pb, pos);
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
748 }
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
749
6243
40f3dc7e5fcb In mov muxer, write pixel aspect ratio tag in mov files.
bcoudurier
parents: 6132
diff changeset
750 static int mov_write_pasp_tag(ByteIOContext *pb, MOVTrack *track)
40f3dc7e5fcb In mov muxer, write pixel aspect ratio tag in mov files.
bcoudurier
parents: 6132
diff changeset
751 {
40f3dc7e5fcb In mov muxer, write pixel aspect ratio tag in mov files.
bcoudurier
parents: 6132
diff changeset
752 AVRational sar;
40f3dc7e5fcb In mov muxer, write pixel aspect ratio tag in mov files.
bcoudurier
parents: 6132
diff changeset
753 av_reduce(&sar.num, &sar.den, track->enc->sample_aspect_ratio.num,
40f3dc7e5fcb In mov muxer, write pixel aspect ratio tag in mov files.
bcoudurier
parents: 6132
diff changeset
754 track->enc->sample_aspect_ratio.den, INT_MAX);
40f3dc7e5fcb In mov muxer, write pixel aspect ratio tag in mov files.
bcoudurier
parents: 6132
diff changeset
755
40f3dc7e5fcb In mov muxer, write pixel aspect ratio tag in mov files.
bcoudurier
parents: 6132
diff changeset
756 put_be32(pb, 16);
40f3dc7e5fcb In mov muxer, write pixel aspect ratio tag in mov files.
bcoudurier
parents: 6132
diff changeset
757 put_tag(pb, "pasp");
40f3dc7e5fcb In mov muxer, write pixel aspect ratio tag in mov files.
bcoudurier
parents: 6132
diff changeset
758 put_be32(pb, track->enc->sample_aspect_ratio.num);
40f3dc7e5fcb In mov muxer, write pixel aspect ratio tag in mov files.
bcoudurier
parents: 6132
diff changeset
759 put_be32(pb, track->enc->sample_aspect_ratio.den);
40f3dc7e5fcb In mov muxer, write pixel aspect ratio tag in mov files.
bcoudurier
parents: 6132
diff changeset
760 return 16;
40f3dc7e5fcb In mov muxer, write pixel aspect ratio tag in mov files.
bcoudurier
parents: 6132
diff changeset
761 }
40f3dc7e5fcb In mov muxer, write pixel aspect ratio tag in mov files.
bcoudurier
parents: 6132
diff changeset
762
3446
7d73c4a64714 cosmetics
bcoudurier
parents: 3424
diff changeset
763 static int mov_write_video_tag(ByteIOContext *pb, MOVTrack *track)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
764 {
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3909
diff changeset
765 int64_t pos = url_ftell(pb);
657
5b9575f5b6e8 mov header field and compressor name patch by Roine Gustafsson <roine AT users DOT sourceforge DOT net>
mmu_man
parents: 619
diff changeset
766 char compressor_name[32];
422
2f30932cda1f support for wider range of codecs
alex
parents: 400
diff changeset
767
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
768 put_be32(pb, 0); /* size */
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
769 put_le32(pb, track->tag); // store it byteswapped
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
770 put_be32(pb, 0); /* Reserved */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
771 put_be16(pb, 0); /* Reserved */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
772 put_be16(pb, 1); /* Data-reference index */
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
773
657
5b9575f5b6e8 mov header field and compressor name patch by Roine Gustafsson <roine AT users DOT sourceforge DOT net>
mmu_man
parents: 619
diff changeset
774 put_be16(pb, 0); /* Codec stream version */
5b9575f5b6e8 mov header field and compressor name patch by Roine Gustafsson <roine AT users DOT sourceforge DOT net>
mmu_man
parents: 619
diff changeset
775 put_be16(pb, 0); /* Codec stream revision (=0) */
1238
eb749ae2b181 only set fields for mov, reserved for 3gp, mp4
bcoudurier
parents: 1237
diff changeset
776 if (track->mode == MODE_MOV) {
1239
18130af77b09 indention
bcoudurier
parents: 1238
diff changeset
777 put_tag(pb, "FFMP"); /* Vendor */
18130af77b09 indention
bcoudurier
parents: 1238
diff changeset
778 if(track->enc->codec_id == CODEC_ID_RAWVIDEO) {
18130af77b09 indention
bcoudurier
parents: 1238
diff changeset
779 put_be32(pb, 0); /* Temporal Quality */
18130af77b09 indention
bcoudurier
parents: 1238
diff changeset
780 put_be32(pb, 0x400); /* Spatial Quality = lossless*/
18130af77b09 indention
bcoudurier
parents: 1238
diff changeset
781 } else {
18130af77b09 indention
bcoudurier
parents: 1238
diff changeset
782 put_be32(pb, 0x200); /* Temporal Quality = normal */
18130af77b09 indention
bcoudurier
parents: 1238
diff changeset
783 put_be32(pb, 0x200); /* Spatial Quality = normal */
18130af77b09 indention
bcoudurier
parents: 1238
diff changeset
784 }
1238
eb749ae2b181 only set fields for mov, reserved for 3gp, mp4
bcoudurier
parents: 1237
diff changeset
785 } else {
eb749ae2b181 only set fields for mov, reserved for 3gp, mp4
bcoudurier
parents: 1237
diff changeset
786 put_be32(pb, 0); /* Reserved */
eb749ae2b181 only set fields for mov, reserved for 3gp, mp4
bcoudurier
parents: 1237
diff changeset
787 put_be32(pb, 0); /* Reserved */
eb749ae2b181 only set fields for mov, reserved for 3gp, mp4
bcoudurier
parents: 1237
diff changeset
788 put_be32(pb, 0); /* Reserved */
eb749ae2b181 only set fields for mov, reserved for 3gp, mp4
bcoudurier
parents: 1237
diff changeset
789 }
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
790 put_be16(pb, track->enc->width); /* Video width */
4463
0cd7acf426f3 write active picture height for d-10/imx in mov
bcoudurier
parents: 4251
diff changeset
791 put_be16(pb, track->height); /* Video height */
657
5b9575f5b6e8 mov header field and compressor name patch by Roine Gustafsson <roine AT users DOT sourceforge DOT net>
mmu_man
parents: 619
diff changeset
792 put_be32(pb, 0x00480000); /* Horizontal resolution 72dpi */
5b9575f5b6e8 mov header field and compressor name patch by Roine Gustafsson <roine AT users DOT sourceforge DOT net>
mmu_man
parents: 619
diff changeset
793 put_be32(pb, 0x00480000); /* Vertical resolution 72dpi */
399
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
794 put_be32(pb, 0); /* Data size (= 0) */
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
795 put_be16(pb, 1); /* Frame count (= 1) */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
796
657
5b9575f5b6e8 mov header field and compressor name patch by Roine Gustafsson <roine AT users DOT sourceforge DOT net>
mmu_man
parents: 619
diff changeset
797 memset(compressor_name,0,32);
1238
eb749ae2b181 only set fields for mov, reserved for 3gp, mp4
bcoudurier
parents: 1237
diff changeset
798 /* FIXME not sure, ISO 14496-1 draft where it shall be set to 0 */
eb749ae2b181 only set fields for mov, reserved for 3gp, mp4
bcoudurier
parents: 1237
diff changeset
799 if (track->mode == MODE_MOV && track->enc->codec && track->enc->codec->name)
657
5b9575f5b6e8 mov header field and compressor name patch by Roine Gustafsson <roine AT users DOT sourceforge DOT net>
mmu_man
parents: 619
diff changeset
800 strncpy(compressor_name,track->enc->codec->name,31);
664
76d0af843707 don't crash on null codec; by matthieu castet <castet DOT matthieu AT free DOT fr>
mmu_man
parents: 663
diff changeset
801 put_byte(pb, strlen(compressor_name));
657
5b9575f5b6e8 mov header field and compressor name patch by Roine Gustafsson <roine AT users DOT sourceforge DOT net>
mmu_man
parents: 619
diff changeset
802 put_buffer(pb, compressor_name, 31);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
803
3908
1d3d17de20ba Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 3907
diff changeset
804 if (track->mode == MODE_MOV && track->enc->bits_per_coded_sample)
1d3d17de20ba Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 3907
diff changeset
805 put_be16(pb, track->enc->bits_per_coded_sample);
2992
0cdcc2b1a272 support rawvideo in mov
bcoudurier
parents: 2987
diff changeset
806 else
0cdcc2b1a272 support rawvideo in mov
bcoudurier
parents: 2987
diff changeset
807 put_be16(pb, 0x18); /* Reserved */
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
808 put_be16(pb, 0xffff); /* Reserved */
2977
b5ad3169a579 write esds atom when mpeg-4 systems tags are used
bcoudurier
parents: 2975
diff changeset
809 if(track->tag == MKTAG('m','p','4','v'))
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
810 mov_write_esds_tag(pb, track);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
811 else if(track->enc->codec_id == CODEC_ID_H263)
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
812 mov_write_d263_tag(pb);
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
813 else if(track->enc->codec_id == CODEC_ID_SVQ3)
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
814 mov_write_svq3_tag(pb);
3158
710917feb10a cosmetics, move case up
bcoudurier
parents: 3143
diff changeset
815 else if(track->enc->codec_id == CODEC_ID_DNXHD)
710917feb10a cosmetics, move case up
bcoudurier
parents: 3143
diff changeset
816 mov_write_avid_tag(pb, track);
3143
7f0f50bbfe23 ipod/iphone compatible mp4 muxer
bcoudurier
parents: 3024
diff changeset
817 else if(track->enc->codec_id == CODEC_ID_H264) {
1006
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
818 mov_write_avcc_tag(pb, track);
3143
7f0f50bbfe23 ipod/iphone compatible mp4 muxer
bcoudurier
parents: 3024
diff changeset
819 if(track->mode == MODE_IPOD)
7f0f50bbfe23 ipod/iphone compatible mp4 muxer
bcoudurier
parents: 3024
diff changeset
820 mov_write_uuid_tag_ipod(pb);
3203
e5991c49acdc special mpeg2 handling is no more needed
bcoudurier
parents: 3192
diff changeset
821 } else if(track->vosLen > 0)
2838
6bea49ef18b1 use generic 'glbl' atom if extradata is present but no specific method is known
bcoudurier
parents: 2802
diff changeset
822 mov_write_glbl_tag(pb, track);
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
823
6243
40f3dc7e5fcb In mov muxer, write pixel aspect ratio tag in mov files.
bcoudurier
parents: 6132
diff changeset
824 if (track->mode == MODE_MOV &&
40f3dc7e5fcb In mov muxer, write pixel aspect ratio tag in mov files.
bcoudurier
parents: 6132
diff changeset
825 track->enc->sample_aspect_ratio.den && track->enc->sample_aspect_ratio.num &&
40f3dc7e5fcb In mov muxer, write pixel aspect ratio tag in mov files.
bcoudurier
parents: 6132
diff changeset
826 track->enc->sample_aspect_ratio.den != track->enc->sample_aspect_ratio.num) {
40f3dc7e5fcb In mov muxer, write pixel aspect ratio tag in mov files.
bcoudurier
parents: 6132
diff changeset
827 mov_write_pasp_tag(pb, track);
40f3dc7e5fcb In mov muxer, write pixel aspect ratio tag in mov files.
bcoudurier
parents: 6132
diff changeset
828 }
40f3dc7e5fcb In mov muxer, write pixel aspect ratio tag in mov files.
bcoudurier
parents: 6132
diff changeset
829
3455
aefb1cbf9479 cosmetics
bcoudurier
parents: 3454
diff changeset
830 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
831 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
832
6013
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
833 static int mov_write_rtp_tag(ByteIOContext *pb, MOVTrack *track)
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
834 {
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
835 int64_t pos = url_ftell(pb);
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
836 put_be32(pb, 0); /* size */
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
837 put_tag(pb, "rtp ");
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
838 put_be32(pb, 0); /* Reserved */
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
839 put_be16(pb, 0); /* Reserved */
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
840 put_be16(pb, 1); /* Data-reference index */
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
841
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
842 put_be16(pb, 1); /* Hint track version */
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
843 put_be16(pb, 1); /* Highest compatible version */
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
844 put_be32(pb, track->max_packet_size); /* Max packet size */
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
845
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
846 put_be32(pb, 12); /* size */
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
847 put_tag(pb, "tims");
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
848 put_be32(pb, track->timescale);
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
849
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
850 return updateSize(pb, pos);
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
851 }
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
852
3446
7d73c4a64714 cosmetics
bcoudurier
parents: 3424
diff changeset
853 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
854 {
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3909
diff changeset
855 int64_t pos = url_ftell(pb);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
856 put_be32(pb, 0); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
857 put_tag(pb, "stsd");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
858 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
859 put_be32(pb, 1); /* entry count */
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5792
diff changeset
860 if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO)
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
861 mov_write_video_tag(pb, track);
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5792
diff changeset
862 else if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO)
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
863 mov_write_audio_tag(pb, track);
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5792
diff changeset
864 else if (track->enc->codec_type == AVMEDIA_TYPE_SUBTITLE)
4193
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
865 mov_write_subtitle_tag(pb, track);
6013
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
866 else if (track->enc->codec_tag == MKTAG('r','t','p',' '))
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
867 mov_write_rtp_tag(pb, track);
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
868 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
869 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
870
3446
7d73c4a64714 cosmetics
bcoudurier
parents: 3424
diff changeset
871 static int mov_write_ctts_tag(ByteIOContext *pb, MOVTrack *track)
971
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
872 {
4079
82cbec030af5 remove _t in typedef for POSIX compatibility
bcoudurier
parents: 3973
diff changeset
873 MOVStts *ctts_entries;
971
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
874 uint32_t entries = 0;
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
875 uint32_t atom_size;
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
876 int i;
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
877
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
878 ctts_entries = av_malloc((track->entry + 1) * sizeof(*ctts_entries)); /* worst case */
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
879 ctts_entries[0].count = 1;
1129
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
880 ctts_entries[0].duration = track->cluster[0].cts;
971
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
881 for (i=1; i<track->entry; i++) {
1129
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
882 if (track->cluster[i].cts == ctts_entries[entries].duration) {
971
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
883 ctts_entries[entries].count++; /* compress */
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
884 } else {
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
885 entries++;
1129
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
886 ctts_entries[entries].duration = track->cluster[i].cts;
971
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
887 ctts_entries[entries].count = 1;
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
888 }
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
889 }
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
890 entries++; /* last one */
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
891 atom_size = 16 + (entries * 8);
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
892 put_be32(pb, atom_size); /* size */
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
893 put_tag(pb, "ctts");
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
894 put_be32(pb, 0); /* version & flags */
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
895 put_be32(pb, entries); /* entry count */
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
896 for (i=0; i<entries; i++) {
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
897 put_be32(pb, ctts_entries[i].count);
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
898 put_be32(pb, ctts_entries[i].duration);
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
899 }
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
900 av_free(ctts_entries);
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
901 return atom_size;
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
902 }
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
903
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
904 /* Time to sample atom */
3446
7d73c4a64714 cosmetics
bcoudurier
parents: 3424
diff changeset
905 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
906 {
4079
82cbec030af5 remove _t in typedef for POSIX compatibility
bcoudurier
parents: 3973
diff changeset
907 MOVStts *stts_entries;
1437
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
908 uint32_t entries = -1;
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
909 uint32_t atom_size;
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
910 int i;
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
911
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5792
diff changeset
912 if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO && !track->audio_vbr) {
1437
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
913 stts_entries = av_malloc(sizeof(*stts_entries)); /* one entry */
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
914 stts_entries[0].count = track->sampleCount;
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
915 stts_entries[0].duration = 1;
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
916 entries = 1;
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
917 } else {
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
918 stts_entries = av_malloc(track->entry * sizeof(*stts_entries)); /* worst case */
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
919 for (i=0; i<track->entry; i++) {
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
920 int64_t duration = i + 1 == track->entry ?
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
921 track->trackDuration - track->cluster[i].dts + track->cluster[0].dts : /* readjusting */
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
922 track->cluster[i+1].dts - track->cluster[i].dts;
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
923 if (i && duration == stts_entries[entries].duration) {
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
924 stts_entries[entries].count++; /* compress */
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
925 } else {
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
926 entries++;
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
927 stts_entries[entries].duration = duration;
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
928 stts_entries[entries].count = 1;
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
929 }
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
930 }
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
931 entries++; /* last one */
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
932 }
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
933 atom_size = 16 + (entries * 8);
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
934 put_be32(pb, atom_size); /* size */
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
935 put_tag(pb, "stts");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
936 put_be32(pb, 0); /* version & flags */
1437
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
937 put_be32(pb, entries); /* entry count */
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
938 for (i=0; i<entries; i++) {
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
939 put_be32(pb, stts_entries[i].count);
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
940 put_be32(pb, stts_entries[i].duration);
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
941 }
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
942 av_free(stts_entries);
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
943 return atom_size;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
944 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
945
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
946 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
947 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
948 put_be32(pb, 28); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
949 put_tag(pb, "dref");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
950 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
951 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
952
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
953 put_be32(pb, 0xc); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
954 put_tag(pb, "url ");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
955 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
956
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
957 return 28;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
958 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
959
3446
7d73c4a64714 cosmetics
bcoudurier
parents: 3424
diff changeset
960 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
961 {
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3909
diff changeset
962 int64_t pos = url_ftell(pb);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
963 put_be32(pb, 0); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
964 put_tag(pb, "stbl");
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
965 mov_write_stsd_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
966 mov_write_stts_tag(pb, track);
6013
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
967 if ((track->enc->codec_type == AVMEDIA_TYPE_VIDEO ||
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
968 track->enc->codec_tag == MKTAG('r','t','p',' ')) &&
3192
85a48dbf1844 prevent writing empty stss atom
bcoudurier
parents: 3159
diff changeset
969 track->hasKeyframes && track->hasKeyframes < track->entry)
4941
45a08facad6f write 'stps' for mpeg-2 open gop in .mov
bcoudurier
parents: 4937
diff changeset
970 mov_write_stss_tag(pb, track, MOV_SYNC_SAMPLE);
45a08facad6f write 'stps' for mpeg-2 open gop in .mov
bcoudurier
parents: 4937
diff changeset
971 if (track->mode == MODE_MOV && track->flags & MOV_TRACK_STPS)
45a08facad6f write 'stps' for mpeg-2 open gop in .mov
bcoudurier
parents: 4937
diff changeset
972 mov_write_stss_tag(pb, track, MOV_PARTIAL_SYNC_SAMPLE);
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5792
diff changeset
973 if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO &&
4941
45a08facad6f write 'stps' for mpeg-2 open gop in .mov
bcoudurier
parents: 4937
diff changeset
974 track->flags & MOV_TRACK_CTTS)
971
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
975 mov_write_ctts_tag(pb, track);
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
976 mov_write_stsc_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
977 mov_write_stsz_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
978 mov_write_stco_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
979 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
980 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
981
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
982 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
983 {
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3909
diff changeset
984 int64_t pos = url_ftell(pb);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
985 put_be32(pb, 0); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
986 put_tag(pb, "dinf");
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
987 mov_write_dref_tag(pb);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
988 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
989 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
990
4193
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
991 static int mov_write_nmhd_tag(ByteIOContext *pb)
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
992 {
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
993 put_be32(pb, 12);
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
994 put_tag(pb, "nmhd");
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
995 put_be32(pb, 0);
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
996 return 12;
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
997 }
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
998
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
999 static int mov_write_gmhd_tag(ByteIOContext *pb)
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
1000 {
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
1001 put_be32(pb, 0x20); /* size */
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
1002 put_tag(pb, "gmhd");
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
1003 put_be32(pb, 0x18); /* gmin size */
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
1004 put_tag(pb, "gmin"); /* generic media info */
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
1005 put_be32(pb, 0); /* version & flags */
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
1006 put_be16(pb, 0x40); /* graphics mode = */
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
1007 put_be16(pb, 0x8000); /* opColor (r?) */
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
1008 put_be16(pb, 0x8000); /* opColor (g?) */
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
1009 put_be16(pb, 0x8000); /* opColor (b?) */
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
1010 put_be16(pb, 0); /* balance */
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
1011 put_be16(pb, 0); /* reserved */
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
1012 return 0x20;
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
1013 }
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
1014
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
1015 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
1016 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1017 put_be32(pb, 16); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1018 put_tag(pb, "smhd");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1019 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
1020 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
1021 put_be16(pb, 0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1022 return 16;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1023 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1024
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
1025 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
1026 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1027 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
1028 put_tag(pb, "vmhd");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1029 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
1030 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
1031 return 0x14;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1032 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1033
3446
7d73c4a64714 cosmetics
bcoudurier
parents: 3424
diff changeset
1034 static int mov_write_hdlr_tag(ByteIOContext *pb, MOVTrack *track)
399
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
1035 {
4195
89299a4307eb remove warnings about uninitialized vars
bcoudurier
parents: 4194
diff changeset
1036 const char *hdlr, *descr = NULL, *hdlr_type = NULL;
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3909
diff changeset
1037 int64_t pos = url_ftell(pb);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
1038
399
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
1039 if (!track) { /* no media --> data handler */
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
1040 hdlr = "dhlr";
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
1041 hdlr_type = "url ";
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
1042 descr = "DataHandler";
399
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
1043 } else {
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
1044 hdlr = (track->mode == MODE_MOV) ? "mhlr" : "\0\0\0\0";
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5792
diff changeset
1045 if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO) {
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
1046 hdlr_type = "vide";
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
1047 descr = "VideoHandler";
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5792
diff changeset
1048 } else if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO) {
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
1049 hdlr_type = "soun";
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
1050 descr = "SoundHandler";
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5792
diff changeset
1051 } else if (track->enc->codec_type == AVMEDIA_TYPE_SUBTITLE) {
4699
59ee17ee14fa write correct atoms based on tag and not format, fixes subs stream copy
bcoudurier
parents: 4698
diff changeset
1052 if (track->tag == MKTAG('t','x','3','g')) hdlr_type = "sbtl";
4700
7042140487b7 reindent
bcoudurier
parents: 4699
diff changeset
1053 else hdlr_type = "text";
4193
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
1054 descr = "SubtitleHandler";
6013
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1055 } else if (track->enc->codec_tag == MKTAG('r','t','p',' ')) {
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1056 hdlr_type = "hint";
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1057 descr = "HintHandler";
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
1058 }
399
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
1059 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
1060
399
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
1061 put_be32(pb, 0); /* size */
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
1062 put_tag(pb, "hdlr");
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
1063 put_be32(pb, 0); /* Version & flags */
400
62e4ea840c52 * fixing 10l in movenc.c + updating regression patterns.
romansh
parents: 399
diff changeset
1064 put_buffer(pb, hdlr, 4); /* handler */
399
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
1065 put_tag(pb, hdlr_type); /* handler type */
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
1066 put_be32(pb ,0); /* reserved */
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
1067 put_be32(pb ,0); /* reserved */
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
1068 put_be32(pb ,0); /* reserved */
4953
1b3487b81ac7 fix hdlr descr in mp4 which use c string, patch by Larbi Joubala, larbi dot joubala at resonate-mp4 dot com
bcoudurier
parents: 4941
diff changeset
1069 if (!track || track->mode == MODE_MOV)
1b3487b81ac7 fix hdlr descr in mp4 which use c string, patch by Larbi Joubala, larbi dot joubala at resonate-mp4 dot com
bcoudurier
parents: 4941
diff changeset
1070 put_byte(pb, strlen(descr)); /* pascal string */
399
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
1071 put_buffer(pb, descr, strlen(descr)); /* handler description */
4953
1b3487b81ac7 fix hdlr descr in mp4 which use c string, patch by Larbi Joubala, larbi dot joubala at resonate-mp4 dot com
bcoudurier
parents: 4941
diff changeset
1072 if (track && track->mode != MODE_MOV)
1b3487b81ac7 fix hdlr descr in mp4 which use c string, patch by Larbi Joubala, larbi dot joubala at resonate-mp4 dot com
bcoudurier
parents: 4941
diff changeset
1073 put_byte(pb, 0); /* c string */
399
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
1074 return updateSize(pb, pos);
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
1075 }
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
1076
6013
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1077 static int mov_write_hmhd_tag(ByteIOContext *pb)
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1078 {
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1079 /* This atom must be present, but leaving the values at zero
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1080 * seems harmless. */
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1081 put_be32(pb, 28); /* size */
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1082 put_tag(pb, "hmhd");
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1083 put_be32(pb, 0); /* version, flags */
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1084 put_be16(pb, 0); /* maxPDUsize */
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1085 put_be16(pb, 0); /* avgPDUsize */
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1086 put_be32(pb, 0); /* maxbitrate */
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1087 put_be32(pb, 0); /* avgbitrate */
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1088 put_be32(pb, 0); /* reserved */
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1089 return 28;
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1090 }
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1091
3446
7d73c4a64714 cosmetics
bcoudurier
parents: 3424
diff changeset
1092 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
1093 {
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3909
diff changeset
1094 int64_t pos = url_ftell(pb);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1095 put_be32(pb, 0); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1096 put_tag(pb, "minf");
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5792
diff changeset
1097 if(track->enc->codec_type == AVMEDIA_TYPE_VIDEO)
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
1098 mov_write_vmhd_tag(pb);
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5792
diff changeset
1099 else if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO)
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
1100 mov_write_smhd_tag(pb);
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5792
diff changeset
1101 else if (track->enc->codec_type == AVMEDIA_TYPE_SUBTITLE) {
4699
59ee17ee14fa write correct atoms based on tag and not format, fixes subs stream copy
bcoudurier
parents: 4698
diff changeset
1102 if (track->tag == MKTAG('t','e','x','t')) mov_write_gmhd_tag(pb);
4700
7042140487b7 reindent
bcoudurier
parents: 4699
diff changeset
1103 else mov_write_nmhd_tag(pb);
6013
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1104 } else if (track->tag == MKTAG('r','t','p',' ')) {
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1105 mov_write_hmhd_tag(pb);
4193
2d3be324c648 Add support for muxing mov/mp4/3gp timed text streams
conrad
parents: 4079
diff changeset
1106 }
399
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
1107 if (track->mode == MODE_MOV) /* FIXME: Why do it for MODE_MOV only ? */
6ab5454567b6 * making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents: 397
diff changeset
1108 mov_write_hdlr_tag(pb, NULL);
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
1109 mov_write_dinf_tag(pb);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
1110 mov_write_stbl_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
1111 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1112 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1113
3446
7d73c4a64714 cosmetics
bcoudurier
parents: 3424
diff changeset
1114 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
1115 {
1037
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1116 int version = track->trackDuration < INT32_MAX ? 0 : 1;
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1117
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1118 (version == 1) ? put_be32(pb, 44) : put_be32(pb, 32); /* size */
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1119 put_tag(pb, "mdhd");
1037
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1120 put_byte(pb, version);
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1121 put_be24(pb, 0); /* flags */
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1122 if (version == 1) {
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1123 put_be64(pb, track->time);
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1124 put_be64(pb, track->time);
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1125 } else {
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1126 put_be32(pb, track->time); /* creation time */
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1127 put_be32(pb, track->time); /* modification time */
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1128 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
1129 put_be32(pb, track->timescale); /* time scale (sample rate for audio) */
1037
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1130 (version == 1) ? put_be64(pb, track->trackDuration) : put_be32(pb, track->trackDuration); /* duration */
890
1e49bfea0ffb finally found what those >138 codes were... crappy compressed 5bit ascii. this gets them correctly, and adds setting track lang in movenc too.
mmu_man
parents: 887
diff changeset
1131 put_be16(pb, track->language); /* language */
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1132 put_be16(pb, 0); /* reserved (quality) */
2102
ea6094e10af8 warn the user about the the mdhd problem
michael
parents: 2091
diff changeset
1133
ea6094e10af8 warn the user about the the mdhd problem
michael
parents: 2091
diff changeset
1134 if(version!=0 && track->mode == MODE_MOV){
ea6094e10af8 warn the user about the the mdhd problem
michael
parents: 2091
diff changeset
1135 av_log(NULL, AV_LOG_ERROR,
ea6094e10af8 warn the user about the the mdhd problem
michael
parents: 2091
diff changeset
1136 "FATAL error, file duration too long for timebase, this file will not be\n"
2106
aurel
parents: 2102
diff changeset
1137 "playable with quicktime. Choose a different timebase or a different\n"
2102
ea6094e10af8 warn the user about the the mdhd problem
michael
parents: 2091
diff changeset
1138 "container format\n");
ea6094e10af8 warn the user about the the mdhd problem
michael
parents: 2091
diff changeset
1139 }
ea6094e10af8 warn the user about the the mdhd problem
michael
parents: 2091
diff changeset
1140
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1141 return 32;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1142 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1143
3446
7d73c4a64714 cosmetics
bcoudurier
parents: 3424
diff changeset
1144 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
1145 {
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3909
diff changeset
1146 int64_t pos = url_ftell(pb);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1147 put_be32(pb, 0); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1148 put_tag(pb, "mdia");
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
1149 mov_write_mdhd_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
1150 mov_write_hdlr_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
1151 mov_write_minf_tag(pb, track);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
1152 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1153 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1154
3759
27537074f2a9 convert every muxer/demuxer to write/read sample_aspect_ratio from/to
aurel
parents: 3526
diff changeset
1155 static int mov_write_tkhd_tag(ByteIOContext *pb, MOVTrack *track, AVStream *st)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1156 {
5393
a3853508bb5c remove useless mov timescale field
bcoudurier
parents: 5392
diff changeset
1157 int64_t duration = av_rescale_rnd(track->trackDuration, MOV_TIMESCALE,
a3853508bb5c remove useless mov timescale field
bcoudurier
parents: 5392
diff changeset
1158 track->timescale, AV_ROUND_UP);
1037
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1159 int version = duration < INT32_MAX ? 0 : 1;
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1160
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1161 (version == 1) ? put_be32(pb, 104) : put_be32(pb, 92); /* size */
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1162 put_tag(pb, "tkhd");
1037
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1163 put_byte(pb, version);
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1164 put_be24(pb, 0xf); /* flags (track enabled) */
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1165 if (version == 1) {
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1166 put_be64(pb, track->time);
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1167 put_be64(pb, track->time);
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1168 } else {
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1169 put_be32(pb, track->time); /* creation time */
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1170 put_be32(pb, track->time); /* modification time */
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1171 }
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1172 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
1173 put_be32(pb, 0); /* reserved */
1037
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1174 (version == 1) ? put_be64(pb, duration) : put_be32(pb, duration);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1175
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1176 put_be32(pb, 0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1177 put_be32(pb, 0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1178 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
1179 /* Volume, only for audio */
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5792
diff changeset
1180 if(track->enc->codec_type == AVMEDIA_TYPE_AUDIO)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1181 put_be16(pb, 0x0100);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1182 else
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1183 put_be16(pb, 0);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1184 put_be16(pb, 0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1185
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1186 /* Matrix structure */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1187 put_be32(pb, 0x00010000); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1188 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1189 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1190 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1191 put_be32(pb, 0x00010000); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1192 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1193 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1194 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1195 put_be32(pb, 0x40000000); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1196
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1197 /* Track width and height, for visual only */
5993
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
1198 if(st && (track->enc->codec_type == AVMEDIA_TYPE_VIDEO ||
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
1199 track->enc->codec_type == AVMEDIA_TYPE_SUBTITLE)) {
3759
27537074f2a9 convert every muxer/demuxer to write/read sample_aspect_ratio from/to
aurel
parents: 3526
diff changeset
1200 double sample_aspect_ratio = av_q2d(st->sample_aspect_ratio);
4463
0cd7acf426f3 write active picture height for d-10/imx in mov
bcoudurier
parents: 4251
diff changeset
1201 if(!sample_aspect_ratio || track->height != track->enc->height)
0cd7acf426f3 write active picture height for d-10/imx in mov
bcoudurier
parents: 4251
diff changeset
1202 sample_aspect_ratio = 1;
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
1203 put_be32(pb, sample_aspect_ratio * track->enc->width*0x10000);
4463
0cd7acf426f3 write active picture height for d-10/imx in mov
bcoudurier
parents: 4251
diff changeset
1204 put_be32(pb, track->height*0x10000);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1205 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1206 else {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1207 put_be32(pb, 0);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1208 put_be32(pb, 0);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1209 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1210 return 0x5c;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1211 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1212
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1213 // This box seems important for the psp playback ... without it the movie seems to hang
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1214 static int mov_write_edts_tag(ByteIOContext *pb, MOVTrack *track)
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1215 {
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1216 put_be32(pb, 0x24); /* size */
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1217 put_tag(pb, "edts");
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1218 put_be32(pb, 0x1c); /* size */
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1219 put_tag(pb, "elst");
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1220 put_be32(pb, 0x0);
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1221 put_be32(pb, 0x1);
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1222
5393
a3853508bb5c remove useless mov timescale field
bcoudurier
parents: 5392
diff changeset
1223 /* duration ... doesn't seem to effect psp */
a3853508bb5c remove useless mov timescale field
bcoudurier
parents: 5392
diff changeset
1224 put_be32(pb, av_rescale_rnd(track->trackDuration, MOV_TIMESCALE,
a3853508bb5c remove useless mov timescale field
bcoudurier
parents: 5392
diff changeset
1225 track->timescale, AV_ROUND_UP));
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1226
1250
0492aa3dffc9 set elst start time to first pts
bcoudurier
parents: 1241
diff changeset
1227 put_be32(pb, track->cluster[0].cts); /* first pts is cts since dts is 0 */
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1228 put_be32(pb, 0x00010000);
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1229 return 0x24;
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1230 }
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1231
5993
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
1232 static int mov_write_tref_tag(ByteIOContext *pb, MOVTrack *track)
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
1233 {
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
1234 put_be32(pb, 20); // size
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
1235 put_tag(pb, "tref");
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
1236 put_be32(pb, 12); // size (subatom)
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
1237 put_le32(pb, track->tref_tag);
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
1238 put_be32(pb, track->tref_id);
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
1239 return 20;
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
1240 }
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
1241
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1242 // goes at the end of each track! ... Critical for PSP playback ("Incompatible data" without it)
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1243 static int mov_write_uuid_tag_psp(ByteIOContext *pb, MOVTrack *mov)
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1244 {
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1245 put_be32(pb, 0x34); /* size ... reports as 28 in mp4box! */
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1246 put_tag(pb, "uuid");
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1247 put_tag(pb, "USMT");
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1248 put_be32(pb, 0x21d24fce);
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1249 put_be32(pb, 0xbb88695c);
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1250 put_be32(pb, 0xfac9c740);
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1251 put_be32(pb, 0x1c); // another size here!
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1252 put_tag(pb, "MTDT");
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1253 put_be32(pb, 0x00010012);
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1254 put_be32(pb, 0x0a);
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1255 put_be32(pb, 0x55c40000);
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1256 put_be32(pb, 0x1);
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1257 put_be32(pb, 0x0);
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1258 return 0x34;
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1259 }
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1260
6013
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1261 static int mov_write_udta_sdp(ByteIOContext *pb, AVCodecContext *ctx, int index)
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1262 {
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1263 char buf[1000] = "";
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1264 int len;
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1265
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1266 ff_sdp_write_media(buf, sizeof(buf), ctx, NULL, 0, 0);
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1267 av_strlcatf(buf, sizeof(buf), "a=control:streamid=%d\r\n", index);
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1268 len = strlen(buf);
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1269
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1270 put_be32(pb, len + 24);
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1271 put_tag (pb, "udta");
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1272 put_be32(pb, len + 16);
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1273 put_tag (pb, "hnti");
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1274 put_be32(pb, len + 8);
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1275 put_tag (pb, "sdp ");
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1276 put_buffer(pb, buf, len);
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1277 return len + 24;
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1278 }
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1279
3759
27537074f2a9 convert every muxer/demuxer to write/read sample_aspect_ratio from/to
aurel
parents: 3526
diff changeset
1280 static int mov_write_trak_tag(ByteIOContext *pb, MOVTrack *track, AVStream *st)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1281 {
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3909
diff changeset
1282 int64_t pos = url_ftell(pb);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1283 put_be32(pb, 0); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1284 put_tag(pb, "trak");
3759
27537074f2a9 convert every muxer/demuxer to write/read sample_aspect_ratio from/to
aurel
parents: 3526
diff changeset
1285 mov_write_tkhd_tag(pb, track, st);
4941
45a08facad6f write 'stps' for mpeg-2 open gop in .mov
bcoudurier
parents: 4937
diff changeset
1286 if (track->mode == MODE_PSP || track->flags & MOV_TRACK_CTTS)
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1287 mov_write_edts_tag(pb, track); // PSP Movies require edts box
5993
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
1288 if (track->tref_tag)
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
1289 mov_write_tref_tag(pb, track);
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
1290 mov_write_mdia_tag(pb, track);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
1291 if (track->mode == MODE_PSP)
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1292 mov_write_uuid_tag_psp(pb,track); // PSP Movies require this uuid box
6013
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1293 if (track->tag == MKTAG('r','t','p',' '))
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1294 mov_write_udta_sdp(pb, track->rtp_ctx->streams[0]->codec, track->trackID);
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
1295 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1296 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1297
683
095009fc2f35 kill warnings patch by (M«©ns Rullg«©rd <mru inprovide com>)
michael
parents: 677
diff changeset
1298 #if 0
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1299 /* TODO: Not sorted out, but not necessary either */
4609
065557d6fffb Rename movenc.c MOVContext to MOVMuxContext, since MOVContext is already used
rbultje
parents: 4587
diff changeset
1300 static int mov_write_iods_tag(ByteIOContext *pb, MOVMuxContext *mov)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1301 {
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1302 put_be32(pb, 0x15); /* size */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1303 put_tag(pb, "iods");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1304 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
1305 put_be16(pb, 0x1007);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1306 put_byte(pb, 0);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1307 put_be16(pb, 0x4fff);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1308 put_be16(pb, 0xfffe);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1309 put_be16(pb, 0x01ff);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1310 return 0x15;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1311 }
683
095009fc2f35 kill warnings patch by (M«©ns Rullg«©rd <mru inprovide com>)
michael
parents: 677
diff changeset
1312 #endif
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1313
4609
065557d6fffb Rename movenc.c MOVContext to MOVMuxContext, since MOVContext is already used
rbultje
parents: 4587
diff changeset
1314 static int mov_write_mvhd_tag(ByteIOContext *pb, MOVMuxContext *mov)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1315 {
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
1316 int maxTrackID = 1, i;
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
1317 int64_t maxTrackLenTemp, maxTrackLen = 0;
1037
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1318 int version;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1319
1131
a9f78ea5c6a3 check only existing streams
bcoudurier
parents: 1129
diff changeset
1320 for (i=0; i<mov->nb_streams; i++) {
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1321 if(mov->tracks[i].entry > 0) {
5393
a3853508bb5c remove useless mov timescale field
bcoudurier
parents: 5392
diff changeset
1322 maxTrackLenTemp = av_rescale_rnd(mov->tracks[i].trackDuration,
a3853508bb5c remove useless mov timescale field
bcoudurier
parents: 5392
diff changeset
1323 MOV_TIMESCALE,
a3853508bb5c remove useless mov timescale field
bcoudurier
parents: 5392
diff changeset
1324 mov->tracks[i].timescale,
a3853508bb5c remove useless mov timescale field
bcoudurier
parents: 5392
diff changeset
1325 AV_ROUND_UP);
259
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
1326 if(maxTrackLen < maxTrackLenTemp)
e091218eccd2 mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents: 241
diff changeset
1327 maxTrackLen = maxTrackLenTemp;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1328 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
1329 maxTrackID = mov->tracks[i].trackID;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1330 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1331 }
1037
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1332
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1333 version = maxTrackLen < UINT32_MAX ? 0 : 1;
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1334 (version == 1) ? put_be32(pb, 120) : put_be32(pb, 108); /* size */
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1335 put_tag(pb, "mvhd");
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1336 put_byte(pb, version);
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1337 put_be24(pb, 0); /* flags */
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1338 if (version == 1) {
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1339 put_be64(pb, mov->time);
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1340 put_be64(pb, mov->time);
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1341 } else {
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1342 put_be32(pb, mov->time); /* creation time */
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1343 put_be32(pb, mov->time); /* modification time */
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1344 }
5393
a3853508bb5c remove useless mov timescale field
bcoudurier
parents: 5392
diff changeset
1345 put_be32(pb, MOV_TIMESCALE);
1037
aa2712de50bf use 64bit atom version if needed
bcoudurier
parents: 1026
diff changeset
1346 (version == 1) ? put_be64(pb, maxTrackLen) : put_be32(pb, maxTrackLen); /* duration of longest track */
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1347
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1348 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
1349 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
1350 put_be16(pb, 0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1351 put_be32(pb, 0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1352 put_be32(pb, 0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1353
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1354 /* Matrix structure */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1355 put_be32(pb, 0x00010000); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1356 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1357 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1358 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1359 put_be32(pb, 0x00010000); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1360 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1361 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1362 put_be32(pb, 0x0); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1363 put_be32(pb, 0x40000000); /* reserved */
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1364
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1365 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
1366 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
1367 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
1368 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
1369 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
1370 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
1371 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
1372 return 0x6c;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1373 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1374
4609
065557d6fffb Rename movenc.c MOVContext to MOVMuxContext, since MOVContext is already used
rbultje
parents: 4587
diff changeset
1375 static int mov_write_itunes_hdlr_tag(ByteIOContext *pb, MOVMuxContext *mov,
513
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1376 AVFormatContext *s)
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1377 {
5947
8b59caee931c Predicting the size of the hdlr, string data and trkn tags in the MOV muxer
thardin
parents: 5913
diff changeset
1378 put_be32(pb, 33); /* size */
513
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1379 put_tag(pb, "hdlr");
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1380 put_be32(pb, 0);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1381 put_be32(pb, 0);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1382 put_tag(pb, "mdir");
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1383 put_tag(pb, "appl");
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1384 put_be32(pb, 0);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1385 put_be32(pb, 0);
5375
222bbba5fd35 Do not write an extra byte in the iTunes 'hdlr' tag. The files on iTMS have an
jbr
parents: 5058
diff changeset
1386 put_byte(pb, 0);
5947
8b59caee931c Predicting the size of the hdlr, string data and trkn tags in the MOV muxer
thardin
parents: 5913
diff changeset
1387 return 33;
513
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1388 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1389
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1390 /* helper function to write a data tag with the specified string as data */
4587
b41ab5937218 movenc: add muxing of language along with metadata tags when available
aurel
parents: 4586
diff changeset
1391 static int mov_write_string_data_tag(ByteIOContext *pb, const char *data, int lang, int long_style)
513
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1392 {
1094
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1393 if(long_style){
5947
8b59caee931c Predicting the size of the hdlr, string data and trkn tags in the MOV muxer
thardin
parents: 5913
diff changeset
1394 int size = 16 + strlen(data);
8b59caee931c Predicting the size of the hdlr, string data and trkn tags in the MOV muxer
thardin
parents: 5913
diff changeset
1395 put_be32(pb, size); /* size */
1094
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1396 put_tag(pb, "data");
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1397 put_be32(pb, 1);
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1398 put_be32(pb, 0);
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1399 put_buffer(pb, data, strlen(data));
5947
8b59caee931c Predicting the size of the hdlr, string data and trkn tags in the MOV muxer
thardin
parents: 5913
diff changeset
1400 return size;
1094
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1401 }else{
5792
2fb291f12e5f Fix encoder metadata string langcode in mov muxer
bcoudurier
parents: 5791
diff changeset
1402 if (!lang)
2fb291f12e5f Fix encoder metadata string langcode in mov muxer
bcoudurier
parents: 5791
diff changeset
1403 lang = ff_mov_iso639_to_lang("und", 1);
1094
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1404 put_be16(pb, strlen(data)); /* string length */
4587
b41ab5937218 movenc: add muxing of language along with metadata tags when available
aurel
parents: 4586
diff changeset
1405 put_be16(pb, lang);
1094
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1406 put_buffer(pb, data, strlen(data));
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1407 return strlen(data) + 4;
513
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1408 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1409 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1410
4587
b41ab5937218 movenc: add muxing of language along with metadata tags when available
aurel
parents: 4586
diff changeset
1411 static int mov_write_string_tag(ByteIOContext *pb, const char *name, const char *value, int lang, int long_style){
513
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1412 int size = 0;
3024
19de43025f0f cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents: 3010
diff changeset
1413 if (value && value[0]) {
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3909
diff changeset
1414 int64_t pos = url_ftell(pb);
513
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1415 put_be32(pb, 0); /* size */
1094
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1416 put_tag(pb, name);
4587
b41ab5937218 movenc: add muxing of language along with metadata tags when available
aurel
parents: 4586
diff changeset
1417 mov_write_string_data_tag(pb, value, lang, long_style);
1094
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1418 size= updateSize(pb, pos);
513
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1419 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1420 return size;
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1421 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1422
4584
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1423 static int mov_write_string_metadata(AVFormatContext *s, ByteIOContext *pb,
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1424 const char *name, const char *tag,
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1425 int long_style)
513
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1426 {
4587
b41ab5937218 movenc: add muxing of language along with metadata tags when available
aurel
parents: 4586
diff changeset
1427 int l, lang = 0, len, len2;
b41ab5937218 movenc: add muxing of language along with metadata tags when available
aurel
parents: 4586
diff changeset
1428 AVMetadataTag *t, *t2 = NULL;
b41ab5937218 movenc: add muxing of language along with metadata tags when available
aurel
parents: 4586
diff changeset
1429 char tag2[16];
4584
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1430
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1431 if (!(t = av_metadata_get(s->metadata, tag, NULL, 0)))
1094
1010b89986bd simplify meta tag writing code
michael
parents: 1088
diff changeset
1432 return 0;
4584
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1433
4587
b41ab5937218 movenc: add muxing of language along with metadata tags when available
aurel
parents: 4586
diff changeset
1434 len = strlen(t->key);
b41ab5937218 movenc: add muxing of language along with metadata tags when available
aurel
parents: 4586
diff changeset
1435 snprintf(tag2, sizeof(tag2), "%s-", tag);
b41ab5937218 movenc: add muxing of language along with metadata tags when available
aurel
parents: 4586
diff changeset
1436 while ((t2 = av_metadata_get(s->metadata, tag2, t2, AV_METADATA_IGNORE_SUFFIX))) {
b41ab5937218 movenc: add muxing of language along with metadata tags when available
aurel
parents: 4586
diff changeset
1437 len2 = strlen(t2->key);
b41ab5937218 movenc: add muxing of language along with metadata tags when available
aurel
parents: 4586
diff changeset
1438 if (len2 == len+4 && !strcmp(t->value, t2->value)
5791
9cde0ca98839 Correctly mark mov metadata as utf-8, using iso language code
bcoudurier
parents: 5618
diff changeset
1439 && (l=ff_mov_iso639_to_lang(&t2->key[len2-3], 1)) >= 0) {
4587
b41ab5937218 movenc: add muxing of language along with metadata tags when available
aurel
parents: 4586
diff changeset
1440 lang = l;
b41ab5937218 movenc: add muxing of language along with metadata tags when available
aurel
parents: 4586
diff changeset
1441 break;
b41ab5937218 movenc: add muxing of language along with metadata tags when available
aurel
parents: 4586
diff changeset
1442 }
b41ab5937218 movenc: add muxing of language along with metadata tags when available
aurel
parents: 4586
diff changeset
1443 }
b41ab5937218 movenc: add muxing of language along with metadata tags when available
aurel
parents: 4586
diff changeset
1444 return mov_write_string_tag(pb, name, t->value, lang, long_style);
513
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1445 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1446
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1447 /* iTunes track number */
4609
065557d6fffb Rename movenc.c MOVContext to MOVMuxContext, since MOVContext is already used
rbultje
parents: 4587
diff changeset
1448 static int mov_write_trkn_tag(ByteIOContext *pb, MOVMuxContext *mov,
513
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1449 AVFormatContext *s)
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1450 {
4584
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1451 AVMetadataTag *t = av_metadata_get(s->metadata, "track", NULL, 0);
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1452 int size = 0, track = t ? atoi(t->value) : 0;
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1453 if (track) {
5947
8b59caee931c Predicting the size of the hdlr, string data and trkn tags in the MOV muxer
thardin
parents: 5913
diff changeset
1454 put_be32(pb, 32); /* size */
513
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1455 put_tag(pb, "trkn");
5947
8b59caee931c Predicting the size of the hdlr, string data and trkn tags in the MOV muxer
thardin
parents: 5913
diff changeset
1456 put_be32(pb, 24); /* size */
513
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1457 put_tag(pb, "data");
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1458 put_be32(pb, 0); // 8 bytes empty
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1459 put_be32(pb, 0);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1460 put_be16(pb, 0); // empty
4584
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1461 put_be16(pb, track); // track number
513
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1462 put_be16(pb, 0); // total track number
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1463 put_be16(pb, 0); // empty
5947
8b59caee931c Predicting the size of the hdlr, string data and trkn tags in the MOV muxer
thardin
parents: 5913
diff changeset
1464 size = 32;
513
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1465 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1466 return size;
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1467 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1468
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1469 /* iTunes meta data list */
4609
065557d6fffb Rename movenc.c MOVContext to MOVMuxContext, since MOVContext is already used
rbultje
parents: 4587
diff changeset
1470 static int mov_write_ilst_tag(ByteIOContext *pb, MOVMuxContext *mov,
513
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1471 AVFormatContext *s)
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1472 {
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3909
diff changeset
1473 int64_t pos = url_ftell(pb);
513
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1474 put_be32(pb, 0); /* size */
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1475 put_tag(pb, "ilst");
4584
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1476 mov_write_string_metadata(s, pb, "\251nam", "title" , 1);
6040
2bab410094e0 change author metadata to artist in mov de/muxer
bcoudurier
parents: 6013
diff changeset
1477 mov_write_string_metadata(s, pb, "\251ART", "artist" , 1);
5492
2aecc666c976 Add support for these widely-used iTunes metadata fields: Album Artist,
melanson
parents: 5394
diff changeset
1478 mov_write_string_metadata(s, pb, "aART", "album_artist", 1);
5381
b54fa3ff2f61 MOV: Fix writing \251wrt metadata (r20453 only fixed the demuxer)
conrad
parents: 5375
diff changeset
1479 mov_write_string_metadata(s, pb, "\251wrt", "composer" , 1);
4584
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1480 mov_write_string_metadata(s, pb, "\251alb", "album" , 1);
5618
27fd77f20a89 Add a list of generic tags and change demuxers to follow it.
pross
parents: 5556
diff changeset
1481 mov_write_string_metadata(s, pb, "\251day", "date" , 1);
4587
b41ab5937218 movenc: add muxing of language along with metadata tags when available
aurel
parents: 4586
diff changeset
1482 mov_write_string_tag(pb, "\251too", LIBAVFORMAT_IDENT, 0, 1);
4584
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1483 mov_write_string_metadata(s, pb, "\251cmt", "comment" , 1);
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1484 mov_write_string_metadata(s, pb, "\251gen", "genre" , 1);
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1485 mov_write_string_metadata(s, pb, "\251cpy", "copyright", 1);
5492
2aecc666c976 Add support for these widely-used iTunes metadata fields: Album Artist,
melanson
parents: 5394
diff changeset
1486 mov_write_string_metadata(s, pb, "\251grp", "grouping" , 1);
2aecc666c976 Add support for these widely-used iTunes metadata fields: Album Artist,
melanson
parents: 5394
diff changeset
1487 mov_write_string_metadata(s, pb, "\251lyr", "lyrics" , 1);
5382
45d0832f48b6 MOV: Add several iTunes metadata tags
conrad
parents: 5381
diff changeset
1488 mov_write_string_metadata(s, pb, "desc", "description",1);
45d0832f48b6 MOV: Add several iTunes metadata tags
conrad
parents: 5381
diff changeset
1489 mov_write_string_metadata(s, pb, "ldes", "synopsis" , 1);
45d0832f48b6 MOV: Add several iTunes metadata tags
conrad
parents: 5381
diff changeset
1490 mov_write_string_metadata(s, pb, "tvsh", "show" , 1);
45d0832f48b6 MOV: Add several iTunes metadata tags
conrad
parents: 5381
diff changeset
1491 mov_write_string_metadata(s, pb, "tven", "episode_id",1);
45d0832f48b6 MOV: Add several iTunes metadata tags
conrad
parents: 5381
diff changeset
1492 mov_write_string_metadata(s, pb, "tvnn", "network" , 1);
513
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1493 mov_write_trkn_tag(pb, mov, s);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1494 return updateSize(pb, pos);
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1495 }
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1496
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1497 /* iTunes meta data tag */
4609
065557d6fffb Rename movenc.c MOVContext to MOVMuxContext, since MOVContext is already used
rbultje
parents: 4587
diff changeset
1498 static int mov_write_meta_tag(ByteIOContext *pb, MOVMuxContext *mov,
513
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1499 AVFormatContext *s)
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1500 {
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1501 int size = 0;
4585
f777070fd15b cosmetics: indentation
aurel
parents: 4584
diff changeset
1502 int64_t pos = url_ftell(pb);
f777070fd15b cosmetics: indentation
aurel
parents: 4584
diff changeset
1503 put_be32(pb, 0); /* size */
f777070fd15b cosmetics: indentation
aurel
parents: 4584
diff changeset
1504 put_tag(pb, "meta");
f777070fd15b cosmetics: indentation
aurel
parents: 4584
diff changeset
1505 put_be32(pb, 0);
f777070fd15b cosmetics: indentation
aurel
parents: 4584
diff changeset
1506 mov_write_itunes_hdlr_tag(pb, mov, s);
f777070fd15b cosmetics: indentation
aurel
parents: 4584
diff changeset
1507 mov_write_ilst_tag(pb, mov, s);
f777070fd15b cosmetics: indentation
aurel
parents: 4584
diff changeset
1508 size = updateSize(pb, pos);
513
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1509 return size;
2b4edca40885 iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents: 505
diff changeset
1510 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
1511
3459
a79f6237c3d2 move utf8 code before udta func, will be used by 3gp tags
bcoudurier
parents: 3458
diff changeset
1512 static int utf8len(const uint8_t *b)
a79f6237c3d2 move utf8 code before udta func, will be used by 3gp tags
bcoudurier
parents: 3458
diff changeset
1513 {
a79f6237c3d2 move utf8 code before udta func, will be used by 3gp tags
bcoudurier
parents: 3458
diff changeset
1514 int len=0;
a79f6237c3d2 move utf8 code before udta func, will be used by 3gp tags
bcoudurier
parents: 3458
diff changeset
1515 int val;
a79f6237c3d2 move utf8 code before udta func, will be used by 3gp tags
bcoudurier
parents: 3458
diff changeset
1516 while(*b){
a79f6237c3d2 move utf8 code before udta func, will be used by 3gp tags
bcoudurier
parents: 3458
diff changeset
1517 GET_UTF8(val, *b++, return -1;)
a79f6237c3d2 move utf8 code before udta func, will be used by 3gp tags
bcoudurier
parents: 3458
diff changeset
1518 len++;
a79f6237c3d2 move utf8 code before udta func, will be used by 3gp tags
bcoudurier
parents: 3458
diff changeset
1519 }
a79f6237c3d2 move utf8 code before udta func, will be used by 3gp tags
bcoudurier
parents: 3458
diff changeset
1520 return len;
a79f6237c3d2 move utf8 code before udta func, will be used by 3gp tags
bcoudurier
parents: 3458
diff changeset
1521 }
a79f6237c3d2 move utf8 code before udta func, will be used by 3gp tags
bcoudurier
parents: 3458
diff changeset
1522
a79f6237c3d2 move utf8 code before udta func, will be used by 3gp tags
bcoudurier
parents: 3458
diff changeset
1523 static int ascii_to_wc(ByteIOContext *pb, const uint8_t *b)
a79f6237c3d2 move utf8 code before udta func, will be used by 3gp tags
bcoudurier
parents: 3458
diff changeset
1524 {
a79f6237c3d2 move utf8 code before udta func, will be used by 3gp tags
bcoudurier
parents: 3458
diff changeset
1525 int val;
a79f6237c3d2 move utf8 code before udta func, will be used by 3gp tags
bcoudurier
parents: 3458
diff changeset
1526 while(*b){
a79f6237c3d2 move utf8 code before udta func, will be used by 3gp tags
bcoudurier
parents: 3458
diff changeset
1527 GET_UTF8(val, *b++, return -1;)
a79f6237c3d2 move utf8 code before udta func, will be used by 3gp tags
bcoudurier
parents: 3458
diff changeset
1528 put_be16(pb, val);
a79f6237c3d2 move utf8 code before udta func, will be used by 3gp tags
bcoudurier
parents: 3458
diff changeset
1529 }
a79f6237c3d2 move utf8 code before udta func, will be used by 3gp tags
bcoudurier
parents: 3458
diff changeset
1530 put_be16(pb, 0x00);
a79f6237c3d2 move utf8 code before udta func, will be used by 3gp tags
bcoudurier
parents: 3458
diff changeset
1531 return 0;
a79f6237c3d2 move utf8 code before udta func, will be used by 3gp tags
bcoudurier
parents: 3458
diff changeset
1532 }
a79f6237c3d2 move utf8 code before udta func, will be used by 3gp tags
bcoudurier
parents: 3458
diff changeset
1533
a79f6237c3d2 move utf8 code before udta func, will be used by 3gp tags
bcoudurier
parents: 3458
diff changeset
1534 static uint16_t language_code(const char *str)
a79f6237c3d2 move utf8 code before udta func, will be used by 3gp tags
bcoudurier
parents: 3458
diff changeset
1535 {
a79f6237c3d2 move utf8 code before udta func, will be used by 3gp tags
bcoudurier
parents: 3458
diff changeset
1536 return (((str[0]-0x60) & 0x1F) << 10) + (((str[1]-0x60) & 0x1F) << 5) + ((str[2]-0x60) & 0x1F);
a79f6237c3d2 move utf8 code before udta func, will be used by 3gp tags
bcoudurier
parents: 3458
diff changeset
1537 }
a79f6237c3d2 move utf8 code before udta func, will be used by 3gp tags
bcoudurier
parents: 3458
diff changeset
1538
3460
bd563026a5af support for 3gp metadata
bcoudurier
parents: 3459
diff changeset
1539 static int mov_write_3gp_udta_tag(ByteIOContext *pb, AVFormatContext *s,
bd563026a5af support for 3gp metadata
bcoudurier
parents: 3459
diff changeset
1540 const char *tag, const char *str)
bd563026a5af support for 3gp metadata
bcoudurier
parents: 3459
diff changeset
1541 {
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3909
diff changeset
1542 int64_t pos = url_ftell(pb);
4584
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1543 AVMetadataTag *t = av_metadata_get(s->metadata, str, NULL, 0);
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1544 if (!t || !utf8len(t->value))
3460
bd563026a5af support for 3gp metadata
bcoudurier
parents: 3459
diff changeset
1545 return 0;
bd563026a5af support for 3gp metadata
bcoudurier
parents: 3459
diff changeset
1546 put_be32(pb, 0); /* size */
bd563026a5af support for 3gp metadata
bcoudurier
parents: 3459
diff changeset
1547 put_tag (pb, tag); /* type */
bd563026a5af support for 3gp metadata
bcoudurier
parents: 3459
diff changeset
1548 put_be32(pb, 0); /* version + flags */
bd563026a5af support for 3gp metadata
bcoudurier
parents: 3459
diff changeset
1549 if (!strcmp(tag, "yrrc"))
4584
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1550 put_be16(pb, atoi(t->value));
3460
bd563026a5af support for 3gp metadata
bcoudurier
parents: 3459
diff changeset
1551 else {
bd563026a5af support for 3gp metadata
bcoudurier
parents: 3459
diff changeset
1552 put_be16(pb, language_code("eng")); /* language */
4996
9d88db925e05 fix 3gp metadata, write strings in UTF8, patch by Larbi Joubala, larbi dot joubala at resonate-mp4 dot com
bcoudurier
parents: 4953
diff changeset
1553 put_buffer(pb, t->value, strlen(t->value)+1); /* UTF8 string value */
4584
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1554 if (!strcmp(tag, "albm") &&
6041
de15f3f1f2ba albm 3gp tag has optional track field not date
bcoudurier
parents: 6040
diff changeset
1555 (t = av_metadata_get(s->metadata, "track", NULL, 0)))
4584
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1556 put_byte(pb, atoi(t->value));
3460
bd563026a5af support for 3gp metadata
bcoudurier
parents: 3459
diff changeset
1557 }
bd563026a5af support for 3gp metadata
bcoudurier
parents: 3459
diff changeset
1558 return updateSize(pb, pos);
bd563026a5af support for 3gp metadata
bcoudurier
parents: 3459
diff changeset
1559 }
bd563026a5af support for 3gp metadata
bcoudurier
parents: 3459
diff changeset
1560
5974
0361768bfa73 movenc: Write nero chapters
conrad
parents: 5947
diff changeset
1561 static int mov_write_chpl_tag(ByteIOContext *pb, AVFormatContext *s)
0361768bfa73 movenc: Write nero chapters
conrad
parents: 5947
diff changeset
1562 {
0361768bfa73 movenc: Write nero chapters
conrad
parents: 5947
diff changeset
1563 int64_t pos = url_ftell(pb);
0361768bfa73 movenc: Write nero chapters
conrad
parents: 5947
diff changeset
1564 int i, nb_chapters = FFMIN(s->nb_chapters, 255);
0361768bfa73 movenc: Write nero chapters
conrad
parents: 5947
diff changeset
1565
0361768bfa73 movenc: Write nero chapters
conrad
parents: 5947
diff changeset
1566 put_be32(pb, 0); // size
0361768bfa73 movenc: Write nero chapters
conrad
parents: 5947
diff changeset
1567 put_tag (pb, "chpl");
0361768bfa73 movenc: Write nero chapters
conrad
parents: 5947
diff changeset
1568 put_be32(pb, 0x01000000); // version + flags
0361768bfa73 movenc: Write nero chapters
conrad
parents: 5947
diff changeset
1569 put_be32(pb, 0); // unknown
0361768bfa73 movenc: Write nero chapters
conrad
parents: 5947
diff changeset
1570 put_byte(pb, nb_chapters);
0361768bfa73 movenc: Write nero chapters
conrad
parents: 5947
diff changeset
1571
0361768bfa73 movenc: Write nero chapters
conrad
parents: 5947
diff changeset
1572 for (i = 0; i < nb_chapters; i++) {
0361768bfa73 movenc: Write nero chapters
conrad
parents: 5947
diff changeset
1573 AVChapter *c = s->chapters[i];
0361768bfa73 movenc: Write nero chapters
conrad
parents: 5947
diff changeset
1574 AVMetadataTag *t;
0361768bfa73 movenc: Write nero chapters
conrad
parents: 5947
diff changeset
1575 put_be64(pb, av_rescale_q(c->start, c->time_base, (AVRational){1,10000000}));
0361768bfa73 movenc: Write nero chapters
conrad
parents: 5947
diff changeset
1576
0361768bfa73 movenc: Write nero chapters
conrad
parents: 5947
diff changeset
1577 if ((t = av_metadata_get(c->metadata, "title", NULL, 0))) {
0361768bfa73 movenc: Write nero chapters
conrad
parents: 5947
diff changeset
1578 int len = FFMIN(strlen(t->value), 255);
0361768bfa73 movenc: Write nero chapters
conrad
parents: 5947
diff changeset
1579 put_byte(pb, len);
0361768bfa73 movenc: Write nero chapters
conrad
parents: 5947
diff changeset
1580 put_buffer(pb, t->value, len);
0361768bfa73 movenc: Write nero chapters
conrad
parents: 5947
diff changeset
1581 } else
0361768bfa73 movenc: Write nero chapters
conrad
parents: 5947
diff changeset
1582 put_byte(pb, 0);
0361768bfa73 movenc: Write nero chapters
conrad
parents: 5947
diff changeset
1583 }
0361768bfa73 movenc: Write nero chapters
conrad
parents: 5947
diff changeset
1584 return updateSize(pb, pos);
0361768bfa73 movenc: Write nero chapters
conrad
parents: 5947
diff changeset
1585 }
0361768bfa73 movenc: Write nero chapters
conrad
parents: 5947
diff changeset
1586
4609
065557d6fffb Rename movenc.c MOVContext to MOVMuxContext, since MOVContext is already used
rbultje
parents: 4587
diff changeset
1587 static int mov_write_udta_tag(ByteIOContext *pb, MOVMuxContext *mov,
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
1588 AVFormatContext *s)
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
1589 {
4584
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1590 ByteIOContext *pb_buf;
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1591 int i, ret, size;
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1592 uint8_t *buf;
2668
8d400e382d6e Prevent mov muxer from writing empty udta atoms.
benoit
parents: 2617
diff changeset
1593
3450
0e53bfbd3a1c rework udta handling, if any track set bitexact, don't write any metadata
bcoudurier
parents: 3449
diff changeset
1594 for (i = 0; i < s->nb_streams; i++)
0e53bfbd3a1c rework udta handling, if any track set bitexact, don't write any metadata
bcoudurier
parents: 3449
diff changeset
1595 if (mov->tracks[i].enc->flags & CODEC_FLAG_BITEXACT) {
4584
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1596 return 0;
3450
0e53bfbd3a1c rework udta handling, if any track set bitexact, don't write any metadata
bcoudurier
parents: 3449
diff changeset
1597 }
0e53bfbd3a1c rework udta handling, if any track set bitexact, don't write any metadata
bcoudurier
parents: 3449
diff changeset
1598
4584
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1599 ret = url_open_dyn_buf(&pb_buf);
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1600 if(ret < 0)
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1601 return ret;
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
1602
3466
b00b81c315e5 simplify MODE_3G2
michael
parents: 3465
diff changeset
1603 if (mov->mode & MODE_3GP) {
6042
0b0e8fff6673 write 3gp perf tag for artist metadata
bcoudurier
parents: 6041
diff changeset
1604 mov_write_3gp_udta_tag(pb_buf, s, "perf", "artist");
4584
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1605 mov_write_3gp_udta_tag(pb_buf, s, "titl", "title");
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1606 mov_write_3gp_udta_tag(pb_buf, s, "auth", "author");
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1607 mov_write_3gp_udta_tag(pb_buf, s, "gnre", "genre");
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1608 mov_write_3gp_udta_tag(pb_buf, s, "dscp", "comment");
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1609 mov_write_3gp_udta_tag(pb_buf, s, "albm", "album");
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1610 mov_write_3gp_udta_tag(pb_buf, s, "cprt", "copyright");
5618
27fd77f20a89 Add a list of generic tags and change demuxers to follow it.
pross
parents: 5556
diff changeset
1611 mov_write_3gp_udta_tag(pb_buf, s, "yrrc", "date");
3464
88e25bd62781 cosmetics, reindent
bcoudurier
parents: 3463
diff changeset
1612 } else if (mov->mode == MODE_MOV) { // the title field breaks gtkpod with mp4 and my suspicion is that stuff is not valid in mp4
4584
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1613 mov_write_string_metadata(s, pb_buf, "\251nam", "title" , 0);
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1614 mov_write_string_metadata(s, pb_buf, "\251aut", "author" , 0);
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1615 mov_write_string_metadata(s, pb_buf, "\251alb", "album" , 0);
5618
27fd77f20a89 Add a list of generic tags and change demuxers to follow it.
pross
parents: 5556
diff changeset
1616 mov_write_string_metadata(s, pb_buf, "\251day", "date" , 0);
4587
b41ab5937218 movenc: add muxing of language along with metadata tags when available
aurel
parents: 4586
diff changeset
1617 mov_write_string_tag(pb_buf, "\251enc", LIBAVFORMAT_IDENT, 0, 0);
4584
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1618 mov_write_string_metadata(s, pb_buf, "\251des", "comment" , 0);
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1619 mov_write_string_metadata(s, pb_buf, "\251gen", "genre" , 0);
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1620 mov_write_string_metadata(s, pb_buf, "\251cpy", "copyright" , 0);
3460
bd563026a5af support for 3gp metadata
bcoudurier
parents: 3459
diff changeset
1621 } else {
3463
91a688e89d31 don't write double sets of metadata in mov, only write usual ones
bcoudurier
parents: 3461
diff changeset
1622 /* iTunes meta data */
4584
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1623 mov_write_meta_tag(pb_buf, mov, s);
3460
bd563026a5af support for 3gp metadata
bcoudurier
parents: 3459
diff changeset
1624 }
4584
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1625
5974
0361768bfa73 movenc: Write nero chapters
conrad
parents: 5947
diff changeset
1626 if (s->nb_chapters)
0361768bfa73 movenc: Write nero chapters
conrad
parents: 5947
diff changeset
1627 mov_write_chpl_tag(pb_buf, s);
0361768bfa73 movenc: Write nero chapters
conrad
parents: 5947
diff changeset
1628
4584
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1629 if ((size = url_close_dyn_buf(pb_buf, &buf)) > 0) {
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1630 put_be32(pb, size+8);
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1631 put_tag(pb, "udta");
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1632 put_buffer(pb, buf, size);
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1633 av_free(buf);
2668
8d400e382d6e Prevent mov muxer from writing empty udta atoms.
benoit
parents: 2617
diff changeset
1634 }
8d400e382d6e Prevent mov muxer from writing empty udta atoms.
benoit
parents: 2617
diff changeset
1635
8d400e382d6e Prevent mov muxer from writing empty udta atoms.
benoit
parents: 2617
diff changeset
1636 return 0;
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
1637 }
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
1638
3457
0bbc97acefde simplify
bcoudurier
parents: 3456
diff changeset
1639 static void mov_write_psp_udta_tag(ByteIOContext *pb,
3456
fb5dd21f7e18 factorize psp metadata
bcoudurier
parents: 3455
diff changeset
1640 const char *str, const char *lang, int type)
fb5dd21f7e18 factorize psp metadata
bcoudurier
parents: 3455
diff changeset
1641 {
fb5dd21f7e18 factorize psp metadata
bcoudurier
parents: 3455
diff changeset
1642 int len = utf8len(str)+1;
fb5dd21f7e18 factorize psp metadata
bcoudurier
parents: 3455
diff changeset
1643 if(len<=0)
3457
0bbc97acefde simplify
bcoudurier
parents: 3456
diff changeset
1644 return;
3456
fb5dd21f7e18 factorize psp metadata
bcoudurier
parents: 3455
diff changeset
1645 put_be16(pb, len*2+10); /* size */
fb5dd21f7e18 factorize psp metadata
bcoudurier
parents: 3455
diff changeset
1646 put_be32(pb, type); /* type */
fb5dd21f7e18 factorize psp metadata
bcoudurier
parents: 3455
diff changeset
1647 put_be16(pb, language_code(lang)); /* language */
fb5dd21f7e18 factorize psp metadata
bcoudurier
parents: 3455
diff changeset
1648 put_be16(pb, 0x01); /* ? */
fb5dd21f7e18 factorize psp metadata
bcoudurier
parents: 3455
diff changeset
1649 ascii_to_wc(pb, str);
fb5dd21f7e18 factorize psp metadata
bcoudurier
parents: 3455
diff changeset
1650 }
fb5dd21f7e18 factorize psp metadata
bcoudurier
parents: 3455
diff changeset
1651
3446
7d73c4a64714 cosmetics
bcoudurier
parents: 3424
diff changeset
1652 static int mov_write_uuidusmt_tag(ByteIOContext *pb, AVFormatContext *s)
911
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1653 {
4584
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1654 AVMetadataTag *title = av_metadata_get(s->metadata, "title", NULL, 0);
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3909
diff changeset
1655 int64_t pos, pos2;
911
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1656
4584
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1657 if (title) {
911
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1658 pos = url_ftell(pb);
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1659 put_be32(pb, 0); /* size placeholder*/
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1660 put_tag(pb, "uuid");
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1661 put_tag(pb, "USMT");
3024
19de43025f0f cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents: 3010
diff changeset
1662 put_be32(pb, 0x21d24fce); /* 96 bit UUID */
19de43025f0f cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents: 3010
diff changeset
1663 put_be32(pb, 0xbb88695c);
19de43025f0f cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents: 3010
diff changeset
1664 put_be32(pb, 0xfac9c740);
911
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1665
3457
0bbc97acefde simplify
bcoudurier
parents: 3456
diff changeset
1666 pos2 = url_ftell(pb);
911
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1667 put_be32(pb, 0); /* size placeholder*/
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1668 put_tag(pb, "MTDT");
1097
acabd3a4b903 fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents: 1096
diff changeset
1669 put_be16(pb, 4);
911
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1670
1097
acabd3a4b903 fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents: 1096
diff changeset
1671 // ?
acabd3a4b903 fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents: 1096
diff changeset
1672 put_be16(pb, 0x0C); /* size */
acabd3a4b903 fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents: 1096
diff changeset
1673 put_be32(pb, 0x0B); /* type */
acabd3a4b903 fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents: 1096
diff changeset
1674 put_be16(pb, language_code("und")); /* language */
acabd3a4b903 fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents: 1096
diff changeset
1675 put_be16(pb, 0x0); /* ? */
acabd3a4b903 fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents: 1096
diff changeset
1676 put_be16(pb, 0x021C); /* data */
acabd3a4b903 fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents: 1096
diff changeset
1677
3457
0bbc97acefde simplify
bcoudurier
parents: 3456
diff changeset
1678 mov_write_psp_udta_tag(pb, LIBAVCODEC_IDENT, "eng", 0x04);
4584
da9b09dd57b8 use new metadata API in mov muxer
aurel
parents: 4567
diff changeset
1679 mov_write_psp_udta_tag(pb, title->value, "eng", 0x01);
3457
0bbc97acefde simplify
bcoudurier
parents: 3456
diff changeset
1680 // snprintf(dt,32,"%04d/%02d/%02d %02d:%02d:%02d",t_st->tm_year+1900,t_st->tm_mon+1,t_st->tm_mday,t_st->tm_hour,t_st->tm_min,t_st->tm_sec);
0bbc97acefde simplify
bcoudurier
parents: 3456
diff changeset
1681 mov_write_psp_udta_tag(pb, "2006/04/01 11:11:11", "und", 0x03);
0bbc97acefde simplify
bcoudurier
parents: 3456
diff changeset
1682
0bbc97acefde simplify
bcoudurier
parents: 3456
diff changeset
1683 updateSize(pb, pos2);
0bbc97acefde simplify
bcoudurier
parents: 3456
diff changeset
1684 return updateSize(pb, pos);
911
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1685 }
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1686
3457
0bbc97acefde simplify
bcoudurier
parents: 3456
diff changeset
1687 return 0;
911
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1688 }
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1689
4609
065557d6fffb Rename movenc.c MOVContext to MOVMuxContext, since MOVContext is already used
rbultje
parents: 4587
diff changeset
1690 static int mov_write_moov_tag(ByteIOContext *pb, MOVMuxContext *mov,
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
1691 AVFormatContext *s)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1692 {
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
1693 int i;
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3909
diff changeset
1694 int64_t pos = url_ftell(pb);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1695 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
1696 put_tag(pb, "moov");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1697
1131
a9f78ea5c6a3 check only existing streams
bcoudurier
parents: 1129
diff changeset
1698 for (i=0; i<mov->nb_streams; i++) {
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1699 if(mov->tracks[i].entry <= 0) continue;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1700
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1701 mov->tracks[i].time = mov->time;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1702 mov->tracks[i].trackID = i+1;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1703 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1704
5993
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
1705 if (mov->chapter_track)
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
1706 for (i=0; i<s->nb_streams; i++) {
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
1707 mov->tracks[i].tref_tag = MKTAG('c','h','a','p');
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
1708 mov->tracks[i].tref_id = mov->tracks[mov->chapter_track].trackID;
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
1709 }
6013
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1710 for (i = 0; i < mov->nb_streams; i++) {
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1711 if (mov->tracks[i].tag == MKTAG('r','t','p',' ')) {
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1712 mov->tracks[i].tref_tag = MKTAG('h','i','n','t');
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1713 mov->tracks[i].tref_id =
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1714 mov->tracks[mov->tracks[i].src_track].trackID;
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1715 }
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1716 }
5993
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
1717
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
1718 mov_write_mvhd_tag(pb, mov);
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
1719 //mov_write_iods_tag(pb, mov);
1131
a9f78ea5c6a3 check only existing streams
bcoudurier
parents: 1129
diff changeset
1720 for (i=0; i<mov->nb_streams; i++) {
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1721 if(mov->tracks[i].entry > 0) {
5993
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
1722 mov_write_trak_tag(pb, &(mov->tracks[i]), i < s->nb_streams ? s->streams[i] : NULL);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1723 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1724 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1725
911
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1726 if (mov->mode == MODE_PSP)
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1727 mov_write_uuidusmt_tag(pb, s);
3460
bd563026a5af support for 3gp metadata
bcoudurier
parents: 3459
diff changeset
1728 else
1441
ad3b03b7b142 reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents: 1438
diff changeset
1729 mov_write_udta_tag(pb, mov, s);
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
1730
238
3519903c6c2a mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents: 202
diff changeset
1731 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1732 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1733
4609
065557d6fffb Rename movenc.c MOVContext to MOVMuxContext, since MOVContext is already used
rbultje
parents: 4587
diff changeset
1734 static int mov_write_mdat_tag(ByteIOContext *pb, MOVMuxContext *mov)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1735 {
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
1736 put_be32(pb, 8); // placeholder for extended size field (64 bit)
1273
07137c477f09 wide atom is only defined in mov, use free for mp4/3gp
bcoudurier
parents: 1250
diff changeset
1737 put_tag(pb, mov->mode == MODE_MOV ? "wide" : "free");
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
1738
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 851
diff changeset
1739 mov->mdat_pos = url_ftell(pb);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1740 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
1741 put_tag(pb, "mdat");
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1742 return 0;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1743 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1744
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1745 /* TODO: This needs to be more general */
3471
a7ba44edfacb fix warning, write_ftyp return int now
bcoudurier
parents: 3470
diff changeset
1746 static int mov_write_ftyp_tag(ByteIOContext *pb, AVFormatContext *s)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1747 {
4609
065557d6fffb Rename movenc.c MOVContext to MOVMuxContext, since MOVContext is already used
rbultje
parents: 4587
diff changeset
1748 MOVMuxContext *mov = s->priv_data;
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3909
diff changeset
1749 int64_t pos = url_ftell(pb);
3472
0edcd0638ecc simplify ipod brand selection
bcoudurier
parents: 3471
diff changeset
1750 int has_h264 = 0, has_video = 0;
3476
3026020083e8 set correct ftyp minor version for 3gp/2
bcoudurier
parents: 3475
diff changeset
1751 int minor = 0x200;
3458
1ccb0b1813c9 write usual brand for ipod format
bcoudurier
parents: 3457
diff changeset
1752 int i;
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
1753
3470
d8bbf9265f03 put avc1 brand in compat list when h264 is present
bcoudurier
parents: 3469
diff changeset
1754 for (i = 0; i < s->nb_streams; i++) {
d8bbf9265f03 put avc1 brand in compat list when h264 is present
bcoudurier
parents: 3469
diff changeset
1755 AVStream *st = s->streams[i];
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5792
diff changeset
1756 if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO)
3472
0edcd0638ecc simplify ipod brand selection
bcoudurier
parents: 3471
diff changeset
1757 has_video = 1;
3470
d8bbf9265f03 put avc1 brand in compat list when h264 is present
bcoudurier
parents: 3469
diff changeset
1758 if (st->codec->codec_id == CODEC_ID_H264)
d8bbf9265f03 put avc1 brand in compat list when h264 is present
bcoudurier
parents: 3469
diff changeset
1759 has_h264 = 1;
d8bbf9265f03 put avc1 brand in compat list when h264 is present
bcoudurier
parents: 3469
diff changeset
1760 }
d8bbf9265f03 put avc1 brand in compat list when h264 is present
bcoudurier
parents: 3469
diff changeset
1761
3467
7baaf426d757 Calculate ftyp size instead of hardcoding it.
michael
parents: 3466
diff changeset
1762 put_be32(pb, 0); /* size */
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1763 put_tag(pb, "ftyp");
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1764
3476
3026020083e8 set correct ftyp minor version for 3gp/2
bcoudurier
parents: 3475
diff changeset
1765 if (mov->mode == MODE_3GP) {
3026020083e8 set correct ftyp minor version for 3gp/2
bcoudurier
parents: 3475
diff changeset
1766 put_tag(pb, has_h264 ? "3gp6" : "3gp4");
3026020083e8 set correct ftyp minor version for 3gp/2
bcoudurier
parents: 3475
diff changeset
1767 minor = has_h264 ? 0x100 : 0x200;
3026020083e8 set correct ftyp minor version for 3gp/2
bcoudurier
parents: 3475
diff changeset
1768 } else if (mov->mode & MODE_3G2) {
3026020083e8 set correct ftyp minor version for 3gp/2
bcoudurier
parents: 3475
diff changeset
1769 put_tag(pb, has_h264 ? "3g2b" : "3g2a");
3026020083e8 set correct ftyp minor version for 3gp/2
bcoudurier
parents: 3475
diff changeset
1770 minor = has_h264 ? 0x20000 : 0x10000;
3026020083e8 set correct ftyp minor version for 3gp/2
bcoudurier
parents: 3475
diff changeset
1771 }else if (mov->mode == MODE_PSP)
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1772 put_tag(pb, "MSNV");
3458
1ccb0b1813c9 write usual brand for ipod format
bcoudurier
parents: 3457
diff changeset
1773 else if (mov->mode == MODE_MP4)
990
f7394f02e95a ftyp patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents: 987
diff changeset
1774 put_tag(pb, "isom");
3472
0edcd0638ecc simplify ipod brand selection
bcoudurier
parents: 3471
diff changeset
1775 else if (mov->mode == MODE_IPOD)
0edcd0638ecc simplify ipod brand selection
bcoudurier
parents: 3471
diff changeset
1776 put_tag(pb, has_video ? "M4V ":"M4A ");
0edcd0638ecc simplify ipod brand selection
bcoudurier
parents: 3471
diff changeset
1777 else
990
f7394f02e95a ftyp patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents: 987
diff changeset
1778 put_tag(pb, "qt ");
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1779
3476
3026020083e8 set correct ftyp minor version for 3gp/2
bcoudurier
parents: 3475
diff changeset
1780 put_be32(pb, minor);
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1781
3475
654b3aa1cab4 invert mode_mov condition
bcoudurier
parents: 3474
diff changeset
1782 if(mov->mode == MODE_MOV)
654b3aa1cab4 invert mode_mov condition
bcoudurier
parents: 3474
diff changeset
1783 put_tag(pb, "qt ");
654b3aa1cab4 invert mode_mov condition
bcoudurier
parents: 3474
diff changeset
1784 else{
3468
08e0dba7c5b1 Add isom to the compatible brands.
michael
parents: 3467
diff changeset
1785 put_tag(pb, "isom");
3469
e819cfc46b1d I think we are also compliant to iso2.
michael
parents: 3468
diff changeset
1786 put_tag(pb, "iso2");
3470
d8bbf9265f03 put avc1 brand in compat list when h264 is present
bcoudurier
parents: 3469
diff changeset
1787 if(has_h264)
d8bbf9265f03 put avc1 brand in compat list when h264 is present
bcoudurier
parents: 3469
diff changeset
1788 put_tag(pb, "avc1");
3475
654b3aa1cab4 invert mode_mov condition
bcoudurier
parents: 3474
diff changeset
1789 }
3468
08e0dba7c5b1 Add isom to the compatible brands.
michael
parents: 3467
diff changeset
1790
3024
19de43025f0f cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents: 3010
diff changeset
1791 if (mov->mode == MODE_3GP)
3473
87259205d376 change 3gp/3g2 brands if h264 is present
bcoudurier
parents: 3472
diff changeset
1792 put_tag(pb, has_h264 ? "3gp6":"3gp4");
3466
b00b81c315e5 simplify MODE_3G2
michael
parents: 3465
diff changeset
1793 else if (mov->mode & MODE_3G2)
3473
87259205d376 change 3gp/3g2 brands if h264 is present
bcoudurier
parents: 3472
diff changeset
1794 put_tag(pb, has_h264 ? "3g2b":"3g2a");
3024
19de43025f0f cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents: 3010
diff changeset
1795 else if (mov->mode == MODE_PSP)
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1796 put_tag(pb, "MSNV");
3458
1ccb0b1813c9 write usual brand for ipod format
bcoudurier
parents: 3457
diff changeset
1797 else if (mov->mode == MODE_MP4)
990
f7394f02e95a ftyp patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents: 987
diff changeset
1798 put_tag(pb, "mp41");
3467
7baaf426d757 Calculate ftyp size instead of hardcoding it.
michael
parents: 3466
diff changeset
1799 return updateSize(pb, pos);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1800 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1801
665
47d5b20c9aba fix segfault by matthieu castet <castet DOT matthieu AT free DOT fr>
mmu_man
parents: 664
diff changeset
1802 static void mov_write_uuidprof_tag(ByteIOContext *pb, AVFormatContext *s)
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1803 {
911
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1804 AVCodecContext *VideoCodec = s->streams[0]->codec;
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1805 AVCodecContext *AudioCodec = s->streams[1]->codec;
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1806 int AudioRate = AudioCodec->sample_rate;
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1807 int FrameRate = ((VideoCodec->time_base.den) * (0x10000))/ (VideoCodec->time_base.num);
1049
23d44137105f the PSP rejects video with too high bitrates so lets claim they arent too high ...
michael
parents: 1037
diff changeset
1808 int audio_kbitrate= AudioCodec->bit_rate / 1000;
23d44137105f the PSP rejects video with too high bitrates so lets claim they arent too high ...
michael
parents: 1037
diff changeset
1809 int video_kbitrate= FFMIN(VideoCodec->bit_rate / 1000, 800 - audio_kbitrate);
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1810
3024
19de43025f0f cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents: 3010
diff changeset
1811 put_be32(pb, 0x94); /* size */
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1812 put_tag(pb, "uuid");
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1813 put_tag(pb, "PROF");
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1814
3024
19de43025f0f cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents: 3010
diff changeset
1815 put_be32(pb, 0x21d24fce); /* 96 bit UUID */
19de43025f0f cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents: 3010
diff changeset
1816 put_be32(pb, 0xbb88695c);
19de43025f0f cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents: 3010
diff changeset
1817 put_be32(pb, 0xfac9c740);
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1818
3024
19de43025f0f cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents: 3010
diff changeset
1819 put_be32(pb, 0x0); /* ? */
19de43025f0f cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents: 3010
diff changeset
1820 put_be32(pb, 0x3); /* 3 sections ? */
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1821
3024
19de43025f0f cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents: 3010
diff changeset
1822 put_be32(pb, 0x14); /* size */
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1823 put_tag(pb, "FPRF");
3024
19de43025f0f cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents: 3010
diff changeset
1824 put_be32(pb, 0x0); /* ? */
19de43025f0f cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents: 3010
diff changeset
1825 put_be32(pb, 0x0); /* ? */
19de43025f0f cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents: 3010
diff changeset
1826 put_be32(pb, 0x0); /* ? */
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1827
3024
19de43025f0f cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents: 3010
diff changeset
1828 put_be32(pb, 0x2c); /* size */
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1829 put_tag(pb, "APRF"); /* audio */
3024
19de43025f0f cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents: 3010
diff changeset
1830 put_be32(pb, 0x0);
19de43025f0f cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents: 3010
diff changeset
1831 put_be32(pb, 0x2); /* TrackID */
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1832 put_tag(pb, "mp4a");
3024
19de43025f0f cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents: 3010
diff changeset
1833 put_be32(pb, 0x20f);
19de43025f0f cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents: 3010
diff changeset
1834 put_be32(pb, 0x0);
1049
23d44137105f the PSP rejects video with too high bitrates so lets claim they arent too high ...
michael
parents: 1037
diff changeset
1835 put_be32(pb, audio_kbitrate);
23d44137105f the PSP rejects video with too high bitrates so lets claim they arent too high ...
michael
parents: 1037
diff changeset
1836 put_be32(pb, audio_kbitrate);
3024
19de43025f0f cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents: 3010
diff changeset
1837 put_be32(pb, AudioRate);
19de43025f0f cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents: 3010
diff changeset
1838 put_be32(pb, AudioCodec->channels);
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1839
3024
19de43025f0f cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents: 3010
diff changeset
1840 put_be32(pb, 0x34); /* size */
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1841 put_tag(pb, "VPRF"); /* video */
3024
19de43025f0f cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents: 3010
diff changeset
1842 put_be32(pb, 0x0);
19de43025f0f cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents: 3010
diff changeset
1843 put_be32(pb, 0x1); /* TrackID */
1050
ece3b7eecba2 little h.264 related hunk from diff between cvs and mobile hackerz
michael
parents: 1049
diff changeset
1844 if (VideoCodec->codec_id == CODEC_ID_H264) {
ece3b7eecba2 little h.264 related hunk from diff between cvs and mobile hackerz
michael
parents: 1049
diff changeset
1845 put_tag(pb, "avc1");
3024
19de43025f0f cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents: 3010
diff changeset
1846 put_be16(pb, 0x014D);
19de43025f0f cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents: 3010
diff changeset
1847 put_be16(pb, 0x0015);
1050
ece3b7eecba2 little h.264 related hunk from diff between cvs and mobile hackerz
michael
parents: 1049
diff changeset
1848 } else {
ece3b7eecba2 little h.264 related hunk from diff between cvs and mobile hackerz
michael
parents: 1049
diff changeset
1849 put_tag(pb, "mp4v");
3024
19de43025f0f cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents: 3010
diff changeset
1850 put_be16(pb, 0x0000);
19de43025f0f cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents: 3010
diff changeset
1851 put_be16(pb, 0x0103);
1050
ece3b7eecba2 little h.264 related hunk from diff between cvs and mobile hackerz
michael
parents: 1049
diff changeset
1852 }
3024
19de43025f0f cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents: 3010
diff changeset
1853 put_be32(pb, 0x0);
1049
23d44137105f the PSP rejects video with too high bitrates so lets claim they arent too high ...
michael
parents: 1037
diff changeset
1854 put_be32(pb, video_kbitrate);
23d44137105f the PSP rejects video with too high bitrates so lets claim they arent too high ...
michael
parents: 1037
diff changeset
1855 put_be32(pb, video_kbitrate);
911
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1856 put_be32(pb, FrameRate);
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1857 put_be32(pb, FrameRate);
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1858 put_be16(pb, VideoCodec->width);
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1859 put_be16(pb, VideoCodec->height);
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
1860 put_be32(pb, 0x010001); /* ? */
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1861 }
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
1862
4941
45a08facad6f write 'stps' for mpeg-2 open gop in .mov
bcoudurier
parents: 4937
diff changeset
1863 static int mov_parse_mpeg2_frame(AVPacket *pkt, uint32_t *flags)
45a08facad6f write 'stps' for mpeg-2 open gop in .mov
bcoudurier
parents: 4937
diff changeset
1864 {
45a08facad6f write 'stps' for mpeg-2 open gop in .mov
bcoudurier
parents: 4937
diff changeset
1865 uint32_t c = -1;
45a08facad6f write 'stps' for mpeg-2 open gop in .mov
bcoudurier
parents: 4937
diff changeset
1866 int i, closed_gop = 0;
45a08facad6f write 'stps' for mpeg-2 open gop in .mov
bcoudurier
parents: 4937
diff changeset
1867
45a08facad6f write 'stps' for mpeg-2 open gop in .mov
bcoudurier
parents: 4937
diff changeset
1868 for (i = 0; i < pkt->size - 4; i++) {
45a08facad6f write 'stps' for mpeg-2 open gop in .mov
bcoudurier
parents: 4937
diff changeset
1869 c = (c<<8) + pkt->data[i];
45a08facad6f write 'stps' for mpeg-2 open gop in .mov
bcoudurier
parents: 4937
diff changeset
1870 if (c == 0x1b8) { // gop
45a08facad6f write 'stps' for mpeg-2 open gop in .mov
bcoudurier
parents: 4937
diff changeset
1871 closed_gop = pkt->data[i+4]>>6 & 0x01;
45a08facad6f write 'stps' for mpeg-2 open gop in .mov
bcoudurier
parents: 4937
diff changeset
1872 } else if (c == 0x100) { // pic
45a08facad6f write 'stps' for mpeg-2 open gop in .mov
bcoudurier
parents: 4937
diff changeset
1873 int temp_ref = (pkt->data[i+1]<<2) | (pkt->data[i+2]>>6);
45a08facad6f write 'stps' for mpeg-2 open gop in .mov
bcoudurier
parents: 4937
diff changeset
1874 if (!temp_ref || closed_gop) // I picture is not reordered
45a08facad6f write 'stps' for mpeg-2 open gop in .mov
bcoudurier
parents: 4937
diff changeset
1875 *flags = MOV_SYNC_SAMPLE;
45a08facad6f write 'stps' for mpeg-2 open gop in .mov
bcoudurier
parents: 4937
diff changeset
1876 else
45a08facad6f write 'stps' for mpeg-2 open gop in .mov
bcoudurier
parents: 4937
diff changeset
1877 *flags = MOV_PARTIAL_SYNC_SAMPLE;
45a08facad6f write 'stps' for mpeg-2 open gop in .mov
bcoudurier
parents: 4937
diff changeset
1878 break;
45a08facad6f write 'stps' for mpeg-2 open gop in .mov
bcoudurier
parents: 4937
diff changeset
1879 }
45a08facad6f write 'stps' for mpeg-2 open gop in .mov
bcoudurier
parents: 4937
diff changeset
1880 }
45a08facad6f write 'stps' for mpeg-2 open gop in .mov
bcoudurier
parents: 4937
diff changeset
1881 return 0;
45a08facad6f write 'stps' for mpeg-2 open gop in .mov
bcoudurier
parents: 4937
diff changeset
1882 }
45a08facad6f write 'stps' for mpeg-2 open gop in .mov
bcoudurier
parents: 4937
diff changeset
1883
6012
8298cc054242 Make mov_write_packet non-static, add ff_ prefix
mstorsjo
parents: 6011
diff changeset
1884 int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt)
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1885 {
4609
065557d6fffb Rename movenc.c MOVContext to MOVMuxContext, since MOVContext is already used
rbultje
parents: 4587
diff changeset
1886 MOVMuxContext *mov = s->priv_data;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2669
diff changeset
1887 ByteIOContext *pb = s->pb;
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
1888 MOVTrack *trk = &mov->tracks[pkt->stream_index];
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
1889 AVCodecContext *enc = trk->enc;
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1890 unsigned int samplesInChunk = 0;
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 441
diff changeset
1891 int size= pkt->size;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1892
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2669
diff changeset
1893 if (url_is_streamed(s->pb)) return 0; /* Can't handle that */
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1894 if (!size) return 0; /* Discard 0 sized packets */
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1895
1154
322bb8541a9e typo fix
bcoudurier
parents: 1153
diff changeset
1896 if (enc->codec_id == CODEC_ID_AMR_NB) {
1147
5cac4246a84a write exact values for audio stsd v1
bcoudurier
parents: 1131
diff changeset
1897 /* We must find out how many AMR blocks there are in one packet */
5cac4246a84a write exact values for audio stsd v1
bcoudurier
parents: 1131
diff changeset
1898 static uint16_t packed_size[16] =
5cac4246a84a write exact values for audio stsd v1
bcoudurier
parents: 1131
diff changeset
1899 {13, 14, 16, 18, 20, 21, 27, 32, 6, 0, 0, 0, 0, 0, 0, 0};
5cac4246a84a write exact values for audio stsd v1
bcoudurier
parents: 1131
diff changeset
1900 int len = 0;
1057
6c53db379305 clean and simplify mov_write_packet
bcoudurier
parents: 1056
diff changeset
1901
1147
5cac4246a84a write exact values for audio stsd v1
bcoudurier
parents: 1131
diff changeset
1902 while (len < size && samplesInChunk < 100) {
5cac4246a84a write exact values for audio stsd v1
bcoudurier
parents: 1131
diff changeset
1903 len += packed_size[(pkt->data[len] >> 3) & 0x0F];
5cac4246a84a write exact values for audio stsd v1
bcoudurier
parents: 1131
diff changeset
1904 samplesInChunk++;
1057
6c53db379305 clean and simplify mov_write_packet
bcoudurier
parents: 1056
diff changeset
1905 }
1151
bf808f3f7f46 check for unparsed AMR input
michael
parents: 1150
diff changeset
1906 if(samplesInChunk > 1){
2546
ramiro
parents: 2233
diff changeset
1907 av_log(s, AV_LOG_ERROR, "fatal error, input is not a single packet, implement a AVParser for it\n");
1151
bf808f3f7f46 check for unparsed AMR input
michael
parents: 1150
diff changeset
1908 return -1;
bf808f3f7f46 check for unparsed AMR input
michael
parents: 1150
diff changeset
1909 }
1147
5cac4246a84a write exact values for audio stsd v1
bcoudurier
parents: 1131
diff changeset
1910 } else if (trk->sampleSize)
5cac4246a84a write exact values for audio stsd v1
bcoudurier
parents: 1131
diff changeset
1911 samplesInChunk = size/trk->sampleSize;
5cac4246a84a write exact values for audio stsd v1
bcoudurier
parents: 1131
diff changeset
1912 else
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1913 samplesInChunk = 1;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1914
1057
6c53db379305 clean and simplify mov_write_packet
bcoudurier
parents: 1056
diff changeset
1915 /* copy extradata if it exists */
6c53db379305 clean and simplify mov_write_packet
bcoudurier
parents: 1056
diff changeset
1916 if (trk->vosLen == 0 && enc->extradata_size > 0) {
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1917 trk->vosLen = enc->extradata_size;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1918 trk->vosData = av_malloc(trk->vosLen);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1919 memcpy(trk->vosData, enc->extradata, trk->vosLen);
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1920 }
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1921
4225
0231b1d5cd15 move actual writing before so new size can be taken into account
bcoudurier
parents: 4223
diff changeset
1922 if (enc->codec_id == CODEC_ID_H264 && trk->vosLen > 0 && *(uint8_t *)trk->vosData != 1) {
0231b1d5cd15 move actual writing before so new size can be taken into account
bcoudurier
parents: 4223
diff changeset
1923 /* from x264 or from bytestream h264 */
0231b1d5cd15 move actual writing before so new size can be taken into account
bcoudurier
parents: 4223
diff changeset
1924 /* nal reformating needed */
0231b1d5cd15 move actual writing before so new size can be taken into account
bcoudurier
parents: 4223
diff changeset
1925 size = ff_avc_parse_nal_units(pb, pkt->data, pkt->size);
0231b1d5cd15 move actual writing before so new size can be taken into account
bcoudurier
parents: 4223
diff changeset
1926 } else {
0231b1d5cd15 move actual writing before so new size can be taken into account
bcoudurier
parents: 4223
diff changeset
1927 put_buffer(pb, pkt->data, size);
0231b1d5cd15 move actual writing before so new size can be taken into account
bcoudurier
parents: 4223
diff changeset
1928 }
0231b1d5cd15 move actual writing before so new size can be taken into account
bcoudurier
parents: 4223
diff changeset
1929
4222
0267c4299992 Do not reallocate AVPacket's data when muxing a packet
lucabe
parents: 4206
diff changeset
1930 if ((enc->codec_id == CODEC_ID_DNXHD ||
4928
ba1072d90812 cosmetics, alignment
bcoudurier
parents: 4920
diff changeset
1931 enc->codec_id == CODEC_ID_AC3) && !trk->vosLen) {
3857
50bb82abb278 copy whole frame in vosData for dnxhd, this code will be used for other codecs too
bcoudurier
parents: 3766
diff changeset
1932 /* copy frame to create needed atoms */
50bb82abb278 copy whole frame in vosData for dnxhd, this code will be used for other codecs too
bcoudurier
parents: 3766
diff changeset
1933 trk->vosLen = size;
50bb82abb278 copy whole frame in vosData for dnxhd, this code will be used for other codecs too
bcoudurier
parents: 3766
diff changeset
1934 trk->vosData = av_malloc(size);
3858
62a7a6a6a038 check for malloc failure
bcoudurier
parents: 3857
diff changeset
1935 if (!trk->vosData)
62a7a6a6a038 check for malloc failure
bcoudurier
parents: 3857
diff changeset
1936 return AVERROR(ENOMEM);
3857
50bb82abb278 copy whole frame in vosData for dnxhd, this code will be used for other codecs too
bcoudurier
parents: 3766
diff changeset
1937 memcpy(trk->vosData, pkt->data, size);
1006
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
1938 }
15bfc3c063dc do nal reformating when muxing H264, create avcc atom
bcoudurier
parents: 1000
diff changeset
1939
1129
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
1940 if (!(trk->entry % MOV_INDEX_CLUSTER_SIZE)) {
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
1941 trk->cluster = av_realloc(trk->cluster, (trk->entry + MOV_INDEX_CLUSTER_SIZE) * sizeof(*trk->cluster));
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1942 if (!trk->cluster)
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1943 return -1;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1944 }
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1945
4225
0231b1d5cd15 move actual writing before so new size can be taken into account
bcoudurier
parents: 4223
diff changeset
1946 trk->cluster[trk->entry].pos = url_ftell(pb) - size;
1129
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
1947 trk->cluster[trk->entry].samplesInChunk = samplesInChunk;
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
1948 trk->cluster[trk->entry].size = size;
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
1949 trk->cluster[trk->entry].entries = samplesInChunk;
1437
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
1950 trk->cluster[trk->entry].dts = pkt->dts;
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
1951 trk->trackDuration = pkt->dts - trk->cluster[0].dts + pkt->duration;
6f4a44ab3f2a mov vfr muxing
bcoudurier
parents: 1415
diff changeset
1952
3397
76918939de90 warn if pts is not set, prevent writing negative/weird cts, happens when using genpts and streamcopy
bcoudurier
parents: 3396
diff changeset
1953 if (pkt->pts == AV_NOPTS_VALUE) {
76918939de90 warn if pts is not set, prevent writing negative/weird cts, happens when using genpts and streamcopy
bcoudurier
parents: 3396
diff changeset
1954 av_log(s, AV_LOG_WARNING, "pts has no value\n");
76918939de90 warn if pts is not set, prevent writing negative/weird cts, happens when using genpts and streamcopy
bcoudurier
parents: 3396
diff changeset
1955 pkt->pts = pkt->dts;
76918939de90 warn if pts is not set, prevent writing negative/weird cts, happens when using genpts and streamcopy
bcoudurier
parents: 3396
diff changeset
1956 }
3396
f7f09ceea992 reindent
bcoudurier
parents: 3395
diff changeset
1957 if (pkt->dts != pkt->pts)
4941
45a08facad6f write 'stps' for mpeg-2 open gop in .mov
bcoudurier
parents: 4937
diff changeset
1958 trk->flags |= MOV_TRACK_CTTS;
3396
f7f09ceea992 reindent
bcoudurier
parents: 3395
diff changeset
1959 trk->cluster[trk->entry].cts = pkt->pts - pkt->dts;
4941
45a08facad6f write 'stps' for mpeg-2 open gop in .mov
bcoudurier
parents: 4937
diff changeset
1960 trk->cluster[trk->entry].flags = 0;
5913
11bb10c37225 Replace all occurences of PKT_FLAG_KEY with AV_PKT_FLAG_KEY.
cehoyos
parents: 5910
diff changeset
1961 if (pkt->flags & AV_PKT_FLAG_KEY) {
4941
45a08facad6f write 'stps' for mpeg-2 open gop in .mov
bcoudurier
parents: 4937
diff changeset
1962 if (mov->mode == MODE_MOV && enc->codec_id == CODEC_ID_MPEG2VIDEO) {
45a08facad6f write 'stps' for mpeg-2 open gop in .mov
bcoudurier
parents: 4937
diff changeset
1963 mov_parse_mpeg2_frame(pkt, &trk->cluster[trk->entry].flags);
45a08facad6f write 'stps' for mpeg-2 open gop in .mov
bcoudurier
parents: 4937
diff changeset
1964 if (trk->cluster[trk->entry].flags & MOV_PARTIAL_SYNC_SAMPLE)
45a08facad6f write 'stps' for mpeg-2 open gop in .mov
bcoudurier
parents: 4937
diff changeset
1965 trk->flags |= MOV_TRACK_STPS;
45a08facad6f write 'stps' for mpeg-2 open gop in .mov
bcoudurier
parents: 4937
diff changeset
1966 } else {
45a08facad6f write 'stps' for mpeg-2 open gop in .mov
bcoudurier
parents: 4937
diff changeset
1967 trk->cluster[trk->entry].flags = MOV_SYNC_SAMPLE;
45a08facad6f write 'stps' for mpeg-2 open gop in .mov
bcoudurier
parents: 4937
diff changeset
1968 }
45a08facad6f write 'stps' for mpeg-2 open gop in .mov
bcoudurier
parents: 4937
diff changeset
1969 if (trk->cluster[trk->entry].flags & MOV_SYNC_SAMPLE)
45a08facad6f write 'stps' for mpeg-2 open gop in .mov
bcoudurier
parents: 4937
diff changeset
1970 trk->hasKeyframes++;
4937
14cb663f11c3 use flags field and remove key_frame field
bcoudurier
parents: 4936
diff changeset
1971 }
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1972 trk->entry++;
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1973 trk->sampleCount += samplesInChunk;
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
1974 mov->mdat_size += size;
298
0b2eed7b1210 movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 286
diff changeset
1975
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1976 put_flush_packet(pb);
6013
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1977
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1978 if (trk->hint_track >= 0 && trk->hint_track < mov->nb_streams)
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
1979 ff_mov_add_hinted_packet(s, pkt, trk->hint_track, trk->entry);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1980 return 0;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1981 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
1982
5993
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
1983 // QuickTime chapters involve an additional text track with the chapter names
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
1984 // as samples, and a tref pointing from the other tracks to the chapter one.
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
1985 static void mov_create_chapter_track(AVFormatContext *s, int tracknum)
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
1986 {
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
1987 MOVMuxContext *mov = s->priv_data;
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
1988 MOVTrack *track = &mov->tracks[tracknum];
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
1989 AVPacket pkt = { .stream_index = tracknum, .flags = AV_PKT_FLAG_KEY };
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
1990 int i, len;
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
1991
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
1992 track->mode = mov->mode;
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
1993 track->tag = MKTAG('t','e','x','t');
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
1994 track->timescale = MOV_TIMESCALE;
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
1995 track->enc = avcodec_alloc_context();
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
1996 track->enc->codec_type = AVMEDIA_TYPE_SUBTITLE;
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
1997
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
1998 for (i = 0; i < s->nb_chapters; i++) {
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
1999 AVChapter *c = s->chapters[i];
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
2000 AVMetadataTag *t;
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
2001
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
2002 int64_t end = av_rescale_q(c->end, c->time_base, (AVRational){1,MOV_TIMESCALE});
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
2003 pkt.pts = pkt.dts = av_rescale_q(c->start, c->time_base, (AVRational){1,MOV_TIMESCALE});
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
2004 pkt.duration = end - pkt.dts;
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
2005
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
2006 if ((t = av_metadata_get(c->metadata, "title", NULL, 0))) {
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
2007 len = strlen(t->value);
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
2008 pkt.size = len+2;
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
2009 pkt.data = av_malloc(pkt.size);
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
2010 AV_WB16(pkt.data, len);
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
2011 memcpy(pkt.data+2, t->value, len);
6012
8298cc054242 Make mov_write_packet non-static, add ff_ prefix
mstorsjo
parents: 6011
diff changeset
2012 ff_mov_write_packet(s, &pkt);
5993
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
2013 av_freep(&pkt.data);
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
2014 }
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
2015 }
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
2016 }
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
2017
5992
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2018 static int mov_write_header(AVFormatContext *s)
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2019 {
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2020 ByteIOContext *pb = s->pb;
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2021 MOVMuxContext *mov = s->priv_data;
6013
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
2022 int i, hint_track = 0;
5992
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2023
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2024 if (url_is_streamed(s->pb)) {
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2025 av_log(s, AV_LOG_ERROR, "muxer does not support non seekable output\n");
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2026 return -1;
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2027 }
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2028
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2029 /* Default mode == MP4 */
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2030 mov->mode = MODE_MP4;
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2031
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2032 if (s->oformat != NULL) {
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2033 if (!strcmp("3gp", s->oformat->name)) mov->mode = MODE_3GP;
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2034 else if (!strcmp("3g2", s->oformat->name)) mov->mode = MODE_3GP|MODE_3G2;
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2035 else if (!strcmp("mov", s->oformat->name)) mov->mode = MODE_MOV;
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2036 else if (!strcmp("psp", s->oformat->name)) mov->mode = MODE_PSP;
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2037 else if (!strcmp("ipod",s->oformat->name)) mov->mode = MODE_IPOD;
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2038
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2039 mov_write_ftyp_tag(pb,s);
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2040 if (mov->mode == MODE_PSP) {
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2041 if (s->nb_streams != 2) {
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2042 av_log(s, AV_LOG_ERROR, "PSP mode need one video and one audio stream\n");
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2043 return -1;
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2044 }
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2045 mov_write_uuidprof_tag(pb,s);
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2046 }
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2047 }
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2048
5993
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
2049 mov->nb_streams = s->nb_streams;
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
2050 if (mov->mode & (MODE_MOV|MODE_IPOD) && s->nb_chapters)
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
2051 mov->chapter_track = mov->nb_streams++;
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
2052
6013
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
2053 if (s->flags & AVFMT_FLAG_RTP_HINT) {
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
2054 /* Add hint tracks for each audio and video stream */
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
2055 hint_track = mov->nb_streams;
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
2056 for (i = 0; i < s->nb_streams; i++) {
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
2057 AVStream *st = s->streams[i];
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
2058 if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO ||
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
2059 st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
2060 mov->nb_streams++;
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
2061 }
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
2062 }
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
2063 }
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
2064
5993
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
2065 mov->tracks = av_mallocz(mov->nb_streams*sizeof(*mov->tracks));
5992
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2066 if (!mov->tracks)
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2067 return AVERROR(ENOMEM);
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2068
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2069 for(i=0; i<s->nb_streams; i++){
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2070 AVStream *st= s->streams[i];
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2071 MOVTrack *track= &mov->tracks[i];
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2072 AVMetadataTag *lang = av_metadata_get(st->metadata, "language", NULL,0);
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2073
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2074 track->enc = st->codec;
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2075 track->language = ff_mov_iso639_to_lang(lang?lang->value:"und", mov->mode!=MODE_MOV);
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2076 if (track->language < 0)
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2077 track->language = 0;
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2078 track->mode = mov->mode;
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2079 track->tag = mov_find_codec_tag(s, track);
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2080 if (!track->tag) {
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2081 av_log(s, AV_LOG_ERROR, "track %d: could not find tag, "
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2082 "codec not currently supported in container\n", i);
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2083 goto error;
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2084 }
6013
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
2085 /* If hinting of this track is enabled by a later hint track,
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
2086 * this is updated. */
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
2087 track->hint_track = -1;
5992
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2088 if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO){
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2089 if (track->tag == MKTAG('m','x','3','p') || track->tag == MKTAG('m','x','3','n') ||
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2090 track->tag == MKTAG('m','x','4','p') || track->tag == MKTAG('m','x','4','n') ||
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2091 track->tag == MKTAG('m','x','5','p') || track->tag == MKTAG('m','x','5','n')) {
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2092 if (st->codec->width != 720 || (st->codec->height != 608 && st->codec->height != 512)) {
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2093 av_log(s, AV_LOG_ERROR, "D-10/IMX must use 720x608 or 720x512 video resolution\n");
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2094 goto error;
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2095 }
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2096 track->height = track->tag>>24 == 'n' ? 486 : 576;
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2097 }
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2098 track->timescale = st->codec->time_base.den;
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2099 if (track->mode == MODE_MOV && track->timescale > 100000)
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2100 av_log(s, AV_LOG_WARNING,
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2101 "WARNING codec timebase is very high. If duration is too long,\n"
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2102 "file may not be playable by quicktime. Specify a shorter timebase\n"
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2103 "or choose different container.\n");
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2104 }else if(st->codec->codec_type == AVMEDIA_TYPE_AUDIO){
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2105 track->timescale = st->codec->sample_rate;
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2106 if(!st->codec->frame_size && !av_get_bits_per_sample(st->codec->codec_id)) {
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2107 av_log(s, AV_LOG_ERROR, "track %d: codec frame size is not set\n", i);
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2108 goto error;
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2109 }else if(st->codec->frame_size > 1){ /* assume compressed audio */
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2110 track->audio_vbr = 1;
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2111 }else{
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2112 st->codec->frame_size = 1;
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2113 track->sampleSize = (av_get_bits_per_sample(st->codec->codec_id) >> 3) * st->codec->channels;
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2114 }
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2115 if (track->mode != MODE_MOV) {
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2116 if (track->timescale > UINT16_MAX) {
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2117 av_log(s, AV_LOG_ERROR, "track %d: output format does not support "
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2118 "sample rate %dhz\n", i, track->timescale);
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2119 goto error;
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2120 }
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2121 if (track->enc->codec_id == CODEC_ID_MP3 && track->timescale < 16000) {
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2122 av_log(s, AV_LOG_ERROR, "track %d: muxing mp3 at %dhz is not supported\n",
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2123 i, track->enc->sample_rate);
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2124 goto error;
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2125 }
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2126 }
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2127 }else if(st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE){
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2128 track->timescale = st->codec->time_base.den;
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2129 }
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2130 if (!track->height)
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2131 track->height = st->codec->height;
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2132
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2133 av_set_pts_info(st, 64, 1, track->timescale);
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2134 }
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2135
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2136 mov_write_mdat_tag(pb, mov);
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2137 mov->time = s->timestamp + 0x7C25B080; //1970 based -> 1904 based
5993
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
2138
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
2139 if (mov->chapter_track)
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
2140 mov_create_chapter_track(s, mov->chapter_track);
5992
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2141
6013
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
2142 if (s->flags & AVFMT_FLAG_RTP_HINT) {
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
2143 /* Initialize the hint tracks for each audio and video stream */
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
2144 for (i = 0; i < s->nb_streams; i++) {
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
2145 AVStream *st = s->streams[i];
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
2146 if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO ||
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
2147 st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
2148 ff_mov_init_hinting(s, hint_track, i);
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
2149 hint_track++;
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
2150 }
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
2151 }
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
2152 }
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
2153
5992
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2154 put_flush_packet(pb);
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2155
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2156 return 0;
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2157 error:
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2158 av_freep(&mov->tracks);
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2159 return -1;
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2160 }
391e3ca10474 movenc: Swap positions of mov_write_header and mov_write_packet
conrad
parents: 5974
diff changeset
2161
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
2162 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
2163 {
4609
065557d6fffb Rename movenc.c MOVContext to MOVMuxContext, since MOVContext is already used
rbultje
parents: 4587
diff changeset
2164 MOVMuxContext *mov = s->priv_data;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2669
diff changeset
2165 ByteIOContext *pb = s->pb;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
2166 int res = 0;
1129
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
2167 int i;
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
2168
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3909
diff changeset
2169 int64_t moov_pos = url_ftell(pb);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
2170
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
2171 /* Write size of mdat tag */
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
2172 if (mov->mdat_size+8 <= UINT32_MAX) {
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
2173 url_fseek(pb, mov->mdat_pos, SEEK_SET);
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
2174 put_be32(pb, mov->mdat_size+8);
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
2175 } else {
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
2176 /* overwrite 'wide' placeholder atom */
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
2177 url_fseek(pb, mov->mdat_pos - 8, SEEK_SET);
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
2178 put_be32(pb, 1); /* special value: real atom size will be 64 bit value after tag field */
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
2179 put_tag(pb, "mdat");
1080
3170bb428809 clean and simplify
bcoudurier
parents: 1074
diff changeset
2180 put_be64(pb, mov->mdat_size+16);
909
69e06b6f91a3 >4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents: 896
diff changeset
2181 }
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
2182 url_fseek(pb, moov_pos, SEEK_SET);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
2183
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
2184 mov_write_moov_tag(pb, mov, s);
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
2185
5993
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
2186 if (mov->chapter_track)
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
2187 av_freep(&mov->tracks[mov->chapter_track].enc);
51b194d7393f movenc: Write QuickTime chapters
conrad
parents: 5992
diff changeset
2188
1131
a9f78ea5c6a3 check only existing streams
bcoudurier
parents: 1129
diff changeset
2189 for (i=0; i<mov->nb_streams; i++) {
6013
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
2190 if (mov->tracks[i].tag == MKTAG('r','t','p',' '))
332ad5f30c0e Add initial support for RTP hinting in the mov muxer
mstorsjo
parents: 6012
diff changeset
2191 ff_mov_close_hinting(&mov->tracks[i]);
1129
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
2192 av_freep(&mov->tracks[i].cluster);
2eb2fd065a50 simplify
bcoudurier
parents: 1125
diff changeset
2193
3024
19de43025f0f cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents: 3010
diff changeset
2194 if(mov->tracks[i].vosLen) av_free(mov->tracks[i].vosData);
342
0c1b489c96bf memleak patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 299
diff changeset
2195
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
2196 }
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
2197
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
2198 put_flush_packet(pb);
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
2199
4783
fda46f120854 allocate tracks instead of using MAX_STREAMS
bcoudurier
parents: 4722
diff changeset
2200 av_freep(&mov->tracks);
fda46f120854 allocate tracks instead of using MAX_STREAMS
bcoudurier
parents: 4722
diff changeset
2201
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
2202 return res;
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
2203 }
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
2204
4206
c3102b189cb6 Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 4196
diff changeset
2205 #if CONFIG_MOV_MUXER
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
2206 AVOutputFormat mov_muxer = {
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
2207 "mov",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 3397
diff changeset
2208 NULL_IF_CONFIG_SMALL("MOV format"),
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
2209 NULL,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
2210 "mov",
4609
065557d6fffb Rename movenc.c MOVContext to MOVMuxContext, since MOVContext is already used
rbultje
parents: 4587
diff changeset
2211 sizeof(MOVMuxContext),
365
4ae9fac22a5d AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
2212 CODEC_ID_AAC,
239
48c3134e93c3 theres no SVQ1 encoder -> it cant be default
michaelni
parents: 238
diff changeset
2213 CODEC_ID_MPEG4,
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
2214 mov_write_header,
6012
8298cc054242 Make mov_write_packet non-static, add ff_ prefix
mstorsjo
parents: 6011
diff changeset
2215 ff_mov_write_packet,
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
2216 mov_write_trailer,
4567
963e3b76c7a6 Add AVFMT_VARIABLE_FPS to specify which muxers do not need duplicated frames.
michael
parents: 4463
diff changeset
2217 .flags = AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS,
3766
f062deeedb8d Change codec_tag type from const struct AVCodecTag ** to const struct AVCodecTag * const *
reimar
parents: 3759
diff changeset
2218 .codec_tag = (const AVCodecTag* const []){codec_movvideo_tags, codec_movaudio_tags, 0},
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
2219 };
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
2220 #endif
4206
c3102b189cb6 Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 4196
diff changeset
2221 #if CONFIG_TGP_MUXER
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
2222 AVOutputFormat tgp_muxer = {
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
2223 "3gp",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 3397
diff changeset
2224 NULL_IF_CONFIG_SMALL("3GP format"),
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
2225 NULL,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
2226 "3gp",
4609
065557d6fffb Rename movenc.c MOVContext to MOVMuxContext, since MOVContext is already used
rbultje
parents: 4587
diff changeset
2227 sizeof(MOVMuxContext),
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
2228 CODEC_ID_AMR_NB,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
2229 CODEC_ID_H263,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
2230 mov_write_header,
6012
8298cc054242 Make mov_write_packet non-static, add ff_ prefix
mstorsjo
parents: 6011
diff changeset
2231 ff_mov_write_packet,
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
2232 mov_write_trailer,
715
e214703e4b76 30_clean_up_global_header_flag.patch by (Calcium | calcium nurs or jp)
michael
parents: 711
diff changeset
2233 .flags = AVFMT_GLOBALHEADER,
3766
f062deeedb8d Change codec_tag type from const struct AVCodecTag ** to const struct AVCodecTag * const *
reimar
parents: 3759
diff changeset
2234 .codec_tag = (const AVCodecTag* const []){codec_3gp_tags, 0},
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
2235 };
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
2236 #endif
4206
c3102b189cb6 Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 4196
diff changeset
2237 #if CONFIG_MP4_MUXER
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
2238 AVOutputFormat mp4_muxer = {
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
2239 "mp4",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 3397
diff changeset
2240 NULL_IF_CONFIG_SMALL("MP4 format"),
286
eccf0c3e3289 Using the extension m4a for audio only MPEG-4 files is increasingly
michael
parents: 259
diff changeset
2241 "application/mp4",
3452
712d6fab85ee m4v/m4a are usual itunes/ipod/iphone extensions
bcoudurier
parents: 3451
diff changeset
2242 "mp4",
4609
065557d6fffb Rename movenc.c MOVContext to MOVMuxContext, since MOVContext is already used
rbultje
parents: 4587
diff changeset
2243 sizeof(MOVMuxContext),
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
2244 CODEC_ID_AAC,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
2245 CODEC_ID_MPEG4,
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
2246 mov_write_header,
6012
8298cc054242 Make mov_write_packet non-static, add ff_ prefix
mstorsjo
parents: 6011
diff changeset
2247 ff_mov_write_packet,
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
2248 mov_write_trailer,
4567
963e3b76c7a6 Add AVFMT_VARIABLE_FPS to specify which muxers do not need duplicated frames.
michael
parents: 4463
diff changeset
2249 .flags = AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS,
3766
f062deeedb8d Change codec_tag type from const struct AVCodecTag ** to const struct AVCodecTag * const *
reimar
parents: 3759
diff changeset
2250 .codec_tag = (const AVCodecTag* const []){ff_mp4_obj_type, 0},
201
85def00971c3 mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff changeset
2251 };
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
2252 #endif
4206
c3102b189cb6 Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 4196
diff changeset
2253 #if CONFIG_PSP_MUXER
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
2254 AVOutputFormat psp_muxer = {
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
2255 "psp",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 3397
diff changeset
2256 NULL_IF_CONFIG_SMALL("PSP MP4 format"),
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
2257 NULL,
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
2258 "mp4,psp",
4609
065557d6fffb Rename movenc.c MOVContext to MOVMuxContext, since MOVContext is already used
rbultje
parents: 4587
diff changeset
2259 sizeof(MOVMuxContext),
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
2260 CODEC_ID_AAC,
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
2261 CODEC_ID_MPEG4,
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
2262 mov_write_header,
6012
8298cc054242 Make mov_write_packet non-static, add ff_ prefix
mstorsjo
parents: 6011
diff changeset
2263 ff_mov_write_packet,
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
2264 mov_write_trailer,
911
343ddd5b793c Fix for title field in PSP compatible mp4 files. Patch by
banan
parents: 910
diff changeset
2265 .flags = AVFMT_GLOBALHEADER,
3766
f062deeedb8d Change codec_tag type from const struct AVCodecTag ** to const struct AVCodecTag * const *
reimar
parents: 3759
diff changeset
2266 .codec_tag = (const AVCodecTag* const []){ff_mp4_obj_type, 0},
659
6d7c0e6d929e Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents: 657
diff changeset
2267 };
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
2268 #endif
4206
c3102b189cb6 Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 4196
diff changeset
2269 #if CONFIG_TG2_MUXER
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
2270 AVOutputFormat tg2_muxer = {
677
6d6a11ba402a quick patch for adding 3g2 support to ffmpeg (muxer and demuxer). No movie fragment support yet patch by (tjraivio cc.hut fi)
michael
parents: 676
diff changeset
2271 "3g2",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 3397
diff changeset
2272 NULL_IF_CONFIG_SMALL("3GP2 format"),
677
6d6a11ba402a quick patch for adding 3g2 support to ffmpeg (muxer and demuxer). No movie fragment support yet patch by (tjraivio cc.hut fi)
michael
parents: 676
diff changeset
2273 NULL,
6d6a11ba402a quick patch for adding 3g2 support to ffmpeg (muxer and demuxer). No movie fragment support yet patch by (tjraivio cc.hut fi)
michael
parents: 676
diff changeset
2274 "3g2",
4609
065557d6fffb Rename movenc.c MOVContext to MOVMuxContext, since MOVContext is already used
rbultje
parents: 4587
diff changeset
2275 sizeof(MOVMuxContext),
677
6d6a11ba402a quick patch for adding 3g2 support to ffmpeg (muxer and demuxer). No movie fragment support yet patch by (tjraivio cc.hut fi)
michael
parents: 676
diff changeset
2276 CODEC_ID_AMR_NB,
6d6a11ba402a quick patch for adding 3g2 support to ffmpeg (muxer and demuxer). No movie fragment support yet patch by (tjraivio cc.hut fi)
michael
parents: 676
diff changeset
2277 CODEC_ID_H263,
6d6a11ba402a quick patch for adding 3g2 support to ffmpeg (muxer and demuxer). No movie fragment support yet patch by (tjraivio cc.hut fi)
michael
parents: 676
diff changeset
2278 mov_write_header,
6012
8298cc054242 Make mov_write_packet non-static, add ff_ prefix
mstorsjo
parents: 6011
diff changeset
2279 ff_mov_write_packet,
677
6d6a11ba402a quick patch for adding 3g2 support to ffmpeg (muxer and demuxer). No movie fragment support yet patch by (tjraivio cc.hut fi)
michael
parents: 676
diff changeset
2280 mov_write_trailer,
715
e214703e4b76 30_clean_up_global_header_flag.patch by (Calcium | calcium nurs or jp)
michael
parents: 711
diff changeset
2281 .flags = AVFMT_GLOBALHEADER,
3766
f062deeedb8d Change codec_tag type from const struct AVCodecTag ** to const struct AVCodecTag * const *
reimar
parents: 3759
diff changeset
2282 .codec_tag = (const AVCodecTag* const []){codec_3gp_tags, 0},
677
6d6a11ba402a quick patch for adding 3g2 support to ffmpeg (muxer and demuxer). No movie fragment support yet patch by (tjraivio cc.hut fi)
michael
parents: 676
diff changeset
2283 };
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
2284 #endif
4206
c3102b189cb6 Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 4196
diff changeset
2285 #if CONFIG_IPOD_MUXER
3143
7f0f50bbfe23 ipod/iphone compatible mp4 muxer
bcoudurier
parents: 3024
diff changeset
2286 AVOutputFormat ipod_muxer = {
7f0f50bbfe23 ipod/iphone compatible mp4 muxer
bcoudurier
parents: 3024
diff changeset
2287 "ipod",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 3397
diff changeset
2288 NULL_IF_CONFIG_SMALL("iPod H.264 MP4 format"),
3143
7f0f50bbfe23 ipod/iphone compatible mp4 muxer
bcoudurier
parents: 3024
diff changeset
2289 "application/mp4",
3452
712d6fab85ee m4v/m4a are usual itunes/ipod/iphone extensions
bcoudurier
parents: 3451
diff changeset
2290 "m4v,m4a",
4609
065557d6fffb Rename movenc.c MOVContext to MOVMuxContext, since MOVContext is already used
rbultje
parents: 4587
diff changeset
2291 sizeof(MOVMuxContext),
3143
7f0f50bbfe23 ipod/iphone compatible mp4 muxer
bcoudurier
parents: 3024
diff changeset
2292 CODEC_ID_AAC,
7f0f50bbfe23 ipod/iphone compatible mp4 muxer
bcoudurier
parents: 3024
diff changeset
2293 CODEC_ID_H264,
7f0f50bbfe23 ipod/iphone compatible mp4 muxer
bcoudurier
parents: 3024
diff changeset
2294 mov_write_header,
6012
8298cc054242 Make mov_write_packet non-static, add ff_ prefix
mstorsjo
parents: 6011
diff changeset
2295 ff_mov_write_packet,
3143
7f0f50bbfe23 ipod/iphone compatible mp4 muxer
bcoudurier
parents: 3024
diff changeset
2296 mov_write_trailer,
7f0f50bbfe23 ipod/iphone compatible mp4 muxer
bcoudurier
parents: 3024
diff changeset
2297 .flags = AVFMT_GLOBALHEADER,
4698
3c93138ca17b use correct codec tag list for ipod format
bcoudurier
parents: 4695
diff changeset
2298 .codec_tag = (const AVCodecTag* const []){codec_ipod_tags, 0},
3143
7f0f50bbfe23 ipod/iphone compatible mp4 muxer
bcoudurier
parents: 3024
diff changeset
2299 };
7f0f50bbfe23 ipod/iphone compatible mp4 muxer
bcoudurier
parents: 3024
diff changeset
2300 #endif