annotate libmpdemux/muxer_avi.c @ 11977:efb37725d616

flushing stuff after seeking (finally we can view MPEG without thouse blocks after seeking with -vc ffmpeg12)
author michael
date Wed, 18 Feb 2004 15:23:41 +0000
parents 9d5fdc9847ec
children 846ed866f86c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
587
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 1
diff changeset
1
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 1
diff changeset
2 #include <stdio.h>
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 1
diff changeset
3 #include <stdlib.h>
2529
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
4 #include <string.h>
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents: 8074
diff changeset
5 #include <inttypes.h>
8591
35bfd508bf5f FreeBSD fix
nexus
parents: 8585
diff changeset
6 #include <unistd.h>
2529
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
7
2555
66837325b929 config.h cleanup, few things added to steram/demuxer headers
arpi
parents: 2529
diff changeset
8 #include "config.h"
7149
aa9debe16559 10l bug, found by Nexus
arpi
parents: 7145
diff changeset
9 #include "../version.h"
2555
66837325b929 config.h cleanup, few things added to steram/demuxer headers
arpi
parents: 2529
diff changeset
10
2529
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
11 //#include "stream.h"
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
12 //#include "demuxer.h"
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
13 //#include "stheader.h"
587
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 1
diff changeset
14
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 1
diff changeset
15 #include "wine/mmreg.h"
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 1
diff changeset
16 #include "wine/avifmt.h"
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 1
diff changeset
17 #include "wine/vfw.h"
6918
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
18 #include "bswap.h"
587
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 1
diff changeset
19
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents: 8074
diff changeset
20 #include "muxer.h"
6918
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
21 #include "aviheader.h"
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
22
7145
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
23 extern char *info_name;
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
24 extern char *info_artist;
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
25 extern char *info_genre;
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
26 extern char *info_subject;
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
27 extern char *info_copyright;
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
28 extern char *info_sourceform;
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
29 extern char *info_comment;
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
30
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents: 8074
diff changeset
31 static muxer_stream_t* avifile_new_stream(muxer_t *muxer,int type){
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents: 8074
diff changeset
32 muxer_stream_t* s;
9007
12fc55eb3373 Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents: 8591
diff changeset
33 if (!muxer) return NULL;
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents: 8074
diff changeset
34 if(muxer->avih.dwStreams>=MUXER_MAX_STREAMS){
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents: 8074
diff changeset
35 printf("Too many streams! increase MUXER_MAX_STREAMS !\n");
2529
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
36 return NULL;
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
37 }
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents: 8074
diff changeset
38 s=malloc(sizeof(muxer_stream_t));
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents: 8074
diff changeset
39 memset(s,0,sizeof(muxer_stream_t));
2529
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
40 if(!s) return NULL; // no mem!?
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
41 muxer->streams[muxer->avih.dwStreams]=s;
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
42 s->type=type;
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
43 s->id=muxer->avih.dwStreams;
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
44 s->timer=0.0;
2652
fd279f14b9ab new stream field: size
arpi
parents: 2635
diff changeset
45 s->size=0;
9007
12fc55eb3373 Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents: 8591
diff changeset
46 s->muxer=muxer;
2529
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
47 switch(type){
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents: 8074
diff changeset
48 case MUXER_TYPE_VIDEO:
2529
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
49 s->ckid=mmioFOURCC(('0'+s->id/10),('0'+(s->id%10)),'d','c');
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
50 s->h.fccType=streamtypeVIDEO;
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
51 if(!muxer->def_v) muxer->def_v=s;
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
52 break;
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents: 8074
diff changeset
53 case MUXER_TYPE_AUDIO:
2529
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
54 s->ckid=mmioFOURCC(('0'+s->id/10),('0'+(s->id%10)),'w','b');
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
55 s->h.fccType=streamtypeAUDIO;
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
56 break;
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
57 default:
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
58 printf("WarninG! unknown stream type: %d\n",type);
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
59 return NULL;
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
60 }
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
61 muxer->avih.dwStreams++;
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
62 return s;
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
63 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
64
2529
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
65 static void write_avi_chunk(FILE *f,unsigned int id,int len,void* data){
6918
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
66 int le_len = le2me_32(len);
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
67 int le_id = le2me_32(id);
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
68 fwrite(&le_id,4,1,f);
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
69 fwrite(&le_len,4,1,f);
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
70
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
71 if(len>0){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72 if(data){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
73 // DATA
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
74 fwrite(data,len,1,f);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75 if(len&1){ // padding
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
76 unsigned char zerobyte=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
77 fwrite(&zerobyte,1,1,f);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
78 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
79 } else {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
80 // JUNK
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
81 char *avi_junk_data="[= MPlayer junk data! =]";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
82 if(len&1) ++len; // padding
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
83 while(len>0){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
84 int l=strlen(avi_junk_data);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
85 if(l>len) l=len;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
86 fwrite(avi_junk_data,l,1,f);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
87 len-=l;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
88 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
89 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
90 }
2529
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
91 }
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
92
9007
12fc55eb3373 Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents: 8591
diff changeset
93 static void avifile_write_chunk(muxer_stream_t *s,size_t len,unsigned int flags){
12fc55eb3373 Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents: 8591
diff changeset
94 muxer_t *muxer=s->muxer;
2529
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
95
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
96 // add to the index:
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
97 if(muxer->idx_pos>=muxer->idx_size){
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
98 muxer->idx_size+=256; // 4kB
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
99 muxer->idx=realloc(muxer->idx,16*muxer->idx_size);
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
100 }
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
101 muxer->idx[muxer->idx_pos].ckid=s->ckid;
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
102 muxer->idx[muxer->idx_pos].dwFlags=flags; // keyframe?
9007
12fc55eb3373 Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents: 8591
diff changeset
103 muxer->idx[muxer->idx_pos].dwChunkOffset=ftell(muxer->file)-(muxer->movi_start-4);
2529
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
104 muxer->idx[muxer->idx_pos].dwChunkLength=len;
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
105 ++muxer->idx_pos;
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
106
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
107 // write out the chunk:
9007
12fc55eb3373 Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents: 8591
diff changeset
108 write_avi_chunk(muxer->file,s->ckid,len,s->buffer); /* unsigned char */
6918
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
109
2529
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
110 // alter counters:
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
111 if(s->h.dwSampleSize){
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
112 // CBR
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
113 s->h.dwLength+=len/s->h.dwSampleSize;
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
114 if(len%s->h.dwSampleSize) printf("Warning! len isn't divisable by samplesize!\n");
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
115 } else {
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
116 // VBR
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
117 s->h.dwLength++;
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
118 }
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
119 s->timer=(double)s->h.dwLength*s->h.dwScale/s->h.dwRate;
2652
fd279f14b9ab new stream field: size
arpi
parents: 2635
diff changeset
120 s->size+=len;
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents: 8074
diff changeset
121 if((unsigned int)len>s->h.dwSuggestedBufferSize) s->h.dwSuggestedBufferSize=len;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
122
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
123 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
124
2529
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
125 static void write_avi_list(FILE *f,unsigned int id,int len){
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
126 unsigned int list_id=FOURCC_LIST;
6918
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
127 int le_len;
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
128 int le_id;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
129 len+=4; // list fix
6918
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
130 list_id = le2me_32(list_id);
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
131 le_len = le2me_32(len);
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
132 le_id = le2me_32(id);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
133 fwrite(&list_id,4,1,f);
6918
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
134 fwrite(&le_len,4,1,f);
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
135 fwrite(&le_id,4,1,f);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
136 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
137
11374
e00d3351b912 Fix waveformatex size calculation
ranma
parents: 9007
diff changeset
138 #define WFSIZE(wf) (sizeof(WAVEFORMATEX)+(wf)->cbSize)
2635
c1e24e01601b fixed AVI header creation - now should be compatible with NaNdub
arpi
parents: 2555
diff changeset
139
9007
12fc55eb3373 Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents: 8591
diff changeset
140 static void avifile_write_header(muxer_t *muxer){
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents: 8074
diff changeset
141 uint32_t riff[3];
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents: 8074
diff changeset
142 unsigned int i;
2529
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
143 unsigned int hdrsize;
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents: 8074
diff changeset
144 muxer_info_t info[16];
9007
12fc55eb3373 Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents: 8591
diff changeset
145 FILE *f=muxer->file;
7145
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
146
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
147 // RIFF header:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
148 riff[0]=mmioFOURCC('R','I','F','F');
7144
4f912998013e fixed RIFF chunk size - patch by "Andriy N. Gritsenko" <andrej@lucky.net>
arpi
parents: 6918
diff changeset
149 riff[1]=muxer->file_end-2*sizeof(unsigned int); // filesize
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
150 riff[2]=formtypeAVI; // 'AVI '
6918
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
151 riff[0]=le2me_32(riff[0]);
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
152 riff[1]=le2me_32(riff[1]);
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
153 riff[2]=le2me_32(riff[2]);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
154 fwrite(&riff,12,1,f);
2529
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
155 // update AVI header:
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
156 if(muxer->def_v){
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
157 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
158 // muxer->avih.dwMaxBytesPerSec=1000000; // dummy!!!!! FIXME
c1e24e01601b fixed AVI header creation - now should be compatible with NaNdub
arpi
parents: 2555
diff changeset
159 // muxer->avih.dwPaddingGranularity=2; // ???
2529
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
160 muxer->avih.dwFlags|=AVIF_ISINTERLEAVED|AVIF_TRUSTCKTYPE;
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
161 muxer->avih.dwTotalFrames=muxer->def_v->h.dwLength;
2635
c1e24e01601b fixed AVI header creation - now should be compatible with NaNdub
arpi
parents: 2555
diff changeset
162 // muxer->avih.dwSuggestedBufferSize=muxer->def_v->h.dwSuggestedBufferSize;
2529
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
163 muxer->avih.dwWidth=muxer->def_v->bih->biWidth;
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
164 muxer->avih.dwHeight=muxer->def_v->bih->biHeight;
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
165 }
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
166
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
167 // AVI header:
2529
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
168 hdrsize=sizeof(muxer->avih)+8;
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
169 // calc total header size:
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
170 for(i=0;i<muxer->avih.dwStreams;i++){
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
171 hdrsize+=12; // LIST
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
172 hdrsize+=sizeof(muxer->streams[i]->h)+8; // strh
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
173 switch(muxer->streams[i]->type){
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents: 8074
diff changeset
174 case MUXER_TYPE_VIDEO:
2529
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
175 hdrsize+=muxer->streams[i]->bih->biSize+8; // strf
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
176 break;
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents: 8074
diff changeset
177 case MUXER_TYPE_AUDIO:
2635
c1e24e01601b fixed AVI header creation - now should be compatible with NaNdub
arpi
parents: 2555
diff changeset
178 hdrsize+=WFSIZE(muxer->streams[i]->wf)+8; // strf
2529
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
179 break;
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
180 }
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
181 }
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
182 write_avi_list(f,listtypeAVIHEADER,hdrsize);
6918
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
183
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
184 le2me_MainAVIHeader(&muxer->avih);
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
185 write_avi_chunk(f,ckidAVIMAINHDR,sizeof(muxer->avih),&muxer->avih); /* MainAVIHeader */
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
186 le2me_MainAVIHeader(&muxer->avih);
2529
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
187
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
188 // stream headers:
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
189 for(i=0;i<muxer->avih.dwStreams;i++){
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
190 hdrsize=sizeof(muxer->streams[i]->h)+8; // strh
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
191 switch(muxer->streams[i]->type){
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents: 8074
diff changeset
192 case MUXER_TYPE_VIDEO:
2529
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
193 hdrsize+=muxer->streams[i]->bih->biSize+8; // strf
11863
9d5fdc9847ec Set fcchandler according to fourcc, some players (Archos Jukebox) need it, also imho a player should use that field for determining fourcc, hopefully it doesn't break anything
alex
parents: 11374
diff changeset
194 muxer->streams[i]->h.fccHandler = muxer->streams[i]->bih->biCompression;
2529
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
195 break;
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents: 8074
diff changeset
196 case MUXER_TYPE_AUDIO:
2635
c1e24e01601b fixed AVI header creation - now should be compatible with NaNdub
arpi
parents: 2555
diff changeset
197 hdrsize+=WFSIZE(muxer->streams[i]->wf)+8; // strf
11863
9d5fdc9847ec Set fcchandler according to fourcc, some players (Archos Jukebox) need it, also imho a player should use that field for determining fourcc, hopefully it doesn't break anything
alex
parents: 11374
diff changeset
198 muxer->streams[i]->h.fccHandler = muxer->streams[i]->wf->wFormatTag;
2529
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
199 break;
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
200 }
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
201 write_avi_list(f,listtypeSTREAMHEADER,hdrsize);
6918
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
202 le2me_AVIStreamHeader(&muxer->streams[i]->h);
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
203 write_avi_chunk(f,ckidSTREAMHEADER,sizeof(muxer->streams[i]->h),&muxer->streams[i]->h); /* AVISTreamHeader */ // strh
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
204 le2me_AVIStreamHeader(&muxer->streams[i]->h);
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
205
2529
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
206 switch(muxer->streams[i]->type){
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents: 8074
diff changeset
207 case MUXER_TYPE_VIDEO:
6918
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
208 {
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
209 int biSize=muxer->streams[i]->bih->biSize;
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
210 le2me_BITMAPINFOHEADER(muxer->streams[i]->bih);
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
211 write_avi_chunk(f,ckidSTREAMFORMAT,biSize,muxer->streams[i]->bih); /* BITMAPINFOHEADER */
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
212 le2me_BITMAPINFOHEADER(muxer->streams[i]->bih);
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
213 }
2529
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
214 break;
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents: 8074
diff changeset
215 case MUXER_TYPE_AUDIO:
6918
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
216 {
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
217 int wfsize = WFSIZE(muxer->streams[i]->wf);
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
218 le2me_WAVEFORMATEX(muxer->streams[i]->wf);
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
219 write_avi_chunk(f,ckidSTREAMFORMAT,wfsize,muxer->streams[i]->wf); /* WAVEFORMATEX */
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
220 le2me_WAVEFORMATEX(muxer->streams[i]->wf);
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
221 }
2529
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
222 break;
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
223 }
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
224 }
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
225
7145
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
226 // ============= INFO ===============
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
227 // always include software info
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
228 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
229 info[0].text="MEncoder " VERSION;
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
230 // include any optional strings
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
231 i=1;
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
232 if(info_name!=NULL){
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
233 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
234 info[i++].text=info_name;
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
235 }
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
236 if(info_artist!=NULL){
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
237 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
238 info[i++].text=info_artist;
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
239 }
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
240 if(info_genre!=NULL){
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
241 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
242 info[i++].text=info_genre;
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
243 }
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
244 if(info_subject!=NULL){
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
245 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
246 info[i++].text=info_subject;
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
247 }
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
248 if(info_copyright!=NULL){
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
249 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
250 info[i++].text=info_copyright;
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
251 }
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
252 if(info_sourceform!=NULL){
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
253 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
254 info[i++].text=info_sourceform;
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
255 }
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
256 if(info_comment!=NULL){
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
257 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
258 info[i++].text=info_comment;
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
259 }
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
260 info[i].id=0;
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
261
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
262 hdrsize=0;
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
263 // calc info size:
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
264 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
265 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
266 hdrsize+=sz+8+sz%2;
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
267 }
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
268 // write infos:
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
269 if (hdrsize!=0){
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
270 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
271 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
272 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
273 }
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
274 }
3854945aefbb new mencoder option -info, to store copyright, title, encoder version etc in AVI
arpi
parents: 7144
diff changeset
275
2529
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
276 // JUNK:
6918
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
277 write_avi_chunk(f,ckidAVIPADDING,2048-(ftell(f)&2047)-8,NULL); /* junk */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
278 // 'movi' header:
2529
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
279 write_avi_list(f,listtypeAVIMOVIE,muxer->movi_end-ftell(f)-12);
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
280 muxer->movi_start=ftell(f);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
281 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
282
9007
12fc55eb3373 Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents: 8591
diff changeset
283 static void avifile_write_index(muxer_t *muxer){
12fc55eb3373 Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents: 8591
diff changeset
284 muxer->movi_end=ftell(muxer->file);
2529
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
285 if(muxer->idx && muxer->idx_pos>0){
6918
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
286 int i;
2529
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
287 // fixup index entries:
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
288 // for(i=0;i<muxer->idx_pos;i++) muxer->idx[i].dwChunkOffset-=muxer->movi_start-4;
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
289 // write index chunk:
6918
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
290 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
291 write_avi_chunk(muxer->file,ckidAVINEWINDEX,16*muxer->idx_pos,muxer->idx); /* AVIINDEXENTRY */
6918
62ac2cac100d PPC endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 5572
diff changeset
292 for (i=0; i<muxer->idx_pos; i++) le2me_AVIINDEXENTRY((&muxer->idx[i]));
2529
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
293 muxer->avih.dwFlags|=AVIF_HASINDEX;
266dab71162b AVI muxer rewritten
arpi
parents: 2310
diff changeset
294 }
9007
12fc55eb3373 Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents: 8591
diff changeset
295 muxer->file_end=ftell(muxer->file);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
296 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
297
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents: 8074
diff changeset
298 void muxer_init_muxer_avi(muxer_t *muxer){
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents: 8074
diff changeset
299 muxer->cont_new_stream = &avifile_new_stream;
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents: 8074
diff changeset
300 muxer->cont_write_chunk = &avifile_write_chunk;
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents: 8074
diff changeset
301 muxer->cont_write_header = &avifile_write_header;
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents: 8074
diff changeset
302 muxer->cont_write_index = &avifile_write_index;
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents: 8074
diff changeset
303 }