annotate libmpdemux/muxer_avi.c @ 32254:70cdc0575aff

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