Mercurial > libavformat.hg
annotate avienc.c @ 5632:4c2b20d0233c libavformat
Doxument url_fdopen().
author | stefano |
---|---|
date | Fri, 05 Feb 2010 23:03:32 +0000 |
parents | 5f128b4359e7 |
children | 5d3ac5652047 |
rev | line source |
---|---|
0 | 1 /* |
1415
3b00fb8ef8e4
replace coder/decoder file description in libavformat by muxer/demuxer
aurel
parents:
1358
diff
changeset
|
2 * AVI muxer |
4251
77e0c7511d41
cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents:
4250
diff
changeset
|
3 * Copyright (c) 2000 Fabrice Bellard |
0 | 4 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1332
diff
changeset
|
5 * This file is part of FFmpeg. |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1332
diff
changeset
|
6 * |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1332
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
0 | 8 * modify it under the terms of the GNU Lesser General Public |
9 * License as published by the Free Software Foundation; either | |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1332
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
0 | 11 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1332
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
0 | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Lesser General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Lesser General Public | |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1332
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
896
edbe5c3717f9
Update licensing information: The FSF changed postal address.
diego
parents:
894
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 20 */ |
21 #include "avformat.h" | |
22 #include "avi.h" | |
1172
6a5e58d2114b
move common stuff from avienc.c and wav.c to new file riff.c
mru
parents:
1169
diff
changeset
|
23 #include "riff.h" |
0 | 24 |
25 /* | |
885 | 26 * TODO: |
0 | 27 * - fill all fields if non streamed (nb_frames for example) |
28 */ | |
29 | |
119 | 30 typedef struct AVIIentry { |
31 unsigned int flags, pos, len; | |
32 } AVIIentry; | |
33 | |
34 #define AVI_INDEX_CLUSTER_SIZE 16384 | |
35 | |
0 | 36 typedef struct AVIIndex { |
3973
549a09cf23fe
Remove offset_t typedef and use int64_t directly instead.
diego
parents:
3872
diff
changeset
|
37 int64_t indx_start; |
119 | 38 int entry; |
39 int ents_allocated; | |
40 AVIIentry** cluster; | |
0 | 41 } AVIIndex; |
42 | |
43 typedef struct { | |
3973
549a09cf23fe
Remove offset_t typedef and use int64_t directly instead.
diego
parents:
3872
diff
changeset
|
44 int64_t riff_start, movi_list, odml_list; |
5597
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
45 int64_t frames_hdr_all; |
119 | 46 int riff_id; |
5597
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
47 } AVIContext; |
119 | 48 |
5597
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
49 typedef struct { |
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
50 int64_t frames_hdr_strm; |
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
51 int audio_strm_length; |
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
52 int packet_count; |
5598 | 53 int entry; |
5597
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
54 |
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
55 AVIIndex indexes; |
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
56 } AVIStream ; |
0 | 57 |
885 | 58 static inline AVIIentry* avi_get_ientry(AVIIndex* idx, int ent_id) |
119 | 59 { |
60 int cl = ent_id / AVI_INDEX_CLUSTER_SIZE; | |
61 int id = ent_id % AVI_INDEX_CLUSTER_SIZE; | |
62 return &idx->cluster[cl][id]; | |
63 } | |
64 | |
5597
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
65 static int64_t avi_start_new_riff(AVFormatContext *s, ByteIOContext *pb, |
3973
549a09cf23fe
Remove offset_t typedef and use int64_t directly instead.
diego
parents:
3872
diff
changeset
|
66 const char* riff_tag, const char* list_tag) |
102
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
67 { |
5597
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
68 AVIContext *avi= s->priv_data; |
3973
549a09cf23fe
Remove offset_t typedef and use int64_t directly instead.
diego
parents:
3872
diff
changeset
|
69 int64_t loff; |
119 | 70 int i; |
885 | 71 |
119 | 72 avi->riff_id++; |
5597
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
73 for (i=0; i<s->nb_streams; i++){ |
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
74 AVIStream *avist= s->streams[i]->priv_data; |
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
75 avist->indexes.entry = 0; |
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
76 } |
885 | 77 |
5058
33a244b7ca65
Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents:
5044
diff
changeset
|
78 avi->riff_start = ff_start_tag(pb, "RIFF"); |
102
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
79 put_tag(pb, riff_tag); |
5058
33a244b7ca65
Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents:
5044
diff
changeset
|
80 loff = ff_start_tag(pb, "LIST"); |
102
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
81 put_tag(pb, list_tag); |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
82 return loff; |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
83 } |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
84 |
1332 | 85 static char* avi_stream2fourcc(char* tag, int index, enum CodecType type) |
119 | 86 { |
87 tag[0] = '0'; | |
88 tag[1] = '0' + index; | |
89 if (type == CODEC_TYPE_VIDEO) { | |
90 tag[2] = 'd'; | |
91 tag[3] = 'c'; | |
5044
2ef633b32f7a
Add support for muxing XSUB subtitles to AVI muxer.
reimar
parents:
4816
diff
changeset
|
92 } else if (type == CODEC_TYPE_SUBTITLE) { |
2ef633b32f7a
Add support for muxing XSUB subtitles to AVI muxer.
reimar
parents:
4816
diff
changeset
|
93 // note: this is not an official code |
2ef633b32f7a
Add support for muxing XSUB subtitles to AVI muxer.
reimar
parents:
4816
diff
changeset
|
94 tag[2] = 's'; |
2ef633b32f7a
Add support for muxing XSUB subtitles to AVI muxer.
reimar
parents:
4816
diff
changeset
|
95 tag[3] = 'b'; |
119 | 96 } else { |
97 tag[2] = 'w'; | |
98 tag[3] = 'b'; | |
99 } | |
100 tag[4] = '\0'; | |
101 return tag; | |
102 } | |
103 | |
1256 | 104 static void avi_write_info_tag(ByteIOContext *pb, const char *tag, const char *str) |
105 { | |
106 int len = strlen(str); | |
107 if (len > 0) { | |
108 len++; | |
109 put_tag(pb, tag); | |
110 put_le32(pb, len); | |
111 put_strz(pb, str); | |
112 if (len & 1) | |
113 put_byte(pb, 0); | |
114 } | |
115 } | |
116 | |
5631 | 117 static void avi_write_info_tag2(AVFormatContext *s, AVStream *st, const char *fourcc, const char *key1, const char *key2) |
4149 | 118 { |
5631 | 119 AVMetadataTag *tag; |
120 if(st){ | |
121 tag= av_metadata_get(st->metadata, key1, NULL, 0); | |
122 if(!tag && key2) | |
123 tag= av_metadata_get(st->metadata, key2, NULL, 0); | |
124 }else{ | |
125 tag= av_metadata_get(s->metadata, key1, NULL, 0); | |
4149 | 126 if(!tag && key2) |
4250
2fc899894f5e
replace AV_METADATA_IGNORE_CASE flag by a new AV_METADATA_MATCH_CASE flag
aurel
parents:
4206
diff
changeset
|
127 tag= av_metadata_get(s->metadata, key2, NULL, 0); |
5631 | 128 } |
4149 | 129 if(tag) |
130 avi_write_info_tag(s->pb, fourcc, tag->value); | |
131 } | |
132 | |
1267 | 133 static int avi_write_counters(AVFormatContext* s, int riff_id) |
134 { | |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2227
diff
changeset
|
135 ByteIOContext *pb = s->pb; |
1267 | 136 AVIContext *avi = s->priv_data; |
137 int n, au_byterate, au_ssize, au_scale, nb_frames = 0; | |
3973
549a09cf23fe
Remove offset_t typedef and use int64_t directly instead.
diego
parents:
3872
diff
changeset
|
138 int64_t file_size; |
1267 | 139 AVCodecContext* stream; |
140 | |
141 file_size = url_ftell(pb); | |
142 for(n = 0; n < s->nb_streams; n++) { | |
5597
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
143 AVIStream *avist= s->streams[n]->priv_data; |
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
144 |
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
145 assert(avist->frames_hdr_strm); |
1267 | 146 stream = s->streams[n]->codec; |
5597
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
147 url_fseek(pb, avist->frames_hdr_strm, SEEK_SET); |
1267 | 148 ff_parse_specific_params(stream, &au_byterate, &au_ssize, &au_scale); |
149 if(au_ssize == 0) { | |
5597
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
150 put_le32(pb, avist->packet_count); |
1267 | 151 } else { |
5597
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
152 put_le32(pb, avist->audio_strm_length / au_ssize); |
1267 | 153 } |
154 if(stream->codec_type == CODEC_TYPE_VIDEO) | |
5597
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
155 nb_frames = FFMAX(nb_frames, avist->packet_count); |
1267 | 156 } |
157 if(riff_id == 1) { | |
158 assert(avi->frames_hdr_all); | |
159 url_fseek(pb, avi->frames_hdr_all, SEEK_SET); | |
160 put_le32(pb, nb_frames); | |
161 } | |
162 url_fseek(pb, file_size, SEEK_SET); | |
163 | |
164 return 0; | |
165 } | |
166 | |
0 | 167 static int avi_write_header(AVFormatContext *s) |
168 { | |
169 AVIContext *avi = s->priv_data; | |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2227
diff
changeset
|
170 ByteIOContext *pb = s->pb; |
0 | 171 int bitrate, n, i, nb_frames, au_byterate, au_ssize, au_scale; |
172 AVCodecContext *stream, *video_enc; | |
3973
549a09cf23fe
Remove offset_t typedef and use int64_t directly instead.
diego
parents:
3872
diff
changeset
|
173 int64_t list1, list2, strh, strf; |
0 | 174 |
5597
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
175 for(n=0;n<s->nb_streams;n++) { |
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
176 s->streams[n]->priv_data= av_mallocz(sizeof(AVIStream)); |
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
177 if(!s->streams[n]->priv_data) |
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
178 return AVERROR(ENOMEM); |
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
179 } |
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
180 |
0 | 181 /* header list */ |
119 | 182 avi->riff_id = 0; |
5597
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
183 list1 = avi_start_new_riff(s, pb, "AVI ", "hdrl"); |
0 | 184 |
185 /* avi header */ | |
186 put_tag(pb, "avih"); | |
187 put_le32(pb, 14 * 4); | |
188 bitrate = 0; | |
189 | |
190 video_enc = NULL; | |
191 for(n=0;n<s->nb_streams;n++) { | |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
796
diff
changeset
|
192 stream = s->streams[n]->codec; |
0 | 193 bitrate += stream->bit_rate; |
194 if (stream->codec_type == CODEC_TYPE_VIDEO) | |
195 video_enc = stream; | |
196 } | |
885 | 197 |
0 | 198 nb_frames = 0; |
199 | |
36
1188ad85857a
audio only avi patch by (Andriy Rysin <arysin at bcsii dot net>)
michaelni
parents:
15
diff
changeset
|
200 if(video_enc){ |
1556 | 201 put_le32(pb, (uint32_t)(INT64_C(1000000) * video_enc->time_base.num / video_enc->time_base.den)); |
36
1188ad85857a
audio only avi patch by (Andriy Rysin <arysin at bcsii dot net>)
michaelni
parents:
15
diff
changeset
|
202 } else { |
887 | 203 put_le32(pb, 0); |
36
1188ad85857a
audio only avi patch by (Andriy Rysin <arysin at bcsii dot net>)
michaelni
parents:
15
diff
changeset
|
204 } |
0 | 205 put_le32(pb, bitrate / 8); /* XXX: not quite exact */ |
206 put_le32(pb, 0); /* padding */ | |
873
7af647503b67
Support for streaming: dont write indexes and dont signal HAS_INDEX in header. Also set filesize to max in this case.
alex
parents:
863
diff
changeset
|
207 if (url_is_streamed(pb)) |
887 | 208 put_le32(pb, AVIF_TRUSTCKTYPE | AVIF_ISINTERLEAVED); /* flags */ |
873
7af647503b67
Support for streaming: dont write indexes and dont signal HAS_INDEX in header. Also set filesize to max in this case.
alex
parents:
863
diff
changeset
|
209 else |
887 | 210 put_le32(pb, AVIF_TRUSTCKTYPE | AVIF_HASINDEX | AVIF_ISINTERLEAVED); /* flags */ |
0 | 211 avi->frames_hdr_all = url_ftell(pb); /* remember this offset to fill later */ |
212 put_le32(pb, nb_frames); /* nb frames, filled later */ | |
213 put_le32(pb, 0); /* initial frame */ | |
214 put_le32(pb, s->nb_streams); /* nb streams */ | |
215 put_le32(pb, 1024 * 1024); /* suggested buffer size */ | |
885 | 216 if(video_enc){ |
992 | 217 put_le32(pb, video_enc->width); |
218 put_le32(pb, video_enc->height); | |
36
1188ad85857a
audio only avi patch by (Andriy Rysin <arysin at bcsii dot net>)
michaelni
parents:
15
diff
changeset
|
219 } else { |
887 | 220 put_le32(pb, 0); |
221 put_le32(pb, 0); | |
885 | 222 } |
0 | 223 put_le32(pb, 0); /* reserved */ |
224 put_le32(pb, 0); /* reserved */ | |
225 put_le32(pb, 0); /* reserved */ | |
226 put_le32(pb, 0); /* reserved */ | |
885 | 227 |
0 | 228 /* stream list */ |
229 for(i=0;i<n;i++) { | |
5597
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
230 AVIStream *avist= s->streams[i]->priv_data; |
5058
33a244b7ca65
Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents:
5044
diff
changeset
|
231 list2 = ff_start_tag(pb, "LIST"); |
0 | 232 put_tag(pb, "strl"); |
885 | 233 |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
796
diff
changeset
|
234 stream = s->streams[i]->codec; |
0 | 235 |
236 /* stream generic header */ | |
5058
33a244b7ca65
Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents:
5044
diff
changeset
|
237 strh = ff_start_tag(pb, "strh"); |
0 | 238 switch(stream->codec_type) { |
5044
2ef633b32f7a
Add support for muxing XSUB subtitles to AVI muxer.
reimar
parents:
4816
diff
changeset
|
239 case CODEC_TYPE_SUBTITLE: |
2ef633b32f7a
Add support for muxing XSUB subtitles to AVI muxer.
reimar
parents:
4816
diff
changeset
|
240 // XSUB subtitles behave like video tracks, other subtitles |
2ef633b32f7a
Add support for muxing XSUB subtitles to AVI muxer.
reimar
parents:
4816
diff
changeset
|
241 // are not (yet) supported. |
2ef633b32f7a
Add support for muxing XSUB subtitles to AVI muxer.
reimar
parents:
4816
diff
changeset
|
242 if (stream->codec_id != CODEC_ID_XSUB) break; |
781 | 243 case CODEC_TYPE_VIDEO: put_tag(pb, "vids"); break; |
244 case CODEC_TYPE_AUDIO: put_tag(pb, "auds"); break; | |
245 // case CODEC_TYPE_TEXT : put_tag(pb, "txts"); break; | |
246 case CODEC_TYPE_DATA : put_tag(pb, "dats"); break; | |
247 } | |
5044
2ef633b32f7a
Add support for muxing XSUB subtitles to AVI muxer.
reimar
parents:
4816
diff
changeset
|
248 if(stream->codec_type == CODEC_TYPE_VIDEO || |
2ef633b32f7a
Add support for muxing XSUB subtitles to AVI muxer.
reimar
parents:
4816
diff
changeset
|
249 stream->codec_id == CODEC_ID_XSUB) |
89
8e3cf4e9fc5a
rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
85
diff
changeset
|
250 put_le32(pb, stream->codec_tag); |
781 | 251 else |
252 put_le32(pb, 1); | |
253 put_le32(pb, 0); /* flags */ | |
254 put_le16(pb, 0); /* priority */ | |
255 put_le16(pb, 0); /* language */ | |
256 put_le32(pb, 0); /* initial frame */ | |
257 | |
258 ff_parse_specific_params(stream, &au_byterate, &au_ssize, &au_scale); | |
75
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
65
diff
changeset
|
259 |
781 | 260 put_le32(pb, au_scale); /* scale */ |
261 put_le32(pb, au_byterate); /* rate */ | |
262 av_set_pts_info(s->streams[i], 64, au_scale, au_byterate); | |
263 | |
264 put_le32(pb, 0); /* start */ | |
5597
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
265 avist->frames_hdr_strm = url_ftell(pb); /* remember this offset to fill later */ |
887 | 266 if (url_is_streamed(pb)) |
267 put_le32(pb, AVI_MAX_RIFF_SIZE); /* FIXME: this may be broken, but who cares */ | |
268 else | |
269 put_le32(pb, 0); /* length, XXX: filled later */ | |
885 | 270 |
781 | 271 /* suggested buffer size */ //FIXME set at the end to largest chunk |
272 if(stream->codec_type == CODEC_TYPE_VIDEO) | |
885 | 273 put_le32(pb, 1024 * 1024); |
781 | 274 else if(stream->codec_type == CODEC_TYPE_AUDIO) |
885 | 275 put_le32(pb, 12 * 1024); |
781 | 276 else |
885 | 277 put_le32(pb, 0); |
781 | 278 put_le32(pb, -1); /* quality */ |
279 put_le32(pb, au_ssize); /* sample size */ | |
280 put_le32(pb, 0); | |
281 put_le16(pb, stream->width); | |
282 put_le16(pb, stream->height); | |
5058
33a244b7ca65
Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents:
5044
diff
changeset
|
283 ff_end_tag(pb, strh); |
0 | 284 |
781 | 285 if(stream->codec_type != CODEC_TYPE_DATA){ |
5058
33a244b7ca65
Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents:
5044
diff
changeset
|
286 strf = ff_start_tag(pb, "strf"); |
0 | 287 switch(stream->codec_type) { |
5044
2ef633b32f7a
Add support for muxing XSUB subtitles to AVI muxer.
reimar
parents:
4816
diff
changeset
|
288 case CODEC_TYPE_SUBTITLE: |
2ef633b32f7a
Add support for muxing XSUB subtitles to AVI muxer.
reimar
parents:
4816
diff
changeset
|
289 // XSUB subtitles behave like video tracks, other subtitles |
2ef633b32f7a
Add support for muxing XSUB subtitles to AVI muxer.
reimar
parents:
4816
diff
changeset
|
290 // are not (yet) supported. |
2ef633b32f7a
Add support for muxing XSUB subtitles to AVI muxer.
reimar
parents:
4816
diff
changeset
|
291 if (stream->codec_id != CODEC_ID_XSUB) break; |
0 | 292 case CODEC_TYPE_VIDEO: |
5058
33a244b7ca65
Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents:
5044
diff
changeset
|
293 ff_put_bmp_header(pb, stream, ff_codec_bmp_tags, 0); |
0 | 294 break; |
295 case CODEC_TYPE_AUDIO: | |
5058
33a244b7ca65
Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents:
5044
diff
changeset
|
296 if (ff_put_wav_header(pb, stream) < 0) { |
0 | 297 return -1; |
298 } | |
299 break; | |
300 default: | |
537 | 301 return -1; |
0 | 302 } |
5058
33a244b7ca65
Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents:
5044
diff
changeset
|
303 ff_end_tag(pb, strf); |
5631 | 304 avi_write_info_tag2(s, s->streams[i], "strn", "Title", "Description"); |
781 | 305 } |
885 | 306 |
887 | 307 if (!url_is_streamed(pb)) { |
308 unsigned char tag[5]; | |
309 int j; | |
885 | 310 |
311 /* Starting to lay out AVI OpenDML master index. | |
887 | 312 * We want to make it JUNK entry for now, since we'd |
313 * like to get away without making AVI an OpenDML one | |
314 * for compatibility reasons. | |
315 */ | |
5597
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
316 avist->indexes.entry = avist->indexes.ents_allocated = 0; |
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
317 avist->indexes.indx_start = ff_start_tag(pb, "JUNK"); |
887 | 318 put_le16(pb, 4); /* wLongsPerEntry */ |
319 put_byte(pb, 0); /* bIndexSubType (0 == frame index) */ | |
320 put_byte(pb, 0); /* bIndexType (0 == AVI_INDEX_OF_INDEXES) */ | |
321 put_le32(pb, 0); /* nEntriesInUse (will fill out later on) */ | |
322 put_tag(pb, avi_stream2fourcc(&tag[0], i, stream->codec_type)); | |
323 /* dwChunkId */ | |
324 put_le64(pb, 0); /* dwReserved[3] | |
325 put_le32(pb, 0); Must be 0. */ | |
326 for (j=0; j < AVI_MASTER_INDEX_SIZE * 2; j++) | |
327 put_le64(pb, 0); | |
5597
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
328 ff_end_tag(pb, avist->indexes.indx_start); |
887 | 329 } |
885 | 330 |
3100 | 331 if( stream->codec_type == CODEC_TYPE_VIDEO |
3759
27537074f2a9
convert every muxer/demuxer to write/read sample_aspect_ratio from/to
aurel
parents:
3424
diff
changeset
|
332 && s->streams[i]->sample_aspect_ratio.num>0 |
27537074f2a9
convert every muxer/demuxer to write/read sample_aspect_ratio from/to
aurel
parents:
3424
diff
changeset
|
333 && s->streams[i]->sample_aspect_ratio.den>0){ |
5058
33a244b7ca65
Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents:
5044
diff
changeset
|
334 int vprp= ff_start_tag(pb, "vprp"); |
3759
27537074f2a9
convert every muxer/demuxer to write/read sample_aspect_ratio from/to
aurel
parents:
3424
diff
changeset
|
335 AVRational dar = av_mul_q(s->streams[i]->sample_aspect_ratio, |
3100 | 336 (AVRational){stream->width, stream->height}); |
337 int num, den; | |
338 av_reduce(&num, &den, dar.num, dar.den, 0xFFFF); | |
339 | |
340 put_le32(pb, 0); //video format = unknown | |
341 put_le32(pb, 0); //video standard= unknown | |
342 put_le32(pb, lrintf(1.0/av_q2d(stream->time_base))); | |
343 put_le32(pb, stream->width ); | |
344 put_le32(pb, stream->height); | |
3177 | 345 put_le16(pb, den); |
3100 | 346 put_le16(pb, num); |
347 put_le32(pb, stream->width ); | |
348 put_le32(pb, stream->height); | |
349 put_le32(pb, 1); //progressive FIXME | |
350 | |
351 put_le32(pb, stream->height); | |
352 put_le32(pb, stream->width ); | |
353 put_le32(pb, stream->height); | |
354 put_le32(pb, stream->width ); | |
355 put_le32(pb, 0); | |
356 put_le32(pb, 0); | |
357 | |
358 put_le32(pb, 0); | |
359 put_le32(pb, 0); | |
5058
33a244b7ca65
Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents:
5044
diff
changeset
|
360 ff_end_tag(pb, vprp); |
3100 | 361 } |
362 | |
5058
33a244b7ca65
Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents:
5044
diff
changeset
|
363 ff_end_tag(pb, list2); |
0 | 364 } |
885 | 365 |
119 | 366 if (!url_is_streamed(pb)) { |
367 /* AVI could become an OpenDML one, if it grows beyond 2Gb range */ | |
5058
33a244b7ca65
Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents:
5044
diff
changeset
|
368 avi->odml_list = ff_start_tag(pb, "JUNK"); |
119 | 369 put_tag(pb, "odml"); |
370 put_tag(pb, "dmlh"); | |
371 put_le32(pb, 248); | |
372 for (i = 0; i < 248; i+= 4) | |
373 put_le32(pb, 0); | |
5058
33a244b7ca65
Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents:
5044
diff
changeset
|
374 ff_end_tag(pb, avi->odml_list); |
119 | 375 } |
0 | 376 |
5058
33a244b7ca65
Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents:
5044
diff
changeset
|
377 ff_end_tag(pb, list1); |
885 | 378 |
5058
33a244b7ca65
Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents:
5044
diff
changeset
|
379 list2 = ff_start_tag(pb, "LIST"); |
1256 | 380 put_tag(pb, "INFO"); |
5631 | 381 avi_write_info_tag2(s, NULL, "INAM", "Title", NULL); |
382 avi_write_info_tag2(s, NULL, "IART", "Artist", "Author"); | |
383 avi_write_info_tag2(s, NULL, "ICOP", "Copyright", NULL); | |
384 avi_write_info_tag2(s, NULL, "ICMT", "Comment", NULL); | |
385 avi_write_info_tag2(s, NULL, "IPRD", "Album", NULL); | |
386 avi_write_info_tag2(s, NULL, "IGNR", "Genre", NULL); | |
387 avi_write_info_tag2(s, NULL, "IPRT", "Track", NULL); | |
1256 | 388 if(!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT)) |
389 avi_write_info_tag(pb, "ISFT", LIBAVFORMAT_IDENT); | |
5058
33a244b7ca65
Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents:
5044
diff
changeset
|
390 ff_end_tag(pb, list2); |
1256 | 391 |
392 /* some padding for easier tag editing */ | |
5058
33a244b7ca65
Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents:
5044
diff
changeset
|
393 list2 = ff_start_tag(pb, "JUNK"); |
1256 | 394 for (i = 0; i < 1016; i += 4) |
395 put_le32(pb, 0); | |
5058
33a244b7ca65
Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents:
5044
diff
changeset
|
396 ff_end_tag(pb, list2); |
1256 | 397 |
5058
33a244b7ca65
Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents:
5044
diff
changeset
|
398 avi->movi_list = ff_start_tag(pb, "LIST"); |
0 | 399 put_tag(pb, "movi"); |
400 | |
401 put_flush_packet(pb); | |
402 | |
403 return 0; | |
404 } | |
405 | |
119 | 406 static int avi_write_ix(AVFormatContext *s) |
407 { | |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2227
diff
changeset
|
408 ByteIOContext *pb = s->pb; |
119 | 409 AVIContext *avi = s->priv_data; |
1332 | 410 char tag[5]; |
411 char ix_tag[] = "ix00"; | |
119 | 412 int i, j; |
885 | 413 |
976 | 414 assert(!url_is_streamed(pb)); |
873
7af647503b67
Support for streaming: dont write indexes and dont signal HAS_INDEX in header. Also set filesize to max in this case.
alex
parents:
863
diff
changeset
|
415 |
119 | 416 if (avi->riff_id > AVI_MASTER_INDEX_SIZE) |
417 return -1; | |
885 | 418 |
119 | 419 for (i=0;i<s->nb_streams;i++) { |
5597
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
420 AVIStream *avist= s->streams[i]->priv_data; |
3973
549a09cf23fe
Remove offset_t typedef and use int64_t directly instead.
diego
parents:
3872
diff
changeset
|
421 int64_t ix, pos; |
885 | 422 |
887 | 423 avi_stream2fourcc(&tag[0], i, s->streams[i]->codec->codec_type); |
424 ix_tag[3] = '0' + i; | |
885 | 425 |
887 | 426 /* Writing AVI OpenDML leaf index chunk */ |
427 ix = url_ftell(pb); | |
428 put_tag(pb, &ix_tag[0]); /* ix?? */ | |
5597
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
429 put_le32(pb, avist->indexes.entry * 8 + 24); |
887 | 430 /* chunk size */ |
119 | 431 put_le16(pb, 2); /* wLongsPerEntry */ |
887 | 432 put_byte(pb, 0); /* bIndexSubType (0 == frame index) */ |
433 put_byte(pb, 1); /* bIndexType (1 == AVI_INDEX_OF_CHUNKS) */ | |
5597
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
434 put_le32(pb, avist->indexes.entry); |
887 | 435 /* nEntriesInUse */ |
436 put_tag(pb, &tag[0]); /* dwChunkId */ | |
437 put_le64(pb, avi->movi_list);/* qwBaseOffset */ | |
438 put_le32(pb, 0); /* dwReserved_3 (must be 0) */ | |
119 | 439 |
5597
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
440 for (j=0; j<avist->indexes.entry; j++) { |
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
441 AVIIentry* ie = avi_get_ientry(&avist->indexes, j); |
887 | 442 put_le32(pb, ie->pos + 8); |
443 put_le32(pb, ((uint32_t)ie->len & ~0x80000000) | | |
444 (ie->flags & 0x10 ? 0 : 0x80000000)); | |
119 | 445 } |
887 | 446 put_flush_packet(pb); |
119 | 447 pos = url_ftell(pb); |
885 | 448 |
887 | 449 /* Updating one entry in the AVI OpenDML master index */ |
5597
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
450 url_fseek(pb, avist->indexes.indx_start - 8, SEEK_SET); |
887 | 451 put_tag(pb, "indx"); /* enabling this entry */ |
452 url_fskip(pb, 8); | |
453 put_le32(pb, avi->riff_id); /* nEntriesInUse */ | |
454 url_fskip(pb, 16*avi->riff_id); | |
455 put_le64(pb, ix); /* qwOffset */ | |
456 put_le32(pb, pos - ix); /* dwSize */ | |
5597
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
457 put_le32(pb, avist->indexes.entry); /* dwDuration */ |
119 | 458 |
887 | 459 url_fseek(pb, pos, SEEK_SET); |
119 | 460 } |
461 return 0; | |
462 } | |
463 | |
464 static int avi_write_idx1(AVFormatContext *s) | |
102
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
465 { |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2227
diff
changeset
|
466 ByteIOContext *pb = s->pb; |
102
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
467 AVIContext *avi = s->priv_data; |
3973
549a09cf23fe
Remove offset_t typedef and use int64_t directly instead.
diego
parents:
3872
diff
changeset
|
468 int64_t idx_chunk; |
1267 | 469 int i; |
1332 | 470 char tag[5]; |
102
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
471 |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
472 if (!url_is_streamed(pb)) { |
5598 | 473 AVIStream *avist; |
887 | 474 AVIIentry* ie = 0, *tie; |
475 int empty, stream_id = -1; | |
102
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
476 |
5058
33a244b7ca65
Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents:
5044
diff
changeset
|
477 idx_chunk = ff_start_tag(pb, "idx1"); |
5598 | 478 for(i=0; i<s->nb_streams; i++){ |
479 avist= s->streams[i]->priv_data; | |
480 avist->entry=0; | |
481 } | |
482 | |
887 | 483 do { |
484 empty = 1; | |
485 for (i=0; i<s->nb_streams; i++) { | |
5598 | 486 avist= s->streams[i]->priv_data; |
487 if (avist->indexes.entry <= avist->entry) | |
887 | 488 continue; |
885 | 489 |
5598 | 490 tie = avi_get_ientry(&avist->indexes, avist->entry); |
887 | 491 if (empty || tie->pos < ie->pos) { |
492 ie = tie; | |
493 stream_id = i; | |
494 } | |
495 empty = 0; | |
496 } | |
497 if (!empty) { | |
5598 | 498 avist= s->streams[stream_id]->priv_data; |
887 | 499 avi_stream2fourcc(&tag[0], stream_id, |
500 s->streams[stream_id]->codec->codec_type); | |
501 put_tag(pb, &tag[0]); | |
502 put_le32(pb, ie->flags); | |
119 | 503 put_le32(pb, ie->pos); |
504 put_le32(pb, ie->len); | |
5598 | 505 avist->entry++; |
887 | 506 } |
507 } while (!empty); | |
5058
33a244b7ca65
Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents:
5044
diff
changeset
|
508 ff_end_tag(pb, idx_chunk); |
102
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
509 |
1267 | 510 avi_write_counters(s, avi->riff_id); |
102
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
511 } |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
512 return 0; |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
513 } |
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
514 |
468 | 515 static int avi_write_packet(AVFormatContext *s, AVPacket *pkt) |
0 | 516 { |
517 AVIContext *avi = s->priv_data; | |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2227
diff
changeset
|
518 ByteIOContext *pb = s->pb; |
0 | 519 unsigned char tag[5]; |
468 | 520 unsigned int flags=0; |
521 const int stream_index= pkt->stream_index; | |
5597
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
522 AVIStream *avist= s->streams[stream_index]->priv_data; |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
796
diff
changeset
|
523 AVCodecContext *enc= s->streams[stream_index]->codec; |
468 | 524 int size= pkt->size; |
102
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
525 |
1443
404048ea11bc
Replace most of the %lld and %llx by their (cleaner) PRI*64 counterparts.
diego
parents:
1415
diff
changeset
|
526 // av_log(s, AV_LOG_DEBUG, "%"PRId64" %d %d\n", pkt->dts, avi->packet_count[stream_index], stream_index); |
5597
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
527 while(enc->block_align==0 && pkt->dts != AV_NOPTS_VALUE && pkt->dts > avist->packet_count){ |
479 | 528 AVPacket empty_packet; |
529 | |
530 av_init_packet(&empty_packet); | |
531 empty_packet.size= 0; | |
532 empty_packet.data= NULL; | |
533 empty_packet.stream_index= stream_index; | |
534 avi_write_packet(s, &empty_packet); | |
1443
404048ea11bc
Replace most of the %lld and %llx by their (cleaner) PRI*64 counterparts.
diego
parents:
1415
diff
changeset
|
535 // av_log(s, AV_LOG_DEBUG, "dup %"PRId64" %d\n", pkt->dts, avi->packet_count[stream_index]); |
479 | 536 } |
5597
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
537 avist->packet_count++; |
479 | 538 |
873
7af647503b67
Support for streaming: dont write indexes and dont signal HAS_INDEX in header. Also set filesize to max in this case.
alex
parents:
863
diff
changeset
|
539 // Make sure to put an OpenDML chunk when the file size exceeds the limits |
885 | 540 if (!url_is_streamed(pb) && |
887 | 541 (url_ftell(pb) - avi->riff_start > AVI_MAX_RIFF_SIZE)) { |
885 | 542 |
119 | 543 avi_write_ix(s); |
5058
33a244b7ca65
Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents:
5044
diff
changeset
|
544 ff_end_tag(pb, avi->movi_list); |
885 | 545 |
887 | 546 if (avi->riff_id == 1) |
547 avi_write_idx1(s); | |
119 | 548 |
5058
33a244b7ca65
Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents:
5044
diff
changeset
|
549 ff_end_tag(pb, avi->riff_start); |
5597
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
550 avi->movi_list = avi_start_new_riff(s, pb, "AVIX", "movi"); |
102
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
551 } |
885 | 552 |
119 | 553 avi_stream2fourcc(&tag[0], stream_index, enc->codec_type); |
468 | 554 if(pkt->flags&PKT_FLAG_KEY) |
555 flags = 0x10; | |
119 | 556 if (enc->codec_type == CODEC_TYPE_AUDIO) { |
5597
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
557 avist->audio_strm_length += size; |
468 | 558 } |
0 | 559 |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2227
diff
changeset
|
560 if (!url_is_streamed(s->pb)) { |
5597
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
561 AVIIndex* idx = &avist->indexes; |
887 | 562 int cl = idx->entry / AVI_INDEX_CLUSTER_SIZE; |
563 int id = idx->entry % AVI_INDEX_CLUSTER_SIZE; | |
119 | 564 if (idx->ents_allocated <= idx->entry) { |
887 | 565 idx->cluster = av_realloc(idx->cluster, (cl+1)*sizeof(void*)); |
566 if (!idx->cluster) | |
567 return -1; | |
119 | 568 idx->cluster[cl] = av_malloc(AVI_INDEX_CLUSTER_SIZE*sizeof(AVIIentry)); |
887 | 569 if (!idx->cluster[cl]) |
570 return -1; | |
571 idx->ents_allocated += AVI_INDEX_CLUSTER_SIZE; | |
572 } | |
885 | 573 |
887 | 574 idx->cluster[cl][id].flags = flags; |
119 | 575 idx->cluster[cl][id].pos = url_ftell(pb) - avi->movi_list; |
576 idx->cluster[cl][id].len = size; | |
887 | 577 idx->entry++; |
0 | 578 } |
885 | 579 |
0 | 580 put_buffer(pb, tag, 4); |
581 put_le32(pb, size); | |
468 | 582 put_buffer(pb, pkt->data, size); |
0 | 583 if (size & 1) |
584 put_byte(pb, 0); | |
585 | |
586 put_flush_packet(pb); | |
587 return 0; | |
588 } | |
589 | |
590 static int avi_write_trailer(AVFormatContext *s) | |
591 { | |
102
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
592 AVIContext *avi = s->priv_data; |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2227
diff
changeset
|
593 ByteIOContext *pb = s->pb; |
102
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
594 int res = 0; |
119 | 595 int i, j, n, nb_frames; |
3973
549a09cf23fe
Remove offset_t typedef and use int64_t directly instead.
diego
parents:
3872
diff
changeset
|
596 int64_t file_size; |
0 | 597 |
1676 | 598 if (!url_is_streamed(pb)){ |
599 if (avi->riff_id == 1) { | |
5058
33a244b7ca65
Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents:
5044
diff
changeset
|
600 ff_end_tag(pb, avi->movi_list); |
1676 | 601 res = avi_write_idx1(s); |
5058
33a244b7ca65
Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents:
5044
diff
changeset
|
602 ff_end_tag(pb, avi->riff_start); |
1676 | 603 } else { |
604 avi_write_ix(s); | |
5058
33a244b7ca65
Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents:
5044
diff
changeset
|
605 ff_end_tag(pb, avi->movi_list); |
33a244b7ca65
Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents:
5044
diff
changeset
|
606 ff_end_tag(pb, avi->riff_start); |
119 | 607 |
1676 | 608 file_size = url_ftell(pb); |
609 url_fseek(pb, avi->odml_list - 8, SEEK_SET); | |
610 put_tag(pb, "LIST"); /* Making this AVI OpenDML one */ | |
611 url_fskip(pb, 16); | |
0 | 612 |
1676 | 613 for (n=nb_frames=0;n<s->nb_streams;n++) { |
614 AVCodecContext *stream = s->streams[n]->codec; | |
5597
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
615 AVIStream *avist= s->streams[n]->priv_data; |
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
616 |
1676 | 617 if (stream->codec_type == CODEC_TYPE_VIDEO) { |
5597
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
618 if (nb_frames < avist->packet_count) |
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
619 nb_frames = avist->packet_count; |
1676 | 620 } else { |
621 if (stream->codec_id == CODEC_ID_MP2 || stream->codec_id == CODEC_ID_MP3) { | |
5597
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
622 nb_frames += avist->packet_count; |
1676 | 623 } |
0 | 624 } |
625 } | |
1676 | 626 put_le32(pb, nb_frames); |
627 url_fseek(pb, file_size, SEEK_SET); | |
628 | |
629 avi_write_counters(s, avi->riff_id); | |
102
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
630 } |
873
7af647503b67
Support for streaming: dont write indexes and dont signal HAS_INDEX in header. Also set filesize to max in this case.
alex
parents:
863
diff
changeset
|
631 } |
119 | 632 put_flush_packet(pb); |
102
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
633 |
5597
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
634 for (i=0; i<s->nb_streams; i++) { |
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
635 AVIStream *avist= s->streams[i]->priv_data; |
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
636 for (j=0; j<avist->indexes.ents_allocated/AVI_INDEX_CLUSTER_SIZE; j++) |
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
637 av_free(avist->indexes.cluster[j]); |
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
638 av_freep(&avist->indexes.cluster); |
d7c68046a431
Introduce AVIStream struct and move stream based variables to it.
michael
parents:
5058
diff
changeset
|
639 avist->indexes.ents_allocated = avist->indexes.entry = 0; |
119 | 640 } |
885 | 641 |
102
c48108fe538e
AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
94
diff
changeset
|
642 return res; |
0 | 643 } |
644 | |
1169 | 645 AVOutputFormat avi_muxer = { |
0 | 646 "avi", |
3424
7a0230981402
Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents:
3177
diff
changeset
|
647 NULL_IF_CONFIG_SMALL("AVI format"), |
0 | 648 "video/x-msvideo", |
649 "avi", | |
650 sizeof(AVIContext), | |
651 CODEC_ID_MP2, | |
106
4da5d55b3690
we really shouldnt use M$* as default codec -> use MPEG4 as default
michaelni
parents:
105
diff
changeset
|
652 CODEC_ID_MPEG4, |
0 | 653 avi_write_header, |
654 avi_write_packet, | |
655 avi_write_trailer, | |
5058
33a244b7ca65
Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents:
5044
diff
changeset
|
656 .codec_tag= (const AVCodecTag* const []){ff_codec_bmp_tags, ff_codec_wav_tags, 0}, |
4567
963e3b76c7a6
Add AVFMT_VARIABLE_FPS to specify which muxers do not need duplicated frames.
michael
parents:
4477
diff
changeset
|
657 .flags= AVFMT_VARIABLE_FPS, |
0 | 658 }; |