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