Mercurial > libavformat.hg
annotate avienc.c @ 142:720bab5adc70 libavformat
asv1 regression test
author | michaelni |
---|---|
date | Tue, 27 May 2003 22:43:34 +0000 |
parents | 45633cd5518a |
children | 46e80c40ab9f |
rev | line source |
---|---|
0 | 1 /* |
2 * AVI encoder. | |
3 * Copyright (c) 2000 Fabrice Bellard. | |
4 * | |
5 * This library is free software; you can redistribute it and/or | |
6 * modify it under the terms of the GNU Lesser General Public | |
7 * License as published by the Free Software Foundation; either | |
8 * version 2 of the License, or (at your option) any later version. | |
9 * | |
10 * This library is distributed in the hope that it will be useful, | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 * Lesser General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU Lesser General Public | |
16 * License along with this library; if not, write to the Free Software | |
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 */ | |
19 #include "avformat.h" | |
20 #include "avi.h" | |
21 | |
22 /* | |
23 * TODO: | |
24 * - fill all fields if non streamed (nb_frames for example) | |
25 */ | |
26 | |
119 | 27 typedef struct AVIIentry { |
28 unsigned int flags, pos, len; | |
29 } AVIIentry; | |
30 | |
31 #define AVI_INDEX_CLUSTER_SIZE 16384 | |
32 | |
0 | 33 typedef struct AVIIndex { |
119 | 34 offset_t indx_start; |
35 int entry; | |
36 int ents_allocated; | |
37 AVIIentry** cluster; | |
0 | 38 } AVIIndex; |
39 | |
40 typedef struct { | |
102
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
41 offset_t riff_start, movi_list, odml_list; |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
42 offset_t frames_hdr_all, frames_hdr_strm[MAX_STREAMS]; |
0 | 43 int audio_strm_length[MAX_STREAMS]; |
119 | 44 int riff_id; |
45 | |
46 AVIIndex indexes[MAX_STREAMS]; | |
0 | 47 } AVIContext; |
48 | |
119 | 49 static inline AVIIentry* avi_get_ientry(AVIIndex* idx, int ent_id) |
50 { | |
51 int cl = ent_id / AVI_INDEX_CLUSTER_SIZE; | |
52 int id = ent_id % AVI_INDEX_CLUSTER_SIZE; | |
53 return &idx->cluster[cl][id]; | |
54 } | |
55 | |
0 | 56 offset_t start_tag(ByteIOContext *pb, const char *tag) |
57 { | |
58 put_tag(pb, tag); | |
59 put_le32(pb, 0); | |
60 return url_ftell(pb); | |
61 } | |
62 | |
63 void end_tag(ByteIOContext *pb, offset_t start) | |
64 { | |
65 offset_t pos; | |
66 | |
67 pos = url_ftell(pb); | |
68 url_fseek(pb, start - 4, SEEK_SET); | |
65 | 69 put_le32(pb, (uint32_t)(pos - start)); |
0 | 70 url_fseek(pb, pos, SEEK_SET); |
71 } | |
72 | |
73 /* Note: when encoding, the first matching tag is used, so order is | |
74 important if multiple tags possible for a given codec. */ | |
75 const CodecTag codec_bmp_tags[] = { | |
76 { CODEC_ID_H263, MKTAG('H', '2', '6', '3') }, | |
77 { CODEC_ID_H263P, MKTAG('H', '2', '6', '3') }, | |
78 { CODEC_ID_H263I, MKTAG('I', '2', '6', '3') }, /* intel h263 */ | |
90
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
79 |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
80 /* added based on MPlayer */ |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
81 { CODEC_ID_H263I, MKTAG('i', '2', '6', '3') }, |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
82 { CODEC_ID_H263P, MKTAG('U', '2', '6', '3') }, |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
83 { CODEC_ID_H263P, MKTAG('h', '2', '6', '3') }, |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
84 { CODEC_ID_H263P, MKTAG('v', 'i', 'v', '1') }, |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
85 |
0 | 86 { CODEC_ID_MJPEG, MKTAG('M', 'J', 'P', 'G') }, |
87 { CODEC_ID_MPEG4, MKTAG('D', 'I', 'V', 'X'), .invalid_asf = 1 }, | |
88 { CODEC_ID_MPEG4, MKTAG('d', 'i', 'v', 'x'), .invalid_asf = 1 }, | |
89 { CODEC_ID_MPEG4, MKTAG('D', 'X', '5', '0'), .invalid_asf = 1 }, | |
90 { CODEC_ID_MPEG4, MKTAG('X', 'V', 'I', 'D'), .invalid_asf = 1 }, | |
91 { CODEC_ID_MPEG4, MKTAG('x', 'v', 'i', 'd'), .invalid_asf = 1 }, | |
92 { CODEC_ID_MPEG4, MKTAG('m', 'p', '4', 's'), .invalid_asf = 1 }, | |
93 { CODEC_ID_MPEG4, MKTAG('M', 'P', '4', 'S') }, | |
94 { CODEC_ID_MPEG4, MKTAG('M', '4', 'S', '2') }, | |
95 { CODEC_ID_MPEG4, MKTAG('m', '4', 's', '2') }, | |
96 { CODEC_ID_MPEG4, MKTAG(0x04, 0, 0, 0) }, /* some broken avi use this */ | |
90
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
97 |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
98 /* added based on MPlayer */ |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
99 { CODEC_ID_MPEG4, MKTAG('D', 'I', 'V', '1') }, |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
100 { CODEC_ID_MPEG4, MKTAG('d', 'i', 'v', '1') }, |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
101 { CODEC_ID_MPEG4, MKTAG('X', 'v', 'i', 'D') }, |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
102 { CODEC_ID_MPEG4, MKTAG('B', 'L', 'Z', '0') }, |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
103 { CODEC_ID_MPEG4, MKTAG('m', 'p', '4', 'v') }, |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
104 { CODEC_ID_MPEG4, MKTAG('U', 'M', 'P', '4') }, |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
105 |
0 | 106 { CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '3'), .invalid_asf = 1 }, /* default signature when using MSMPEG4 */ |
107 { CODEC_ID_MSMPEG4V3, MKTAG('d', 'i', 'v', '3'), .invalid_asf = 1 }, | |
108 { CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', '4', '3') }, | |
90
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
109 |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
110 /* added based on MPlayer */ |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
111 { CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', 'G', '3') }, |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
112 { CODEC_ID_MSMPEG4V3, MKTAG('m', 'p', 'g', '3') }, |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
113 { CODEC_ID_MSMPEG4V3, MKTAG('m', 'p', '4', '3') }, |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
114 { CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '5') }, |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
115 { CODEC_ID_MSMPEG4V3, MKTAG('d', 'i', 'v', '5') }, |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
116 { CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '6') }, |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
117 { CODEC_ID_MSMPEG4V3, MKTAG('d', 'i', 'v', '6') }, |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
118 { CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '4') }, |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
119 { CODEC_ID_MSMPEG4V3, MKTAG('d', 'i', 'v', '4') }, |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
120 { CODEC_ID_MSMPEG4V3, MKTAG('A', 'P', '4', '1') }, |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
121 { CODEC_ID_MSMPEG4V3, MKTAG('C', 'O', 'L', '1') }, |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
122 { CODEC_ID_MSMPEG4V3, MKTAG('c', 'o', 'l', '1') }, |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
123 { CODEC_ID_MSMPEG4V3, MKTAG('C', 'O', 'L', '0') }, |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
124 { CODEC_ID_MSMPEG4V3, MKTAG('c', 'o', 'l', '0') }, |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
125 |
0 | 126 { CODEC_ID_MSMPEG4V2, MKTAG('M', 'P', '4', '2') }, |
90
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
127 |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
128 /* added based on MPlayer */ |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
129 { CODEC_ID_MSMPEG4V2, MKTAG('D', 'I', 'V', '2') }, |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
130 { CODEC_ID_MSMPEG4V2, MKTAG('d', 'i', 'v', '2') }, |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
131 { CODEC_ID_MSMPEG4V2, MKTAG('m', 'p', '4', '2') }, |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
132 |
0 | 133 { CODEC_ID_MSMPEG4V1, MKTAG('M', 'P', 'G', '4') }, |
90
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
134 |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
135 /* added based on MPlayer */ |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
136 { CODEC_ID_MSMPEG4V1, MKTAG('D', 'I', 'V', '4') }, |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
137 { CODEC_ID_MSMPEG4V1, MKTAG('d', 'i', 'v', '4') }, |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
138 { CODEC_ID_MSMPEG4V1, MKTAG('m', 'p', 'g', '4') }, |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
139 |
0 | 140 { CODEC_ID_WMV1, MKTAG('W', 'M', 'V', '1') }, |
90
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
141 |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
142 /* added based on MPlayer */ |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
143 { CODEC_ID_WMV1, MKTAG('w', 'm', 'v', '1') }, |
27d6df9208d4
merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents:
89
diff
changeset
|
144 |
77 | 145 { CODEC_ID_WMV2, MKTAG('W', 'M', 'V', '2') }, |
0 | 146 { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 's', 'd') }, |
147 { CODEC_ID_DVVIDEO, MKTAG('D', 'V', 'S', 'D') }, | |
148 { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'h', 'd') }, | |
102
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
149 { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 's', 'l') }, |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
150 { CODEC_ID_DVVIDEO, MKTAG('d', 'v', '2', '5') }, |
0 | 151 { CODEC_ID_MPEG1VIDEO, MKTAG('m', 'p', 'g', '1') }, |
152 { CODEC_ID_MPEG1VIDEO, MKTAG('m', 'p', 'g', '2') }, | |
153 { CODEC_ID_MPEG1VIDEO, MKTAG('P', 'I', 'M', '1') }, | |
154 { CODEC_ID_MJPEG, MKTAG('M', 'J', 'P', 'G') }, | |
15 | 155 { CODEC_ID_HUFFYUV, MKTAG('H', 'F', 'Y', 'U') }, |
156 { CODEC_ID_HUFFYUV, MKTAG('h', 'f', 'y', 'u') }, | |
61 | 157 { CODEC_ID_CYUV, MKTAG('C', 'Y', 'U', 'V') }, |
158 { CODEC_ID_CYUV, MKTAG('c', 'y', 'u', 'v') }, | |
89
8e3cf4e9fc5a
rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
85
diff
changeset
|
159 { CODEC_ID_RAWVIDEO, MKTAG('Y', '4', '2', '2') }, |
94
79b7d70d6c37
I420 patch by (Sebastien Bechet <s dot bechet at av7 dot net>)
michaelni
parents:
90
diff
changeset
|
160 { CODEC_ID_RAWVIDEO, MKTAG('I', '4', '2', '0') }, |
105 | 161 { CODEC_ID_INDEO3, MKTAG('i', 'v', '3', '1') }, |
162 { CODEC_ID_INDEO3, MKTAG('i', 'v', '3', '2') }, | |
163 { CODEC_ID_INDEO3, MKTAG('I', 'V', '3', '1') }, | |
164 { CODEC_ID_INDEO3, MKTAG('I', 'V', '3', '2') }, | |
124 | 165 { CODEC_ID_VP3, MKTAG('V', 'P', '3', '1') }, |
142 | 166 { CODEC_ID_ASV1, MKTAG('A', 'S', 'V', '1') }, |
0 | 167 { 0, 0 }, |
168 }; | |
169 | |
170 unsigned int codec_get_tag(const CodecTag *tags, int id) | |
171 { | |
172 while (tags->id != 0) { | |
173 if (tags->id == id) | |
174 return tags->tag; | |
175 tags++; | |
176 } | |
177 return 0; | |
178 } | |
179 | |
180 static unsigned int codec_get_asf_tag(const CodecTag *tags, int id) | |
181 { | |
182 while (tags->id != 0) { | |
183 if (!tags->invalid_asf && tags->id == id) | |
184 return tags->tag; | |
185 tags++; | |
186 } | |
187 return 0; | |
188 } | |
189 | |
120 | 190 enum CodecID codec_get_id(const CodecTag *tags, unsigned int tag) |
0 | 191 { |
192 while (tags->id != 0) { | |
193 if (tags->tag == tag) | |
194 return tags->id; | |
195 tags++; | |
196 } | |
120 | 197 return CODEC_ID_NONE; |
0 | 198 } |
199 | |
200 unsigned int codec_get_bmp_tag(int id) | |
201 { | |
202 return codec_get_tag(codec_bmp_tags, id); | |
203 } | |
204 | |
205 /* BITMAPINFOHEADER header */ | |
206 void put_bmp_header(ByteIOContext *pb, AVCodecContext *enc, const CodecTag *tags, int for_asf) | |
207 { | |
76 | 208 put_le32(pb, 40 + enc->extradata_size); /* size */ |
0 | 209 put_le32(pb, enc->width); |
210 put_le32(pb, enc->height); | |
211 put_le16(pb, 1); /* planes */ | |
76 | 212 |
213 put_le16(pb, enc->bits_per_sample ? enc->bits_per_sample : 24); /* depth */ | |
0 | 214 /* compression type */ |
128 | 215 put_le32(pb, for_asf ? codec_get_asf_tag(tags, enc->codec_id) : enc->codec_tag); |
0 | 216 put_le32(pb, enc->width * enc->height * 3); |
217 put_le32(pb, 0); | |
218 put_le32(pb, 0); | |
219 put_le32(pb, 0); | |
220 put_le32(pb, 0); | |
76 | 221 |
222 put_buffer(pb, enc->extradata, enc->extradata_size); | |
223 | |
224 if (enc->extradata_size & 1) | |
225 put_byte(pb, 0); | |
0 | 226 } |
227 | |
228 static void parse_specific_params(AVCodecContext *stream, int *au_byterate, int *au_ssize, int *au_scale) | |
229 { | |
230 switch(stream->codec_id) { | |
231 case CODEC_ID_PCM_S16LE: | |
232 *au_scale = *au_ssize = 2*stream->channels; | |
233 *au_byterate = *au_ssize * stream->sample_rate; | |
234 break; | |
235 case CODEC_ID_PCM_U8: | |
236 case CODEC_ID_PCM_ALAW: | |
237 case CODEC_ID_PCM_MULAW: | |
238 *au_scale = *au_ssize = stream->channels; | |
239 *au_byterate = *au_ssize * stream->sample_rate; | |
240 break; | |
241 case CODEC_ID_MP2: | |
242 *au_ssize = 1; | |
243 *au_scale = 1; | |
244 *au_byterate = stream->bit_rate / 8; | |
245 case CODEC_ID_MP3LAME: | |
246 *au_ssize = 1; | |
247 *au_scale = 1; | |
248 *au_byterate = stream->bit_rate / 8; | |
249 default: | |
250 *au_ssize = 1; | |
251 *au_scale = 1; | |
252 *au_byterate = stream->bit_rate / 8; | |
253 break; | |
254 } | |
255 } | |
256 | |
102
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
257 static offset_t avi_start_new_riff(AVIContext *avi, ByteIOContext *pb, |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
258 const char* riff_tag, const char* list_tag) |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
259 { |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
260 offset_t loff; |
119 | 261 int i; |
262 | |
263 avi->riff_id++; | |
264 for (i=0; i<MAX_STREAMS; i++) | |
265 avi->indexes[i].entry = 0; | |
266 | |
102
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
267 avi->riff_start = start_tag(pb, "RIFF"); |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
268 put_tag(pb, riff_tag); |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
269 loff = start_tag(pb, "LIST"); |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
270 put_tag(pb, list_tag); |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
271 return loff; |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
272 } |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
273 |
119 | 274 static unsigned char* avi_stream2fourcc(unsigned char* tag, int index, |
275 enum CodecType type) | |
276 { | |
277 tag[0] = '0'; | |
278 tag[1] = '0' + index; | |
279 if (type == CODEC_TYPE_VIDEO) { | |
280 tag[2] = 'd'; | |
281 tag[3] = 'c'; | |
282 } else { | |
283 tag[2] = 'w'; | |
284 tag[3] = 'b'; | |
285 } | |
286 tag[4] = '\0'; | |
287 return tag; | |
288 } | |
289 | |
0 | 290 static int avi_write_header(AVFormatContext *s) |
291 { | |
292 AVIContext *avi = s->priv_data; | |
293 ByteIOContext *pb = &s->pb; | |
294 int bitrate, n, i, nb_frames, au_byterate, au_ssize, au_scale; | |
295 AVCodecContext *stream, *video_enc; | |
296 offset_t list1, list2, strh, strf; | |
297 | |
298 /* header list */ | |
119 | 299 avi->riff_id = 0; |
102
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
300 list1 = avi_start_new_riff(avi, pb, "AVI ", "hdrl"); |
0 | 301 |
302 /* avi header */ | |
303 put_tag(pb, "avih"); | |
304 put_le32(pb, 14 * 4); | |
305 bitrate = 0; | |
306 | |
307 video_enc = NULL; | |
308 for(n=0;n<s->nb_streams;n++) { | |
309 stream = &s->streams[n]->codec; | |
310 bitrate += stream->bit_rate; | |
311 if (stream->codec_type == CODEC_TYPE_VIDEO) | |
312 video_enc = stream; | |
313 } | |
314 | |
315 nb_frames = 0; | |
316 | |
36
1188ad85857a
audio only avi patch by (Andriy Rysin <arysin at bcsii dot net>)
michaelni
parents:
15
diff
changeset
|
317 if(video_enc){ |
85
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
77
diff
changeset
|
318 put_le32(pb, (uint32_t)(int64_t_C(1000000) * video_enc->frame_rate_base / video_enc->frame_rate)); |
36
1188ad85857a
audio only avi patch by (Andriy Rysin <arysin at bcsii dot net>)
michaelni
parents:
15
diff
changeset
|
319 } else { |
1188ad85857a
audio only avi patch by (Andriy Rysin <arysin at bcsii dot net>)
michaelni
parents:
15
diff
changeset
|
320 put_le32(pb, 0); |
1188ad85857a
audio only avi patch by (Andriy Rysin <arysin at bcsii dot net>)
michaelni
parents:
15
diff
changeset
|
321 } |
0 | 322 put_le32(pb, bitrate / 8); /* XXX: not quite exact */ |
323 put_le32(pb, 0); /* padding */ | |
324 put_le32(pb, AVIF_TRUSTCKTYPE | AVIF_HASINDEX | AVIF_ISINTERLEAVED); /* flags */ | |
325 avi->frames_hdr_all = url_ftell(pb); /* remember this offset to fill later */ | |
326 put_le32(pb, nb_frames); /* nb frames, filled later */ | |
327 put_le32(pb, 0); /* initial frame */ | |
328 put_le32(pb, s->nb_streams); /* nb streams */ | |
329 put_le32(pb, 1024 * 1024); /* suggested buffer size */ | |
36
1188ad85857a
audio only avi patch by (Andriy Rysin <arysin at bcsii dot net>)
michaelni
parents:
15
diff
changeset
|
330 if(video_enc){ |
0 | 331 put_le32(pb, video_enc->width); |
332 put_le32(pb, video_enc->height); | |
36
1188ad85857a
audio only avi patch by (Andriy Rysin <arysin at bcsii dot net>)
michaelni
parents:
15
diff
changeset
|
333 } else { |
1188ad85857a
audio only avi patch by (Andriy Rysin <arysin at bcsii dot net>)
michaelni
parents:
15
diff
changeset
|
334 put_le32(pb, 0); |
1188ad85857a
audio only avi patch by (Andriy Rysin <arysin at bcsii dot net>)
michaelni
parents:
15
diff
changeset
|
335 put_le32(pb, 0); |
1188ad85857a
audio only avi patch by (Andriy Rysin <arysin at bcsii dot net>)
michaelni
parents:
15
diff
changeset
|
336 } |
0 | 337 put_le32(pb, 0); /* reserved */ |
338 put_le32(pb, 0); /* reserved */ | |
339 put_le32(pb, 0); /* reserved */ | |
340 put_le32(pb, 0); /* reserved */ | |
341 | |
342 /* stream list */ | |
343 for(i=0;i<n;i++) { | |
344 list2 = start_tag(pb, "LIST"); | |
345 put_tag(pb, "strl"); | |
346 | |
347 stream = &s->streams[i]->codec; | |
348 | |
89
8e3cf4e9fc5a
rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
85
diff
changeset
|
349 /* FourCC should really be set by the codec itself */ |
8e3cf4e9fc5a
rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
85
diff
changeset
|
350 if (! stream->codec_tag) { |
8e3cf4e9fc5a
rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
85
diff
changeset
|
351 stream->codec_tag = codec_get_bmp_tag(stream->codec_id); |
8e3cf4e9fc5a
rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
85
diff
changeset
|
352 } |
8e3cf4e9fc5a
rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
85
diff
changeset
|
353 |
0 | 354 /* stream generic header */ |
355 strh = start_tag(pb, "strh"); | |
356 switch(stream->codec_type) { | |
357 case CODEC_TYPE_VIDEO: | |
358 put_tag(pb, "vids"); | |
89
8e3cf4e9fc5a
rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
85
diff
changeset
|
359 put_le32(pb, stream->codec_tag); |
0 | 360 put_le32(pb, 0); /* flags */ |
361 put_le16(pb, 0); /* priority */ | |
362 put_le16(pb, 0); /* language */ | |
363 put_le32(pb, 0); /* initial frame */ | |
75
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
65
diff
changeset
|
364 |
85
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
77
diff
changeset
|
365 put_le32(pb, stream->frame_rate_base); /* scale */ |
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
77
diff
changeset
|
366 put_le32(pb, stream->frame_rate); /* rate */ |
75
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
65
diff
changeset
|
367 |
0 | 368 put_le32(pb, 0); /* start */ |
369 avi->frames_hdr_strm[i] = url_ftell(pb); /* remember this offset to fill later */ | |
370 put_le32(pb, nb_frames); /* length, XXX: fill later */ | |
371 put_le32(pb, 1024 * 1024); /* suggested buffer size */ | |
372 put_le32(pb, -1); /* quality */ | |
373 put_le32(pb, stream->width * stream->height * 3); /* sample size */ | |
374 put_le16(pb, 0); | |
375 put_le16(pb, 0); | |
376 put_le16(pb, stream->width); | |
377 put_le16(pb, stream->height); | |
378 break; | |
379 case CODEC_TYPE_AUDIO: | |
380 put_tag(pb, "auds"); | |
381 put_le32(pb, 1); /* tag */ | |
382 put_le32(pb, 0); /* flags */ | |
383 put_le16(pb, 0); /* priority */ | |
384 put_le16(pb, 0); /* language */ | |
385 put_le32(pb, 0); /* initial frame */ | |
386 parse_specific_params(stream, &au_byterate, &au_ssize, &au_scale); | |
387 put_le32(pb, au_scale); /* scale */ | |
388 put_le32(pb, au_byterate); /* rate */ | |
389 put_le32(pb, 0); /* start */ | |
390 avi->frames_hdr_strm[i] = url_ftell(pb); /* remember this offset to fill later */ | |
391 put_le32(pb, 0); /* length, XXX: filled later */ | |
392 put_le32(pb, 12 * 1024); /* suggested buffer size */ | |
393 put_le32(pb, -1); /* quality */ | |
394 put_le32(pb, au_ssize); /* sample size */ | |
395 put_le32(pb, 0); | |
396 put_le32(pb, 0); | |
397 break; | |
398 default: | |
399 av_abort(); | |
400 } | |
401 end_tag(pb, strh); | |
402 | |
403 strf = start_tag(pb, "strf"); | |
404 switch(stream->codec_type) { | |
405 case CODEC_TYPE_VIDEO: | |
406 put_bmp_header(pb, stream, codec_bmp_tags, 0); | |
407 break; | |
408 case CODEC_TYPE_AUDIO: | |
409 if (put_wav_header(pb, stream) < 0) { | |
410 av_free(avi); | |
411 return -1; | |
412 } | |
413 break; | |
414 default: | |
415 av_abort(); | |
416 } | |
417 end_tag(pb, strf); | |
119 | 418 |
419 if (!url_is_streamed(pb)) { | |
420 unsigned char tag[5]; | |
123
3b9e4b0a91e2
* Making AVI encoding predictable (all JUNK chunks are filled with 0)
romansh
parents:
122
diff
changeset
|
421 int j; |
119 | 422 |
423 /* Starting to lay out AVI OpenDML master index. | |
424 * We want to make it JUNK entry for now, since we'd | |
123
3b9e4b0a91e2
* Making AVI encoding predictable (all JUNK chunks are filled with 0)
romansh
parents:
122
diff
changeset
|
425 * like to get away without making AVI an OpenDML one |
119 | 426 * for compatibility reasons. |
427 */ | |
428 avi->indexes[i].entry = avi->indexes[i].ents_allocated = 0; | |
429 avi->indexes[i].indx_start = start_tag(pb, "JUNK"); | |
430 put_le16(pb, 4); /* wLongsPerEntry */ | |
431 put_byte(pb, 0); /* bIndexSubType (0 == frame index) */ | |
432 put_byte(pb, 0); /* bIndexType (0 == AVI_INDEX_OF_INDEXES) */ | |
433 put_le32(pb, 0); /* nEntriesInUse (will fill out later on) */ | |
434 put_tag(pb, avi_stream2fourcc(&tag[0], i, stream->codec_type)); | |
435 /* dwChunkId */ | |
436 put_le64(pb, 0); /* dwReserved[3] | |
437 put_le32(pb, 0); Must be 0. */ | |
123
3b9e4b0a91e2
* Making AVI encoding predictable (all JUNK chunks are filled with 0)
romansh
parents:
122
diff
changeset
|
438 for (j=0; j < AVI_MASTER_INDEX_SIZE * 2; j++) |
3b9e4b0a91e2
* Making AVI encoding predictable (all JUNK chunks are filled with 0)
romansh
parents:
122
diff
changeset
|
439 put_le64(pb, 0); |
119 | 440 end_tag(pb, avi->indexes[i].indx_start); |
441 } | |
442 | |
0 | 443 end_tag(pb, list2); |
444 } | |
102
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
445 |
119 | 446 if (!url_is_streamed(pb)) { |
447 /* AVI could become an OpenDML one, if it grows beyond 2Gb range */ | |
448 avi->odml_list = start_tag(pb, "JUNK"); | |
449 put_tag(pb, "odml"); | |
450 put_tag(pb, "dmlh"); | |
451 put_le32(pb, 248); | |
452 for (i = 0; i < 248; i+= 4) | |
453 put_le32(pb, 0); | |
454 end_tag(pb, avi->odml_list); | |
455 } | |
0 | 456 |
457 end_tag(pb, list1); | |
458 | |
459 avi->movi_list = start_tag(pb, "LIST"); | |
460 put_tag(pb, "movi"); | |
461 | |
462 put_flush_packet(pb); | |
463 | |
464 return 0; | |
465 } | |
466 | |
119 | 467 static int avi_write_ix(AVFormatContext *s) |
468 { | |
469 ByteIOContext *pb = &s->pb; | |
470 AVIContext *avi = s->priv_data; | |
471 unsigned char tag[5]; | |
472 unsigned char ix_tag[] = "ix00"; | |
473 int i, j; | |
474 | |
475 if (avi->riff_id > AVI_MASTER_INDEX_SIZE) | |
476 return -1; | |
477 | |
478 for (i=0;i<s->nb_streams;i++) { | |
479 offset_t ix, pos; | |
480 | |
481 avi_stream2fourcc(&tag[0], i, s->streams[i]->codec.codec_type); | |
482 ix_tag[3] = '0' + i; | |
483 | |
484 /* Writing AVI OpenDML leaf index chunk */ | |
485 ix = url_ftell(pb); | |
486 put_tag(pb, &ix_tag[0]); /* ix?? */ | |
487 put_le32(pb, avi->indexes[i].entry * 8 + 24); | |
488 /* chunk size */ | |
489 put_le16(pb, 2); /* wLongsPerEntry */ | |
490 put_byte(pb, 0); /* bIndexSubType (0 == frame index) */ | |
491 put_byte(pb, 1); /* bIndexType (1 == AVI_INDEX_OF_CHUNKS) */ | |
492 put_le32(pb, avi->indexes[i].entry); | |
493 /* nEntriesInUse */ | |
494 put_tag(pb, &tag[0]); /* dwChunkId */ | |
495 put_le64(pb, avi->movi_list);/* qwBaseOffset */ | |
496 put_le32(pb, 0); /* dwReserved_3 (must be 0) */ | |
497 | |
498 for (j=0; j<avi->indexes[i].entry; j++) { | |
499 AVIIentry* ie = avi_get_ientry(&avi->indexes[i], j); | |
500 put_le32(pb, ie->pos + 8); | |
501 put_le32(pb, ((uint32_t)ie->len & ~0x80000000) | | |
502 (ie->flags & 0x10 ? 0 : 0x80000000)); | |
503 } | |
504 put_flush_packet(pb); | |
505 pos = url_ftell(pb); | |
506 | |
507 /* Updating one entry in the AVI OpenDML master index */ | |
508 url_fseek(pb, avi->indexes[i].indx_start - 8, SEEK_SET); | |
509 put_tag(pb, "indx"); /* enabling this entry */ | |
510 url_fskip(pb, 8); | |
511 put_le32(pb, avi->riff_id); /* nEntriesInUse */ | |
512 url_fskip(pb, 16*avi->riff_id); | |
513 put_le64(pb, ix); /* qwOffset */ | |
514 put_le32(pb, pos - ix); /* dwSize */ | |
515 put_le32(pb, avi->indexes[i].entry); /* dwDuration */ | |
516 | |
517 url_fseek(pb, pos, SEEK_SET); | |
518 } | |
519 return 0; | |
520 } | |
521 | |
522 static int avi_write_idx1(AVFormatContext *s) | |
102
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
523 { |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
524 ByteIOContext *pb = &s->pb; |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
525 AVIContext *avi = s->priv_data; |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
526 offset_t file_size, idx_chunk; |
119 | 527 int i, n, nb_frames, au_byterate, au_ssize, au_scale; |
102
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
528 AVCodecContext *stream; |
119 | 529 unsigned char tag[5]; |
102
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
530 |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
531 if (!url_is_streamed(pb)) { |
122 | 532 AVIIentry* ie = 0, *tie; |
119 | 533 int entry[MAX_STREAMS]; |
122 | 534 int empty, stream_id = -1; |
102
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
535 |
119 | 536 idx_chunk = start_tag(pb, "idx1"); |
537 memset(&entry[0], 0, sizeof(entry)); | |
538 do { | |
539 empty = 1; | |
540 for (i=0; i<s->nb_streams; i++) { | |
541 if (avi->indexes[i].entry <= entry[i]) | |
542 continue; | |
543 | |
544 tie = avi_get_ientry(&avi->indexes[i], entry[i]); | |
545 if (empty || tie->pos < ie->pos) { | |
546 ie = tie; | |
547 stream_id = i; | |
548 } | |
549 empty = 0; | |
550 } | |
551 if (!empty) { | |
552 avi_stream2fourcc(&tag[0], stream_id, | |
553 s->streams[stream_id]->codec.codec_type); | |
554 put_tag(pb, &tag[0]); | |
555 put_le32(pb, ie->flags); | |
556 put_le32(pb, ie->pos); | |
557 put_le32(pb, ie->len); | |
558 entry[stream_id]++; | |
559 } | |
560 } while (!empty); | |
561 end_tag(pb, idx_chunk); | |
102
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
562 |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
563 /* Fill in frame/sample counters */ |
119 | 564 file_size = url_ftell(pb); |
102
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
565 nb_frames = 0; |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
566 for(n=0;n<s->nb_streams;n++) { |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
567 if (avi->frames_hdr_strm[n] != 0) { |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
568 stream = &s->streams[n]->codec; |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
569 url_fseek(pb, avi->frames_hdr_strm[n], SEEK_SET); |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
570 if (stream->codec_type == CODEC_TYPE_VIDEO) { |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
571 put_le32(pb, stream->frame_number); |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
572 if (nb_frames < stream->frame_number) |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
573 nb_frames = stream->frame_number; |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
574 } else { |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
575 if (stream->codec_id == CODEC_ID_MP2 || stream->codec_id == CODEC_ID_MP3LAME) { |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
576 put_le32(pb, stream->frame_number); |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
577 nb_frames += stream->frame_number; |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
578 } else { |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
579 parse_specific_params(stream, &au_byterate, &au_ssize, &au_scale); |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
580 put_le32(pb, avi->audio_strm_length[n] / au_ssize); |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
581 } |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
582 } |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
583 } |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
584 } |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
585 if (avi->frames_hdr_all != 0) { |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
586 url_fseek(pb, avi->frames_hdr_all, SEEK_SET); |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
587 put_le32(pb, nb_frames); |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
588 } |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
589 url_fseek(pb, file_size, SEEK_SET); |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
590 } |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
591 return 0; |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
592 } |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
593 |
0 | 594 static int avi_write_packet(AVFormatContext *s, int stream_index, |
65 | 595 uint8_t *buf, int size, int force_pts) |
0 | 596 { |
597 AVIContext *avi = s->priv_data; | |
598 ByteIOContext *pb = &s->pb; | |
599 unsigned char tag[5]; | |
600 unsigned int flags; | |
601 AVCodecContext *enc; | |
102
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
602 |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
603 if (url_ftell(pb) - avi->riff_start > AVI_MAX_RIFF_SIZE) { |
119 | 604 avi_write_ix(s); |
605 end_tag(pb, avi->movi_list); | |
606 | |
607 if (avi->riff_id == 1) | |
608 avi_write_idx1(s); | |
609 | |
610 end_tag(pb, avi->riff_start); | |
102
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
611 avi->movi_list = avi_start_new_riff(avi, pb, "AVIX", "movi"); |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
612 } |
0 | 613 |
614 enc = &s->streams[stream_index]->codec; | |
119 | 615 avi_stream2fourcc(&tag[0], stream_index, enc->codec_type); |
616 if (enc->codec_type == CODEC_TYPE_AUDIO) { | |
0 | 617 avi->audio_strm_length[stream_index] += size; |
119 | 618 flags = 0x10; |
619 } else | |
620 flags = enc->coded_frame->key_frame ? 0x10 : 0x00; | |
0 | 621 |
622 if (!url_is_streamed(&s->pb)) { | |
119 | 623 AVIIndex* idx = &avi->indexes[stream_index]; |
624 int cl = idx->entry / AVI_INDEX_CLUSTER_SIZE; | |
625 int id = idx->entry % AVI_INDEX_CLUSTER_SIZE; | |
626 if (idx->ents_allocated <= idx->entry) { | |
627 idx->cluster = av_realloc(idx->cluster, (cl+1)*sizeof(void*)); | |
628 if (!idx->cluster) | |
629 return -1; | |
630 idx->cluster[cl] = av_malloc(AVI_INDEX_CLUSTER_SIZE*sizeof(AVIIentry)); | |
631 if (!idx->cluster[cl]) | |
632 return -1; | |
633 idx->ents_allocated += AVI_INDEX_CLUSTER_SIZE; | |
634 } | |
635 | |
636 idx->cluster[cl][id].flags = flags; | |
637 idx->cluster[cl][id].pos = url_ftell(pb) - avi->movi_list; | |
638 idx->cluster[cl][id].len = size; | |
639 idx->entry++; | |
0 | 640 } |
641 | |
642 put_buffer(pb, tag, 4); | |
643 put_le32(pb, size); | |
644 put_buffer(pb, buf, size); | |
645 if (size & 1) | |
646 put_byte(pb, 0); | |
647 | |
648 put_flush_packet(pb); | |
649 return 0; | |
650 } | |
651 | |
652 static int avi_write_trailer(AVFormatContext *s) | |
653 { | |
102
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
654 AVIContext *avi = s->priv_data; |
0 | 655 ByteIOContext *pb = &s->pb; |
102
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
656 int res = 0; |
119 | 657 int i, j, n, nb_frames; |
658 offset_t file_size; | |
0 | 659 |
119 | 660 if (avi->riff_id == 1) { |
661 end_tag(pb, avi->movi_list); | |
662 res = avi_write_idx1(s); | |
663 end_tag(pb, avi->riff_start); | |
664 } else { | |
665 avi_write_ix(s); | |
666 end_tag(pb, avi->movi_list); | |
667 end_tag(pb, avi->riff_start); | |
668 | |
0 | 669 file_size = url_ftell(pb); |
102
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
670 url_fseek(pb, avi->odml_list - 8, SEEK_SET); |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
671 put_tag(pb, "LIST"); /* Making this AVI OpenDML one */ |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
672 url_fskip(pb, 16); |
0 | 673 |
102
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
674 for (n=nb_frames=0;n<s->nb_streams;n++) { |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
675 AVCodecContext *stream = &s->streams[n]->codec; |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
676 if (stream->codec_type == CODEC_TYPE_VIDEO) { |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
677 if (nb_frames < stream->frame_number) |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
678 nb_frames = stream->frame_number; |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
679 } else { |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
680 if (stream->codec_id == CODEC_ID_MP2 || stream->codec_id == CODEC_ID_MP3LAME) { |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
681 nb_frames += stream->frame_number; |
0 | 682 } |
683 } | |
102
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
684 } |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
685 put_le32(pb, nb_frames); |
119 | 686 url_fseek(pb, file_size, SEEK_SET); |
687 } | |
688 put_flush_packet(pb); | |
102
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
689 |
119 | 690 for (i=0; i<MAX_STREAMS; i++) { |
691 for (j=0; j<avi->indexes[i].ents_allocated/AVI_INDEX_CLUSTER_SIZE; j++) | |
692 av_free(avi->indexes[i].cluster[j]); | |
693 av_free(avi->indexes[i].cluster); | |
694 avi->indexes[i].cluster = NULL; | |
695 avi->indexes[i].ents_allocated = avi->indexes[i].entry = 0; | |
696 } | |
697 | |
102
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
698 return res; |
0 | 699 } |
700 | |
701 static AVOutputFormat avi_oformat = { | |
702 "avi", | |
703 "avi format", | |
704 "video/x-msvideo", | |
705 "avi", | |
706 sizeof(AVIContext), | |
707 CODEC_ID_MP2, | |
106
4da5d55b3690
we really shouldnt use M$* as default codec -> use MPEG4 as default
michaelni
parents:
105
diff
changeset
|
708 CODEC_ID_MPEG4, |
0 | 709 avi_write_header, |
710 avi_write_packet, | |
711 avi_write_trailer, | |
712 }; | |
713 | |
714 int avienc_init(void) | |
715 { | |
716 av_register_output_format(&avi_oformat); | |
717 return 0; | |
718 } |