annotate libmpdemux/muxer_avi.c @ 12930:b200b94ebc4b

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