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