Mercurial > libavformat.hg
annotate movenc.c @ 3406:ea339cc7c630 libavformat
flvenc.o depends on avc.o (for H.264 support functions).
patch by Peter Ross, pross xvid org
author | diego |
---|---|
date | Sat, 31 May 2008 14:26:56 +0000 |
parents | 76918939de90 |
children | 7a0230981402 |
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 |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
3 * Copyright (c) 2003 Thomas Raivio. |
365
4ae9fac22a5d
AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
342
diff
changeset
|
4 * Copyright (c) 2004 Gildas Bazin <gbazin at videolan dot org>. |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
5 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1292
diff
changeset
|
6 * This file is part of FFmpeg. |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1292
diff
changeset
|
7 * |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1292
diff
changeset
|
8 * 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
|
9 * 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
|
10 * 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
|
11 * 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
|
12 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1292
diff
changeset
|
13 * 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
|
14 * 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
|
15 * 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
|
16 * 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
|
17 * |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
18 * 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
|
19 * 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
|
20 * 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
|
21 */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
22 #include "avformat.h" |
1172
6a5e58d2114b
move common stuff from avienc.c and wav.c to new file riff.c
mru
parents:
1169
diff
changeset
|
23 #include "riff.h" |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
24 #include "avio.h" |
1216
fec0a3d5408f
move common code from mov.c and movenc.c to isom.c
bcoudurier
parents:
1172
diff
changeset
|
25 #include "isom.h" |
2922
dcd599833abc
Move isom_write_avcc() and related functions into a separate file.
aurel
parents:
2921
diff
changeset
|
26 #include "avc.h" |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
27 |
238
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
28 #undef NDEBUG |
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
29 #include <assert.h> |
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
30 |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
31 #define MOV_INDEX_CLUSTER_SIZE 16384 |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
32 #define globalTimescale 1000 |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
33 |
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
|
34 #define MODE_MP4 0 |
4ae9fac22a5d
AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
342
diff
changeset
|
35 #define MODE_MOV 1 |
4ae9fac22a5d
AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
342
diff
changeset
|
36 #define MODE_3GP 2 |
885 | 37 #define MODE_PSP 3 // example working PSP command line: |
659
6d7c0e6d929e
Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents:
657
diff
changeset
|
38 // ffmpeg -i testinput.avi -f psp -r 14.985 -s 320x240 -b 768 -ar 24000 -ab 32 M4V00001.MP4 |
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
|
39 #define MODE_3G2 4 |
3143 | 40 #define MODE_IPOD 5 |
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
|
41 |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
42 typedef struct MOVIentry { |
909
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
43 unsigned int flags, size; |
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
44 uint64_t pos; |
298
0b2eed7b1210
movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
286
diff
changeset
|
45 unsigned int samplesInChunk; |
259
e091218eccd2
mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
241
diff
changeset
|
46 char key_frame; |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
47 unsigned int entries; |
971
43f85eba04c4
CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents:
943
diff
changeset
|
48 int64_t cts; |
1437 | 49 int64_t dts; |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
50 } MOVIentry; |
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 typedef struct MOVIndex { |
365
4ae9fac22a5d
AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
342
diff
changeset
|
53 int mode; |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
54 int entry; |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
55 long timescale; |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
56 long time; |
1037 | 57 int64_t trackDuration; |
298
0b2eed7b1210
movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
286
diff
changeset
|
58 long sampleCount; |
1147 | 59 long sampleSize; |
259
e091218eccd2
mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
241
diff
changeset
|
60 int hasKeyframes; |
971
43f85eba04c4
CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents:
943
diff
changeset
|
61 int hasBframes; |
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
|
62 int language; |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
63 int trackID; |
2975 | 64 int tag; ///< stsd fourcc |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
65 AVCodecContext *enc; |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
66 |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
67 int vosLen; |
238
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
68 uint8_t *vosData; |
1129 | 69 MOVIentry *cluster; |
1437 | 70 int audio_vbr; |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
71 } MOVTrack; |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
72 |
659
6d7c0e6d929e
Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents:
657
diff
changeset
|
73 typedef struct MOVContext { |
365
4ae9fac22a5d
AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
342
diff
changeset
|
74 int mode; |
1037 | 75 int64_t time; |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
76 int nb_streams; |
259
e091218eccd2
mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
241
diff
changeset
|
77 offset_t mdat_pos; |
1080 | 78 uint64_t mdat_size; |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
79 long timescale; |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
80 MOVTrack tracks[MAX_STREAMS]; |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
81 } MOVContext; |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
82 |
2165 | 83 //FIXME support 64 bit variant with wide placeholders |
909
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
84 static offset_t updateSize (ByteIOContext *pb, offset_t pos) |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
85 { |
909
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
86 offset_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
|
87 url_fseek(pb, pos, SEEK_SET); |
238
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
88 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
|
89 url_fseek(pb, curpos, SEEK_SET); |
238
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
90 |
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
91 return curpos - pos; |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
92 } |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
93 |
298
0b2eed7b1210
movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
286
diff
changeset
|
94 /* Chunk offset atom */ |
238
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
95 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
|
96 { |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
97 int i; |
910 | 98 int mode64 = 0; // use 32 bit size variant if possible |
909
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
99 offset_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
|
100 put_be32(pb, 0); /* size */ |
909
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
101 if (pos > UINT32_MAX) { |
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
102 mode64 = 1; |
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
103 put_tag(pb, "co64"); |
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
104 } else |
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
105 put_tag(pb, "stco"); |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
106 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
|
107 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
|
108 for (i=0; i<track->entry; i++) { |
909
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
109 if(mode64 == 1) |
1129 | 110 put_be64(pb, track->cluster[i].pos); |
909
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
111 else |
1129 | 112 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
|
113 } |
259
e091218eccd2
mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
241
diff
changeset
|
114 return updateSize (pb, pos); |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
115 } |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
116 |
298
0b2eed7b1210
movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
286
diff
changeset
|
117 /* Sample size atom */ |
238
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
118 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
|
119 { |
259
e091218eccd2
mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
241
diff
changeset
|
120 int equalChunks = 1; |
298
0b2eed7b1210
movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
286
diff
changeset
|
121 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
|
122 |
909
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
123 offset_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
|
124 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
|
125 put_tag(pb, "stsz"); |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
126 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
|
127 |
259
e091218eccd2
mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
241
diff
changeset
|
128 for (i=0; i<track->entry; i++) { |
1129 | 129 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
|
130 if(oldtst != -1 && tst != oldtst) { |
0b2eed7b1210
movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
286
diff
changeset
|
131 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
|
132 } |
e091218eccd2
mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
241
diff
changeset
|
133 oldtst = tst; |
1129 | 134 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
|
135 } |
298
0b2eed7b1210
movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
286
diff
changeset
|
136 if (equalChunks) { |
1129 | 137 int sSize = track->cluster[0].size/track->cluster[0].entries; |
885 | 138 put_be32(pb, sSize); // sample size |
298
0b2eed7b1210
movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
286
diff
changeset
|
139 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
|
140 } |
e091218eccd2
mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
241
diff
changeset
|
141 else { |
885 | 142 put_be32(pb, 0); // sample size |
143 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
|
144 for (i=0; i<track->entry; i++) { |
3024
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
145 for (j=0; j<track->cluster[i].entries; j++) { |
1129 | 146 put_be32(pb, track->cluster[i].size / |
147 track->cluster[i].entries); | |
298
0b2eed7b1210
movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
286
diff
changeset
|
148 } |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
149 } |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
150 } |
259
e091218eccd2
mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
241
diff
changeset
|
151 return updateSize (pb, pos); |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
152 } |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
153 |
298
0b2eed7b1210
movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
286
diff
changeset
|
154 /* Sample to chunk atom */ |
238
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
155 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
|
156 { |
909
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
157 int index = 0, oldval = -1, i; |
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
158 offset_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
|
159 |
909
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
160 offset_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
|
161 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
|
162 put_tag(pb, "stsc"); |
885 | 163 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
|
164 entryPos = url_ftell(pb); |
885 | 165 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
|
166 for (i=0; i<track->entry; i++) { |
1129 | 167 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
|
168 { |
885 | 169 put_be32(pb, i+1); // first chunk |
1129 | 170 put_be32(pb, track->cluster[i].samplesInChunk); // samples per chunk |
885 | 171 put_be32(pb, 0x1); // sample description index |
1129 | 172 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
|
173 index++; |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
174 } |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
175 } |
259
e091218eccd2
mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
241
diff
changeset
|
176 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
|
177 url_fseek(pb, entryPos, SEEK_SET); |
885 | 178 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
|
179 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
|
180 |
259
e091218eccd2
mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
241
diff
changeset
|
181 return updateSize (pb, pos); |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
182 } |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
183 |
298
0b2eed7b1210
movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
286
diff
changeset
|
184 /* Sync sample atom */ |
259
e091218eccd2
mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
241
diff
changeset
|
185 static int mov_write_stss_tag(ByteIOContext *pb, MOVTrack* track) |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
186 { |
909
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
187 offset_t curpos, entryPos; |
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
188 int i, index = 0; |
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
189 offset_t pos = url_ftell(pb); |
885 | 190 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
|
191 put_tag(pb, "stss"); |
885 | 192 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
|
193 entryPos = url_ftell(pb); |
885 | 194 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
|
195 for (i=0; i<track->entry; i++) { |
1129 | 196 if(track->cluster[i].key_frame == 1) { |
259
e091218eccd2
mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
241
diff
changeset
|
197 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
|
198 index++; |
e091218eccd2
mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
241
diff
changeset
|
199 } |
e091218eccd2
mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
241
diff
changeset
|
200 } |
e091218eccd2
mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
241
diff
changeset
|
201 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
|
202 url_fseek(pb, entryPos, SEEK_SET); |
885 | 203 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
|
204 url_fseek(pb, curpos, SEEK_SET); |
e091218eccd2
mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
241
diff
changeset
|
205 return updateSize (pb, pos); |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
206 } |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
207 |
1152
c7cf3d1f9bd7
simplify and write correct values conforming to specs
bcoudurier
parents:
1151
diff
changeset
|
208 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
|
209 { |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
210 put_be32(pb, 0x11); /* size */ |
1152
c7cf3d1f9bd7
simplify and write correct values conforming to specs
bcoudurier
parents:
1151
diff
changeset
|
211 if (track->mode == MODE_MOV) put_tag(pb, "samr"); |
c7cf3d1f9bd7
simplify and write correct values conforming to specs
bcoudurier
parents:
1151
diff
changeset
|
212 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
|
213 put_tag(pb, "FFMP"); |
1152
c7cf3d1f9bd7
simplify and write correct values conforming to specs
bcoudurier
parents:
1151
diff
changeset
|
214 put_byte(pb, 0); /* decoder version */ |
1083 | 215 |
1153 | 216 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
|
217 put_byte(pb, 0x00); /* Mode change period (no restriction) */ |
c7cf3d1f9bd7
simplify and write correct values conforming to specs
bcoudurier
parents:
1151
diff
changeset
|
218 put_byte(pb, 0x01); /* Frames per sample */ |
1083 | 219 return 0x11; |
220 } | |
221 | |
3243 | 222 /** |
223 * This function writes extradata "as is". | |
224 * Extradata must be formated like a valid atom (with size and tag) | |
225 */ | |
226 static int mov_write_extradata_tag(ByteIOContext *pb, MOVTrack *track) | |
227 { | |
228 put_buffer(pb, track->enc->extradata, track->enc->extradata_size); | |
229 return track->enc->extradata_size; | |
230 } | |
231 | |
1082 | 232 static int mov_write_enda_tag(ByteIOContext *pb) |
233 { | |
234 put_be32(pb, 10); | |
235 put_tag(pb, "enda"); | |
236 put_be16(pb, 1); /* little endian */ | |
237 return 10; | |
238 } | |
239 | |
1080 | 240 static unsigned int descrLength(unsigned int len) |
241 { | |
1081 | 242 int i; |
243 for(i=1; len>>(7*i); i++); | |
244 return len + 1 + i; | |
1080 | 245 } |
246 | |
1081 | 247 static void putDescr(ByteIOContext *pb, int tag, unsigned int size) |
1080 | 248 { |
1081 | 249 int i= descrLength(size) - size - 2; |
250 put_byte(pb, tag); | |
251 for(; i>0; i--) | |
252 put_byte(pb, (size>>(7*i)) | 0x80); | |
253 put_byte(pb, size & 0x7F); | |
1080 | 254 } |
255 | |
256 static int mov_write_esds_tag(ByteIOContext *pb, MOVTrack* track) // Basic | |
257 { | |
258 offset_t pos = url_ftell(pb); | |
1082 | 259 int decoderSpecificInfoLen = track->vosLen ? descrLength(track->vosLen):0; |
1080 | 260 |
3246
a6a78c1cbf33
cosmetics: remove useless whitespaces and put braces correctly
bcoudurier
parents:
3243
diff
changeset
|
261 put_be32(pb, 0); // size |
1080 | 262 put_tag(pb, "esds"); |
3246
a6a78c1cbf33
cosmetics: remove useless whitespaces and put braces correctly
bcoudurier
parents:
3243
diff
changeset
|
263 put_be32(pb, 0); // Version |
1080 | 264 |
265 // ES descriptor | |
266 putDescr(pb, 0x03, 3 + descrLength(13 + decoderSpecificInfoLen) + | |
267 descrLength(1)); | |
268 put_be16(pb, track->trackID); | |
3246
a6a78c1cbf33
cosmetics: remove useless whitespaces and put braces correctly
bcoudurier
parents:
3243
diff
changeset
|
269 put_byte(pb, 0x00); // flags (= no flags) |
1080 | 270 |
271 // DecoderConfig descriptor | |
272 putDescr(pb, 0x04, 13 + decoderSpecificInfoLen); | |
273 | |
274 // Object type indication | |
1948 | 275 put_byte(pb, codec_get_tag(ff_mp4_obj_type, track->enc->codec_id)); |
1080 | 276 |
277 // the following fields is made of 6 bits to identify the streamtype (4 for video, 5 for audio) | |
278 // plus 1 bit to indicate upstream and 1 bit set to 1 (reserved) | |
279 if(track->enc->codec_type == CODEC_TYPE_AUDIO) | |
3246
a6a78c1cbf33
cosmetics: remove useless whitespaces and put braces correctly
bcoudurier
parents:
3243
diff
changeset
|
280 put_byte(pb, 0x15); // flags (= Audiostream) |
1080 | 281 else |
3246
a6a78c1cbf33
cosmetics: remove useless whitespaces and put braces correctly
bcoudurier
parents:
3243
diff
changeset
|
282 put_byte(pb, 0x11); // flags (= Visualstream) |
1080 | 283 |
3246
a6a78c1cbf33
cosmetics: remove useless whitespaces and put braces correctly
bcoudurier
parents:
3243
diff
changeset
|
284 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
|
285 put_be16(pb, (track->enc->rc_buffer_size>>3)&0xFFFF); // Buffersize DB |
1080 | 286 |
3246
a6a78c1cbf33
cosmetics: remove useless whitespaces and put braces correctly
bcoudurier
parents:
3243
diff
changeset
|
287 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 | 288 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
|
289 put_be32(pb, 0); // vbr |
1080 | 290 else |
3246
a6a78c1cbf33
cosmetics: remove useless whitespaces and put braces correctly
bcoudurier
parents:
3243
diff
changeset
|
291 put_be32(pb, track->enc->rc_max_rate); // avg bitrate |
1080 | 292 |
3246
a6a78c1cbf33
cosmetics: remove useless whitespaces and put braces correctly
bcoudurier
parents:
3243
diff
changeset
|
293 if (track->vosLen) { |
1080 | 294 // DecoderSpecific info descriptor |
295 putDescr(pb, 0x05, track->vosLen); | |
296 put_buffer(pb, track->vosData, track->vosLen); | |
297 } | |
298 | |
299 // SL descriptor | |
300 putDescr(pb, 0x06, 1); | |
301 put_byte(pb, 0x02); | |
302 return updateSize (pb, pos); | |
303 } | |
304 | |
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
|
305 static int mov_write_wave_tag(ByteIOContext *pb, MOVTrack* track) |
4ae9fac22a5d
AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
342
diff
changeset
|
306 { |
909
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
307 offset_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
|
308 |
4ae9fac22a5d
AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
342
diff
changeset
|
309 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
|
310 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
|
311 |
4ae9fac22a5d
AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
342
diff
changeset
|
312 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
|
313 put_tag(pb, "frma"); |
1082 | 314 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
|
315 |
1082 | 316 if (track->enc->codec_id == CODEC_ID_AAC) { |
1125 | 317 /* useless atom needed by mplayer, ipod, not needed by quicktime */ |
318 put_be32(pb, 12); /* size */ | |
319 put_tag(pb, "mp4a"); | |
320 put_be32(pb, 0); | |
1082 | 321 mov_write_esds_tag(pb, track); |
322 } else if (track->enc->codec_id == CODEC_ID_PCM_S24LE || | |
323 track->enc->codec_id == CODEC_ID_PCM_S32LE) { | |
324 mov_write_enda_tag(pb); | |
1083 | 325 } 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
|
326 mov_write_amr_tag(pb, track); |
3243 | 327 } else if (track->enc->codec_id == CODEC_ID_ALAC) { |
328 mov_write_extradata_tag(pb, track); | |
1082 | 329 } |
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
|
330 |
4ae9fac22a5d
AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
342
diff
changeset
|
331 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
|
332 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
|
333 |
4ae9fac22a5d
AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
342
diff
changeset
|
334 return updateSize (pb, pos); |
4ae9fac22a5d
AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
342
diff
changeset
|
335 } |
4ae9fac22a5d
AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
342
diff
changeset
|
336 |
2838
6bea49ef18b1
use generic 'glbl' atom if extradata is present but no specific method is known
bcoudurier
parents:
2802
diff
changeset
|
337 static int mov_write_glbl_tag(ByteIOContext *pb, MOVTrack* track) |
6bea49ef18b1
use generic 'glbl' atom if extradata is present but no specific method is known
bcoudurier
parents:
2802
diff
changeset
|
338 { |
6bea49ef18b1
use generic 'glbl' atom if extradata is present but no specific method is known
bcoudurier
parents:
2802
diff
changeset
|
339 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
|
340 put_tag(pb, "glbl"); |
6bea49ef18b1
use generic 'glbl' atom if extradata is present but no specific method is known
bcoudurier
parents:
2802
diff
changeset
|
341 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
|
342 return 8+track->vosLen; |
6bea49ef18b1
use generic 'glbl' atom if extradata is present but no specific method is known
bcoudurier
parents:
2802
diff
changeset
|
343 } |
6bea49ef18b1
use generic 'glbl' atom if extradata is present but no specific method is known
bcoudurier
parents:
2802
diff
changeset
|
344 |
259
e091218eccd2
mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
241
diff
changeset
|
345 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
|
346 { |
909
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
347 offset_t pos = url_ftell(pb); |
1438 | 348 int version = track->mode == MODE_MOV && |
349 (track->audio_vbr || | |
350 track->enc->codec_id == CODEC_ID_PCM_S32LE || | |
351 track->enc->codec_id == CODEC_ID_PCM_S24LE); | |
885 | 352 |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
353 put_be32(pb, 0); /* size */ |
1080 | 354 put_le32(pb, track->tag); // store it byteswapped |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
355 put_be32(pb, 0); /* Reserved */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
356 put_be16(pb, 0); /* Reserved */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
357 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
|
358 |
298
0b2eed7b1210
movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
286
diff
changeset
|
359 /* SoundDescription */ |
1082 | 360 put_be16(pb, version); /* Version */ |
298
0b2eed7b1210
movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
286
diff
changeset
|
361 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
|
362 put_be32(pb, 0); /* Reserved */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
363 |
1849 | 364 if (track->mode == MODE_MOV) { |
365 put_be16(pb, track->enc->channels); | |
1850 | 366 if (track->enc->codec_id == CODEC_ID_PCM_U8 || |
367 track->enc->codec_id == CODEC_ID_PCM_S8) | |
368 put_be16(pb, 8); /* bits per sample */ | |
369 else | |
370 put_be16(pb, 16); | |
1849 | 371 put_be16(pb, track->audio_vbr ? -2 : 0); /* compression ID */ |
372 } else { /* reserved for mp4/3gp */ | |
373 put_be16(pb, 2); | |
374 put_be16(pb, 16); | |
375 put_be16(pb, 0); | |
376 } | |
505
e996e7da971c
AAC in mov/mp4 patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
494
diff
changeset
|
377 |
399
6ab5454567b6
* making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents:
397
diff
changeset
|
378 put_be16(pb, 0); /* packet size (= 0) */ |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
379 put_be16(pb, track->timescale); /* Time scale */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
380 put_be16(pb, 0); /* Reserved */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
381 |
1147 | 382 if(version == 1) { /* SoundDescription V1 extended info */ |
383 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
|
384 put_be32(pb, track->sampleSize / track->enc->channels); /* Bytes per packet */ |
1147 | 385 put_be32(pb, track->sampleSize); /* Bytes per frame */ |
1125 | 386 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
|
387 } |
4ae9fac22a5d
AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
342
diff
changeset
|
388 |
1084 | 389 if(track->mode == MODE_MOV && |
390 (track->enc->codec_id == CODEC_ID_AAC || | |
391 track->enc->codec_id == CODEC_ID_AMR_NB || | |
392 track->enc->codec_id == CODEC_ID_PCM_S24LE || | |
3243 | 393 track->enc->codec_id == CODEC_ID_PCM_S32LE || |
394 track->enc->codec_id == CODEC_ID_ALAC)) | |
1083 | 395 mov_write_wave_tag(pb, track); |
2977
b5ad3169a579
write esds atom when mpeg-4 systems tags are used
bcoudurier
parents:
2975
diff
changeset
|
396 else if(track->tag == MKTAG('m','p','4','a')) |
1083 | 397 mov_write_esds_tag(pb, track); |
398 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
|
399 mov_write_amr_tag(pb, track); |
2838
6bea49ef18b1
use generic 'glbl' atom if extradata is present but no specific method is known
bcoudurier
parents:
2802
diff
changeset
|
400 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
|
401 mov_write_glbl_tag(pb, track); |
1083 | 402 |
238
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
403 return updateSize (pb, pos); |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
404 } |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
405 |
238
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
406 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
|
407 { |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
408 put_be32(pb, 0xf); /* size */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
409 put_tag(pb, "d263"); |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
410 put_tag(pb, "FFMP"); |
1240 | 411 put_byte(pb, 0); /* decoder version */ |
412 /* FIXME use AVCodecContext level/profile, when encoder will set values */ | |
413 put_byte(pb, 0xa); /* level */ | |
414 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
|
415 return 0xf; |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
416 } |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
417 |
259
e091218eccd2
mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
241
diff
changeset
|
418 /* 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
|
419 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
|
420 { |
259
e091218eccd2
mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
241
diff
changeset
|
421 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
|
422 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
|
423 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
|
424 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
|
425 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
|
426 put_be32(pb, 0xc0000000); |
885 | 427 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
|
428 return 0x15; |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
429 } |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
430 |
2921 | 431 static int mov_write_avcc_tag(ByteIOContext *pb, MOVTrack *track) |
432 { | |
433 offset_t pos = url_ftell(pb); | |
434 | |
435 put_be32(pb, 0); | |
436 put_tag(pb, "avcC"); | |
2927
b75a49790f31
add a ff_ prefix to newly exported functions from avc.c
aurel
parents:
2922
diff
changeset
|
437 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
|
438 return updateSize(pb, pos); |
15bfc3c063dc
do nal reformating when muxing H264, create avcc atom
bcoudurier
parents:
1000
diff
changeset
|
439 } |
15bfc3c063dc
do nal reformating when muxing H264, create avcc atom
bcoudurier
parents:
1000
diff
changeset
|
440 |
2588 | 441 /* also used by all avid codecs (dv, imx, meridien) and their variants */ |
442 static int mov_write_avid_tag(ByteIOContext *pb, MOVTrack *track) | |
443 { | |
444 int i; | |
445 put_be32(pb, 24); /* size */ | |
446 put_tag(pb, "ACLR"); | |
447 put_tag(pb, "ACLR"); | |
448 put_tag(pb, "0001"); | |
449 put_be32(pb, 1); /* yuv 1 / rgb 2 ? */ | |
450 put_be32(pb, 0); /* unknown */ | |
451 | |
452 put_be32(pb, 24); /* size */ | |
453 put_tag(pb, "APRG"); | |
454 put_tag(pb, "APRG"); | |
455 put_tag(pb, "0001"); | |
456 put_be32(pb, 1); /* unknown */ | |
457 put_be32(pb, 0); /* unknown */ | |
458 | |
459 put_be32(pb, 120); /* size */ | |
460 put_tag(pb, "ARES"); | |
461 put_tag(pb, "ARES"); | |
462 put_tag(pb, "0001"); | |
463 put_be32(pb, AV_RB32(track->vosData + 0x28)); /* dnxhd cid, some id ? */ | |
464 put_be32(pb, track->enc->width); | |
465 /* values below are based on samples created with quicktime and avid codecs */ | |
466 if (track->vosData[5] & 2) { // interlaced | |
467 put_be32(pb, track->enc->height/2); | |
468 put_be32(pb, 2); /* unknown */ | |
469 put_be32(pb, 0); /* unknown */ | |
470 put_be32(pb, 4); /* unknown */ | |
471 } else { | |
472 put_be32(pb, track->enc->height); | |
473 put_be32(pb, 1); /* unknown */ | |
474 put_be32(pb, 0); /* unknown */ | |
2802 | 475 if (track->enc->height == 1080) |
476 put_be32(pb, 5); /* unknown */ | |
477 else | |
478 put_be32(pb, 6); /* unknown */ | |
2588 | 479 } |
480 /* padding */ | |
481 for (i = 0; i < 10; i++) | |
482 put_be64(pb, 0); | |
483 | |
484 /* extra padding for stsd needed */ | |
485 put_be32(pb, 0); | |
486 return 0; | |
487 } | |
488 | |
2978
8dcdecbbf7e6
correctly and only set standard stsd fourcc for mp4/3gp
bcoudurier
parents:
2977
diff
changeset
|
489 static const AVCodecTag codec_3gp_tags[] = { |
8dcdecbbf7e6
correctly and only set standard stsd fourcc for mp4/3gp
bcoudurier
parents:
2977
diff
changeset
|
490 { CODEC_ID_H263, MKTAG('s','2','6','3') }, |
8dcdecbbf7e6
correctly and only set standard stsd fourcc for mp4/3gp
bcoudurier
parents:
2977
diff
changeset
|
491 { CODEC_ID_H264, MKTAG('a','v','c','1') }, |
8dcdecbbf7e6
correctly and only set standard stsd fourcc for mp4/3gp
bcoudurier
parents:
2977
diff
changeset
|
492 { CODEC_ID_MPEG4, MKTAG('m','p','4','v') }, |
8dcdecbbf7e6
correctly and only set standard stsd fourcc for mp4/3gp
bcoudurier
parents:
2977
diff
changeset
|
493 { CODEC_ID_AAC, MKTAG('m','p','4','a') }, |
8dcdecbbf7e6
correctly and only set standard stsd fourcc for mp4/3gp
bcoudurier
parents:
2977
diff
changeset
|
494 { CODEC_ID_AMR_NB, MKTAG('s','a','m','r') }, |
8dcdecbbf7e6
correctly and only set standard stsd fourcc for mp4/3gp
bcoudurier
parents:
2977
diff
changeset
|
495 { CODEC_ID_AMR_WB, MKTAG('s','a','w','b') }, |
8dcdecbbf7e6
correctly and only set standard stsd fourcc for mp4/3gp
bcoudurier
parents:
2977
diff
changeset
|
496 }; |
8dcdecbbf7e6
correctly and only set standard stsd fourcc for mp4/3gp
bcoudurier
parents:
2977
diff
changeset
|
497 |
2992 | 498 static const AVCodecTag mov_pix_fmt_tags[] = { |
499 { PIX_FMT_YUYV422, MKTAG('y','u','v','s') }, | |
2993 | 500 { PIX_FMT_UYVY422, MKTAG('2','v','u','y') }, |
2992 | 501 { PIX_FMT_BGR555, MKTAG('r','a','w',' ') }, |
502 { PIX_FMT_RGB24, MKTAG('r','a','w',' ') }, | |
503 { PIX_FMT_BGR32_1, MKTAG('r','a','w',' ') }, | |
504 }; | |
505 | |
2978
8dcdecbbf7e6
correctly and only set standard stsd fourcc for mp4/3gp
bcoudurier
parents:
2977
diff
changeset
|
506 static int mov_find_codec_tag(AVFormatContext *s, MOVTrack *track) |
1000 | 507 { |
1080 | 508 int tag = track->enc->codec_tag; |
3143 | 509 if (track->mode == MODE_MP4 || track->mode == MODE_PSP || track->mode == MODE_IPOD) { |
2978
8dcdecbbf7e6
correctly and only set standard stsd fourcc for mp4/3gp
bcoudurier
parents:
2977
diff
changeset
|
510 if (!codec_get_tag(ff_mp4_obj_type, track->enc->codec_id)) |
8dcdecbbf7e6
correctly and only set standard stsd fourcc for mp4/3gp
bcoudurier
parents:
2977
diff
changeset
|
511 return 0; |
8dcdecbbf7e6
correctly and only set standard stsd fourcc for mp4/3gp
bcoudurier
parents:
2977
diff
changeset
|
512 if (track->enc->codec_id == CODEC_ID_H264) tag = MKTAG('a','v','c','1'); |
8dcdecbbf7e6
correctly and only set standard stsd fourcc for mp4/3gp
bcoudurier
parents:
2977
diff
changeset
|
513 else if (track->enc->codec_type == CODEC_TYPE_VIDEO) tag = MKTAG('m','p','4','v'); |
8dcdecbbf7e6
correctly and only set standard stsd fourcc for mp4/3gp
bcoudurier
parents:
2977
diff
changeset
|
514 else if (track->enc->codec_type == CODEC_TYPE_AUDIO) tag = MKTAG('m','p','4','a'); |
8dcdecbbf7e6
correctly and only set standard stsd fourcc for mp4/3gp
bcoudurier
parents:
2977
diff
changeset
|
515 } else if (track->mode == MODE_3GP || track->mode == MODE_3G2) { |
8dcdecbbf7e6
correctly and only set standard stsd fourcc for mp4/3gp
bcoudurier
parents:
2977
diff
changeset
|
516 tag = codec_get_tag(codec_3gp_tags, track->enc->codec_id); |
2981
3c0b2165d82c
spoke too fast, fix dv fourcc in mov accordingly if strict
bcoudurier
parents:
2980
diff
changeset
|
517 } else if (!tag || (track->enc->strict_std_compliance >= FF_COMPLIANCE_NORMAL && |
2992 | 518 (tag == MKTAG('d','v','c','p') || |
519 track->enc->codec_id == CODEC_ID_RAWVIDEO))) { | |
1000 | 520 if (track->enc->codec_id == CODEC_ID_DVVIDEO) { |
2982 | 521 if (track->enc->height == 480) /* NTSC */ |
522 if (track->enc->pix_fmt == PIX_FMT_YUV422P) tag = MKTAG('d','v','5','n'); | |
523 else tag = MKTAG('d','v','c',' '); | |
524 else if (track->enc->pix_fmt == PIX_FMT_YUV422P) tag = MKTAG('d','v','5','p'); | |
525 else if (track->enc->pix_fmt == PIX_FMT_YUV420P) tag = MKTAG('d','v','c','p'); | |
526 else tag = MKTAG('d','v','p','p'); | |
2992 | 527 } else if (track->enc->codec_id == CODEC_ID_RAWVIDEO) { |
528 tag = codec_get_tag(mov_pix_fmt_tags, track->enc->pix_fmt); | |
529 if (!tag) // restore tag | |
530 tag = track->enc->codec_tag; | |
1000 | 531 } else { |
2978
8dcdecbbf7e6
correctly and only set standard stsd fourcc for mp4/3gp
bcoudurier
parents:
2977
diff
changeset
|
532 if (track->enc->codec_type == CODEC_TYPE_VIDEO) { |
2979 | 533 tag = codec_get_tag(codec_movvideo_tags, track->enc->codec_id); |
2983
9b2ec755da98
cosmetics, split long lines, remove useless braces, merge comments and if
bcoudurier
parents:
2982
diff
changeset
|
534 if (!tag) { // if no mac fcc found, try with Microsoft tags |
2979 | 535 tag = codec_get_tag(codec_bmp_tags, track->enc->codec_id); |
2983
9b2ec755da98
cosmetics, split long lines, remove useless braces, merge comments and if
bcoudurier
parents:
2982
diff
changeset
|
536 if (tag) |
9b2ec755da98
cosmetics, split long lines, remove useless braces, merge comments and if
bcoudurier
parents:
2982
diff
changeset
|
537 av_log(s, AV_LOG_INFO, "Warning, using MS style video codec tag, " |
9b2ec755da98
cosmetics, split long lines, remove useless braces, merge comments and if
bcoudurier
parents:
2982
diff
changeset
|
538 "the file may be unplayable!\n"); |
2979 | 539 } |
2978
8dcdecbbf7e6
correctly and only set standard stsd fourcc for mp4/3gp
bcoudurier
parents:
2977
diff
changeset
|
540 } else if (track->enc->codec_type == CODEC_TYPE_AUDIO) { |
2979 | 541 tag = codec_get_tag(codec_movaudio_tags, track->enc->codec_id); |
2983
9b2ec755da98
cosmetics, split long lines, remove useless braces, merge comments and if
bcoudurier
parents:
2982
diff
changeset
|
542 if (!tag) { // if no mac fcc found, try with Microsoft tags |
2979 | 543 int ms_tag = codec_get_tag(codec_wav_tags, track->enc->codec_id); |
544 if (ms_tag) { | |
545 tag = MKTAG('m', 's', ((ms_tag >> 8) & 0xff), (ms_tag & 0xff)); | |
2983
9b2ec755da98
cosmetics, split long lines, remove useless braces, merge comments and if
bcoudurier
parents:
2982
diff
changeset
|
546 av_log(s, AV_LOG_INFO, "Warning, using MS style audio codec tag, " |
9b2ec755da98
cosmetics, split long lines, remove useless braces, merge comments and if
bcoudurier
parents:
2982
diff
changeset
|
547 "the file may be unplayable!\n"); |
2979 | 548 } |
549 } | |
2978
8dcdecbbf7e6
correctly and only set standard stsd fourcc for mp4/3gp
bcoudurier
parents:
2977
diff
changeset
|
550 } |
8dcdecbbf7e6
correctly and only set standard stsd fourcc for mp4/3gp
bcoudurier
parents:
2977
diff
changeset
|
551 } |
8dcdecbbf7e6
correctly and only set standard stsd fourcc for mp4/3gp
bcoudurier
parents:
2977
diff
changeset
|
552 } |
1000 | 553 return tag; |
554 } | |
555 | |
3143 | 556 /** Write uuid atom. |
557 * Needed to make file play in iPods running newest firmware | |
558 * goes after avcC atom in moov.trak.mdia.minf.stbl.stsd.avc1 | |
559 */ | |
560 static int mov_write_uuid_tag_ipod(ByteIOContext *pb) | |
561 { | |
562 put_be32(pb, 28); | |
563 put_tag(pb, "uuid"); | |
564 put_be32(pb, 0x6b6840f2); | |
565 put_be32(pb, 0x5f244fc5); | |
566 put_be32(pb, 0xba39a51b); | |
567 put_be32(pb, 0xcf0323f3); | |
568 put_be32(pb, 0x0); | |
569 return 28; | |
570 } | |
571 | |
259
e091218eccd2
mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
241
diff
changeset
|
572 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
|
573 { |
909
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
574 offset_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
|
575 char compressor_name[32]; |
422 | 576 |
259
e091218eccd2
mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
241
diff
changeset
|
577 put_be32(pb, 0); /* size */ |
1080 | 578 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
|
579 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
|
580 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
|
581 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
|
582 |
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
|
583 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
|
584 put_be16(pb, 0); /* Codec stream revision (=0) */ |
1238 | 585 if (track->mode == MODE_MOV) { |
1239 | 586 put_tag(pb, "FFMP"); /* Vendor */ |
587 if(track->enc->codec_id == CODEC_ID_RAWVIDEO) { | |
588 put_be32(pb, 0); /* Temporal Quality */ | |
589 put_be32(pb, 0x400); /* Spatial Quality = lossless*/ | |
590 } else { | |
591 put_be32(pb, 0x200); /* Temporal Quality = normal */ | |
592 put_be32(pb, 0x200); /* Spatial Quality = normal */ | |
593 } | |
1238 | 594 } else { |
595 put_be32(pb, 0); /* Reserved */ | |
596 put_be32(pb, 0); /* Reserved */ | |
597 put_be32(pb, 0); /* Reserved */ | |
598 } | |
259
e091218eccd2
mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
241
diff
changeset
|
599 put_be16(pb, track->enc->width); /* Video width */ |
e091218eccd2
mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
241
diff
changeset
|
600 put_be16(pb, track->enc->height); /* Video height */ |
657
5b9575f5b6e8
mov header field and compressor name patch by Roine Gustafsson <roine AT users DOT sourceforge DOT net>
mmu_man
parents:
619
diff
changeset
|
601 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
|
602 put_be32(pb, 0x00480000); /* Vertical resolution 72dpi */ |
399
6ab5454567b6
* making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents:
397
diff
changeset
|
603 put_be32(pb, 0); /* Data size (= 0) */ |
6ab5454567b6
* making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents:
397
diff
changeset
|
604 put_be16(pb, 1); /* Frame count (= 1) */ |
885 | 605 |
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
|
606 memset(compressor_name,0,32); |
1238 | 607 /* FIXME not sure, ISO 14496-1 draft where it shall be set to 0 */ |
608 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
|
609 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
|
610 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
|
611 put_buffer(pb, compressor_name, 31); |
885 | 612 |
2992 | 613 if (track->mode == MODE_MOV && track->enc->bits_per_sample) |
614 put_be16(pb, track->enc->bits_per_sample); | |
615 else | |
616 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
|
617 put_be16(pb, 0xffff); /* Reserved */ |
2977
b5ad3169a579
write esds atom when mpeg-4 systems tags are used
bcoudurier
parents:
2975
diff
changeset
|
618 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
|
619 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
|
620 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
|
621 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
|
622 else if(track->enc->codec_id == CODEC_ID_SVQ3) |
885 | 623 mov_write_svq3_tag(pb); |
3158 | 624 else if(track->enc->codec_id == CODEC_ID_DNXHD) |
625 mov_write_avid_tag(pb, track); | |
3143 | 626 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
|
627 mov_write_avcc_tag(pb, track); |
3143 | 628 if(track->mode == MODE_IPOD) |
629 mov_write_uuid_tag_ipod(pb); | |
3203 | 630 } 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
|
631 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
|
632 |
e091218eccd2
mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
241
diff
changeset
|
633 return updateSize (pb, pos); |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
634 } |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
635 |
238
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
636 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
|
637 { |
909
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
638 offset_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
|
639 put_be32(pb, 0); /* size */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
640 put_tag(pb, "stsd"); |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
641 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
|
642 put_be32(pb, 1); /* entry count */ |
259
e091218eccd2
mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
241
diff
changeset
|
643 if (track->enc->codec_type == CODEC_TYPE_VIDEO) |
e091218eccd2
mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
241
diff
changeset
|
644 mov_write_video_tag(pb, track); |
e091218eccd2
mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
241
diff
changeset
|
645 else if (track->enc->codec_type == CODEC_TYPE_AUDIO) |
e091218eccd2
mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
241
diff
changeset
|
646 mov_write_audio_tag(pb, track); |
238
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
647 return updateSize(pb, pos); |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
648 } |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
649 |
971
43f85eba04c4
CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents:
943
diff
changeset
|
650 static int mov_write_ctts_tag(ByteIOContext *pb, MOVTrack* track) |
43f85eba04c4
CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents:
943
diff
changeset
|
651 { |
2045
aa5e56700fdf
cosmectics, use consistant and homogeneous type names for atoms
bcoudurier
parents:
1948
diff
changeset
|
652 MOV_stts_t *ctts_entries; |
971
43f85eba04c4
CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents:
943
diff
changeset
|
653 uint32_t entries = 0; |
43f85eba04c4
CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents:
943
diff
changeset
|
654 uint32_t atom_size; |
43f85eba04c4
CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents:
943
diff
changeset
|
655 int i; |
43f85eba04c4
CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents:
943
diff
changeset
|
656 |
43f85eba04c4
CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents:
943
diff
changeset
|
657 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
|
658 ctts_entries[0].count = 1; |
1129 | 659 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
|
660 for (i=1; i<track->entry; i++) { |
1129 | 661 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
|
662 ctts_entries[entries].count++; /* compress */ |
43f85eba04c4
CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents:
943
diff
changeset
|
663 } else { |
43f85eba04c4
CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents:
943
diff
changeset
|
664 entries++; |
1129 | 665 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
|
666 ctts_entries[entries].count = 1; |
43f85eba04c4
CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents:
943
diff
changeset
|
667 } |
43f85eba04c4
CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents:
943
diff
changeset
|
668 } |
43f85eba04c4
CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents:
943
diff
changeset
|
669 entries++; /* last one */ |
43f85eba04c4
CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents:
943
diff
changeset
|
670 atom_size = 16 + (entries * 8); |
43f85eba04c4
CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents:
943
diff
changeset
|
671 put_be32(pb, atom_size); /* size */ |
43f85eba04c4
CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents:
943
diff
changeset
|
672 put_tag(pb, "ctts"); |
43f85eba04c4
CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents:
943
diff
changeset
|
673 put_be32(pb, 0); /* version & flags */ |
43f85eba04c4
CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents:
943
diff
changeset
|
674 put_be32(pb, entries); /* entry count */ |
43f85eba04c4
CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents:
943
diff
changeset
|
675 for (i=0; i<entries; i++) { |
43f85eba04c4
CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents:
943
diff
changeset
|
676 put_be32(pb, ctts_entries[i].count); |
43f85eba04c4
CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents:
943
diff
changeset
|
677 put_be32(pb, ctts_entries[i].duration); |
43f85eba04c4
CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents:
943
diff
changeset
|
678 } |
43f85eba04c4
CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents:
943
diff
changeset
|
679 av_free(ctts_entries); |
43f85eba04c4
CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents:
943
diff
changeset
|
680 return atom_size; |
43f85eba04c4
CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents:
943
diff
changeset
|
681 } |
43f85eba04c4
CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents:
943
diff
changeset
|
682 |
298
0b2eed7b1210
movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
286
diff
changeset
|
683 /* Time to sample atom */ |
238
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
684 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
|
685 { |
2045
aa5e56700fdf
cosmectics, use consistant and homogeneous type names for atoms
bcoudurier
parents:
1948
diff
changeset
|
686 MOV_stts_t *stts_entries; |
1437 | 687 uint32_t entries = -1; |
688 uint32_t atom_size; | |
689 int i; | |
690 | |
691 if (track->enc->codec_type == CODEC_TYPE_AUDIO && !track->audio_vbr) { | |
692 stts_entries = av_malloc(sizeof(*stts_entries)); /* one entry */ | |
693 stts_entries[0].count = track->sampleCount; | |
694 stts_entries[0].duration = 1; | |
695 entries = 1; | |
696 } else { | |
697 stts_entries = av_malloc(track->entry * sizeof(*stts_entries)); /* worst case */ | |
698 for (i=0; i<track->entry; i++) { | |
699 int64_t duration = i + 1 == track->entry ? | |
700 track->trackDuration - track->cluster[i].dts + track->cluster[0].dts : /* readjusting */ | |
701 track->cluster[i+1].dts - track->cluster[i].dts; | |
702 if (i && duration == stts_entries[entries].duration) { | |
703 stts_entries[entries].count++; /* compress */ | |
704 } else { | |
705 entries++; | |
706 stts_entries[entries].duration = duration; | |
707 stts_entries[entries].count = 1; | |
708 } | |
709 } | |
710 entries++; /* last one */ | |
711 } | |
712 atom_size = 16 + (entries * 8); | |
713 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
|
714 put_tag(pb, "stts"); |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
715 put_be32(pb, 0); /* version & flags */ |
1437 | 716 put_be32(pb, entries); /* entry count */ |
717 for (i=0; i<entries; i++) { | |
718 put_be32(pb, stts_entries[i].count); | |
719 put_be32(pb, stts_entries[i].duration); | |
720 } | |
721 av_free(stts_entries); | |
722 return atom_size; | |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
723 } |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
724 |
238
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
725 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
|
726 { |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
727 put_be32(pb, 28); /* size */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
728 put_tag(pb, "dref"); |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
729 put_be32(pb, 0); /* version & flags */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
730 put_be32(pb, 1); /* entry count */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
731 |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
732 put_be32(pb, 0xc); /* size */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
733 put_tag(pb, "url "); |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
734 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
|
735 |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
736 return 28; |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
737 } |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
738 |
238
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
739 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
|
740 { |
909
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
741 offset_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
|
742 put_be32(pb, 0); /* size */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
743 put_tag(pb, "stbl"); |
238
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
744 mov_write_stsd_tag(pb, track); |
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
745 mov_write_stts_tag(pb, track); |
259
e091218eccd2
mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
241
diff
changeset
|
746 if (track->enc->codec_type == CODEC_TYPE_VIDEO && |
3192 | 747 track->hasKeyframes && track->hasKeyframes < track->entry) |
259
e091218eccd2
mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
241
diff
changeset
|
748 mov_write_stss_tag(pb, track); |
971
43f85eba04c4
CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents:
943
diff
changeset
|
749 if (track->enc->codec_type == CODEC_TYPE_VIDEO && |
43f85eba04c4
CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents:
943
diff
changeset
|
750 track->hasBframes) |
43f85eba04c4
CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents:
943
diff
changeset
|
751 mov_write_ctts_tag(pb, track); |
238
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
752 mov_write_stsc_tag(pb, track); |
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
753 mov_write_stsz_tag(pb, track); |
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
754 mov_write_stco_tag(pb, track); |
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
755 return updateSize(pb, pos); |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
756 } |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
757 |
238
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
758 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
|
759 { |
909
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
760 offset_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
|
761 put_be32(pb, 0); /* size */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
762 put_tag(pb, "dinf"); |
238
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
763 mov_write_dref_tag(pb); |
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
764 return updateSize(pb, pos); |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
765 } |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
766 |
238
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
767 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
|
768 { |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
769 put_be32(pb, 16); /* size */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
770 put_tag(pb, "smhd"); |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
771 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
|
772 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
|
773 put_be16(pb, 0); /* reserved */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
774 return 16; |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
775 } |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
776 |
238
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
777 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
|
778 { |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
779 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
|
780 put_tag(pb, "vmhd"); |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
781 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
|
782 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
|
783 return 0x14; |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
784 } |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
785 |
399
6ab5454567b6
* making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents:
397
diff
changeset
|
786 static int mov_write_hdlr_tag(ByteIOContext *pb, MOVTrack* track) |
6ab5454567b6
* making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents:
397
diff
changeset
|
787 { |
1123
6992dd78ff68
Add (mostly) const to variable and parameter declaration, where a char* was
diego
parents:
1112
diff
changeset
|
788 const char *descr, *hdlr, *hdlr_type; |
909
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
789 offset_t pos = url_ftell(pb); |
885 | 790 |
399
6ab5454567b6
* making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents:
397
diff
changeset
|
791 if (!track) { /* no media --> data handler */ |
887 | 792 hdlr = "dhlr"; |
793 hdlr_type = "url "; | |
794 descr = "DataHandler"; | |
399
6ab5454567b6
* making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents:
397
diff
changeset
|
795 } else { |
887 | 796 hdlr = (track->mode == MODE_MOV) ? "mhlr" : "\0\0\0\0"; |
797 if (track->enc->codec_type == CODEC_TYPE_VIDEO) { | |
798 hdlr_type = "vide"; | |
799 descr = "VideoHandler"; | |
800 } else { | |
801 hdlr_type = "soun"; | |
802 descr = "SoundHandler"; | |
803 } | |
399
6ab5454567b6
* making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents:
397
diff
changeset
|
804 } |
885 | 805 |
399
6ab5454567b6
* making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents:
397
diff
changeset
|
806 put_be32(pb, 0); /* size */ |
6ab5454567b6
* making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents:
397
diff
changeset
|
807 put_tag(pb, "hdlr"); |
6ab5454567b6
* making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents:
397
diff
changeset
|
808 put_be32(pb, 0); /* Version & flags */ |
400
62e4ea840c52
* fixing 10l in movenc.c + updating regression patterns.
romansh
parents:
399
diff
changeset
|
809 put_buffer(pb, hdlr, 4); /* handler */ |
399
6ab5454567b6
* making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents:
397
diff
changeset
|
810 put_tag(pb, hdlr_type); /* handler type */ |
6ab5454567b6
* making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents:
397
diff
changeset
|
811 put_be32(pb ,0); /* reserved */ |
6ab5454567b6
* making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents:
397
diff
changeset
|
812 put_be32(pb ,0); /* reserved */ |
6ab5454567b6
* making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents:
397
diff
changeset
|
813 put_be32(pb ,0); /* reserved */ |
6ab5454567b6
* making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents:
397
diff
changeset
|
814 put_byte(pb, strlen(descr)); /* string counter */ |
6ab5454567b6
* making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents:
397
diff
changeset
|
815 put_buffer(pb, descr, strlen(descr)); /* handler description */ |
6ab5454567b6
* making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents:
397
diff
changeset
|
816 return updateSize(pb, pos); |
6ab5454567b6
* making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents:
397
diff
changeset
|
817 } |
6ab5454567b6
* making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents:
397
diff
changeset
|
818 |
238
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
819 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
|
820 { |
909
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
821 offset_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
|
822 put_be32(pb, 0); /* size */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
823 put_tag(pb, "minf"); |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
824 if(track->enc->codec_type == CODEC_TYPE_VIDEO) |
238
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
825 mov_write_vmhd_tag(pb); |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
826 else |
238
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
827 mov_write_smhd_tag(pb); |
399
6ab5454567b6
* making .mov files generated by ffmpeg compatible with Apple software.
romansh
parents:
397
diff
changeset
|
828 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
|
829 mov_write_hdlr_tag(pb, NULL); |
238
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
830 mov_write_dinf_tag(pb); |
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
831 mov_write_stbl_tag(pb, track); |
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
832 return updateSize(pb, pos); |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
833 } |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
834 |
238
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
835 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
|
836 { |
1037 | 837 int version = track->trackDuration < INT32_MAX ? 0 : 1; |
838 | |
839 (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
|
840 put_tag(pb, "mdhd"); |
1037 | 841 put_byte(pb, version); |
842 put_be24(pb, 0); /* flags */ | |
843 if (version == 1) { | |
844 put_be64(pb, track->time); | |
845 put_be64(pb, track->time); | |
846 } else { | |
847 put_be32(pb, track->time); /* creation time */ | |
848 put_be32(pb, track->time); /* modification time */ | |
849 } | |
885 | 850 put_be32(pb, track->timescale); /* time scale (sample rate for audio) */ |
1037 | 851 (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
|
852 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
|
853 put_be16(pb, 0); /* reserved (quality) */ |
2102 | 854 |
855 if(version!=0 && track->mode == MODE_MOV){ | |
856 av_log(NULL, AV_LOG_ERROR, | |
857 "FATAL error, file duration too long for timebase, this file will not be\n" | |
2106 | 858 "playable with quicktime. Choose a different timebase or a different\n" |
2102 | 859 "container format\n"); |
860 } | |
861 | |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
862 return 32; |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
863 } |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
864 |
238
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
865 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
|
866 { |
909
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
867 offset_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
|
868 put_be32(pb, 0); /* size */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
869 put_tag(pb, "mdia"); |
238
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
870 mov_write_mdhd_tag(pb, track); |
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
871 mov_write_hdlr_tag(pb, track); |
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
872 mov_write_minf_tag(pb, track); |
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
873 return updateSize(pb, pos); |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
874 } |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
875 |
238
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
876 static int mov_write_tkhd_tag(ByteIOContext *pb, MOVTrack* track) |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
877 { |
1037 | 878 int64_t duration = av_rescale_rnd(track->trackDuration, globalTimescale, track->timescale, AV_ROUND_UP); |
879 int version = duration < INT32_MAX ? 0 : 1; | |
880 | |
881 (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
|
882 put_tag(pb, "tkhd"); |
1037 | 883 put_byte(pb, version); |
884 put_be24(pb, 0xf); /* flags (track enabled) */ | |
885 if (version == 1) { | |
886 put_be64(pb, track->time); | |
887 put_be64(pb, track->time); | |
888 } else { | |
889 put_be32(pb, track->time); /* creation time */ | |
890 put_be32(pb, track->time); /* modification time */ | |
891 } | |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
892 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
|
893 put_be32(pb, 0); /* reserved */ |
1037 | 894 (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
|
895 |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
896 put_be32(pb, 0); /* reserved */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
897 put_be32(pb, 0); /* reserved */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
898 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
|
899 /* Volume, only for audio */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
900 if(track->enc->codec_type == CODEC_TYPE_AUDIO) |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
901 put_be16(pb, 0x0100); |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
902 else |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
903 put_be16(pb, 0); |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
904 put_be16(pb, 0); /* reserved */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
905 |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
906 /* Matrix structure */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
907 put_be32(pb, 0x00010000); /* reserved */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
908 put_be32(pb, 0x0); /* reserved */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
909 put_be32(pb, 0x0); /* reserved */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
910 put_be32(pb, 0x0); /* reserved */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
911 put_be32(pb, 0x00010000); /* reserved */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
912 put_be32(pb, 0x0); /* reserved */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
913 put_be32(pb, 0x0); /* reserved */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
914 put_be32(pb, 0x0); /* reserved */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
915 put_be32(pb, 0x40000000); /* reserved */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
916 |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
917 /* Track width and height, for visual only */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
918 if(track->enc->codec_type == CODEC_TYPE_VIDEO) { |
365
4ae9fac22a5d
AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
342
diff
changeset
|
919 double sample_aspect_ratio = av_q2d(track->enc->sample_aspect_ratio); |
3024
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
920 if(!sample_aspect_ratio) 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
|
921 put_be32(pb, sample_aspect_ratio * track->enc->width*0x10000); |
259
e091218eccd2
mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
241
diff
changeset
|
922 put_be32(pb, track->enc->height*0x10000); |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
923 } |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
924 else { |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
925 put_be32(pb, 0); |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
926 put_be32(pb, 0); |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
927 } |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
928 return 0x5c; |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
929 } |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
930 |
659
6d7c0e6d929e
Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents:
657
diff
changeset
|
931 // 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
|
932 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
|
933 { |
6d7c0e6d929e
Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents:
657
diff
changeset
|
934 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
|
935 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
|
936 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
|
937 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
|
938 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
|
939 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
|
940 |
761 | 941 put_be32(pb, av_rescale_rnd(track->trackDuration, globalTimescale, track->timescale, AV_ROUND_UP)); /* duration ... doesn't seem to effect psp */ |
659
6d7c0e6d929e
Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents:
657
diff
changeset
|
942 |
1250 | 943 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
|
944 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
|
945 return 0x24; |
6d7c0e6d929e
Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents:
657
diff
changeset
|
946 } |
6d7c0e6d929e
Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents:
657
diff
changeset
|
947 |
6d7c0e6d929e
Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents:
657
diff
changeset
|
948 // 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
|
949 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
|
950 { |
6d7c0e6d929e
Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents:
657
diff
changeset
|
951 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
|
952 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
|
953 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
|
954 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
|
955 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
|
956 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
|
957 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
|
958 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
|
959 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
|
960 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
|
961 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
|
962 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
|
963 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
|
964 return 0x34; |
6d7c0e6d929e
Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents:
657
diff
changeset
|
965 } |
6d7c0e6d929e
Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents:
657
diff
changeset
|
966 |
238
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
967 static int mov_write_trak_tag(ByteIOContext *pb, MOVTrack* track) |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
968 { |
909
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
969 offset_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
|
970 put_be32(pb, 0); /* size */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
971 put_tag(pb, "trak"); |
238
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
972 mov_write_tkhd_tag(pb, track); |
1007
5fe94e61fdaa
create edts atom when muxing B frames, needed to compute cts
bcoudurier
parents:
1006
diff
changeset
|
973 if (track->mode == MODE_PSP || track->hasBframes) |
659
6d7c0e6d929e
Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents:
657
diff
changeset
|
974 mov_write_edts_tag(pb, track); // PSP Movies require edts box |
238
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
975 mov_write_mdia_tag(pb, track); |
885 | 976 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
|
977 mov_write_uuid_tag_psp(pb,track); // PSP Movies require this uuid box |
238
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
978 return updateSize(pb, pos); |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
979 } |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
980 |
683
095009fc2f35
kill warnings patch by (M«©ns Rullg«©rd <mru inprovide com>)
michael
parents:
677
diff
changeset
|
981 #if 0 |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
982 /* TODO: Not sorted out, but not necessary either */ |
238
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
983 static int mov_write_iods_tag(ByteIOContext *pb, MOVContext *mov) |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
984 { |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
985 put_be32(pb, 0x15); /* size */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
986 put_tag(pb, "iods"); |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
987 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
|
988 put_be16(pb, 0x1007); |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
989 put_byte(pb, 0); |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
990 put_be16(pb, 0x4fff); |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
991 put_be16(pb, 0xfffe); |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
992 put_be16(pb, 0x01ff); |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
993 return 0x15; |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
994 } |
683
095009fc2f35
kill warnings patch by (M«©ns Rullg«©rd <mru inprovide com>)
michael
parents:
677
diff
changeset
|
995 #endif |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
996 |
238
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
997 static int mov_write_mvhd_tag(ByteIOContext *pb, MOVContext *mov) |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
998 { |
909
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
999 int maxTrackID = 1, i; |
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
1000 int64_t maxTrackLenTemp, maxTrackLen = 0; |
1037 | 1001 int version; |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1002 |
1131 | 1003 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
|
1004 if(mov->tracks[i].entry > 0) { |
761 | 1005 maxTrackLenTemp = av_rescale_rnd(mov->tracks[i].trackDuration, globalTimescale, mov->tracks[i].timescale, 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
|
1006 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
|
1007 maxTrackLen = maxTrackLenTemp; |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1008 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
|
1009 maxTrackID = mov->tracks[i].trackID; |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1010 } |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1011 } |
1037 | 1012 |
1013 version = maxTrackLen < UINT32_MAX ? 0 : 1; | |
1014 (version == 1) ? put_be32(pb, 120) : put_be32(pb, 108); /* size */ | |
1015 put_tag(pb, "mvhd"); | |
1016 put_byte(pb, version); | |
1017 put_be24(pb, 0); /* flags */ | |
1018 if (version == 1) { | |
1019 put_be64(pb, mov->time); | |
1020 put_be64(pb, mov->time); | |
1021 } else { | |
1022 put_be32(pb, mov->time); /* creation time */ | |
1023 put_be32(pb, mov->time); /* modification time */ | |
1024 } | |
1025 put_be32(pb, mov->timescale); /* timescale */ | |
1026 (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
|
1027 |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1028 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
|
1029 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
|
1030 put_be16(pb, 0); /* reserved */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1031 put_be32(pb, 0); /* reserved */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1032 put_be32(pb, 0); /* reserved */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1033 |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1034 /* Matrix structure */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1035 put_be32(pb, 0x00010000); /* reserved */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1036 put_be32(pb, 0x0); /* reserved */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1037 put_be32(pb, 0x0); /* reserved */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1038 put_be32(pb, 0x0); /* reserved */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1039 put_be32(pb, 0x00010000); /* reserved */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1040 put_be32(pb, 0x0); /* reserved */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1041 put_be32(pb, 0x0); /* reserved */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1042 put_be32(pb, 0x0); /* reserved */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1043 put_be32(pb, 0x40000000); /* reserved */ |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1044 |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1045 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
|
1046 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
|
1047 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
|
1048 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
|
1049 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
|
1050 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
|
1051 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
|
1052 return 0x6c; |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1053 } |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1054 |
513
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1055 static int mov_write_itunes_hdlr_tag(ByteIOContext *pb, MOVContext* mov, |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1056 AVFormatContext *s) |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1057 { |
909
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
1058 offset_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
|
1059 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
|
1060 put_tag(pb, "hdlr"); |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1061 put_be32(pb, 0); |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1062 put_be32(pb, 0); |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1063 put_tag(pb, "mdir"); |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1064 put_tag(pb, "appl"); |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1065 put_be32(pb, 0); |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1066 put_be32(pb, 0); |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1067 put_be16(pb, 0); |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1068 return updateSize(pb, pos); |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1069 } |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1070 |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1071 /* helper function to write a data tag with the specified string as data */ |
1094 | 1072 static int mov_write_string_data_tag(ByteIOContext *pb, const char *data, int long_style) |
513
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1073 { |
1094 | 1074 if(long_style){ |
909
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
1075 offset_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
|
1076 put_be32(pb, 0); /* size */ |
1094 | 1077 put_tag(pb, "data"); |
1078 put_be32(pb, 1); | |
1079 put_be32(pb, 0); | |
1080 put_buffer(pb, data, strlen(data)); | |
1081 return updateSize(pb, pos); | |
1082 }else{ | |
1083 put_be16(pb, strlen(data)); /* string length */ | |
1084 put_be16(pb, 0); | |
1085 put_buffer(pb, data, strlen(data)); | |
1086 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
|
1087 } |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1088 } |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1089 |
1123
6992dd78ff68
Add (mostly) const to variable and parameter declaration, where a char* was
diego
parents:
1112
diff
changeset
|
1090 static int mov_write_string_tag(ByteIOContext *pb, const char *name, const char *value, int long_style){ |
513
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1091 int size = 0; |
3024
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1092 if (value && value[0]) { |
909
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
1093 offset_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
|
1094 put_be32(pb, 0); /* size */ |
1094 | 1095 put_tag(pb, name); |
1096 mov_write_string_data_tag(pb, value, long_style); | |
1097 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
|
1098 } |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1099 return size; |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1100 } |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1101 |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1102 /* iTunes year */ |
1094 | 1103 static int mov_write_day_tag(ByteIOContext *pb, int year, int long_style) |
513
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1104 { |
1094 | 1105 if(year){ |
1106 char year_str[5]; | |
1107 snprintf(year_str, sizeof(year_str), "%04d", year); | |
1108 return mov_write_string_tag(pb, "\251day", year_str, long_style); | |
1109 }else | |
1110 return 0; | |
513
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1111 } |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1112 |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1113 /* iTunes track number */ |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1114 static int mov_write_trkn_tag(ByteIOContext *pb, MOVContext* mov, |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1115 AVFormatContext *s) |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1116 { |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1117 int size = 0; |
3024
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1118 if (s->track) { |
909
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
1119 offset_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
|
1120 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
|
1121 put_tag(pb, "trkn"); |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1122 { |
909
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
1123 offset_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
|
1124 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
|
1125 put_tag(pb, "data"); |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1126 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
|
1127 put_be32(pb, 0); |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1128 put_be16(pb, 0); // empty |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1129 put_be16(pb, s->track); // track number |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1130 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
|
1131 put_be16(pb, 0); // empty |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1132 updateSize(pb, pos); |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1133 } |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1134 size = updateSize(pb, pos); |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1135 } |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1136 return size; |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1137 } |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1138 |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1139 /* iTunes meta data list */ |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1140 static int mov_write_ilst_tag(ByteIOContext *pb, MOVContext* mov, |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1141 AVFormatContext *s) |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1142 { |
909
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
1143 offset_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
|
1144 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
|
1145 put_tag(pb, "ilst"); |
1094 | 1146 mov_write_string_tag(pb, "\251nam", s->title , 1); |
1147 mov_write_string_tag(pb, "\251ART", s->author , 1); | |
1148 mov_write_string_tag(pb, "\251wrt", s->author , 1); | |
1149 mov_write_string_tag(pb, "\251alb", s->album , 1); | |
1150 mov_write_day_tag(pb, s->year ,1); | |
1095
bf797dc4828e
dont write LAVF_ID if bitexact and any meta tag is set
michael
parents:
1094
diff
changeset
|
1151 if(mov->tracks[0].enc && !(mov->tracks[0].enc->flags & CODEC_FLAG_BITEXACT)) |
bf797dc4828e
dont write LAVF_ID if bitexact and any meta tag is set
michael
parents:
1094
diff
changeset
|
1152 mov_write_string_tag(pb, "\251too", LIBAVFORMAT_IDENT, 1); |
1094 | 1153 mov_write_string_tag(pb, "\251cmt", s->comment , 1); |
1154 mov_write_string_tag(pb, "\251gen", s->genre , 1); | |
513
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1155 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
|
1156 return updateSize(pb, pos); |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1157 } |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1158 |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1159 /* iTunes meta data tag */ |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1160 static int mov_write_meta_tag(ByteIOContext *pb, MOVContext* mov, |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1161 AVFormatContext *s) |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1162 { |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1163 int size = 0; |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1164 |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1165 // only save meta tag if required |
3024
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1166 if (s->title[0] || s->author[0] || s->album[0] || s->year || |
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1167 s->comment[0] || s->genre[0] || s->track) { |
909
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
1168 offset_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
|
1169 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
|
1170 put_tag(pb, "meta"); |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1171 put_be32(pb, 0); |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1172 mov_write_itunes_hdlr_tag(pb, mov, s); |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1173 mov_write_ilst_tag(pb, mov, s); |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1174 size = updateSize(pb, pos); |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1175 } |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1176 return size; |
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1177 } |
885 | 1178 |
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
|
1179 static int mov_write_udta_tag(ByteIOContext *pb, MOVContext* mov, |
4ae9fac22a5d
AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
342
diff
changeset
|
1180 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
|
1181 { |
2668 | 1182 int i, req = 0; |
1183 | |
1184 /* Requirements */ | |
1185 for (i=0; i<mov->nb_streams; i++) { | |
1186 if(mov->tracks[i].entry <= 0) continue; | |
1187 if (mov->tracks[i].enc->codec_id == CODEC_ID_AAC || | |
1188 mov->tracks[i].enc->codec_id == CODEC_ID_MPEG4) { | |
1189 req = 1; | |
1190 break; | |
1191 } | |
1192 } | |
1193 | |
1194 if (s->title[0] || s->author[0] || s->album[0] || s->year || | |
1195 s->comment[0] || s->genre[0] || s->track || | |
1196 (mov->mode == MODE_MOV && | |
1197 ((mov->tracks[0].enc && !mov->tracks[0].enc->flags & CODEC_FLAG_BITEXACT) || req))) { | |
2669 | 1198 offset_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
|
1199 |
2669 | 1200 put_be32(pb, 0); /* size */ |
1201 put_tag(pb, "udta"); | |
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
|
1202 |
2669 | 1203 /* iTunes meta data */ |
1204 mov_write_meta_tag(pb, mov, s); | |
513
2b4edca40885
iTunes metadata encoding support patch by (Patrice Bensoussan <patrice.bensoussan at free dot fr>)
michael
parents:
505
diff
changeset
|
1205 |
2669 | 1206 if(mov->mode == MODE_MOV){ // the title field breaks gtkpod with mp4 and my suspicion is that stuff is not valid in mp4 |
1207 /* Requirements */ | |
1208 if (req) | |
2616 | 1209 mov_write_string_tag(pb, "\251req", "QuickTime 6.0 or greater", 0); |
1210 | |
2669 | 1211 mov_write_string_tag(pb, "\251nam", s->title , 0); |
1212 mov_write_string_tag(pb, "\251aut", s->author , 0); | |
1213 mov_write_string_tag(pb, "\251alb", s->album , 0); | |
1214 mov_write_day_tag(pb, s->year, 0); | |
1215 if(mov->tracks[0].enc && !(mov->tracks[0].enc->flags & CODEC_FLAG_BITEXACT)) | |
1216 mov_write_string_tag(pb, "\251enc", LIBAVFORMAT_IDENT, 0); | |
1217 mov_write_string_tag(pb, "\251des", s->comment , 0); | |
1218 mov_write_string_tag(pb, "\251gen", s->genre , 0); | |
1219 } | |
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
|
1220 |
2669 | 1221 return updateSize(pb, pos); |
2668 | 1222 } |
1223 | |
1224 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
|
1225 } |
4ae9fac22a5d
AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
342
diff
changeset
|
1226 |
3010 | 1227 static int utf8len(const uint8_t *b){ |
1462 | 1228 int len=0; |
1229 int val; | |
1230 while(*b){ | |
1231 GET_UTF8(val, *b++, return -1;) | |
1232 len++; | |
1233 } | |
1234 return len; | |
1235 } | |
911
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1236 |
3010 | 1237 static int ascii_to_wc (ByteIOContext *pb, const uint8_t *b) |
911
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1238 { |
1462 | 1239 int val; |
1240 while(*b){ | |
1241 GET_UTF8(val, *b++, return -1;) | |
1242 put_be16(pb, val); | |
911
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1243 } |
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1244 put_be16(pb, 0x00); |
1462 | 1245 return 0; |
911
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1246 } |
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1247 |
1123
6992dd78ff68
Add (mostly) const to variable and parameter declaration, where a char* was
diego
parents:
1112
diff
changeset
|
1248 static uint16_t language_code (const char *str) |
911
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1249 { |
3278 | 1250 return (((str[0]-0x60) & 0x1F) << 10) + (((str[1]-0x60) & 0x1F) << 5) + ((str[2]-0x60) & 0x1F); |
911
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1251 } |
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1252 |
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1253 static int mov_write_uuidusmt_tag (ByteIOContext *pb, AVFormatContext *s) |
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1254 { |
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1255 size_t len, size; |
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1256 offset_t pos, curpos; |
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1257 |
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1258 size = 0; |
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1259 if (s->title[0]) { |
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1260 pos = url_ftell(pb); |
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1261 put_be32(pb, 0); /* size placeholder*/ |
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1262 put_tag(pb, "uuid"); |
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1263 put_tag(pb, "USMT"); |
3024
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1264 put_be32(pb, 0x21d24fce); /* 96 bit UUID */ |
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1265 put_be32(pb, 0xbb88695c); |
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1266 put_be32(pb, 0xfac9c740); |
911
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1267 size += 24; |
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1268 |
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1269 put_be32(pb, 0); /* size placeholder*/ |
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1270 put_tag(pb, "MTDT"); |
1097
acabd3a4b903
fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents:
1096
diff
changeset
|
1271 put_be16(pb, 4); |
911
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1272 size += 10; |
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1273 |
1097
acabd3a4b903
fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents:
1096
diff
changeset
|
1274 // ? |
acabd3a4b903
fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents:
1096
diff
changeset
|
1275 put_be16(pb, 0x0C); /* size */ |
acabd3a4b903
fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents:
1096
diff
changeset
|
1276 put_be32(pb, 0x0B); /* type */ |
acabd3a4b903
fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents:
1096
diff
changeset
|
1277 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
|
1278 put_be16(pb, 0x0); /* ? */ |
acabd3a4b903
fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents:
1096
diff
changeset
|
1279 put_be16(pb, 0x021C); /* data */ |
acabd3a4b903
fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents:
1096
diff
changeset
|
1280 size += 12; |
acabd3a4b903
fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents:
1096
diff
changeset
|
1281 |
acabd3a4b903
fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents:
1096
diff
changeset
|
1282 // Encoder |
1462 | 1283 len = utf8len(LIBAVCODEC_IDENT)+1; |
1284 if(len<=0) | |
1285 goto not_utf8; | |
1097
acabd3a4b903
fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents:
1096
diff
changeset
|
1286 put_be16(pb, len*2+10); /* size */ |
acabd3a4b903
fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents:
1096
diff
changeset
|
1287 put_be32(pb, 0x04); /* type */ |
acabd3a4b903
fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents:
1096
diff
changeset
|
1288 put_be16(pb, language_code("eng")); /* language */ |
acabd3a4b903
fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents:
1096
diff
changeset
|
1289 put_be16(pb, 0x01); /* ? */ |
1462 | 1290 ascii_to_wc(pb, LIBAVCODEC_IDENT); |
1097
acabd3a4b903
fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents:
1096
diff
changeset
|
1291 size += len*2+10; |
acabd3a4b903
fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents:
1096
diff
changeset
|
1292 |
911
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1293 // Title |
1462 | 1294 len = utf8len(s->title)+1; |
1295 if(len<=0) | |
1296 goto not_utf8; | |
911
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1297 put_be16(pb, len*2+10); /* size */ |
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1298 put_be32(pb, 0x01); /* type */ |
1097
acabd3a4b903
fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents:
1096
diff
changeset
|
1299 put_be16(pb, language_code("eng")); /* language */ |
911
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1300 put_be16(pb, 0x01); /* ? */ |
1462 | 1301 ascii_to_wc (pb, s->title); |
911
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1302 size += len*2+10; |
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1303 |
1097
acabd3a4b903
fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents:
1096
diff
changeset
|
1304 // Date |
acabd3a4b903
fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents:
1096
diff
changeset
|
1305 // 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); |
1462 | 1306 len = utf8len("2006/04/01 11:11:11")+1; |
1307 if(len<=0) | |
1308 goto not_utf8; | |
1097
acabd3a4b903
fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents:
1096
diff
changeset
|
1309 put_be16(pb, len*2+10); /* size */ |
acabd3a4b903
fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents:
1096
diff
changeset
|
1310 put_be32(pb, 0x03); /* type */ |
acabd3a4b903
fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents:
1096
diff
changeset
|
1311 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
|
1312 put_be16(pb, 0x01); /* ? */ |
1462 | 1313 ascii_to_wc (pb, "2006/04/01 11:11:11"); |
1097
acabd3a4b903
fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents:
1096
diff
changeset
|
1314 size += len*2+10; |
acabd3a4b903
fixing title on PSP (0x60 != 'a') someone needs a 10x10km ascii table ...
michael
parents:
1096
diff
changeset
|
1315 |
911
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1316 // size |
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1317 curpos = url_ftell(pb); |
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1318 url_fseek(pb, pos, SEEK_SET); |
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1319 put_be32(pb, size); |
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1320 url_fseek(pb, pos+24, SEEK_SET); |
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1321 put_be32(pb, size-24); |
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1322 url_fseek(pb, curpos, SEEK_SET); |
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1323 } |
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1324 |
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1325 return size; |
1462 | 1326 not_utf8: |
1327 av_log(s, AV_LOG_ERROR, "not utf8\n"); | |
1328 return -1; | |
911
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1329 } |
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1330 |
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
|
1331 static int mov_write_moov_tag(ByteIOContext *pb, MOVContext *mov, |
4ae9fac22a5d
AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
342
diff
changeset
|
1332 AVFormatContext *s) |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1333 { |
909
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
1334 int i; |
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
1335 offset_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
|
1336 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
|
1337 put_tag(pb, "moov"); |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1338 mov->timescale = globalTimescale; |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1339 |
1131 | 1340 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
|
1341 if(mov->tracks[i].entry <= 0) continue; |
0b2eed7b1210
movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
286
diff
changeset
|
1342 |
0b2eed7b1210
movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
286
diff
changeset
|
1343 mov->tracks[i].time = mov->time; |
0b2eed7b1210
movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
286
diff
changeset
|
1344 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
|
1345 } |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1346 |
238
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
1347 mov_write_mvhd_tag(pb, mov); |
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
1348 //mov_write_iods_tag(pb, mov); |
1131 | 1349 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
|
1350 if(mov->tracks[i].entry > 0) { |
238
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
1351 mov_write_trak_tag(pb, &(mov->tracks[i])); |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1352 } |
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 |
911
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1355 if (mov->mode == MODE_PSP) |
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1356 mov_write_uuidusmt_tag(pb, s); |
2617
0b993d441969
dont write udta atom for 3gp/3g2 for now, current written atoms (ilst) are itunes specific
bcoudurier
parents:
2616
diff
changeset
|
1357 else if (mov->mode != MODE_3GP && mov->mode != MODE_3G2) |
1441
ad3b03b7b142
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
1438
diff
changeset
|
1358 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
|
1359 |
238
3519903c6c2a
mov/mp4 muxer cleanup (mostly cosmetics/simplifications & global header fix)
michaelni
parents:
202
diff
changeset
|
1360 return updateSize(pb, pos); |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1361 } |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1362 |
1124
d3aff2c607f9
Add const to (mostly) char* and make some functions static, which aren't used
diego
parents:
1123
diff
changeset
|
1363 static int mov_write_mdat_tag(ByteIOContext *pb, MOVContext* mov) |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1364 { |
909
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
1365 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
|
1366 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
|
1367 |
885 | 1368 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
|
1369 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
|
1370 put_tag(pb, "mdat"); |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1371 return 0; |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1372 } |
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 /* TODO: This needs to be more general */ |
911
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1375 static void 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
|
1376 { |
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
|
1377 MOVContext *mov = s->priv_data; |
4ae9fac22a5d
AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
342
diff
changeset
|
1378 |
3024
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1379 put_be32(pb, 0x14); /* size */ |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1380 put_tag(pb, "ftyp"); |
298
0b2eed7b1210
movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
286
diff
changeset
|
1381 |
3024
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1382 if (mov->mode == MODE_3GP) |
298
0b2eed7b1210
movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
286
diff
changeset
|
1383 put_tag(pb, "3gp4"); |
3024
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1384 else if (mov->mode == MODE_3G2) |
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
|
1385 put_tag(pb, "3g2a"); |
3024
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1386 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
|
1387 put_tag(pb, "MSNV"); |
3143 | 1388 else if (mov->mode == MODE_MP4 || mov->mode == MODE_IPOD) |
990
f7394f02e95a
ftyp patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents:
987
diff
changeset
|
1389 put_tag(pb, "isom"); |
298
0b2eed7b1210
movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
286
diff
changeset
|
1390 else |
990
f7394f02e95a
ftyp patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents:
987
diff
changeset
|
1391 put_tag(pb, "qt "); |
298
0b2eed7b1210
movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
286
diff
changeset
|
1392 |
3024
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1393 put_be32(pb, 0x200); |
298
0b2eed7b1210
movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
286
diff
changeset
|
1394 |
3024
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1395 if (mov->mode == MODE_3GP) |
298
0b2eed7b1210
movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
286
diff
changeset
|
1396 put_tag(pb, "3gp4"); |
3024
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1397 else if (mov->mode == MODE_3G2) |
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
|
1398 put_tag(pb, "3g2a"); |
3024
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1399 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
|
1400 put_tag(pb, "MSNV"); |
3143 | 1401 else if (mov->mode == MODE_MP4 || mov->mode == MODE_IPOD) |
990
f7394f02e95a
ftyp patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents:
987
diff
changeset
|
1402 put_tag(pb, "mp41"); |
298
0b2eed7b1210
movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
286
diff
changeset
|
1403 else |
990
f7394f02e95a
ftyp patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents:
987
diff
changeset
|
1404 put_tag(pb, "qt "); |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1405 } |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1406 |
665
47d5b20c9aba
fix segfault by matthieu castet <castet DOT matthieu AT free DOT fr>
mmu_man
parents:
664
diff
changeset
|
1407 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
|
1408 { |
911
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1409 AVCodecContext *VideoCodec = s->streams[0]->codec; |
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1410 AVCodecContext *AudioCodec = s->streams[1]->codec; |
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1411 int AudioRate = AudioCodec->sample_rate; |
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1412 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
|
1413 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
|
1414 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
|
1415 |
3024
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1416 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
|
1417 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
|
1418 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
|
1419 |
3024
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1420 put_be32(pb, 0x21d24fce); /* 96 bit UUID */ |
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1421 put_be32(pb, 0xbb88695c); |
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1422 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
|
1423 |
3024
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1424 put_be32(pb, 0x0); /* ? */ |
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1425 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
|
1426 |
3024
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1427 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
|
1428 put_tag(pb, "FPRF"); |
3024
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1429 put_be32(pb, 0x0); /* ? */ |
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1430 put_be32(pb, 0x0); /* ? */ |
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1431 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
|
1432 |
3024
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1433 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
|
1434 put_tag(pb, "APRF"); /* audio */ |
3024
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1435 put_be32(pb, 0x0); |
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1436 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
|
1437 put_tag(pb, "mp4a"); |
3024
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1438 put_be32(pb, 0x20f); |
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1439 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
|
1440 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
|
1441 put_be32(pb, audio_kbitrate); |
3024
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1442 put_be32(pb, AudioRate); |
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1443 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
|
1444 |
3024
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1445 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
|
1446 put_tag(pb, "VPRF"); /* video */ |
3024
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1447 put_be32(pb, 0x0); |
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1448 put_be32(pb, 0x1); /* TrackID */ |
1050
ece3b7eecba2
little h.264 related hunk from diff between cvs and mobile hackerz
michael
parents:
1049
diff
changeset
|
1449 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
|
1450 put_tag(pb, "avc1"); |
3024
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1451 put_be16(pb, 0x014D); |
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1452 put_be16(pb, 0x0015); |
1050
ece3b7eecba2
little h.264 related hunk from diff between cvs and mobile hackerz
michael
parents:
1049
diff
changeset
|
1453 } else { |
ece3b7eecba2
little h.264 related hunk from diff between cvs and mobile hackerz
michael
parents:
1049
diff
changeset
|
1454 put_tag(pb, "mp4v"); |
3024
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1455 put_be16(pb, 0x0000); |
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1456 put_be16(pb, 0x0103); |
1050
ece3b7eecba2
little h.264 related hunk from diff between cvs and mobile hackerz
michael
parents:
1049
diff
changeset
|
1457 } |
3024
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1458 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
|
1459 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
|
1460 put_be32(pb, video_kbitrate); |
911
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1461 put_be32(pb, FrameRate); |
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1462 put_be32(pb, FrameRate); |
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1463 put_be16(pb, VideoCodec->width); |
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1464 put_be16(pb, VideoCodec->height); |
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1465 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
|
1466 } |
6d7c0e6d929e
Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents:
657
diff
changeset
|
1467 |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1468 static int mov_write_header(AVFormatContext *s) |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1469 { |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2669
diff
changeset
|
1470 ByteIOContext *pb = s->pb; |
365
4ae9fac22a5d
AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
342
diff
changeset
|
1471 MOVContext *mov = s->priv_data; |
4ae9fac22a5d
AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
342
diff
changeset
|
1472 int i; |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1473 |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2669
diff
changeset
|
1474 if (url_is_streamed(s->pb)) { |
2091
659c9e8f558c
print and return error if output is non seekable
bcoudurier
parents:
2045
diff
changeset
|
1475 av_log(s, AV_LOG_ERROR, "muxer does not support non seekable output\n"); |
659c9e8f558c
print and return error if output is non seekable
bcoudurier
parents:
2045
diff
changeset
|
1476 return -1; |
659c9e8f558c
print and return error if output is non seekable
bcoudurier
parents:
2045
diff
changeset
|
1477 } |
659c9e8f558c
print and return error if output is non seekable
bcoudurier
parents:
2045
diff
changeset
|
1478 |
987
955d23ed733f
compute output format before setting language patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents:
971
diff
changeset
|
1479 /* Default mode == MP4 */ |
955d23ed733f
compute output format before setting language patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents:
971
diff
changeset
|
1480 mov->mode = MODE_MP4; |
955d23ed733f
compute output format before setting language patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents:
971
diff
changeset
|
1481 |
955d23ed733f
compute output format before setting language patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents:
971
diff
changeset
|
1482 if (s->oformat != NULL) { |
955d23ed733f
compute output format before setting language patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents:
971
diff
changeset
|
1483 if (!strcmp("3gp", s->oformat->name)) mov->mode = MODE_3GP; |
955d23ed733f
compute output format before setting language patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents:
971
diff
changeset
|
1484 else if (!strcmp("3g2", s->oformat->name)) mov->mode = MODE_3G2; |
955d23ed733f
compute output format before setting language patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents:
971
diff
changeset
|
1485 else if (!strcmp("mov", s->oformat->name)) mov->mode = MODE_MOV; |
955d23ed733f
compute output format before setting language patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents:
971
diff
changeset
|
1486 else if (!strcmp("psp", s->oformat->name)) mov->mode = MODE_PSP; |
3143 | 1487 else if (!strcmp("ipod",s->oformat->name)) mov->mode = MODE_IPOD; |
987
955d23ed733f
compute output format before setting language patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents:
971
diff
changeset
|
1488 |
990
f7394f02e95a
ftyp patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents:
987
diff
changeset
|
1489 mov_write_ftyp_tag(pb,s); |
3024
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1490 if (mov->mode == MODE_PSP) { |
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1491 if (s->nb_streams != 2) { |
987
955d23ed733f
compute output format before setting language patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents:
971
diff
changeset
|
1492 av_log(s, AV_LOG_ERROR, "PSP mode need one video and one audio stream\n"); |
955d23ed733f
compute output format before setting language patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents:
971
diff
changeset
|
1493 return -1; |
955d23ed733f
compute output format before setting language patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents:
971
diff
changeset
|
1494 } |
955d23ed733f
compute output format before setting language patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents:
971
diff
changeset
|
1495 mov_write_uuidprof_tag(pb,s); |
955d23ed733f
compute output format before setting language patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents:
971
diff
changeset
|
1496 } |
955d23ed733f
compute output format before setting language patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents:
971
diff
changeset
|
1497 } |
955d23ed733f
compute output format before setting language patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents:
971
diff
changeset
|
1498 |
494 | 1499 for(i=0; i<s->nb_streams; i++){ |
1080 | 1500 AVStream *st= s->streams[i]; |
1501 MOVTrack *track= &mov->tracks[i]; | |
494 | 1502 |
1080 | 1503 track->enc = st->codec; |
1241 | 1504 track->language = ff_mov_iso639_to_lang(st->language, mov->mode != MODE_MOV); |
1505 track->mode = mov->mode; | |
2978
8dcdecbbf7e6
correctly and only set standard stsd fourcc for mp4/3gp
bcoudurier
parents:
2977
diff
changeset
|
1506 track->tag = mov_find_codec_tag(s, track); |
8dcdecbbf7e6
correctly and only set standard stsd fourcc for mp4/3gp
bcoudurier
parents:
2977
diff
changeset
|
1507 if (!track->tag) { |
8dcdecbbf7e6
correctly and only set standard stsd fourcc for mp4/3gp
bcoudurier
parents:
2977
diff
changeset
|
1508 av_log(s, AV_LOG_ERROR, "track %d: could not find tag for codec\n", i); |
8dcdecbbf7e6
correctly and only set standard stsd fourcc for mp4/3gp
bcoudurier
parents:
2977
diff
changeset
|
1509 return -1; |
8dcdecbbf7e6
correctly and only set standard stsd fourcc for mp4/3gp
bcoudurier
parents:
2977
diff
changeset
|
1510 } |
1080 | 1511 if(st->codec->codec_type == CODEC_TYPE_VIDEO){ |
1292
6042770198c6
move track timescale/sampleDuration init to write_header and return error if not set
bcoudurier
parents:
1273
diff
changeset
|
1512 track->timescale = st->codec->time_base.den; |
1080 | 1513 av_set_pts_info(st, 64, 1, st->codec->time_base.den); |
2986 | 1514 if (track->mode == MODE_MOV && track->timescale > 100000) |
2987 | 1515 av_log(s, AV_LOG_WARNING, |
2149 | 1516 "WARNING codec timebase is very high. If duration is too long,\n" |
1517 "file may not be playable by quicktime. Specify a shorter timebase\n" | |
1518 "or choose different container.\n"); | |
1080 | 1519 }else if(st->codec->codec_type == CODEC_TYPE_AUDIO){ |
1292
6042770198c6
move track timescale/sampleDuration init to write_header and return error if not set
bcoudurier
parents:
1273
diff
changeset
|
1520 track->timescale = st->codec->sample_rate; |
1080 | 1521 av_set_pts_info(st, 64, 1, st->codec->sample_rate); |
1937 | 1522 if(!st->codec->frame_size){ |
1564
35ab31b4dfa6
check codec frame size directly and only for audio
bcoudurier
parents:
1462
diff
changeset
|
1523 av_log(s, AV_LOG_ERROR, "track %d: codec frame size is not set\n", i); |
35ab31b4dfa6
check codec frame size directly and only for audio
bcoudurier
parents:
1462
diff
changeset
|
1524 return -1; |
1937 | 1525 }else if(st->codec->frame_size > 1){ /* assume compressed audio */ |
1526 track->audio_vbr = 1; | |
1527 }else{ | |
1528 track->sampleSize = (av_get_bits_per_sample(st->codec->codec_id) >> 3) * st->codec->channels; | |
1564
35ab31b4dfa6
check codec frame size directly and only for audio
bcoudurier
parents:
1462
diff
changeset
|
1529 } |
1292
6042770198c6
move track timescale/sampleDuration init to write_header and return error if not set
bcoudurier
parents:
1273
diff
changeset
|
1530 } |
259
e091218eccd2
mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
241
diff
changeset
|
1531 } |
e091218eccd2
mov/mp4/3gp muxer improvements patch by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
241
diff
changeset
|
1532 |
1055
faa09c43a3d6
write mdat in write_header avoid check in write_packet
bcoudurier
parents:
1054
diff
changeset
|
1533 mov_write_mdat_tag(pb, mov); |
faa09c43a3d6
write mdat in write_header avoid check in write_packet
bcoudurier
parents:
1054
diff
changeset
|
1534 mov->time = s->timestamp + 0x7C25B080; //1970 based -> 1904 based |
1131 | 1535 mov->nb_streams = s->nb_streams; |
1055
faa09c43a3d6
write mdat in write_header avoid check in write_packet
bcoudurier
parents:
1054
diff
changeset
|
1536 |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1537 put_flush_packet(pb); |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1538 |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1539 return 0; |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1540 } |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1541 |
468 | 1542 static int mov_write_packet(AVFormatContext *s, AVPacket *pkt) |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1543 { |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1544 MOVContext *mov = s->priv_data; |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2669
diff
changeset
|
1545 ByteIOContext *pb = s->pb; |
1080 | 1546 MOVTrack *trk = &mov->tracks[pkt->stream_index]; |
1547 AVCodecContext *enc = trk->enc; | |
298
0b2eed7b1210
movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
286
diff
changeset
|
1548 unsigned int samplesInChunk = 0; |
468 | 1549 int size= pkt->size; |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1550 |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2669
diff
changeset
|
1551 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
|
1552 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
|
1553 |
1154 | 1554 if (enc->codec_id == CODEC_ID_AMR_NB) { |
1147 | 1555 /* We must find out how many AMR blocks there are in one packet */ |
1556 static uint16_t packed_size[16] = | |
1557 {13, 14, 16, 18, 20, 21, 27, 32, 6, 0, 0, 0, 0, 0, 0, 0}; | |
1558 int len = 0; | |
1057 | 1559 |
1147 | 1560 while (len < size && samplesInChunk < 100) { |
1561 len += packed_size[(pkt->data[len] >> 3) & 0x0F]; | |
1562 samplesInChunk++; | |
1057 | 1563 } |
1151 | 1564 if(samplesInChunk > 1){ |
2546 | 1565 av_log(s, AV_LOG_ERROR, "fatal error, input is not a single packet, implement a AVParser for it\n"); |
1151 | 1566 return -1; |
1567 } | |
1147 | 1568 } else if (trk->sampleSize) |
1569 samplesInChunk = size/trk->sampleSize; | |
1570 else | |
298
0b2eed7b1210
movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
286
diff
changeset
|
1571 samplesInChunk = 1; |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1572 |
1057 | 1573 /* copy extradata if it exists */ |
1574 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
|
1575 trk->vosLen = enc->extradata_size; |
0b2eed7b1210
movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
286
diff
changeset
|
1576 trk->vosData = av_malloc(trk->vosLen); |
0b2eed7b1210
movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
286
diff
changeset
|
1577 memcpy(trk->vosData, enc->extradata, trk->vosLen); |
0b2eed7b1210
movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
286
diff
changeset
|
1578 } |
0b2eed7b1210
movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
286
diff
changeset
|
1579 |
1057 | 1580 if (enc->codec_id == CODEC_ID_H264 && trk->vosLen > 0 && *(uint8_t *)trk->vosData != 1) { |
1581 /* from x264 or from bytestream h264 */ | |
1582 /* nal reformating needed */ | |
2927
b75a49790f31
add a ff_ prefix to newly exported functions from avc.c
aurel
parents:
2922
diff
changeset
|
1583 int ret = ff_avc_parse_nal_units(pkt->data, &pkt->data, &pkt->size); |
2919 | 1584 if (ret < 0) |
1585 return ret; | |
1057 | 1586 assert(pkt->size); |
1587 size = pkt->size; | |
2588 | 1588 } else if (enc->codec_id == CODEC_ID_DNXHD && !trk->vosLen) { |
1589 /* copy frame header to create needed atoms */ | |
1590 if (size < 640) | |
1591 return -1; | |
1592 trk->vosLen = 640; | |
1593 trk->vosData = av_malloc(trk->vosLen); | |
1594 memcpy(trk->vosData, pkt->data, 640); | |
1006
15bfc3c063dc
do nal reformating when muxing H264, create avcc atom
bcoudurier
parents:
1000
diff
changeset
|
1595 } |
15bfc3c063dc
do nal reformating when muxing H264, create avcc atom
bcoudurier
parents:
1000
diff
changeset
|
1596 |
1129 | 1597 if (!(trk->entry % MOV_INDEX_CLUSTER_SIZE)) { |
1598 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
|
1599 if (!trk->cluster) |
0b2eed7b1210
movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
286
diff
changeset
|
1600 return -1; |
0b2eed7b1210
movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
286
diff
changeset
|
1601 } |
0b2eed7b1210
movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
286
diff
changeset
|
1602 |
1129 | 1603 trk->cluster[trk->entry].pos = url_ftell(pb); |
1604 trk->cluster[trk->entry].samplesInChunk = samplesInChunk; | |
1605 trk->cluster[trk->entry].size = size; | |
1606 trk->cluster[trk->entry].entries = samplesInChunk; | |
1437 | 1607 trk->cluster[trk->entry].dts = pkt->dts; |
1608 trk->trackDuration = pkt->dts - trk->cluster[0].dts + pkt->duration; | |
1609 | |
3397
76918939de90
warn if pts is not set, prevent writing negative/weird cts, happens when using genpts and streamcopy
bcoudurier
parents:
3396
diff
changeset
|
1610 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
|
1611 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
|
1612 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
|
1613 } |
3396 | 1614 if (pkt->dts != pkt->pts) |
1615 trk->hasBframes = 1; | |
1616 trk->cluster[trk->entry].cts = pkt->pts - pkt->dts; | |
1617 trk->cluster[trk->entry].key_frame = !!(pkt->flags & PKT_FLAG_KEY); | |
1618 if(trk->cluster[trk->entry].key_frame) | |
1619 trk->hasKeyframes++; | |
298
0b2eed7b1210
movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
286
diff
changeset
|
1620 trk->entry++; |
0b2eed7b1210
movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
286
diff
changeset
|
1621 trk->sampleCount += samplesInChunk; |
1080 | 1622 mov->mdat_size += size; |
298
0b2eed7b1210
movenc patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
286
diff
changeset
|
1623 |
468 | 1624 put_buffer(pb, pkt->data, size); |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1625 |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1626 put_flush_packet(pb); |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1627 return 0; |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1628 } |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1629 |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1630 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
|
1631 { |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1632 MOVContext *mov = s->priv_data; |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2669
diff
changeset
|
1633 ByteIOContext *pb = s->pb; |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1634 int res = 0; |
1129 | 1635 int i; |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1636 |
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 offset_t moov_pos = url_ftell(pb); |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1638 |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1639 /* Write size of mdat tag */ |
1080 | 1640 if (mov->mdat_size+8 <= UINT32_MAX) { |
909
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
1641 url_fseek(pb, mov->mdat_pos, SEEK_SET); |
1080 | 1642 put_be32(pb, mov->mdat_size+8); |
909
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
1643 } else { |
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
1644 /* overwrite 'wide' placeholder atom */ |
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
1645 url_fseek(pb, mov->mdat_pos - 8, SEEK_SET); |
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
1646 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
|
1647 put_tag(pb, "mdat"); |
1080 | 1648 put_be64(pb, mov->mdat_size+16); |
909
69e06b6f91a3
>4gb fixes by (Dirk Musfeldt | d.musfeldt meilenstein de)
michael
parents:
896
diff
changeset
|
1649 } |
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
|
1650 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
|
1651 |
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
|
1652 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
|
1653 |
1131 | 1654 for (i=0; i<mov->nb_streams; i++) { |
1129 | 1655 av_freep(&mov->tracks[i].cluster); |
1656 | |
3024
19de43025f0f
cosmetics, remove whitespaces before and after parenthesis
bcoudurier
parents:
3010
diff
changeset
|
1657 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
|
1658 |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1659 } |
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
|
1660 |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1661 put_flush_packet(pb); |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1662 |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1663 return res; |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1664 } |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1665 |
1169 | 1666 #ifdef CONFIG_MOV_MUXER |
1667 AVOutputFormat mov_muxer = { | |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1668 "mov", |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1669 "mov format", |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1670 NULL, |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1671 "mov", |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1672 sizeof(MOVContext), |
365
4ae9fac22a5d
AAC support in mov, correct aspect ratio support and user data support patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
342
diff
changeset
|
1673 CODEC_ID_AAC, |
239 | 1674 CODEC_ID_MPEG4, |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1675 mov_write_header, |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1676 mov_write_packet, |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1677 mov_write_trailer, |
715
e214703e4b76
30_clean_up_global_header_flag.patch by (Calcium | calcium nurs or jp)
michael
parents:
711
diff
changeset
|
1678 .flags = AVFMT_GLOBALHEADER, |
2980
672d72727b20
finally set codec tags for mov/mp4/3gp muxers, this should not break anything, if it breaks anything, yell
bcoudurier
parents:
2979
diff
changeset
|
1679 .codec_tag = (const AVCodecTag*[]){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
|
1680 }; |
1169 | 1681 #endif |
1682 #ifdef CONFIG_TGP_MUXER | |
1683 AVOutputFormat tgp_muxer = { | |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1684 "3gp", |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1685 "3gp format", |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1686 NULL, |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1687 "3gp", |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1688 sizeof(MOVContext), |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1689 CODEC_ID_AMR_NB, |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1690 CODEC_ID_H263, |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1691 mov_write_header, |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1692 mov_write_packet, |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1693 mov_write_trailer, |
715
e214703e4b76
30_clean_up_global_header_flag.patch by (Calcium | calcium nurs or jp)
michael
parents:
711
diff
changeset
|
1694 .flags = AVFMT_GLOBALHEADER, |
2980
672d72727b20
finally set codec tags for mov/mp4/3gp muxers, this should not break anything, if it breaks anything, yell
bcoudurier
parents:
2979
diff
changeset
|
1695 .codec_tag = (const AVCodecTag*[]){codec_3gp_tags, 0}, |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1696 }; |
1169 | 1697 #endif |
1698 #ifdef CONFIG_MP4_MUXER | |
1699 AVOutputFormat mp4_muxer = { | |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1700 "mp4", |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1701 "mp4 format", |
286
eccf0c3e3289
Using the extension m4a for audio only MPEG-4 files is increasingly
michael
parents:
259
diff
changeset
|
1702 "application/mp4", |
eccf0c3e3289
Using the extension m4a for audio only MPEG-4 files is increasingly
michael
parents:
259
diff
changeset
|
1703 "mp4,m4a", |
201
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1704 sizeof(MOVContext), |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1705 CODEC_ID_AAC, |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1706 CODEC_ID_MPEG4, |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1707 mov_write_header, |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1708 mov_write_packet, |
85def00971c3
mov, 3gp, mp4 muxer by (Thomas Raivio <tjraivio at cc dot hut dot fi>)
michaelni
parents:
diff
changeset
|
1709 mov_write_trailer, |
715
e214703e4b76
30_clean_up_global_header_flag.patch by (Calcium | calcium nurs or jp)
michael
parents:
711
diff
changeset
|
1710 .flags = AVFMT_GLOBALHEADER, |
2980
672d72727b20
finally set codec tags for mov/mp4/3gp muxers, this should not break anything, if it breaks anything, yell
bcoudurier
parents:
2979
diff
changeset
|
1711 .codec_tag = (const AVCodecTag*[]){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
|
1712 }; |
1169 | 1713 #endif |
1714 #ifdef CONFIG_PSP_MUXER | |
1715 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
|
1716 "psp", |
6d7c0e6d929e
Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents:
657
diff
changeset
|
1717 "psp mp4 format", |
6d7c0e6d929e
Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents:
657
diff
changeset
|
1718 NULL, |
6d7c0e6d929e
Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents:
657
diff
changeset
|
1719 "mp4,psp", |
6d7c0e6d929e
Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents:
657
diff
changeset
|
1720 sizeof(MOVContext), |
6d7c0e6d929e
Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents:
657
diff
changeset
|
1721 CODEC_ID_AAC, |
6d7c0e6d929e
Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents:
657
diff
changeset
|
1722 CODEC_ID_MPEG4, |
6d7c0e6d929e
Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents:
657
diff
changeset
|
1723 mov_write_header, |
6d7c0e6d929e
Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents:
657
diff
changeset
|
1724 mov_write_packet, |
6d7c0e6d929e
Sony PSP variation of MP4 patch by <tjcannell AT blueyonder DOT co DOT uk>
mmu_man
parents:
657
diff
changeset
|
1725 mov_write_trailer, |
911
343ddd5b793c
Fix for title field in PSP compatible mp4 files. Patch by
banan
parents:
910
diff
changeset
|
1726 .flags = AVFMT_GLOBALHEADER, |
2980
672d72727b20
finally set codec tags for mov/mp4/3gp muxers, this should not break anything, if it breaks anything, yell
bcoudurier
parents:
2979
diff
changeset
|
1727 .codec_tag = (const AVCodecTag*[]){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
|
1728 }; |
1169 | 1729 #endif |
1730 #ifdef CONFIG_TG2_MUXER | |
1731 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
|
1732 "3g2", |
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
|
1733 "3gp2 format", |
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
|
1734 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
|
1735 "3g2", |
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
|
1736 sizeof(MOVContext), |
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
|
1737 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
|
1738 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
|
1739 mov_write_header, |
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
|
1740 mov_write_packet, |
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
|
1741 mov_write_trailer, |
715
e214703e4b76
30_clean_up_global_header_flag.patch by (Calcium | calcium nurs or jp)
michael
parents:
711
diff
changeset
|
1742 .flags = AVFMT_GLOBALHEADER, |
2980
672d72727b20
finally set codec tags for mov/mp4/3gp muxers, this should not break anything, if it breaks anything, yell
bcoudurier
parents:
2979
diff
changeset
|
1743 .codec_tag = (const AVCodecTag*[]){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
|
1744 }; |
1169 | 1745 #endif |
3143 | 1746 #ifdef CONFIG_IPOD_MUXER |
1747 AVOutputFormat ipod_muxer = { | |
1748 "ipod", | |
1749 "iPod H.264 mp4 format", | |
1750 "application/mp4", | |
1751 NULL, | |
1752 sizeof(MOVContext), | |
1753 CODEC_ID_AAC, | |
1754 CODEC_ID_H264, | |
1755 mov_write_header, | |
1756 mov_write_packet, | |
1757 mov_write_trailer, | |
1758 .flags = AVFMT_GLOBALHEADER, | |
1759 .codec_tag = (const AVCodecTag*[]){ff_mp4_obj_type, 0}, | |
1760 }; | |
1761 #endif |