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