Mercurial > mplayer.hg
annotate libmpdemux/muxer_avi.c @ 31796:a6abbb323d04
10l: Add the Subversion revision to the version string, not "VERSION".
author | diego |
---|---|
date | Sat, 31 Jul 2010 15:17:17 +0000 |
parents | 13ca93203358 |
children | a735105a66b6 |
rev | line source |
---|---|
29238
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
22605
diff
changeset
|
1 /* |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
22605
diff
changeset
|
2 * This file is part of MPlayer. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
22605
diff
changeset
|
3 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
22605
diff
changeset
|
4 * MPlayer is free software; you can redistribute it and/or modify |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
22605
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
22605
diff
changeset
|
6 * the Free Software Foundation; either version 2 of the License, or |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
22605
diff
changeset
|
7 * (at your option) any later version. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
22605
diff
changeset
|
8 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
22605
diff
changeset
|
9 * MPlayer is distributed in the hope that it will be useful, |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
22605
diff
changeset
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
22605
diff
changeset
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
22605
diff
changeset
|
12 * GNU General Public License for more details. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
22605
diff
changeset
|
13 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
22605
diff
changeset
|
14 * You should have received a copy of the GNU General Public License along |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
22605
diff
changeset
|
15 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
22605
diff
changeset
|
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
22605
diff
changeset
|
17 */ |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
22605
diff
changeset
|
18 |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
1
diff
changeset
|
19 #include <stdio.h> |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
1
diff
changeset
|
20 #include <stdlib.h> |
2529 | 21 #include <string.h> |
8585 | 22 #include <inttypes.h> |
8591 | 23 #include <unistd.h> |
12036 | 24 #include <limits.h> |
2529 | 25 |
2555
66837325b929
config.h cleanup, few things added to steram/demuxer headers
arpi
parents:
2529
diff
changeset
|
26 #include "config.h" |
31511
13ca93203358
Factorize MPlayer/MEncoder version string handling.
diego
parents:
31377
diff
changeset
|
27 #include "mpcommon.h" |
22605
4d81dbdf46b9
Add explicit location for headers from the stream/ directory.
diego
parents:
21840
diff
changeset
|
28 #include "stream/stream.h" |
12036 | 29 #include "demuxer.h" |
30 #include "stheader.h" | |
31377
1d38e2c9c005
Add header file for the extern declarations from muxer_avi.c.
diego
parents:
29263
diff
changeset
|
31 #include "muxer_avi.h" |
8585 | 32 #include "muxer.h" |
6918 | 33 #include "aviheader.h" |
12341
0db4a3a5b01d
removed loader/ dependancy, imported some files from g2, also used patches from Dominik Mierzejewski
alex
parents:
12235
diff
changeset
|
34 #include "ms_hdr.h" |
12036 | 35 #include "mp_msg.h" |
17065
cf6bfdf41143
Clean up some muxer messages, patch by Corey Hickey bugfood-ml AT -fatooh/org- , small fixes by me
reynaldo
parents:
17023
diff
changeset
|
36 #include "help_mp.h" |
1 | 37 |
7145
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
38 extern char *info_name; |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
39 extern char *info_artist; |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
40 extern char *info_genre; |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
41 extern char *info_subject; |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
42 extern char *info_copyright; |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
43 extern char *info_sourceform; |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
44 extern char *info_comment; |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
45 |
12036 | 46 /* #define ODML_CHUNKLEN 0x02000000 */ /* for testing purposes */ |
47 #define ODML_CHUNKLEN 0x40000000 | |
48 #define ODML_NOTKEYFRAME 0x80000000U | |
49 #define MOVIALIGN 0x00001000 | |
50 | |
12061 | 51 float avi_aspect_override = -1.0; |
12363 | 52 int write_odml = 1; |
12051 | 53 |
12036 | 54 struct avi_odmlidx_entry { |
55 uint64_t ofs; | |
56 uint32_t len; | |
57 uint32_t flags; | |
58 }; | |
59 | |
60 struct avi_odmlsuperidx_entry { | |
61 uint64_t ofs; | |
62 uint32_t len; | |
63 uint32_t duration; | |
64 }; | |
65 | |
66 struct avi_stream_info { | |
67 int idxsize; | |
68 int idxpos; | |
69 int superidxpos; | |
70 int superidxsize; | |
12235
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
71 int riffofspos; |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
72 int riffofssize; |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
73 off_t *riffofs; |
12036 | 74 struct avi_odmlidx_entry *idx; |
75 struct avi_odmlsuperidx_entry *superidx; | |
76 }; | |
77 | |
12061 | 78 static unsigned int avi_aspect(muxer_stream_t *vstream) |
79 { | |
80 int x,y; | |
81 float aspect = vstream->aspect; | |
82 | |
83 if (avi_aspect_override > 0.0) { | |
84 aspect = avi_aspect_override; | |
85 } | |
86 | |
87 if (aspect <= 0.0) return 0; | |
88 | |
89 if (aspect > 15.99/9.0 && aspect < 16.01/9.0) { | |
90 return MAKE_AVI_ASPECT(16, 9); | |
91 } | |
92 if (aspect > 3.99/3.0 && aspect < 4.01/3.0) { | |
93 return MAKE_AVI_ASPECT(4, 3); | |
94 } | |
95 | |
96 if (aspect >= 1.0) { | |
97 x = 16384; | |
98 y = (float)x / aspect; | |
99 } else { | |
100 y = 16384; | |
101 x = (float)y * aspect; | |
102 } | |
103 | |
104 return MAKE_AVI_ASPECT(x, y); | |
105 } | |
106 | |
8585 | 107 static muxer_stream_t* avifile_new_stream(muxer_t *muxer,int type){ |
12036 | 108 struct avi_stream_info *si; |
8585 | 109 muxer_stream_t* s; |
9007
12fc55eb3373
Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents:
8591
diff
changeset
|
110 if (!muxer) return NULL; |
8585 | 111 if(muxer->avih.dwStreams>=MUXER_MAX_STREAMS){ |
12036 | 112 mp_msg(MSGT_MUXER, MSGL_ERR, "Too many streams! increase MUXER_MAX_STREAMS !\n"); |
2529 | 113 return NULL; |
114 } | |
8585 | 115 s=malloc(sizeof(muxer_stream_t)); |
116 memset(s,0,sizeof(muxer_stream_t)); | |
2529 | 117 if(!s) return NULL; // no mem!? |
118 muxer->streams[muxer->avih.dwStreams]=s; | |
119 s->type=type; | |
120 s->id=muxer->avih.dwStreams; | |
121 s->timer=0.0; | |
2652 | 122 s->size=0; |
9007
12fc55eb3373
Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents:
8591
diff
changeset
|
123 s->muxer=muxer; |
12036 | 124 s->priv=si=malloc(sizeof(struct avi_stream_info)); |
125 memset(si,0,sizeof(struct avi_stream_info)); | |
126 si->idxsize=256; | |
18558
4928dd61f136
Fix potential integer overflows in memory allocation.
rtogni
parents:
17659
diff
changeset
|
127 si->idx=calloc(si->idxsize, sizeof(struct avi_odmlidx_entry)); |
12235
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
128 si->riffofssize=16; |
18558
4928dd61f136
Fix potential integer overflows in memory allocation.
rtogni
parents:
17659
diff
changeset
|
129 si->riffofs=calloc((si->riffofssize+1), sizeof(off_t)); |
12235
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
130 memset(si->riffofs, 0, sizeof(off_t)*si->riffofssize); |
12036 | 131 |
2529 | 132 switch(type){ |
8585 | 133 case MUXER_TYPE_VIDEO: |
2529 | 134 s->ckid=mmioFOURCC(('0'+s->id/10),('0'+(s->id%10)),'d','c'); |
135 s->h.fccType=streamtypeVIDEO; | |
136 if(!muxer->def_v) muxer->def_v=s; | |
137 break; | |
8585 | 138 case MUXER_TYPE_AUDIO: |
2529 | 139 s->ckid=mmioFOURCC(('0'+s->id/10),('0'+(s->id%10)),'w','b'); |
140 s->h.fccType=streamtypeAUDIO; | |
141 break; | |
142 default: | |
12036 | 143 mp_msg(MSGT_MUXER, MSGL_WARN, "Warning! unknown stream type: %d\n",type); |
2529 | 144 return NULL; |
145 } | |
146 muxer->avih.dwStreams++; | |
147 return s; | |
148 } | |
1 | 149 |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
150 static void write_avi_chunk(stream_t *stream,unsigned int id,int len,void* data){ |
6918 | 151 int le_len = le2me_32(len); |
152 int le_id = le2me_32(id); | |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
153 stream_write_buffer(stream, &le_id, 4); |
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
154 stream_write_buffer(stream, &le_len, 4); |
6918 | 155 |
1 | 156 if(len>0){ |
157 if(data){ | |
158 // DATA | |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
159 stream_write_buffer(stream, data, len); |
1 | 160 if(len&1){ // padding |
161 unsigned char zerobyte=0; | |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
162 stream_write_buffer(stream, &zerobyte, 1); |
1 | 163 } |
164 } else { | |
165 // JUNK | |
166 char *avi_junk_data="[= MPlayer junk data! =]"; | |
167 if(len&1) ++len; // padding | |
168 while(len>0){ | |
169 int l=strlen(avi_junk_data); | |
170 if(l>len) l=len; | |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
171 stream_write_buffer(stream, avi_junk_data, l); |
1 | 172 len-=l; |
173 } | |
174 } | |
175 } | |
2529 | 176 } |
177 | |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
178 static void write_avi_list(stream_t *s,unsigned int id,int len); |
12363 | 179 static void avifile_write_standard_index(muxer_t *muxer); |
12036 | 180 |
181 static void avifile_odml_new_riff(muxer_t *muxer) | |
182 { | |
12235
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
183 struct avi_stream_info *vsi = muxer->def_v->priv; |
12036 | 184 uint32_t riff[3]; |
185 | |
12497
da17b2c262de
no kabbe-bytes or men in black or any of that nonsense here...
rfelker
parents:
12363
diff
changeset
|
186 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
|
187 |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
188 vsi->riffofspos++; |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
189 if (vsi->riffofspos>=vsi->riffofssize) { |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
190 vsi->riffofssize+=16; |
18558
4928dd61f136
Fix potential integer overflows in memory allocation.
rtogni
parents:
17659
diff
changeset
|
191 vsi->riffofs=realloc_struct(vsi->riffofs,(vsi->riffofssize+1),sizeof(off_t)); |
12235
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
192 } |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
193 vsi->riffofs[vsi->riffofspos] = stream_tell(muxer->stream); |
12036 | 194 |
195 /* RIFF/AVIX chunk */ | |
196 riff[0]=le2me_32(mmioFOURCC('R','I','F','F')); | |
197 riff[1]=0; | |
198 riff[2]=le2me_32(mmioFOURCC('A','V','I','X')); | |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
199 stream_write_buffer(muxer->stream, riff, 12); |
12036 | 200 |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
201 write_avi_list(muxer->stream,listtypeAVIMOVIE,0); |
12235
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
202 |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
203 muxer->file_end = stream_tell(muxer->stream); |
12036 | 204 } |
205 | |
13250 | 206 static void avifile_write_header(muxer_t *muxer); |
207 | |
17487
fa17424b4c7b
change muxer_write_chunk() so that pts/dts _could_ be passed from encoder to muxer
michael
parents:
17366
diff
changeset
|
208 static void avifile_write_chunk(muxer_stream_t *s,size_t len,unsigned int flags, double dts, double pts){ |
12235
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
209 off_t rifflen; |
9007
12fc55eb3373
Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents:
8591
diff
changeset
|
210 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
|
211 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
|
212 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
|
213 int paddedlen = len + (len&1); |
2529 | 214 |
13249
a6642a4330fa
ensure that avi files have a valid header as soon as possible.
rfelker
parents:
12497
diff
changeset
|
215 if (s->type == MUXER_TYPE_VIDEO && !s->h.dwSuggestedBufferSize) { |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
216 off_t pos=stream_tell(muxer->stream); |
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
217 stream_seek(muxer->stream, 0); |
13249
a6642a4330fa
ensure that avi files have a valid header as soon as possible.
rfelker
parents:
12497
diff
changeset
|
218 avifile_write_header(muxer); |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
219 stream_seek(muxer->stream, pos); |
13249
a6642a4330fa
ensure that avi files have a valid header as soon as possible.
rfelker
parents:
12497
diff
changeset
|
220 } |
21840
06b71b6fdde7
dont write an index and dont use memory to build one if -noidx is specified
michael
parents:
21660
diff
changeset
|
221 if(index_mode){ |
12235
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
222 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
|
223 if (vsi->riffofspos == 0) { |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
224 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
|
225 } |
12363 | 226 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
|
227 if (vsi->riffofspos == 0) { |
12363 | 228 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
|
229 } |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
230 avifile_odml_new_riff(muxer); |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
231 } |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
232 |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
233 if (vsi->riffofspos == 0) { |
12036 | 234 // add to the traditional index: |
235 if(muxer->idx_pos>=muxer->idx_size){ | |
236 muxer->idx_size+=256; // 4kB | |
18558
4928dd61f136
Fix potential integer overflows in memory allocation.
rtogni
parents:
17659
diff
changeset
|
237 muxer->idx=realloc_struct(muxer->idx,muxer->idx_size,16); |
12036 | 238 } |
239 muxer->idx[muxer->idx_pos].ckid=s->ckid; | |
240 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
|
241 muxer->idx[muxer->idx_pos].dwChunkOffset=muxer->file_end-(muxer->movi_start-4); |
12036 | 242 muxer->idx[muxer->idx_pos].dwChunkLength=len; |
243 ++muxer->idx_pos; | |
244 } | |
245 | |
246 // add to odml index | |
247 if(si->idxpos>=si->idxsize){ | |
248 si->idxsize+=256; | |
18558
4928dd61f136
Fix potential integer overflows in memory allocation.
rtogni
parents:
17659
diff
changeset
|
249 si->idx=realloc_struct(si->idx,si->idxsize,sizeof(*si->idx)); |
2529 | 250 } |
12036 | 251 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
|
252 si->idx[si->idxpos].ofs=muxer->file_end; |
12036 | 253 si->idx[si->idxpos].len=len; |
254 ++si->idxpos; | |
21840
06b71b6fdde7
dont write an index and dont use memory to build one if -noidx is specified
michael
parents:
21660
diff
changeset
|
255 } |
2529 | 256 // write out the chunk: |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
257 write_avi_chunk(muxer->stream,s->ckid,len,s->buffer); /* unsigned char */ |
6918 | 258 |
12036 | 259 if (len > s->h.dwSuggestedBufferSize){ |
260 s->h.dwSuggestedBufferSize = len; | |
261 } | |
8585 | 262 if((unsigned int)len>s->h.dwSuggestedBufferSize) s->h.dwSuggestedBufferSize=len; |
1 | 263 |
12235
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
264 muxer->file_end += 8 + paddedlen; |
1 | 265 } |
266 | |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
267 static void write_avi_list(stream_t *stream,unsigned int id,int len){ |
1 | 268 unsigned int list_id=FOURCC_LIST; |
6918 | 269 int le_len; |
270 int le_id; | |
1 | 271 len+=4; // list fix |
6918 | 272 list_id = le2me_32(list_id); |
273 le_len = le2me_32(len); | |
274 le_id = le2me_32(id); | |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
275 stream_write_buffer(stream, &list_id, 4); |
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
276 stream_write_buffer(stream, &le_len, 4); |
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
277 stream_write_buffer(stream, &le_id, 4); |
1 | 278 } |
279 | |
11374 | 280 #define WFSIZE(wf) (sizeof(WAVEFORMATEX)+(wf)->cbSize) |
2635
c1e24e01601b
fixed AVI header creation - now should be compatible with NaNdub
arpi
parents:
2555
diff
changeset
|
281 |
9007
12fc55eb3373
Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents:
8591
diff
changeset
|
282 static void avifile_write_header(muxer_t *muxer){ |
8585 | 283 uint32_t riff[3]; |
12036 | 284 unsigned int dmlh[1]; |
8585 | 285 unsigned int i; |
2529 | 286 unsigned int hdrsize; |
8585 | 287 muxer_info_t info[16]; |
12036 | 288 VideoPropHeader vprp; |
12061 | 289 uint32_t aspect = avi_aspect(muxer->def_v); |
12235
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
290 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
|
291 int isodml = vsi->riffofspos > 0; |
12036 | 292 |
17065
cf6bfdf41143
Clean up some muxer messages, patch by Corey Hickey bugfood-ml AT -fatooh/org- , small fixes by me
reynaldo
parents:
17023
diff
changeset
|
293 mp_msg(MSGT_MUXER, MSGL_INFO, MSGTR_WritingHeader); |
12061 | 294 if (aspect == 0) { |
295 mp_msg(MSGT_MUXER, MSGL_INFO, "ODML: Aspect information not (yet?) available or unspecified, not writing vprp header.\n"); | |
296 } else { | |
297 mp_msg(MSGT_MUXER, MSGL_INFO, "ODML: vprp aspect is %d:%d.\n", aspect >> 16, aspect & 0xffff); | |
298 } | |
299 | |
17648 | 300 /* deal with stream delays */ |
301 for (i = 0; muxer->streams[i] && i < MUXER_MAX_STREAMS; ++i) { | |
302 muxer_stream_t *s = muxer->streams[i]; | |
303 if (s->type == MUXER_TYPE_AUDIO && muxer->audio_delay_fix > 0.0) { | |
19926 | 304 s->h.dwStart = muxer->audio_delay_fix * s->h.dwRate/s->h.dwScale + 0.5; |
17648 | 305 mp_msg(MSGT_MUXER, MSGL_INFO, MSGTR_SettingAudioDelay, (float)s->h.dwStart * s->h.dwScale/s->h.dwRate); |
306 } | |
307 if (s->type == MUXER_TYPE_VIDEO && muxer->audio_delay_fix < 0.0) { | |
19926 | 308 s->h.dwStart = -muxer->audio_delay_fix * s->h.dwRate/s->h.dwScale + 0.5; |
17648 | 309 mp_msg(MSGT_MUXER, MSGL_INFO, MSGTR_SettingVideoDelay, (float)s->h.dwStart * s->h.dwScale/s->h.dwRate); |
310 } | |
311 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
312 |
12036 | 313 if (isodml) { |
314 unsigned int rifflen, movilen; | |
12235
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
315 int i; |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
316 |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
317 vsi->riffofs[vsi->riffofspos+1] = muxer->file_end; |
12036 | 318 |
12235
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
319 /* fixup RIFF lengths */ |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
320 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
|
321 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
|
322 movilen = le2me_32(rifflen - 12); |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
323 rifflen = le2me_32(rifflen); |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
324 stream_seek(muxer->stream, vsi->riffofs[i]+4); |
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
325 stream_write_buffer(muxer->stream,&rifflen,4); |
12235
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
326 |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
327 /* fixup movi length */ |
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
328 if (i > 0) { |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
329 stream_seek(muxer->stream, vsi->riffofs[i]+16); |
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
330 stream_write_buffer(muxer->stream,&movilen,4); |
12235
ca5dc9c2cb51
Get rid of the 'RIFF chunks have to be aligned on ODML_CHUNKLEN'
ranma
parents:
12062
diff
changeset
|
331 } |
12036 | 332 } |
7145
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
333 |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
334 stream_seek(muxer->stream, 12); |
12036 | 335 } else { |
336 // RIFF header: | |
337 riff[0]=mmioFOURCC('R','I','F','F'); | |
338 riff[1]=muxer->file_end-2*sizeof(unsigned int); // filesize | |
339 riff[2]=formtypeAVI; // 'AVI ' | |
340 riff[0]=le2me_32(riff[0]); | |
341 riff[1]=le2me_32(riff[1]); | |
342 riff[2]=le2me_32(riff[2]); | |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
343 stream_write_buffer(muxer->stream,&riff,12); |
12036 | 344 } |
345 | |
2529 | 346 // update AVI header: |
347 if(muxer->def_v){ | |
12036 | 348 int i; |
2529 | 349 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
|
350 // muxer->avih.dwMaxBytesPerSec=1000000; // dummy!!!!! FIXME |
c1e24e01601b
fixed AVI header creation - now should be compatible with NaNdub
arpi
parents:
2555
diff
changeset
|
351 // muxer->avih.dwPaddingGranularity=2; // ??? |
2529 | 352 muxer->avih.dwFlags|=AVIF_ISINTERLEAVED|AVIF_TRUSTCKTYPE; |
12036 | 353 muxer->avih.dwTotalFrames=0; |
354 for (i=0; i<muxer->idx_pos; i++) { | |
355 if (muxer->idx[i].ckid == muxer->def_v->ckid) | |
356 muxer->avih.dwTotalFrames++; | |
357 } | |
2635
c1e24e01601b
fixed AVI header creation - now should be compatible with NaNdub
arpi
parents:
2555
diff
changeset
|
358 // muxer->avih.dwSuggestedBufferSize=muxer->def_v->h.dwSuggestedBufferSize; |
2529 | 359 muxer->avih.dwWidth=muxer->def_v->bih->biWidth; |
360 muxer->avih.dwHeight=muxer->def_v->bih->biHeight; | |
361 } | |
362 | |
1 | 363 // AVI header: |
2529 | 364 hdrsize=sizeof(muxer->avih)+8; |
12036 | 365 if (isodml) hdrsize+=sizeof(dmlh)+20; // dmlh |
2529 | 366 // calc total header size: |
367 for(i=0;i<muxer->avih.dwStreams;i++){ | |
12036 | 368 muxer_stream_t *s = muxer->streams[i]; |
369 struct avi_stream_info *si = s->priv; | |
370 | |
2529 | 371 hdrsize+=12; // LIST |
372 hdrsize+=sizeof(muxer->streams[i]->h)+8; // strh | |
373 switch(muxer->streams[i]->type){ | |
8585 | 374 case MUXER_TYPE_VIDEO: |
2529 | 375 hdrsize+=muxer->streams[i]->bih->biSize+8; // strf |
12061 | 376 if (aspect != 0) { |
12051 | 377 hdrsize+=8+4*(9+8*1); // vprp |
378 } | |
2529 | 379 break; |
8585 | 380 case MUXER_TYPE_AUDIO: |
2635
c1e24e01601b
fixed AVI header creation - now should be compatible with NaNdub
arpi
parents:
2555
diff
changeset
|
381 hdrsize+=WFSIZE(muxer->streams[i]->wf)+8; // strf |
2529 | 382 break; |
383 } | |
12036 | 384 if (isodml && si && si->superidx && si->superidxsize) { |
385 hdrsize += 32 + 16*si->superidxsize; //indx | |
386 } | |
2529 | 387 } |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
388 write_avi_list(muxer->stream,listtypeAVIHEADER,hdrsize); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
389 |
6918 | 390 le2me_MainAVIHeader(&muxer->avih); |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
391 write_avi_chunk(muxer->stream,ckidAVIMAINHDR,sizeof(muxer->avih),&muxer->avih); /* MainAVIHeader */ |
6918 | 392 le2me_MainAVIHeader(&muxer->avih); |
2529 | 393 |
394 // stream headers: | |
395 for(i=0;i<muxer->avih.dwStreams;i++){ | |
12036 | 396 muxer_stream_t *s = muxer->streams[i]; |
397 struct avi_stream_info *si = s->priv; | |
398 unsigned int idxhdr[8]; | |
399 int j,n; | |
400 | |
401 hdrsize=sizeof(s->h)+8; // strh | |
402 if (si && si->superidx && si->superidxsize) { | |
403 hdrsize += 32 + 16*si->superidxsize; //indx | |
404 } | |
405 switch(s->type){ | |
8585 | 406 case MUXER_TYPE_VIDEO: |
12036 | 407 hdrsize+=s->bih->biSize+8; // strf |
408 s->h.fccHandler = s->bih->biCompression; | |
409 s->h.rcFrame.right = s->bih->biWidth; | |
410 s->h.rcFrame.bottom = s->bih->biHeight; | |
12061 | 411 if (aspect != 0) { |
12051 | 412 // fill out vprp info |
413 memset(&vprp, 0, sizeof(vprp)); | |
414 vprp.dwVerticalRefreshRate = (s->h.dwRate+s->h.dwScale-1)/s->h.dwScale; | |
415 vprp.dwHTotalInT = muxer->avih.dwWidth; | |
416 vprp.dwVTotalInLines = muxer->avih.dwHeight; | |
12061 | 417 vprp.dwFrameAspectRatio = aspect; |
12051 | 418 vprp.dwFrameWidthInPixels = muxer->avih.dwWidth; |
419 vprp.dwFrameHeightInLines = muxer->avih.dwHeight; | |
420 vprp.nbFieldPerFrame = 1; | |
421 vprp.FieldInfo[0].CompressedBMHeight = muxer->avih.dwHeight; | |
422 vprp.FieldInfo[0].CompressedBMWidth = muxer->avih.dwWidth; | |
423 vprp.FieldInfo[0].ValidBMHeight = muxer->avih.dwHeight; | |
424 vprp.FieldInfo[0].ValidBMWidth = muxer->avih.dwWidth; | |
425 hdrsize+=8+4*(9+8*1); // vprp | |
426 } | |
2529 | 427 break; |
8585 | 428 case MUXER_TYPE_AUDIO: |
12036 | 429 hdrsize+=WFSIZE(s->wf)+8; // strf |
430 s->h.fccHandler = s->wf->wFormatTag; | |
2529 | 431 break; |
432 } | |
12036 | 433 |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
434 write_avi_list(muxer->stream,listtypeSTREAMHEADER,hdrsize); |
12036 | 435 le2me_AVIStreamHeader(&s->h); |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
436 write_avi_chunk(muxer->stream,ckidSTREAMHEADER,sizeof(s->h),&s->h); /* AVISTreamHeader */ // strh |
12036 | 437 le2me_AVIStreamHeader(&s->h); |
6918 | 438 |
12036 | 439 switch(s->type){ |
8585 | 440 case MUXER_TYPE_VIDEO: |
6918 | 441 { |
12036 | 442 int biSize=s->bih->biSize; |
443 le2me_BITMAPINFOHEADER(s->bih); | |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
444 write_avi_chunk(muxer->stream,ckidSTREAMFORMAT,biSize,s->bih); /* BITMAPINFOHEADER */ |
12053 | 445 le2me_BITMAPINFOHEADER(s->bih); |
446 | |
12061 | 447 if (aspect != 0) { |
12053 | 448 int fields = vprp.nbFieldPerFrame; |
12051 | 449 le2me_VideoPropHeader(&vprp); |
450 le2me_VIDEO_FIELD_DESC(&vprp.FieldInfo[0]); | |
451 le2me_VIDEO_FIELD_DESC(&vprp.FieldInfo[1]); | |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
452 write_avi_chunk(muxer->stream,mmioFOURCC('v','p','r','p'), |
12053 | 453 sizeof(VideoPropHeader) - |
454 sizeof(VIDEO_FIELD_DESC)*(2-fields), | |
455 &vprp); /* Video Properties Header */ | |
12051 | 456 } |
6918 | 457 } |
2529 | 458 break; |
8585 | 459 case MUXER_TYPE_AUDIO: |
6918 | 460 { |
12036 | 461 int wfsize = WFSIZE(s->wf); |
462 le2me_WAVEFORMATEX(s->wf); | |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
463 write_avi_chunk(muxer->stream,ckidSTREAMFORMAT,wfsize,s->wf); /* WAVEFORMATEX */ |
12036 | 464 le2me_WAVEFORMATEX(s->wf); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
465 } |
2529 | 466 break; |
467 } | |
12036 | 468 if (isodml && si && si->superidx && si->superidxsize) { |
469 n = si->superidxsize; | |
470 | |
471 idxhdr[0] = le2me_32(mmioFOURCC('i', 'n', 'd', 'x')); | |
472 idxhdr[1] = le2me_32(24 + 16*n); | |
473 idxhdr[2] = le2me_32(0x00000004); | |
474 idxhdr[3] = le2me_32(si->superidxpos); | |
475 idxhdr[4] = le2me_32(s->ckid); | |
476 idxhdr[5] = 0; | |
477 idxhdr[6] = 0; | |
478 idxhdr[7] = 0; | |
479 | |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
480 stream_write_buffer(muxer->stream,idxhdr,sizeof(idxhdr)); |
12036 | 481 for (j=0; j<n; j++) { |
482 struct avi_odmlsuperidx_entry *entry = &si->superidx[j]; | |
483 unsigned int data[4]; | |
484 data[0] = le2me_32(entry->ofs); | |
485 data[1] = le2me_32(entry->ofs >> 32); | |
486 data[2] = le2me_32(entry->len); | |
487 data[3] = le2me_32(entry->duration); | |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
488 stream_write_buffer(muxer->stream,data,sizeof(data)); |
12036 | 489 } |
490 } | |
491 } | |
492 | |
493 // ODML | |
494 if (isodml) { | |
495 memset(dmlh, 0, sizeof(dmlh)); | |
496 dmlh[0] = le2me_32(muxer->avih.dwTotalFrames); | |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
497 write_avi_list(muxer->stream,mmioFOURCC('o','d','m','l'),sizeof(dmlh)+8); |
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
498 write_avi_chunk(muxer->stream,mmioFOURCC('d','m','l','h'),sizeof(dmlh),dmlh); |
2529 | 499 } |
500 | |
7145
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
501 // ============= INFO =============== |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
502 // always include software info |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
503 info[0].id=mmioFOURCC('I','S','F','T'); // Software: |
31511
13ca93203358
Factorize MPlayer/MEncoder version string handling.
diego
parents:
31377
diff
changeset
|
504 info[0].text=mencoder_version; |
7145
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
505 // include any optional strings |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
506 i=1; |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
507 if(info_name!=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','N','A','M'); // Name: |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
509 info[i++].text=info_name; |
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 if(info_artist!=NULL){ |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
512 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
|
513 info[i++].text=info_artist; |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
514 } |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
515 if(info_genre!=NULL){ |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
516 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
|
517 info[i++].text=info_genre; |
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 if(info_subject!=NULL){ |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
520 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
|
521 info[i++].text=info_subject; |
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 if(info_copyright!=NULL){ |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
524 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
|
525 info[i++].text=info_copyright; |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
526 } |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
527 if(info_sourceform!=NULL){ |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
528 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
|
529 info[i++].text=info_sourceform; |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
530 } |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
531 if(info_comment!=NULL){ |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
532 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
|
533 info[i++].text=info_comment; |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
534 } |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
535 info[i].id=0; |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
536 |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
537 hdrsize=0; |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
538 // calc info size: |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
539 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
|
540 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
|
541 hdrsize+=sz+8+sz%2; |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
542 } |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
543 // write infos: |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
544 if (hdrsize!=0){ |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
545 write_avi_list(muxer->stream,mmioFOURCC('I','N','F','O'),hdrsize); |
7145
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
546 for(i=0;info[i].id!=0;i++) if(info[i].text){ |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
547 write_avi_chunk(muxer->stream,info[i].id,strlen(info[i].text)+1,info[i].text); |
7145
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
548 } |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
549 } |
3854945aefbb
new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents:
7144
diff
changeset
|
550 |
2529 | 551 // JUNK: |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
552 write_avi_chunk(muxer->stream,ckidAVIPADDING,MOVIALIGN-(stream_tell(muxer->stream)%MOVIALIGN)-8,NULL); /* junk */ |
12036 | 553 if (!isodml) { |
554 // 'movi' header: | |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
555 write_avi_list(muxer->stream,listtypeAVIMOVIE,muxer->movi_end-stream_tell(muxer->stream)-12); |
12036 | 556 } else { |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
557 if (stream_tell(muxer->stream) != MOVIALIGN) { |
12036 | 558 mp_msg(MSGT_MUXER, MSGL_ERR, "Opendml superindex is too big for reserved space!\n"); |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
559 mp_msg(MSGT_MUXER, MSGL_ERR, "Expected filepos %d, real filepos %ld, missing space %ld\n", MOVIALIGN, stream_tell(muxer->stream), stream_tell(muxer->stream)-MOVIALIGN); |
12037 | 560 mp_msg(MSGT_MUXER, MSGL_ERR, "Try increasing MOVIALIGN in libmpdemux/muxer_avi.c\n"); |
12036 | 561 } |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
562 write_avi_list(muxer->stream,listtypeAVIMOVIE,muxer->movi_end-stream_tell(muxer->stream)-12); |
12036 | 563 } |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
564 muxer->movi_start=stream_tell(muxer->stream); |
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
565 if (muxer->file_end == 0) muxer->file_end = stream_tell(muxer->stream); |
12036 | 566 } |
567 | |
568 static void avifile_odml_write_index(muxer_t *muxer){ | |
569 muxer_stream_t* s; | |
570 struct avi_stream_info *si; | |
571 int i; | |
572 | |
573 for (i=0; i<muxer->avih.dwStreams; i++) { | |
574 int j,k,n,idxpos,len,last,entries_per_subidx; | |
575 unsigned int idxhdr[8]; | |
576 s = muxer->streams[i]; | |
577 si = s->priv; | |
578 | |
579 /* | |
580 * According to Avery Lee MSMP wants the subidx chunks to have the same size. | |
581 * | |
582 * So this code figures out how many entries we can put into | |
583 * an ix?? chunk, so that each ix?? chunk has the same size and the offsets | |
584 * don't overflow (Using ODML_CHUNKLEN for that is a bit more restrictive | |
585 * than it has to be though). | |
586 */ | |
587 | |
588 len = 0; | |
589 n = 0; | |
590 entries_per_subidx = INT_MAX; | |
591 do { | |
592 off_t start = si->idx[0].ofs; | |
593 last = entries_per_subidx; | |
594 for (j=0; j<si->idxpos; j++) { | |
595 len = si->idx[j].ofs - start; | |
596 if(len >= ODML_CHUNKLEN || n >= entries_per_subidx) { | |
597 if (entries_per_subidx > n) { | |
598 entries_per_subidx = n; | |
599 } | |
600 start = si->idx[j].ofs; | |
601 len = 0; | |
602 n = 0; | |
603 } | |
604 n++; | |
605 } | |
606 } while (last != entries_per_subidx); | |
607 | |
608 si->superidxpos = (si->idxpos+entries_per_subidx-1) / entries_per_subidx; | |
609 | |
610 mp_msg(MSGT_MUXER, MSGL_V, "ODML: Stream %d: Using %d entries per subidx, %d entries in superidx\n", | |
611 i, entries_per_subidx, si->superidxpos); | |
612 | |
613 si->superidxsize = si->superidxpos; | |
18558
4928dd61f136
Fix potential integer overflows in memory allocation.
rtogni
parents:
17659
diff
changeset
|
614 si->superidx = calloc(si->superidxsize, sizeof(*si->superidx)); |
12036 | 615 memset(si->superidx, 0, sizeof(*si->superidx) * si->superidxsize); |
616 | |
617 idxpos = 0; | |
618 for (j=0; j<si->superidxpos; j++) { | |
619 off_t start = si->idx[idxpos].ofs; | |
620 int duration; | |
621 | |
622 duration = 0; | |
623 for (k=0; k<entries_per_subidx && idxpos+k<si->idxpos; k++) { | |
624 duration += s->h.dwSampleSize ? si->idx[idxpos+k].len/s->h.dwSampleSize : 1; | |
625 } | |
626 | |
627 idxhdr[0] = le2me_32((s->ckid << 16) | mmioFOURCC('i', 'x', 0, 0)); | |
628 idxhdr[1] = le2me_32(24 + 8*k); | |
629 idxhdr[2] = le2me_32(0x01000002); | |
630 idxhdr[3] = le2me_32(k); | |
631 idxhdr[4] = le2me_32(s->ckid); | |
632 idxhdr[5] = le2me_32(start + 8); | |
633 idxhdr[6] = le2me_32((start + 8)>> 32); | |
634 idxhdr[7] = 0; /* unused */ | |
635 | |
636 si->superidx[j].len = 32 + 8*k; | |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
637 si->superidx[j].ofs = stream_tell(muxer->stream); |
12036 | 638 si->superidx[j].duration = duration; |
639 | |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
640 stream_write_buffer(muxer->stream, idxhdr,sizeof(idxhdr)); |
12036 | 641 for (k=0; k<entries_per_subidx && idxpos<si->idxpos; k++) { |
642 unsigned int entry[2]; | |
643 entry[0] = le2me_32(si->idx[idxpos].ofs - start); | |
644 entry[1] = le2me_32(si->idx[idxpos].len | si->idx[idxpos].flags); | |
645 idxpos++; | |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
646 stream_write_buffer(muxer->stream, entry, sizeof(entry)); |
12036 | 647 } |
648 } | |
649 } | |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
650 muxer->file_end=stream_tell(muxer->stream); |
1 | 651 } |
652 | |
12363 | 653 static void avifile_write_standard_index(muxer_t *muxer){ |
12036 | 654 |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
655 muxer->movi_end=stream_tell(muxer->stream); |
2529 | 656 if(muxer->idx && muxer->idx_pos>0){ |
6918 | 657 int i; |
2529 | 658 // fixup index entries: |
659 // for(i=0;i<muxer->idx_pos;i++) muxer->idx[i].dwChunkOffset-=muxer->movi_start-4; | |
660 // write index chunk: | |
6918 | 661 for (i=0; i<muxer->idx_pos; i++) le2me_AVIINDEXENTRY((&muxer->idx[i])); |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
662 write_avi_chunk(muxer->stream,ckidAVINEWINDEX,16*muxer->idx_pos,muxer->idx); /* AVIINDEXENTRY */ |
6918 | 663 for (i=0; i<muxer->idx_pos; i++) le2me_AVIINDEXENTRY((&muxer->idx[i])); |
2529 | 664 muxer->avih.dwFlags|=AVIF_HASINDEX; |
665 } | |
21660
ca9da45d13e9
muxers now write to output muxer->stream rather than to muxer->file
nicodvb
parents:
21421
diff
changeset
|
666 muxer->file_end=stream_tell(muxer->stream); |
1 | 667 } |
668 | |
12363 | 669 static void avifile_write_index(muxer_t *muxer){ |
670 struct avi_stream_info *vsi = muxer->def_v->priv; | |
671 | |
17065
cf6bfdf41143
Clean up some muxer messages, patch by Corey Hickey bugfood-ml AT -fatooh/org- , small fixes by me
reynaldo
parents:
17023
diff
changeset
|
672 mp_msg(MSGT_MUXER, MSGL_INFO, MSGTR_WritingTrailer); |
12363 | 673 if (vsi->riffofspos > 0){ |
674 avifile_odml_write_index(muxer); | |
675 } else { | |
676 avifile_write_standard_index(muxer); | |
677 } | |
678 } | |
679 | |
17659 | 680 static void avifile_fix_parameters(muxer_stream_t *s){ |
681 /* adjust audio_delay_fix according to individual stream delay */ | |
682 if (s->type == MUXER_TYPE_AUDIO) | |
683 s->muxer->audio_delay_fix -= (float)s->decoder_delay * s->h.dwScale/s->h.dwRate; | |
684 if (s->type == MUXER_TYPE_VIDEO) | |
685 s->muxer->audio_delay_fix += (float)s->decoder_delay * s->h.dwScale/s->h.dwRate; | |
686 } | |
687 | |
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
|
688 int muxer_init_muxer_avi(muxer_t *muxer){ |
8585 | 689 muxer->cont_new_stream = &avifile_new_stream; |
690 muxer->cont_write_chunk = &avifile_write_chunk; | |
691 muxer->cont_write_header = &avifile_write_header; | |
692 muxer->cont_write_index = &avifile_write_index; | |
17659 | 693 muxer->fix_stream_parameters = &avifile_fix_parameters; |
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
|
694 return 1; |
8585 | 695 } |