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