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