Mercurial > mplayer.hg
annotate libmpdemux/muxer_avi.c @ 12300:95ea9f5f6f14
Fix embedded smil playlist detection if there are parameters on the url
author | rtognimp |
---|---|
date | Mon, 26 Apr 2004 19:33:37 +0000 |
parents | ca5dc9c2cb51 |
children | 0db4a3a5b01d |
rev | line source |
---|---|
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
1
diff
changeset
|
1 #include <stdio.h> |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
1
diff
changeset
|
2 #include <stdlib.h> |
2529 | 3 #include <string.h> |
8585 | 4 #include <inttypes.h> |
8591 | 5 #include <unistd.h> |
12036 | 6 #include <limits.h> |
2529 | 7 |
2555
66837325b929
config.h cleanup, few things added to steram/demuxer headers
arpi
parents:
2529
diff
changeset
|
8 #include "config.h" |
7149 | 9 #include "../version.h" |
2555
66837325b929
config.h cleanup, few things added to steram/demuxer headers
arpi
parents:
2529
diff
changeset
|
10 |
12036 | 11 #include "stream.h" |
12 #include "demuxer.h" | |
13 #include "stheader.h" | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
1
diff
changeset
|
14 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
1
diff
changeset
|
15 #include "wine/mmreg.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
1
diff
changeset
|
16 #include "wine/avifmt.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
1
diff
changeset
|
17 #include "wine/vfw.h" |
6918 | 18 #include "bswap.h" |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
1
diff
changeset
|
19 |
8585 | 20 #include "muxer.h" |
6918 | 21 #include "aviheader.h" |
12036 | 22 #include "mp_msg.h" |
1 | 23 |
7145
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
24 extern char *info_name; |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
25 extern char *info_artist; |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
26 extern char *info_genre; |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
27 extern char *info_subject; |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
28 extern char *info_copyright; |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
29 extern char *info_sourceform; |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
30 extern char *info_comment; |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
31 |
12036 | 32 /* #define ODML_CHUNKLEN 0x02000000 */ /* for testing purposes */ |
33 #define ODML_CHUNKLEN 0x40000000 | |
34 #define ODML_NOTKEYFRAME 0x80000000U | |
35 #define MOVIALIGN 0x00001000 | |
36 | |
12061 | 37 float avi_aspect_override = -1.0; |
12051 | 38 |
12036 | 39 struct avi_odmlidx_entry { |
40 uint64_t ofs; | |
41 uint32_t len; | |
42 uint32_t flags; | |
43 }; | |
44 | |
45 struct avi_odmlsuperidx_entry { | |
46 uint64_t ofs; | |
47 uint32_t len; | |
48 uint32_t duration; | |
49 }; | |
50 | |
51 struct avi_stream_info { | |
52 int idxsize; | |
53 int idxpos; | |
54 int superidxpos; | |
55 int superidxsize; | |
12235
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
56 int riffofspos; |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
57 int riffofssize; |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
58 off_t *riffofs; |
12036 | 59 struct avi_odmlidx_entry *idx; |
60 struct avi_odmlsuperidx_entry *superidx; | |
61 }; | |
62 | |
12061 | 63 static unsigned int avi_aspect(muxer_stream_t *vstream) |
64 { | |
65 int x,y; | |
66 float aspect = vstream->aspect; | |
67 | |
68 if (avi_aspect_override > 0.0) { | |
69 aspect = avi_aspect_override; | |
70 } | |
71 | |
72 if (aspect <= 0.0) return 0; | |
73 | |
74 if (aspect > 15.99/9.0 && aspect < 16.01/9.0) { | |
75 return MAKE_AVI_ASPECT(16, 9); | |
76 } | |
77 if (aspect > 3.99/3.0 && aspect < 4.01/3.0) { | |
78 return MAKE_AVI_ASPECT(4, 3); | |
79 } | |
80 | |
81 if (aspect >= 1.0) { | |
82 x = 16384; | |
83 y = (float)x / aspect; | |
84 } else { | |
85 y = 16384; | |
86 x = (float)y * aspect; | |
87 } | |
88 | |
89 return MAKE_AVI_ASPECT(x, y); | |
90 } | |
91 | |
8585 | 92 static muxer_stream_t* avifile_new_stream(muxer_t *muxer,int type){ |
12036 | 93 struct avi_stream_info *si; |
8585 | 94 muxer_stream_t* s; |
9007
12fc55eb3373
Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents:
8591
diff
changeset
|
95 if (!muxer) return NULL; |
8585 | 96 if(muxer->avih.dwStreams>=MUXER_MAX_STREAMS){ |
12036 | 97 mp_msg(MSGT_MUXER, MSGL_ERR, "Too many streams! increase MUXER_MAX_STREAMS !\n"); |
2529 | 98 return NULL; |
99 } | |
8585 | 100 s=malloc(sizeof(muxer_stream_t)); |
101 memset(s,0,sizeof(muxer_stream_t)); | |
2529 | 102 if(!s) return NULL; // no mem!? |
103 muxer->streams[muxer->avih.dwStreams]=s; | |
104 s->type=type; | |
105 s->id=muxer->avih.dwStreams; | |
106 s->timer=0.0; | |
2652 | 107 s->size=0; |
9007
12fc55eb3373
Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents:
8591
diff
changeset
|
108 s->muxer=muxer; |
12036 | 109 s->priv=si=malloc(sizeof(struct avi_stream_info)); |
110 memset(si,0,sizeof(struct avi_stream_info)); | |
111 si->idxsize=256; | |
112 si->idx=malloc(sizeof(struct avi_odmlidx_entry)*si->idxsize); | |
12235
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
113 si->riffofssize=16; |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
114 si->riffofs=malloc(sizeof(off_t)*(si->riffofssize+1)); |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
115 memset(si->riffofs, 0, sizeof(off_t)*si->riffofssize); |
12036 | 116 |
2529 | 117 switch(type){ |
8585 | 118 case MUXER_TYPE_VIDEO: |
2529 | 119 s->ckid=mmioFOURCC(('0'+s->id/10),('0'+(s->id%10)),'d','c'); |
120 s->h.fccType=streamtypeVIDEO; | |
121 if(!muxer->def_v) muxer->def_v=s; | |
122 break; | |
8585 | 123 case MUXER_TYPE_AUDIO: |
2529 | 124 s->ckid=mmioFOURCC(('0'+s->id/10),('0'+(s->id%10)),'w','b'); |
125 s->h.fccType=streamtypeAUDIO; | |
126 break; | |
127 default: | |
12036 | 128 mp_msg(MSGT_MUXER, MSGL_WARN, "Warning! unknown stream type: %d\n",type); |
2529 | 129 return NULL; |
130 } | |
131 muxer->avih.dwStreams++; | |
132 return s; | |
133 } | |
1 | 134 |
2529 | 135 static void write_avi_chunk(FILE *f,unsigned int id,int len,void* data){ |
6918 | 136 int le_len = le2me_32(len); |
137 int le_id = le2me_32(id); | |
138 fwrite(&le_id,4,1,f); | |
139 fwrite(&le_len,4,1,f); | |
140 | |
1 | 141 if(len>0){ |
142 if(data){ | |
143 // DATA | |
144 fwrite(data,len,1,f); | |
145 if(len&1){ // padding | |
146 unsigned char zerobyte=0; | |
147 fwrite(&zerobyte,1,1,f); | |
148 } | |
149 } else { | |
150 // JUNK | |
151 char *avi_junk_data="[= MPlayer junk data! =]"; | |
152 if(len&1) ++len; // padding | |
153 while(len>0){ | |
154 int l=strlen(avi_junk_data); | |
155 if(l>len) l=len; | |
156 fwrite(avi_junk_data,l,1,f); | |
157 len-=l; | |
158 } | |
159 } | |
160 } | |
2529 | 161 } |
162 | |
12036 | 163 static void write_avi_list(FILE *f,unsigned int id,int len); |
164 static void avifile_write_index(muxer_t *muxer); | |
165 | |
166 static void avifile_odml_new_riff(muxer_t *muxer) | |
167 { | |
12235
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
168 struct avi_stream_info *vsi = muxer->def_v->priv; |
12036 | 169 FILE *f = muxer->file; |
170 uint32_t riff[3]; | |
171 | |
12235
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
172 mp_msg(MSGT_MUXER, MSGL_INFO, "ODML: Starting new RIFF chunk at %dMiB.\n", (int)(muxer->file_end/1024/1024)); |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
173 |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
174 vsi->riffofspos++; |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
175 if (vsi->riffofspos>=vsi->riffofssize) { |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
176 vsi->riffofssize+=16; |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
177 vsi->riffofs=realloc(vsi->riffofs,sizeof(off_t)*(vsi->riffofssize+1)); |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
178 } |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
179 vsi->riffofs[vsi->riffofspos] = ftello(f); |
12036 | 180 |
181 /* RIFF/AVIX chunk */ | |
182 riff[0]=le2me_32(mmioFOURCC('R','I','F','F')); | |
183 riff[1]=0; | |
184 riff[2]=le2me_32(mmioFOURCC('A','V','I','X')); | |
185 fwrite(riff,12,1,f); | |
186 | |
187 write_avi_list(f,listtypeAVIMOVIE,0); | |
12235
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
188 |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
189 muxer->file_end = ftello(f); |
12036 | 190 } |
191 | |
9007
12fc55eb3373
Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents:
8591
diff
changeset
|
192 static void avifile_write_chunk(muxer_stream_t *s,size_t len,unsigned int flags){ |
12235
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
193 off_t rifflen; |
9007
12fc55eb3373
Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents:
8591
diff
changeset
|
194 muxer_t *muxer=s->muxer; |
12235
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
195 struct avi_stream_info *si = s->priv; |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
196 struct avi_stream_info *vsi = muxer->def_v->priv; |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
197 int paddedlen = len + (len&1); |
2529 | 198 |
12235
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
199 rifflen = muxer->file_end - vsi->riffofs[vsi->riffofspos] - 8; |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
200 if (vsi->riffofspos == 0) { |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
201 rifflen += 8+muxer->idx_pos*sizeof(AVIINDEXENTRY); |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
202 } |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
203 if (rifflen + paddedlen > ODML_CHUNKLEN) { |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
204 if (vsi->riffofspos == 0) { |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
205 avifile_write_index(muxer); |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
206 } |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
207 avifile_odml_new_riff(muxer); |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
208 } |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
209 |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
210 if (vsi->riffofspos == 0) { |
12036 | 211 // add to the traditional index: |
212 if(muxer->idx_pos>=muxer->idx_size){ | |
213 muxer->idx_size+=256; // 4kB | |
214 muxer->idx=realloc(muxer->idx,16*muxer->idx_size); | |
215 } | |
216 muxer->idx[muxer->idx_pos].ckid=s->ckid; | |
217 muxer->idx[muxer->idx_pos].dwFlags=flags; // keyframe? | |
12235
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
218 muxer->idx[muxer->idx_pos].dwChunkOffset=muxer->file_end-(muxer->movi_start-4); |
12036 | 219 muxer->idx[muxer->idx_pos].dwChunkLength=len; |
220 ++muxer->idx_pos; | |
221 } | |
222 | |
223 // add to odml index | |
224 if(si->idxpos>=si->idxsize){ | |
225 si->idxsize+=256; | |
226 si->idx=realloc(si->idx,sizeof(*si->idx)*si->idxsize); | |
2529 | 227 } |
12036 | 228 si->idx[si->idxpos].flags=(flags&AVIIF_KEYFRAME)?0:ODML_NOTKEYFRAME; |
12235
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
229 si->idx[si->idxpos].ofs=muxer->file_end; |
12036 | 230 si->idx[si->idxpos].len=len; |
231 ++si->idxpos; | |
232 | |
2529 | 233 // write out the chunk: |
9007
12fc55eb3373
Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents:
8591
diff
changeset
|
234 write_avi_chunk(muxer->file,s->ckid,len,s->buffer); /* unsigned char */ |
6918 | 235 |
2529 | 236 // alter counters: |
12036 | 237 if (len > s->h.dwSuggestedBufferSize){ |
238 s->h.dwSuggestedBufferSize = len; | |
239 } | |
2529 | 240 if(s->h.dwSampleSize){ |
241 // CBR | |
242 s->h.dwLength+=len/s->h.dwSampleSize; | |
12036 | 243 if(len%s->h.dwSampleSize) mp_msg(MSGT_MUXER, MSGL_WARN, "Warning! len isn't divisable by samplesize!\n"); |
2529 | 244 } else { |
245 // VBR | |
246 s->h.dwLength++; | |
247 } | |
248 s->timer=(double)s->h.dwLength*s->h.dwScale/s->h.dwRate; | |
2652 | 249 s->size+=len; |
8585 | 250 if((unsigned int)len>s->h.dwSuggestedBufferSize) s->h.dwSuggestedBufferSize=len; |
1 | 251 |
12235
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
252 muxer->file_end += 8 + paddedlen; |
1 | 253 } |
254 | |
2529 | 255 static void write_avi_list(FILE *f,unsigned int id,int len){ |
1 | 256 unsigned int list_id=FOURCC_LIST; |
6918 | 257 int le_len; |
258 int le_id; | |
1 | 259 len+=4; // list fix |
6918 | 260 list_id = le2me_32(list_id); |
261 le_len = le2me_32(len); | |
262 le_id = le2me_32(id); | |
1 | 263 fwrite(&list_id,4,1,f); |
6918 | 264 fwrite(&le_len,4,1,f); |
265 fwrite(&le_id,4,1,f); | |
1 | 266 } |
267 | |
11374 | 268 #define WFSIZE(wf) (sizeof(WAVEFORMATEX)+(wf)->cbSize) |
2635
c1e24e01601b
fixed AVI header creation - now should be compatible with NaNdub
arpi
parents:
2555
diff
changeset
|
269 |
9007
12fc55eb3373
Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents:
8591
diff
changeset
|
270 static void avifile_write_header(muxer_t *muxer){ |
8585 | 271 uint32_t riff[3]; |
12036 | 272 unsigned int dmlh[1]; |
8585 | 273 unsigned int i; |
2529 | 274 unsigned int hdrsize; |
8585 | 275 muxer_info_t info[16]; |
12036 | 276 FILE *f = muxer->file; |
277 VideoPropHeader vprp; | |
12061 | 278 uint32_t aspect = avi_aspect(muxer->def_v); |
12036 | 279 off_t pos; |
12235
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
280 struct avi_stream_info *vsi = muxer->def_v->priv; |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
281 int isodml = vsi->riffofspos > 0; |
12036 | 282 |
12061 | 283 if (aspect == 0) { |
284 mp_msg(MSGT_MUXER, MSGL_INFO, "ODML: Aspect information not (yet?) available or unspecified, not writing vprp header.\n"); | |
285 } else { | |
286 mp_msg(MSGT_MUXER, MSGL_INFO, "ODML: vprp aspect is %d:%d.\n", aspect >> 16, aspect & 0xffff); | |
287 } | |
288 | |
12036 | 289 if (isodml) { |
290 unsigned int rifflen, movilen; | |
12235
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
291 int i; |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
292 |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
293 vsi->riffofs[vsi->riffofspos+1] = muxer->file_end; |
12036 | 294 |
12235
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
295 /* fixup RIFF lengths */ |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
296 for (i=0; i<=vsi->riffofspos; i++) { |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
297 rifflen = vsi->riffofs[i+1] - vsi->riffofs[i] - 8; |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
298 movilen = le2me_32(rifflen - 12); |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
299 rifflen = le2me_32(rifflen); |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
300 fseeko(f, vsi->riffofs[i]+4, SEEK_SET); |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
301 fwrite(&rifflen,4,1,f); |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
302 |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
303 /* fixup movi length */ |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
304 if (i > 0) { |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
305 fseeko(f, vsi->riffofs[i]+16, SEEK_SET); |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
306 fwrite(&movilen,4,1,f); |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
307 } |
12036 | 308 } |
7145
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
309 |
12235
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
310 fseeko(f, 12, SEEK_SET); |
12036 | 311 } else { |
312 // RIFF header: | |
313 riff[0]=mmioFOURCC('R','I','F','F'); | |
314 riff[1]=muxer->file_end-2*sizeof(unsigned int); // filesize | |
315 riff[2]=formtypeAVI; // 'AVI ' | |
316 riff[0]=le2me_32(riff[0]); | |
317 riff[1]=le2me_32(riff[1]); | |
318 riff[2]=le2me_32(riff[2]); | |
319 fwrite(&riff,12,1,f); | |
320 } | |
321 | |
2529 | 322 // update AVI header: |
323 if(muxer->def_v){ | |
12036 | 324 int i; |
2529 | 325 muxer->avih.dwMicroSecPerFrame=1000000.0*muxer->def_v->h.dwScale/muxer->def_v->h.dwRate; |
2635
c1e24e01601b
fixed AVI header creation - now should be compatible with NaNdub
arpi
parents:
2555
diff
changeset
|
326 // muxer->avih.dwMaxBytesPerSec=1000000; // dummy!!!!! FIXME |
c1e24e01601b
fixed AVI header creation - now should be compatible with NaNdub
arpi
parents:
2555
diff
changeset
|
327 // muxer->avih.dwPaddingGranularity=2; // ??? |
2529 | 328 muxer->avih.dwFlags|=AVIF_ISINTERLEAVED|AVIF_TRUSTCKTYPE; |
12036 | 329 muxer->avih.dwTotalFrames=0; |
330 for (i=0; i<muxer->idx_pos; i++) { | |
331 if (muxer->idx[i].ckid == muxer->def_v->ckid) | |
332 muxer->avih.dwTotalFrames++; | |
333 } | |
2635
c1e24e01601b
fixed AVI header creation - now should be compatible with NaNdub
arpi
parents:
2555
diff
changeset
|
334 // muxer->avih.dwSuggestedBufferSize=muxer->def_v->h.dwSuggestedBufferSize; |
2529 | 335 muxer->avih.dwWidth=muxer->def_v->bih->biWidth; |
336 muxer->avih.dwHeight=muxer->def_v->bih->biHeight; | |
337 } | |
338 | |
1 | 339 // AVI header: |
2529 | 340 hdrsize=sizeof(muxer->avih)+8; |
12036 | 341 if (isodml) hdrsize+=sizeof(dmlh)+20; // dmlh |
2529 | 342 // calc total header size: |
343 for(i=0;i<muxer->avih.dwStreams;i++){ | |
12036 | 344 muxer_stream_t *s = muxer->streams[i]; |
345 struct avi_stream_info *si = s->priv; | |
346 | |
2529 | 347 hdrsize+=12; // LIST |
348 hdrsize+=sizeof(muxer->streams[i]->h)+8; // strh | |
349 switch(muxer->streams[i]->type){ | |
8585 | 350 case MUXER_TYPE_VIDEO: |
2529 | 351 hdrsize+=muxer->streams[i]->bih->biSize+8; // strf |
12061 | 352 if (aspect != 0) { |
12051 | 353 hdrsize+=8+4*(9+8*1); // vprp |
354 } | |
2529 | 355 break; |
8585 | 356 case MUXER_TYPE_AUDIO: |
2635
c1e24e01601b
fixed AVI header creation - now should be compatible with NaNdub
arpi
parents:
2555
diff
changeset
|
357 hdrsize+=WFSIZE(muxer->streams[i]->wf)+8; // strf |
2529 | 358 break; |
359 } | |
12036 | 360 if (isodml && si && si->superidx && si->superidxsize) { |
361 hdrsize += 32 + 16*si->superidxsize; //indx | |
362 } | |
2529 | 363 } |
364 write_avi_list(f,listtypeAVIHEADER,hdrsize); | |
6918 | 365 |
366 le2me_MainAVIHeader(&muxer->avih); | |
367 write_avi_chunk(f,ckidAVIMAINHDR,sizeof(muxer->avih),&muxer->avih); /* MainAVIHeader */ | |
368 le2me_MainAVIHeader(&muxer->avih); | |
2529 | 369 |
370 // stream headers: | |
371 for(i=0;i<muxer->avih.dwStreams;i++){ | |
12036 | 372 muxer_stream_t *s = muxer->streams[i]; |
373 struct avi_stream_info *si = s->priv; | |
374 unsigned int idxhdr[8]; | |
375 int j,n; | |
376 | |
377 hdrsize=sizeof(s->h)+8; // strh | |
378 if (si && si->superidx && si->superidxsize) { | |
379 hdrsize += 32 + 16*si->superidxsize; //indx | |
380 } | |
381 switch(s->type){ | |
8585 | 382 case MUXER_TYPE_VIDEO: |
12036 | 383 hdrsize+=s->bih->biSize+8; // strf |
384 s->h.fccHandler = s->bih->biCompression; | |
385 s->h.rcFrame.right = s->bih->biWidth; | |
386 s->h.rcFrame.bottom = s->bih->biHeight; | |
12061 | 387 if (aspect != 0) { |
12051 | 388 // fill out vprp info |
389 memset(&vprp, 0, sizeof(vprp)); | |
390 vprp.dwVerticalRefreshRate = (s->h.dwRate+s->h.dwScale-1)/s->h.dwScale; | |
391 vprp.dwHTotalInT = muxer->avih.dwWidth; | |
392 vprp.dwVTotalInLines = muxer->avih.dwHeight; | |
12061 | 393 vprp.dwFrameAspectRatio = aspect; |
12051 | 394 vprp.dwFrameWidthInPixels = muxer->avih.dwWidth; |
395 vprp.dwFrameHeightInLines = muxer->avih.dwHeight; | |
396 vprp.nbFieldPerFrame = 1; | |
397 vprp.FieldInfo[0].CompressedBMHeight = muxer->avih.dwHeight; | |
398 vprp.FieldInfo[0].CompressedBMWidth = muxer->avih.dwWidth; | |
399 vprp.FieldInfo[0].ValidBMHeight = muxer->avih.dwHeight; | |
400 vprp.FieldInfo[0].ValidBMWidth = muxer->avih.dwWidth; | |
401 hdrsize+=8+4*(9+8*1); // vprp | |
402 } | |
2529 | 403 break; |
8585 | 404 case MUXER_TYPE_AUDIO: |
12036 | 405 hdrsize+=WFSIZE(s->wf)+8; // strf |
406 s->h.fccHandler = s->wf->wFormatTag; | |
2529 | 407 break; |
408 } | |
12036 | 409 |
2529 | 410 write_avi_list(f,listtypeSTREAMHEADER,hdrsize); |
12036 | 411 le2me_AVIStreamHeader(&s->h); |
412 write_avi_chunk(f,ckidSTREAMHEADER,sizeof(s->h),&s->h); /* AVISTreamHeader */ // strh | |
413 le2me_AVIStreamHeader(&s->h); | |
6918 | 414 |
12036 | 415 switch(s->type){ |
8585 | 416 case MUXER_TYPE_VIDEO: |
6918 | 417 { |
12036 | 418 int biSize=s->bih->biSize; |
419 le2me_BITMAPINFOHEADER(s->bih); | |
420 write_avi_chunk(f,ckidSTREAMFORMAT,biSize,s->bih); /* BITMAPINFOHEADER */ | |
12053 | 421 le2me_BITMAPINFOHEADER(s->bih); |
422 | |
12061 | 423 if (aspect != 0) { |
12053 | 424 int fields = vprp.nbFieldPerFrame; |
12051 | 425 le2me_VideoPropHeader(&vprp); |
426 le2me_VIDEO_FIELD_DESC(&vprp.FieldInfo[0]); | |
427 le2me_VIDEO_FIELD_DESC(&vprp.FieldInfo[1]); | |
428 write_avi_chunk(f,mmioFOURCC('v','p','r','p'), | |
12053 | 429 sizeof(VideoPropHeader) - |
430 sizeof(VIDEO_FIELD_DESC)*(2-fields), | |
431 &vprp); /* Video Properties Header */ | |
12051 | 432 } |
6918 | 433 } |
2529 | 434 break; |
8585 | 435 case MUXER_TYPE_AUDIO: |
6918 | 436 { |
12036 | 437 int wfsize = WFSIZE(s->wf); |
438 le2me_WAVEFORMATEX(s->wf); | |
439 write_avi_chunk(f,ckidSTREAMFORMAT,wfsize,s->wf); /* WAVEFORMATEX */ | |
440 le2me_WAVEFORMATEX(s->wf); | |
6918 | 441 } |
2529 | 442 break; |
443 } | |
12036 | 444 if (isodml && si && si->superidx && si->superidxsize) { |
445 n = si->superidxsize; | |
446 | |
447 idxhdr[0] = le2me_32(mmioFOURCC('i', 'n', 'd', 'x')); | |
448 idxhdr[1] = le2me_32(24 + 16*n); | |
449 idxhdr[2] = le2me_32(0x00000004); | |
450 idxhdr[3] = le2me_32(si->superidxpos); | |
451 idxhdr[4] = le2me_32(s->ckid); | |
452 idxhdr[5] = 0; | |
453 idxhdr[6] = 0; | |
454 idxhdr[7] = 0; | |
455 | |
456 fwrite(idxhdr,sizeof(idxhdr),1,f); | |
457 for (j=0; j<n; j++) { | |
458 struct avi_odmlsuperidx_entry *entry = &si->superidx[j]; | |
459 unsigned int data[4]; | |
460 data[0] = le2me_32(entry->ofs); | |
461 data[1] = le2me_32(entry->ofs >> 32); | |
462 data[2] = le2me_32(entry->len); | |
463 data[3] = le2me_32(entry->duration); | |
464 fwrite(data,sizeof(data),1,f); | |
465 } | |
466 } | |
467 } | |
468 | |
469 // ODML | |
470 if (isodml) { | |
471 memset(dmlh, 0, sizeof(dmlh)); | |
472 dmlh[0] = le2me_32(muxer->avih.dwTotalFrames); | |
473 write_avi_list(f,mmioFOURCC('o','d','m','l'),sizeof(dmlh)+8); | |
474 write_avi_chunk(f,mmioFOURCC('d','m','l','h'),sizeof(dmlh),dmlh); | |
2529 | 475 } |
476 | |
7145
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
477 // ============= INFO =============== |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
478 // always include software info |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
479 info[0].id=mmioFOURCC('I','S','F','T'); // Software: |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
480 info[0].text="MEncoder " VERSION; |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
481 // include any optional strings |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
482 i=1; |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
483 if(info_name!=NULL){ |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
484 info[i].id=mmioFOURCC('I','N','A','M'); // Name: |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
485 info[i++].text=info_name; |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
486 } |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
487 if(info_artist!=NULL){ |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
488 info[i].id=mmioFOURCC('I','A','R','T'); // Artist: |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
489 info[i++].text=info_artist; |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
490 } |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
491 if(info_genre!=NULL){ |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
492 info[i].id=mmioFOURCC('I','G','N','R'); // Genre: |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
493 info[i++].text=info_genre; |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
494 } |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
495 if(info_subject!=NULL){ |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
496 info[i].id=mmioFOURCC('I','S','B','J'); // Subject: |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
497 info[i++].text=info_subject; |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
498 } |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
499 if(info_copyright!=NULL){ |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
500 info[i].id=mmioFOURCC('I','C','O','P'); // Copyright: |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
501 info[i++].text=info_copyright; |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
502 } |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
503 if(info_sourceform!=NULL){ |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
504 info[i].id=mmioFOURCC('I','S','R','F'); // Source Form: |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
505 info[i++].text=info_sourceform; |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
506 } |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
507 if(info_comment!=NULL){ |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
508 info[i].id=mmioFOURCC('I','C','M','T'); // Comment: |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
509 info[i++].text=info_comment; |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
510 } |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
511 info[i].id=0; |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
512 |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
513 hdrsize=0; |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
514 // calc info size: |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
515 for(i=0;info[i].id!=0;i++) if(info[i].text){ |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
516 size_t sz=strlen(info[i].text)+1; |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
517 hdrsize+=sz+8+sz%2; |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
518 } |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
519 // write infos: |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
520 if (hdrsize!=0){ |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
521 write_avi_list(f,mmioFOURCC('I','N','F','O'),hdrsize); |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
522 for(i=0;info[i].id!=0;i++) if(info[i].text){ |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
523 write_avi_chunk(f,info[i].id,strlen(info[i].text)+1,info[i].text); |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
524 } |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
525 } |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
526 |
2529 | 527 // JUNK: |
12036 | 528 write_avi_chunk(f,ckidAVIPADDING,MOVIALIGN-(ftello(f)%MOVIALIGN)-8,NULL); /* junk */ |
529 if (!isodml) { | |
530 // 'movi' header: | |
531 write_avi_list(f,listtypeAVIMOVIE,muxer->movi_end-ftello(f)-12); | |
532 } else { | |
533 if (ftello(f) != MOVIALIGN) { | |
534 mp_msg(MSGT_MUXER, MSGL_ERR, "Opendml superindex is too big for reserved space!\n"); | |
535 mp_msg(MSGT_MUXER, MSGL_ERR, "Expected filepos %d, real filepos %d, missing space %d\n", MOVIALIGN, ftell(muxer->file), ftell(muxer->file)-MOVIALIGN); | |
12037 | 536 mp_msg(MSGT_MUXER, MSGL_ERR, "Try increasing MOVIALIGN in libmpdemux/muxer_avi.c\n"); |
12036 | 537 } |
538 write_avi_list(f,listtypeAVIMOVIE,muxer->movi_end-ftello(f)-12); | |
539 } | |
540 muxer->movi_start=ftello(muxer->file); | |
12235
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
541 if (muxer->file_end == 0) muxer->file_end = ftello(muxer->file); |
12036 | 542 } |
543 | |
544 static void avifile_odml_write_index(muxer_t *muxer){ | |
545 muxer_stream_t* s; | |
546 struct avi_stream_info *si; | |
547 int i; | |
548 | |
549 for (i=0; i<muxer->avih.dwStreams; i++) { | |
550 int j,k,n,idxpos,len,last,entries_per_subidx; | |
551 unsigned int idxhdr[8]; | |
552 s = muxer->streams[i]; | |
553 si = s->priv; | |
554 | |
555 /* | |
556 * According to Avery Lee MSMP wants the subidx chunks to have the same size. | |
557 * | |
558 * So this code figures out how many entries we can put into | |
559 * an ix?? chunk, so that each ix?? chunk has the same size and the offsets | |
560 * don't overflow (Using ODML_CHUNKLEN for that is a bit more restrictive | |
561 * than it has to be though). | |
562 */ | |
563 | |
564 len = 0; | |
565 n = 0; | |
566 entries_per_subidx = INT_MAX; | |
567 do { | |
568 off_t start = si->idx[0].ofs; | |
569 last = entries_per_subidx; | |
570 for (j=0; j<si->idxpos; j++) { | |
571 len = si->idx[j].ofs - start; | |
572 if(len >= ODML_CHUNKLEN || n >= entries_per_subidx) { | |
573 if (entries_per_subidx > n) { | |
574 entries_per_subidx = n; | |
575 } | |
576 start = si->idx[j].ofs; | |
577 len = 0; | |
578 n = 0; | |
579 } | |
580 n++; | |
581 } | |
582 } while (last != entries_per_subidx); | |
583 | |
584 si->superidxpos = (si->idxpos+entries_per_subidx-1) / entries_per_subidx; | |
585 | |
586 mp_msg(MSGT_MUXER, MSGL_V, "ODML: Stream %d: Using %d entries per subidx, %d entries in superidx\n", | |
587 i, entries_per_subidx, si->superidxpos); | |
588 | |
589 si->superidxsize = si->superidxpos; | |
590 si->superidx = malloc(sizeof(*si->superidx) * si->superidxsize); | |
591 memset(si->superidx, 0, sizeof(*si->superidx) * si->superidxsize); | |
592 | |
593 idxpos = 0; | |
594 for (j=0; j<si->superidxpos; j++) { | |
595 off_t start = si->idx[idxpos].ofs; | |
596 int duration; | |
597 | |
598 duration = 0; | |
599 for (k=0; k<entries_per_subidx && idxpos+k<si->idxpos; k++) { | |
600 duration += s->h.dwSampleSize ? si->idx[idxpos+k].len/s->h.dwSampleSize : 1; | |
601 } | |
602 | |
603 idxhdr[0] = le2me_32((s->ckid << 16) | mmioFOURCC('i', 'x', 0, 0)); | |
604 idxhdr[1] = le2me_32(24 + 8*k); | |
605 idxhdr[2] = le2me_32(0x01000002); | |
606 idxhdr[3] = le2me_32(k); | |
607 idxhdr[4] = le2me_32(s->ckid); | |
608 idxhdr[5] = le2me_32(start + 8); | |
609 idxhdr[6] = le2me_32((start + 8)>> 32); | |
610 idxhdr[7] = 0; /* unused */ | |
611 | |
612 si->superidx[j].len = 32 + 8*k; | |
613 si->superidx[j].ofs = ftello(muxer->file); | |
614 si->superidx[j].duration = duration; | |
615 | |
616 fwrite(idxhdr,sizeof(idxhdr),1,muxer->file); | |
617 for (k=0; k<entries_per_subidx && idxpos<si->idxpos; k++) { | |
618 unsigned int entry[2]; | |
619 entry[0] = le2me_32(si->idx[idxpos].ofs - start); | |
620 entry[1] = le2me_32(si->idx[idxpos].len | si->idx[idxpos].flags); | |
621 idxpos++; | |
622 fwrite(entry,sizeof(entry),1,muxer->file); | |
623 } | |
624 } | |
625 } | |
626 muxer->file_end=ftello(muxer->file); | |
1 | 627 } |
628 | |
9007
12fc55eb3373
Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents:
8591
diff
changeset
|
629 static void avifile_write_index(muxer_t *muxer){ |
12036 | 630 |
631 if(muxer->file_end > ODML_CHUNKLEN && | |
632 muxer->idx && muxer->idx_pos>0) { | |
633 avifile_odml_write_index(muxer); | |
634 return; | |
635 } | |
636 | |
637 muxer->movi_end=ftello(muxer->file); | |
2529 | 638 if(muxer->idx && muxer->idx_pos>0){ |
6918 | 639 int i; |
2529 | 640 // fixup index entries: |
641 // for(i=0;i<muxer->idx_pos;i++) muxer->idx[i].dwChunkOffset-=muxer->movi_start-4; | |
642 // write index chunk: | |
6918 | 643 for (i=0; i<muxer->idx_pos; i++) le2me_AVIINDEXENTRY((&muxer->idx[i])); |
9007
12fc55eb3373
Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents:
8591
diff
changeset
|
644 write_avi_chunk(muxer->file,ckidAVINEWINDEX,16*muxer->idx_pos,muxer->idx); /* AVIINDEXENTRY */ |
6918 | 645 for (i=0; i<muxer->idx_pos; i++) le2me_AVIINDEXENTRY((&muxer->idx[i])); |
2529 | 646 muxer->avih.dwFlags|=AVIF_HASINDEX; |
647 } | |
12036 | 648 muxer->file_end=ftello(muxer->file); |
1 | 649 } |
650 | |
8585 | 651 void muxer_init_muxer_avi(muxer_t *muxer){ |
652 muxer->cont_new_stream = &avifile_new_stream; | |
653 muxer->cont_write_chunk = &avifile_write_chunk; | |
654 muxer->cont_write_header = &avifile_write_header; | |
655 muxer->cont_write_index = &avifile_write_index; | |
656 } |