annotate avienc.c @ 3797:5fc16ca7b356 libavformat

simplify size handling code
author bcoudurier
date Fri, 29 Aug 2008 22:03:18 +0000
parents f062deeedb8d
children b2977baec240
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1 /*
1415
3b00fb8ef8e4 replace coder/decoder file description in libavformat by muxer/demuxer
aurel
parents: 1358
diff changeset
2 * AVI muxer
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
3 * Copyright (c) 2000 Fabrice Bellard.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
15 * Lesser General Public License for more details.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
16 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
20 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
21 #include "avformat.h"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
24
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
25 /*
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 876
diff changeset
26 * TODO:
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
27 * - fill all fields if non streamed (nb_frames for example)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
28 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
29
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
30 #ifdef CONFIG_AVI_MUXER
119
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
31 typedef struct AVIIentry {
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
32 unsigned int flags, pos, len;
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
33 } AVIIentry;
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
34
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
35 #define AVI_INDEX_CLUSTER_SIZE 16384
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
36
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
37 typedef struct AVIIndex {
119
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
38 offset_t indx_start;
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
39 int entry;
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
40 int ents_allocated;
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
41 AVIIentry** cluster;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
42 } AVIIndex;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
43
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
44 typedef struct {
102
c48108fe538e AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 94
diff changeset
45 offset_t riff_start, movi_list, odml_list;
c48108fe538e AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 94
diff changeset
46 offset_t frames_hdr_all, frames_hdr_strm[MAX_STREAMS];
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
47 int audio_strm_length[MAX_STREAMS];
119
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
48 int riff_id;
479
d84d9d8bb0a4 pass timestamps correctly for -sync 0
michael
parents: 476
diff changeset
49 int packet_count[MAX_STREAMS];
119
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
50
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
51 AVIIndex indexes[MAX_STREAMS];
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
52 } AVIContext;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
53
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 876
diff changeset
54 static inline AVIIentry* avi_get_ientry(AVIIndex* idx, int ent_id)
119
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
55 {
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
56 int cl = ent_id / AVI_INDEX_CLUSTER_SIZE;
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
57 int id = ent_id % AVI_INDEX_CLUSTER_SIZE;
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
58 return &idx->cluster[cl][id];
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
59 }
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
60
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 876
diff changeset
61 static offset_t avi_start_new_riff(AVIContext *avi, ByteIOContext *pb,
102
c48108fe538e AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 94
diff changeset
62 const char* riff_tag, const char* list_tag)
c48108fe538e AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 94
diff changeset
63 {
c48108fe538e AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 94
diff changeset
64 offset_t loff;
119
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
65 int i;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 876
diff changeset
66
119
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
67 avi->riff_id++;
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
68 for (i=0; i<MAX_STREAMS; i++)
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
69 avi->indexes[i].entry = 0;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 876
diff changeset
70
102
c48108fe538e AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 94
diff changeset
71 avi->riff_start = start_tag(pb, "RIFF");
c48108fe538e AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 94
diff changeset
72 put_tag(pb, riff_tag);
c48108fe538e AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 94
diff changeset
73 loff = start_tag(pb, "LIST");
c48108fe538e AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 94
diff changeset
74 put_tag(pb, list_tag);
c48108fe538e AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 94
diff changeset
75 return loff;
c48108fe538e AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 94
diff changeset
76 }
c48108fe538e AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 94
diff changeset
77
1332
7474cc6383d4 fix some signedness warnings
mru
parents: 1297
diff changeset
78 static char* avi_stream2fourcc(char* tag, int index, enum CodecType type)
119
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
79 {
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
80 tag[0] = '0';
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
81 tag[1] = '0' + index;
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
82 if (type == CODEC_TYPE_VIDEO) {
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
83 tag[2] = 'd';
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
84 tag[3] = 'c';
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
85 } else {
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
86 tag[2] = 'w';
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
87 tag[3] = 'b';
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
88 }
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
89 tag[4] = '\0';
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
90 return tag;
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
91 }
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
92
1256
2cddf00f92a6 AVI tag reading and writing patch by David Conrad.
banan
parents: 1172
diff changeset
93 static void avi_write_info_tag(ByteIOContext *pb, const char *tag, const char *str)
2cddf00f92a6 AVI tag reading and writing patch by David Conrad.
banan
parents: 1172
diff changeset
94 {
2cddf00f92a6 AVI tag reading and writing patch by David Conrad.
banan
parents: 1172
diff changeset
95 int len = strlen(str);
2cddf00f92a6 AVI tag reading and writing patch by David Conrad.
banan
parents: 1172
diff changeset
96 if (len > 0) {
2cddf00f92a6 AVI tag reading and writing patch by David Conrad.
banan
parents: 1172
diff changeset
97 len++;
2cddf00f92a6 AVI tag reading and writing patch by David Conrad.
banan
parents: 1172
diff changeset
98 put_tag(pb, tag);
2cddf00f92a6 AVI tag reading and writing patch by David Conrad.
banan
parents: 1172
diff changeset
99 put_le32(pb, len);
2cddf00f92a6 AVI tag reading and writing patch by David Conrad.
banan
parents: 1172
diff changeset
100 put_strz(pb, str);
2cddf00f92a6 AVI tag reading and writing patch by David Conrad.
banan
parents: 1172
diff changeset
101 if (len & 1)
2cddf00f92a6 AVI tag reading and writing patch by David Conrad.
banan
parents: 1172
diff changeset
102 put_byte(pb, 0);
2cddf00f92a6 AVI tag reading and writing patch by David Conrad.
banan
parents: 1172
diff changeset
103 }
2cddf00f92a6 AVI tag reading and writing patch by David Conrad.
banan
parents: 1172
diff changeset
104 }
2cddf00f92a6 AVI tag reading and writing patch by David Conrad.
banan
parents: 1172
diff changeset
105
1267
47ade5d414f9 fix ODML AVI Duration for files > 2GB
gpoirier
parents: 1256
diff changeset
106 static int avi_write_counters(AVFormatContext* s, int riff_id)
47ade5d414f9 fix ODML AVI Duration for files > 2GB
gpoirier
parents: 1256
diff changeset
107 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2227
diff changeset
108 ByteIOContext *pb = s->pb;
1267
47ade5d414f9 fix ODML AVI Duration for files > 2GB
gpoirier
parents: 1256
diff changeset
109 AVIContext *avi = s->priv_data;
47ade5d414f9 fix ODML AVI Duration for files > 2GB
gpoirier
parents: 1256
diff changeset
110 int n, au_byterate, au_ssize, au_scale, nb_frames = 0;
47ade5d414f9 fix ODML AVI Duration for files > 2GB
gpoirier
parents: 1256
diff changeset
111 offset_t file_size;
47ade5d414f9 fix ODML AVI Duration for files > 2GB
gpoirier
parents: 1256
diff changeset
112 AVCodecContext* stream;
47ade5d414f9 fix ODML AVI Duration for files > 2GB
gpoirier
parents: 1256
diff changeset
113
47ade5d414f9 fix ODML AVI Duration for files > 2GB
gpoirier
parents: 1256
diff changeset
114 file_size = url_ftell(pb);
47ade5d414f9 fix ODML AVI Duration for files > 2GB
gpoirier
parents: 1256
diff changeset
115 for(n = 0; n < s->nb_streams; n++) {
47ade5d414f9 fix ODML AVI Duration for files > 2GB
gpoirier
parents: 1256
diff changeset
116 assert(avi->frames_hdr_strm[n]);
47ade5d414f9 fix ODML AVI Duration for files > 2GB
gpoirier
parents: 1256
diff changeset
117 stream = s->streams[n]->codec;
47ade5d414f9 fix ODML AVI Duration for files > 2GB
gpoirier
parents: 1256
diff changeset
118 url_fseek(pb, avi->frames_hdr_strm[n], SEEK_SET);
47ade5d414f9 fix ODML AVI Duration for files > 2GB
gpoirier
parents: 1256
diff changeset
119 ff_parse_specific_params(stream, &au_byterate, &au_ssize, &au_scale);
47ade5d414f9 fix ODML AVI Duration for files > 2GB
gpoirier
parents: 1256
diff changeset
120 if(au_ssize == 0) {
47ade5d414f9 fix ODML AVI Duration for files > 2GB
gpoirier
parents: 1256
diff changeset
121 put_le32(pb, avi->packet_count[n]);
47ade5d414f9 fix ODML AVI Duration for files > 2GB
gpoirier
parents: 1256
diff changeset
122 } else {
47ade5d414f9 fix ODML AVI Duration for files > 2GB
gpoirier
parents: 1256
diff changeset
123 put_le32(pb, avi->audio_strm_length[n] / au_ssize);
47ade5d414f9 fix ODML AVI Duration for files > 2GB
gpoirier
parents: 1256
diff changeset
124 }
47ade5d414f9 fix ODML AVI Duration for files > 2GB
gpoirier
parents: 1256
diff changeset
125 if(stream->codec_type == CODEC_TYPE_VIDEO)
47ade5d414f9 fix ODML AVI Duration for files > 2GB
gpoirier
parents: 1256
diff changeset
126 nb_frames = FFMAX(nb_frames, avi->packet_count[n]);
47ade5d414f9 fix ODML AVI Duration for files > 2GB
gpoirier
parents: 1256
diff changeset
127 }
47ade5d414f9 fix ODML AVI Duration for files > 2GB
gpoirier
parents: 1256
diff changeset
128 if(riff_id == 1) {
47ade5d414f9 fix ODML AVI Duration for files > 2GB
gpoirier
parents: 1256
diff changeset
129 assert(avi->frames_hdr_all);
47ade5d414f9 fix ODML AVI Duration for files > 2GB
gpoirier
parents: 1256
diff changeset
130 url_fseek(pb, avi->frames_hdr_all, SEEK_SET);
47ade5d414f9 fix ODML AVI Duration for files > 2GB
gpoirier
parents: 1256
diff changeset
131 put_le32(pb, nb_frames);
47ade5d414f9 fix ODML AVI Duration for files > 2GB
gpoirier
parents: 1256
diff changeset
132 }
47ade5d414f9 fix ODML AVI Duration for files > 2GB
gpoirier
parents: 1256
diff changeset
133 url_fseek(pb, file_size, SEEK_SET);
47ade5d414f9 fix ODML AVI Duration for files > 2GB
gpoirier
parents: 1256
diff changeset
134
47ade5d414f9 fix ODML AVI Duration for files > 2GB
gpoirier
parents: 1256
diff changeset
135 return 0;
47ade5d414f9 fix ODML AVI Duration for files > 2GB
gpoirier
parents: 1256
diff changeset
136 }
47ade5d414f9 fix ODML AVI Duration for files > 2GB
gpoirier
parents: 1256
diff changeset
137
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
138 static int avi_write_header(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
139 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
140 AVIContext *avi = s->priv_data;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2227
diff changeset
141 ByteIOContext *pb = s->pb;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
142 int bitrate, n, i, nb_frames, au_byterate, au_ssize, au_scale;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
143 AVCodecContext *stream, *video_enc;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
144 offset_t list1, list2, strh, strf;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
145
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
146 /* header list */
119
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
147 avi->riff_id = 0;
102
c48108fe538e AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 94
diff changeset
148 list1 = avi_start_new_riff(avi, pb, "AVI ", "hdrl");
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
149
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
150 /* avi header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
151 put_tag(pb, "avih");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
152 put_le32(pb, 14 * 4);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
153 bitrate = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
154
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
155 video_enc = NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
156 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
157 stream = s->streams[n]->codec;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
158 bitrate += stream->bit_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
159 if (stream->codec_type == CODEC_TYPE_VIDEO)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
160 video_enc = stream;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
161 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 876
diff changeset
162
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
163 nb_frames = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
164
36
1188ad85857a audio only avi patch by (Andriy Rysin <arysin at bcsii dot net>)
michaelni
parents: 15
diff changeset
165 if(video_enc){
1556
65b7b3ff4ed7 use the standard INT64_C() macro for 64-bit constants
mru
parents: 1443
diff changeset
166 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
167 } else {
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
168 put_le32(pb, 0);
36
1188ad85857a audio only avi patch by (Andriy Rysin <arysin at bcsii dot net>)
michaelni
parents: 15
diff changeset
169 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
170 put_le32(pb, bitrate / 8); /* XXX: not quite exact */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
171 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
172 if (url_is_streamed(pb))
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
173 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
174 else
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
175 put_le32(pb, AVIF_TRUSTCKTYPE | AVIF_HASINDEX | AVIF_ISINTERLEAVED); /* flags */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
176 avi->frames_hdr_all = url_ftell(pb); /* remember this offset to fill later */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
177 put_le32(pb, nb_frames); /* nb frames, filled later */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
178 put_le32(pb, 0); /* initial frame */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
179 put_le32(pb, s->nb_streams); /* nb streams */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
180 put_le32(pb, 1024 * 1024); /* suggested buffer size */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 876
diff changeset
181 if(video_enc){
992
d54472fc2d04 indention
michael
parents: 978
diff changeset
182 put_le32(pb, video_enc->width);
d54472fc2d04 indention
michael
parents: 978
diff changeset
183 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
184 } else {
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
185 put_le32(pb, 0);
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
186 put_le32(pb, 0);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 876
diff changeset
187 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
188 put_le32(pb, 0); /* reserved */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
189 put_le32(pb, 0); /* reserved */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
190 put_le32(pb, 0); /* reserved */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
191 put_le32(pb, 0); /* reserved */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 876
diff changeset
192
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
193 /* stream list */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
194 for(i=0;i<n;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
195 list2 = start_tag(pb, "LIST");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
196 put_tag(pb, "strl");
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 876
diff changeset
197
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 796
diff changeset
198 stream = s->streams[i]->codec;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
199
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
200 /* stream generic header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
201 strh = start_tag(pb, "strh");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
202 switch(stream->codec_type) {
781
ba478112ecb1 a step toward CODEC_TYPE_DATA support
michael
parents: 763
diff changeset
203 case CODEC_TYPE_VIDEO: put_tag(pb, "vids"); break;
ba478112ecb1 a step toward CODEC_TYPE_DATA support
michael
parents: 763
diff changeset
204 case CODEC_TYPE_AUDIO: put_tag(pb, "auds"); break;
ba478112ecb1 a step toward CODEC_TYPE_DATA support
michael
parents: 763
diff changeset
205 // case CODEC_TYPE_TEXT : put_tag(pb, "txts"); break;
ba478112ecb1 a step toward CODEC_TYPE_DATA support
michael
parents: 763
diff changeset
206 case CODEC_TYPE_DATA : put_tag(pb, "dats"); break;
ba478112ecb1 a step toward CODEC_TYPE_DATA support
michael
parents: 763
diff changeset
207 }
ba478112ecb1 a step toward CODEC_TYPE_DATA support
michael
parents: 763
diff changeset
208 if(stream->codec_type == CODEC_TYPE_VIDEO)
89
8e3cf4e9fc5a rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents: 85
diff changeset
209 put_le32(pb, stream->codec_tag);
781
ba478112ecb1 a step toward CODEC_TYPE_DATA support
michael
parents: 763
diff changeset
210 else
ba478112ecb1 a step toward CODEC_TYPE_DATA support
michael
parents: 763
diff changeset
211 put_le32(pb, 1);
ba478112ecb1 a step toward CODEC_TYPE_DATA support
michael
parents: 763
diff changeset
212 put_le32(pb, 0); /* flags */
ba478112ecb1 a step toward CODEC_TYPE_DATA support
michael
parents: 763
diff changeset
213 put_le16(pb, 0); /* priority */
ba478112ecb1 a step toward CODEC_TYPE_DATA support
michael
parents: 763
diff changeset
214 put_le16(pb, 0); /* language */
ba478112ecb1 a step toward CODEC_TYPE_DATA support
michael
parents: 763
diff changeset
215 put_le32(pb, 0); /* initial frame */
ba478112ecb1 a step toward CODEC_TYPE_DATA support
michael
parents: 763
diff changeset
216
ba478112ecb1 a step toward CODEC_TYPE_DATA support
michael
parents: 763
diff changeset
217 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
218
781
ba478112ecb1 a step toward CODEC_TYPE_DATA support
michael
parents: 763
diff changeset
219 put_le32(pb, au_scale); /* scale */
ba478112ecb1 a step toward CODEC_TYPE_DATA support
michael
parents: 763
diff changeset
220 put_le32(pb, au_byterate); /* rate */
ba478112ecb1 a step toward CODEC_TYPE_DATA support
michael
parents: 763
diff changeset
221 av_set_pts_info(s->streams[i], 64, au_scale, au_byterate);
ba478112ecb1 a step toward CODEC_TYPE_DATA support
michael
parents: 763
diff changeset
222
ba478112ecb1 a step toward CODEC_TYPE_DATA support
michael
parents: 763
diff changeset
223 put_le32(pb, 0); /* start */
ba478112ecb1 a step toward CODEC_TYPE_DATA support
michael
parents: 763
diff changeset
224 avi->frames_hdr_strm[i] = url_ftell(pb); /* remember this offset to fill later */
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
225 if (url_is_streamed(pb))
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
226 put_le32(pb, AVI_MAX_RIFF_SIZE); /* FIXME: this may be broken, but who cares */
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
227 else
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
228 put_le32(pb, 0); /* length, XXX: filled later */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 876
diff changeset
229
781
ba478112ecb1 a step toward CODEC_TYPE_DATA support
michael
parents: 763
diff changeset
230 /* suggested buffer size */ //FIXME set at the end to largest chunk
ba478112ecb1 a step toward CODEC_TYPE_DATA support
michael
parents: 763
diff changeset
231 if(stream->codec_type == CODEC_TYPE_VIDEO)
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 876
diff changeset
232 put_le32(pb, 1024 * 1024);
781
ba478112ecb1 a step toward CODEC_TYPE_DATA support
michael
parents: 763
diff changeset
233 else if(stream->codec_type == CODEC_TYPE_AUDIO)
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 876
diff changeset
234 put_le32(pb, 12 * 1024);
781
ba478112ecb1 a step toward CODEC_TYPE_DATA support
michael
parents: 763
diff changeset
235 else
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 876
diff changeset
236 put_le32(pb, 0);
781
ba478112ecb1 a step toward CODEC_TYPE_DATA support
michael
parents: 763
diff changeset
237 put_le32(pb, -1); /* quality */
ba478112ecb1 a step toward CODEC_TYPE_DATA support
michael
parents: 763
diff changeset
238 put_le32(pb, au_ssize); /* sample size */
ba478112ecb1 a step toward CODEC_TYPE_DATA support
michael
parents: 763
diff changeset
239 put_le32(pb, 0);
ba478112ecb1 a step toward CODEC_TYPE_DATA support
michael
parents: 763
diff changeset
240 put_le16(pb, stream->width);
ba478112ecb1 a step toward CODEC_TYPE_DATA support
michael
parents: 763
diff changeset
241 put_le16(pb, stream->height);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
242 end_tag(pb, strh);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
243
781
ba478112ecb1 a step toward CODEC_TYPE_DATA support
michael
parents: 763
diff changeset
244 if(stream->codec_type != CODEC_TYPE_DATA){
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
245 strf = start_tag(pb, "strf");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
246 switch(stream->codec_type) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
247 case CODEC_TYPE_VIDEO:
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
248 put_bmp_header(pb, stream, codec_bmp_tags, 0);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
249 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
250 case CODEC_TYPE_AUDIO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
251 if (put_wav_header(pb, stream) < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
252 av_free(avi);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
253 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
254 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
255 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
256 default:
537
558a093b04db do not call (av_)abort()
michael
parents: 521
diff changeset
257 return -1;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
258 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
259 end_tag(pb, strf);
781
ba478112ecb1 a step toward CODEC_TYPE_DATA support
michael
parents: 763
diff changeset
260 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 876
diff changeset
261
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
262 if (!url_is_streamed(pb)) {
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
263 unsigned char tag[5];
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
264 int j;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 876
diff changeset
265
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 876
diff changeset
266 /* Starting to lay out AVI OpenDML master index.
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
267 * We want to make it JUNK entry for now, since we'd
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
268 * like to get away without making AVI an OpenDML one
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
269 * for compatibility reasons.
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
270 */
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
271 avi->indexes[i].entry = avi->indexes[i].ents_allocated = 0;
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
272 avi->indexes[i].indx_start = start_tag(pb, "JUNK");
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
273 put_le16(pb, 4); /* wLongsPerEntry */
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
274 put_byte(pb, 0); /* bIndexSubType (0 == frame index) */
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
275 put_byte(pb, 0); /* bIndexType (0 == AVI_INDEX_OF_INDEXES) */
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
276 put_le32(pb, 0); /* nEntriesInUse (will fill out later on) */
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
277 put_tag(pb, avi_stream2fourcc(&tag[0], i, stream->codec_type));
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
278 /* dwChunkId */
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
279 put_le64(pb, 0); /* dwReserved[3]
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
280 put_le32(pb, 0); Must be 0. */
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
281 for (j=0; j < AVI_MASTER_INDEX_SIZE * 2; j++)
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
282 put_le64(pb, 0);
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
283 end_tag(pb, avi->indexes[i].indx_start);
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
284 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 876
diff changeset
285
3100
5f769b20cc76 Store aspect ratio in avis.
michael
parents: 2771
diff changeset
286 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
287 && 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
288 && s->streams[i]->sample_aspect_ratio.den>0){
3100
5f769b20cc76 Store aspect ratio in avis.
michael
parents: 2771
diff changeset
289 int vprp= start_tag(pb, "vprp");
3759
27537074f2a9 convert every muxer/demuxer to write/read sample_aspect_ratio from/to
aurel
parents: 3424
diff changeset
290 AVRational dar = av_mul_q(s->streams[i]->sample_aspect_ratio,
3100
5f769b20cc76 Store aspect ratio in avis.
michael
parents: 2771
diff changeset
291 (AVRational){stream->width, stream->height});
5f769b20cc76 Store aspect ratio in avis.
michael
parents: 2771
diff changeset
292 int num, den;
5f769b20cc76 Store aspect ratio in avis.
michael
parents: 2771
diff changeset
293 av_reduce(&num, &den, dar.num, dar.den, 0xFFFF);
5f769b20cc76 Store aspect ratio in avis.
michael
parents: 2771
diff changeset
294
5f769b20cc76 Store aspect ratio in avis.
michael
parents: 2771
diff changeset
295 put_le32(pb, 0); //video format = unknown
5f769b20cc76 Store aspect ratio in avis.
michael
parents: 2771
diff changeset
296 put_le32(pb, 0); //video standard= unknown
5f769b20cc76 Store aspect ratio in avis.
michael
parents: 2771
diff changeset
297 put_le32(pb, lrintf(1.0/av_q2d(stream->time_base)));
5f769b20cc76 Store aspect ratio in avis.
michael
parents: 2771
diff changeset
298 put_le32(pb, stream->width );
5f769b20cc76 Store aspect ratio in avis.
michael
parents: 2771
diff changeset
299 put_le32(pb, stream->height);
3177
f5ee8f2afc83 Fix aspect ratio.
michael
parents: 3100
diff changeset
300 put_le16(pb, den);
3100
5f769b20cc76 Store aspect ratio in avis.
michael
parents: 2771
diff changeset
301 put_le16(pb, num);
5f769b20cc76 Store aspect ratio in avis.
michael
parents: 2771
diff changeset
302 put_le32(pb, stream->width );
5f769b20cc76 Store aspect ratio in avis.
michael
parents: 2771
diff changeset
303 put_le32(pb, stream->height);
5f769b20cc76 Store aspect ratio in avis.
michael
parents: 2771
diff changeset
304 put_le32(pb, 1); //progressive FIXME
5f769b20cc76 Store aspect ratio in avis.
michael
parents: 2771
diff changeset
305
5f769b20cc76 Store aspect ratio in avis.
michael
parents: 2771
diff changeset
306 put_le32(pb, stream->height);
5f769b20cc76 Store aspect ratio in avis.
michael
parents: 2771
diff changeset
307 put_le32(pb, stream->width );
5f769b20cc76 Store aspect ratio in avis.
michael
parents: 2771
diff changeset
308 put_le32(pb, stream->height);
5f769b20cc76 Store aspect ratio in avis.
michael
parents: 2771
diff changeset
309 put_le32(pb, stream->width );
5f769b20cc76 Store aspect ratio in avis.
michael
parents: 2771
diff changeset
310 put_le32(pb, 0);
5f769b20cc76 Store aspect ratio in avis.
michael
parents: 2771
diff changeset
311 put_le32(pb, 0);
5f769b20cc76 Store aspect ratio in avis.
michael
parents: 2771
diff changeset
312
5f769b20cc76 Store aspect ratio in avis.
michael
parents: 2771
diff changeset
313 put_le32(pb, 0);
5f769b20cc76 Store aspect ratio in avis.
michael
parents: 2771
diff changeset
314 put_le32(pb, 0);
5f769b20cc76 Store aspect ratio in avis.
michael
parents: 2771
diff changeset
315 end_tag(pb, vprp);
5f769b20cc76 Store aspect ratio in avis.
michael
parents: 2771
diff changeset
316 }
5f769b20cc76 Store aspect ratio in avis.
michael
parents: 2771
diff changeset
317
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
318 end_tag(pb, list2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
319 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 876
diff changeset
320
119
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
321 if (!url_is_streamed(pb)) {
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
322 /* AVI could become an OpenDML one, if it grows beyond 2Gb range */
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
323 avi->odml_list = start_tag(pb, "JUNK");
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
324 put_tag(pb, "odml");
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
325 put_tag(pb, "dmlh");
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
326 put_le32(pb, 248);
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
327 for (i = 0; i < 248; i+= 4)
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
328 put_le32(pb, 0);
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
329 end_tag(pb, avi->odml_list);
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
330 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
331
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
332 end_tag(pb, list1);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 876
diff changeset
333
1256
2cddf00f92a6 AVI tag reading and writing patch by David Conrad.
banan
parents: 1172
diff changeset
334 list2 = start_tag(pb, "LIST");
2cddf00f92a6 AVI tag reading and writing patch by David Conrad.
banan
parents: 1172
diff changeset
335 put_tag(pb, "INFO");
2cddf00f92a6 AVI tag reading and writing patch by David Conrad.
banan
parents: 1172
diff changeset
336 avi_write_info_tag(pb, "INAM", s->title);
2cddf00f92a6 AVI tag reading and writing patch by David Conrad.
banan
parents: 1172
diff changeset
337 avi_write_info_tag(pb, "IART", s->author);
2cddf00f92a6 AVI tag reading and writing patch by David Conrad.
banan
parents: 1172
diff changeset
338 avi_write_info_tag(pb, "ICOP", s->copyright);
2cddf00f92a6 AVI tag reading and writing patch by David Conrad.
banan
parents: 1172
diff changeset
339 avi_write_info_tag(pb, "ICMT", s->comment);
2cddf00f92a6 AVI tag reading and writing patch by David Conrad.
banan
parents: 1172
diff changeset
340 avi_write_info_tag(pb, "IPRD", s->album);
2cddf00f92a6 AVI tag reading and writing patch by David Conrad.
banan
parents: 1172
diff changeset
341 avi_write_info_tag(pb, "IGNR", s->genre);
1297
f63d2066f478 Allow to store the the track number though the IPRT (part) tag in AVI.
gpoirier
parents: 1267
diff changeset
342 if (s->track) {
f63d2066f478 Allow to store the the track number though the IPRT (part) tag in AVI.
gpoirier
parents: 1267
diff changeset
343 char str_track[4];
f63d2066f478 Allow to store the the track number though the IPRT (part) tag in AVI.
gpoirier
parents: 1267
diff changeset
344 snprintf(str_track, 4, "%d", s->track);
f63d2066f478 Allow to store the the track number though the IPRT (part) tag in AVI.
gpoirier
parents: 1267
diff changeset
345 avi_write_info_tag(pb, "IPRT", str_track);
f63d2066f478 Allow to store the the track number though the IPRT (part) tag in AVI.
gpoirier
parents: 1267
diff changeset
346 }
1256
2cddf00f92a6 AVI tag reading and writing patch by David Conrad.
banan
parents: 1172
diff changeset
347 if(!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT))
2cddf00f92a6 AVI tag reading and writing patch by David Conrad.
banan
parents: 1172
diff changeset
348 avi_write_info_tag(pb, "ISFT", LIBAVFORMAT_IDENT);
2cddf00f92a6 AVI tag reading and writing patch by David Conrad.
banan
parents: 1172
diff changeset
349 end_tag(pb, list2);
2cddf00f92a6 AVI tag reading and writing patch by David Conrad.
banan
parents: 1172
diff changeset
350
2cddf00f92a6 AVI tag reading and writing patch by David Conrad.
banan
parents: 1172
diff changeset
351 /* some padding for easier tag editing */
2cddf00f92a6 AVI tag reading and writing patch by David Conrad.
banan
parents: 1172
diff changeset
352 list2 = start_tag(pb, "JUNK");
2cddf00f92a6 AVI tag reading and writing patch by David Conrad.
banan
parents: 1172
diff changeset
353 for (i = 0; i < 1016; i += 4)
2cddf00f92a6 AVI tag reading and writing patch by David Conrad.
banan
parents: 1172
diff changeset
354 put_le32(pb, 0);
2cddf00f92a6 AVI tag reading and writing patch by David Conrad.
banan
parents: 1172
diff changeset
355 end_tag(pb, list2);
2cddf00f92a6 AVI tag reading and writing patch by David Conrad.
banan
parents: 1172
diff changeset
356
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
357 avi->movi_list = start_tag(pb, "LIST");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
358 put_tag(pb, "movi");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
359
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
360 put_flush_packet(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
361
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
362 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
363 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
364
119
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
365 static int avi_write_ix(AVFormatContext *s)
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
366 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2227
diff changeset
367 ByteIOContext *pb = s->pb;
119
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
368 AVIContext *avi = s->priv_data;
1332
7474cc6383d4 fix some signedness warnings
mru
parents: 1297
diff changeset
369 char tag[5];
7474cc6383d4 fix some signedness warnings
mru
parents: 1297
diff changeset
370 char ix_tag[] = "ix00";
119
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
371 int i, j;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 876
diff changeset
372
976
c4a67d8fa68f replace if by assert as it should never by true
michael
parents: 969
diff changeset
373 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
374
119
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
375 if (avi->riff_id > AVI_MASTER_INDEX_SIZE)
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
376 return -1;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 876
diff changeset
377
119
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
378 for (i=0;i<s->nb_streams;i++) {
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
379 offset_t ix, pos;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 876
diff changeset
380
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
381 avi_stream2fourcc(&tag[0], i, s->streams[i]->codec->codec_type);
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
382 ix_tag[3] = '0' + i;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 876
diff changeset
383
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
384 /* Writing AVI OpenDML leaf index chunk */
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
385 ix = url_ftell(pb);
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
386 put_tag(pb, &ix_tag[0]); /* ix?? */
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
387 put_le32(pb, avi->indexes[i].entry * 8 + 24);
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
388 /* chunk size */
119
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
389 put_le16(pb, 2); /* wLongsPerEntry */
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
390 put_byte(pb, 0); /* bIndexSubType (0 == frame index) */
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
391 put_byte(pb, 1); /* bIndexType (1 == AVI_INDEX_OF_CHUNKS) */
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
392 put_le32(pb, avi->indexes[i].entry);
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
393 /* nEntriesInUse */
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
394 put_tag(pb, &tag[0]); /* dwChunkId */
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
395 put_le64(pb, avi->movi_list);/* qwBaseOffset */
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
396 put_le32(pb, 0); /* dwReserved_3 (must be 0) */
119
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
397
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
398 for (j=0; j<avi->indexes[i].entry; j++) {
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
399 AVIIentry* ie = avi_get_ientry(&avi->indexes[i], j);
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
400 put_le32(pb, ie->pos + 8);
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
401 put_le32(pb, ((uint32_t)ie->len & ~0x80000000) |
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
402 (ie->flags & 0x10 ? 0 : 0x80000000));
119
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
403 }
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
404 put_flush_packet(pb);
119
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
405 pos = url_ftell(pb);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 876
diff changeset
406
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
407 /* Updating one entry in the AVI OpenDML master index */
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
408 url_fseek(pb, avi->indexes[i].indx_start - 8, SEEK_SET);
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
409 put_tag(pb, "indx"); /* enabling this entry */
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
410 url_fskip(pb, 8);
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
411 put_le32(pb, avi->riff_id); /* nEntriesInUse */
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
412 url_fskip(pb, 16*avi->riff_id);
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
413 put_le64(pb, ix); /* qwOffset */
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
414 put_le32(pb, pos - ix); /* dwSize */
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
415 put_le32(pb, avi->indexes[i].entry); /* dwDuration */
119
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
416
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
417 url_fseek(pb, pos, SEEK_SET);
119
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
418 }
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
419 return 0;
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
420 }
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
421
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
422 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
423 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2227
diff changeset
424 ByteIOContext *pb = s->pb;
102
c48108fe538e AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 94
diff changeset
425 AVIContext *avi = s->priv_data;
1267
47ade5d414f9 fix ODML AVI Duration for files > 2GB
gpoirier
parents: 1256
diff changeset
426 offset_t idx_chunk;
47ade5d414f9 fix ODML AVI Duration for files > 2GB
gpoirier
parents: 1256
diff changeset
427 int i;
1332
7474cc6383d4 fix some signedness warnings
mru
parents: 1297
diff changeset
428 char tag[5];
102
c48108fe538e AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 94
diff changeset
429
c48108fe538e AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 94
diff changeset
430 if (!url_is_streamed(pb)) {
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
431 AVIIentry* ie = 0, *tie;
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
432 int entry[MAX_STREAMS];
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
433 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
434
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
435 idx_chunk = start_tag(pb, "idx1");
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
436 memset(&entry[0], 0, sizeof(entry));
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
437 do {
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
438 empty = 1;
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
439 for (i=0; i<s->nb_streams; i++) {
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
440 if (avi->indexes[i].entry <= entry[i])
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
441 continue;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 876
diff changeset
442
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
443 tie = avi_get_ientry(&avi->indexes[i], entry[i]);
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
444 if (empty || tie->pos < ie->pos) {
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
445 ie = tie;
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
446 stream_id = i;
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
447 }
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
448 empty = 0;
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
449 }
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
450 if (!empty) {
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
451 avi_stream2fourcc(&tag[0], stream_id,
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
452 s->streams[stream_id]->codec->codec_type);
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
453 put_tag(pb, &tag[0]);
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
454 put_le32(pb, ie->flags);
119
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
455 put_le32(pb, ie->pos);
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
456 put_le32(pb, ie->len);
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
457 entry[stream_id]++;
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
458 }
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
459 } while (!empty);
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
460 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
461
1267
47ade5d414f9 fix ODML AVI Duration for files > 2GB
gpoirier
parents: 1256
diff changeset
462 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
463 }
c48108fe538e AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 94
diff changeset
464 return 0;
c48108fe538e AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 94
diff changeset
465 }
c48108fe538e AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 94
diff changeset
466
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 458
diff changeset
467 static int avi_write_packet(AVFormatContext *s, AVPacket *pkt)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
468 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
469 AVIContext *avi = s->priv_data;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2227
diff changeset
470 ByteIOContext *pb = s->pb;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
471 unsigned char tag[5];
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 458
diff changeset
472 unsigned int flags=0;
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 458
diff changeset
473 const int stream_index= pkt->stream_index;
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 796
diff changeset
474 AVCodecContext *enc= s->streams[stream_index]->codec;
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 458
diff changeset
475 int size= pkt->size;
102
c48108fe538e AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 94
diff changeset
476
1443
404048ea11bc Replace most of the %lld and %llx by their (cleaner) PRI*64 counterparts.
diego
parents: 1415
diff changeset
477 // av_log(s, AV_LOG_DEBUG, "%"PRId64" %d %d\n", pkt->dts, avi->packet_count[stream_index], stream_index);
724
43e5b8eea963 fix vorbis in avi
michael
parents: 720
diff changeset
478 while(enc->block_align==0 && pkt->dts != AV_NOPTS_VALUE && pkt->dts > avi->packet_count[stream_index]){
479
d84d9d8bb0a4 pass timestamps correctly for -sync 0
michael
parents: 476
diff changeset
479 AVPacket empty_packet;
d84d9d8bb0a4 pass timestamps correctly for -sync 0
michael
parents: 476
diff changeset
480
d84d9d8bb0a4 pass timestamps correctly for -sync 0
michael
parents: 476
diff changeset
481 av_init_packet(&empty_packet);
d84d9d8bb0a4 pass timestamps correctly for -sync 0
michael
parents: 476
diff changeset
482 empty_packet.size= 0;
d84d9d8bb0a4 pass timestamps correctly for -sync 0
michael
parents: 476
diff changeset
483 empty_packet.data= NULL;
d84d9d8bb0a4 pass timestamps correctly for -sync 0
michael
parents: 476
diff changeset
484 empty_packet.stream_index= stream_index;
d84d9d8bb0a4 pass timestamps correctly for -sync 0
michael
parents: 476
diff changeset
485 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
486 // av_log(s, AV_LOG_DEBUG, "dup %"PRId64" %d\n", pkt->dts, avi->packet_count[stream_index]);
479
d84d9d8bb0a4 pass timestamps correctly for -sync 0
michael
parents: 476
diff changeset
487 }
d84d9d8bb0a4 pass timestamps correctly for -sync 0
michael
parents: 476
diff changeset
488 avi->packet_count[stream_index]++;
d84d9d8bb0a4 pass timestamps correctly for -sync 0
michael
parents: 476
diff changeset
489
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
490 // Make sure to put an OpenDML chunk when the file size exceeds the limits
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 876
diff changeset
491 if (!url_is_streamed(pb) &&
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
492 (url_ftell(pb) - avi->riff_start > AVI_MAX_RIFF_SIZE)) {
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 876
diff changeset
493
119
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
494 avi_write_ix(s);
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
495 end_tag(pb, avi->movi_list);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 876
diff changeset
496
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
497 if (avi->riff_id == 1)
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
498 avi_write_idx1(s);
119
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
499
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
500 end_tag(pb, avi->riff_start);
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
501 avi->movi_list = avi_start_new_riff(avi, pb, "AVIX", "movi");
102
c48108fe538e AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 94
diff changeset
502 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 876
diff changeset
503
119
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
504 avi_stream2fourcc(&tag[0], stream_index, enc->codec_type);
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 458
diff changeset
505 if(pkt->flags&PKT_FLAG_KEY)
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 458
diff changeset
506 flags = 0x10;
119
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
507 if (enc->codec_type == CODEC_TYPE_AUDIO) {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
508 avi->audio_strm_length[stream_index] += size;
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 458
diff changeset
509 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
510
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2227
diff changeset
511 if (!url_is_streamed(s->pb)) {
119
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
512 AVIIndex* idx = &avi->indexes[stream_index];
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
513 int cl = idx->entry / AVI_INDEX_CLUSTER_SIZE;
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
514 int id = idx->entry % AVI_INDEX_CLUSTER_SIZE;
119
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
515 if (idx->ents_allocated <= idx->entry) {
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
516 idx->cluster = av_realloc(idx->cluster, (cl+1)*sizeof(void*));
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
517 if (!idx->cluster)
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
518 return -1;
119
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
519 idx->cluster[cl] = av_malloc(AVI_INDEX_CLUSTER_SIZE*sizeof(AVIIentry));
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
520 if (!idx->cluster[cl])
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
521 return -1;
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
522 idx->ents_allocated += AVI_INDEX_CLUSTER_SIZE;
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
523 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 876
diff changeset
524
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
525 idx->cluster[cl][id].flags = flags;
119
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
526 idx->cluster[cl][id].pos = url_ftell(pb) - avi->movi_list;
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
527 idx->cluster[cl][id].len = size;
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
528 idx->entry++;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
529 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 876
diff changeset
530
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
531 put_buffer(pb, tag, 4);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
532 put_le32(pb, size);
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 458
diff changeset
533 put_buffer(pb, pkt->data, size);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
534 if (size & 1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
535 put_byte(pb, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
536
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
537 put_flush_packet(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
538 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
539 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
540
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
541 static int avi_write_trailer(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
542 {
102
c48108fe538e AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 94
diff changeset
543 AVIContext *avi = s->priv_data;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2227
diff changeset
544 ByteIOContext *pb = s->pb;
102
c48108fe538e AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 94
diff changeset
545 int res = 0;
119
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
546 int i, j, n, nb_frames;
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
547 offset_t file_size;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
548
1676
507177b7444c fix indention (dunno why it was messed up ...)
michael
parents: 1556
diff changeset
549 if (!url_is_streamed(pb)){
507177b7444c fix indention (dunno why it was messed up ...)
michael
parents: 1556
diff changeset
550 if (avi->riff_id == 1) {
507177b7444c fix indention (dunno why it was messed up ...)
michael
parents: 1556
diff changeset
551 end_tag(pb, avi->movi_list);
507177b7444c fix indention (dunno why it was messed up ...)
michael
parents: 1556
diff changeset
552 res = avi_write_idx1(s);
507177b7444c fix indention (dunno why it was messed up ...)
michael
parents: 1556
diff changeset
553 end_tag(pb, avi->riff_start);
507177b7444c fix indention (dunno why it was messed up ...)
michael
parents: 1556
diff changeset
554 } else {
507177b7444c fix indention (dunno why it was messed up ...)
michael
parents: 1556
diff changeset
555 avi_write_ix(s);
507177b7444c fix indention (dunno why it was messed up ...)
michael
parents: 1556
diff changeset
556 end_tag(pb, avi->movi_list);
507177b7444c fix indention (dunno why it was messed up ...)
michael
parents: 1556
diff changeset
557 end_tag(pb, avi->riff_start);
119
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
558
1676
507177b7444c fix indention (dunno why it was messed up ...)
michael
parents: 1556
diff changeset
559 file_size = url_ftell(pb);
507177b7444c fix indention (dunno why it was messed up ...)
michael
parents: 1556
diff changeset
560 url_fseek(pb, avi->odml_list - 8, SEEK_SET);
507177b7444c fix indention (dunno why it was messed up ...)
michael
parents: 1556
diff changeset
561 put_tag(pb, "LIST"); /* Making this AVI OpenDML one */
507177b7444c fix indention (dunno why it was messed up ...)
michael
parents: 1556
diff changeset
562 url_fskip(pb, 16);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
563
1676
507177b7444c fix indention (dunno why it was messed up ...)
michael
parents: 1556
diff changeset
564 for (n=nb_frames=0;n<s->nb_streams;n++) {
507177b7444c fix indention (dunno why it was messed up ...)
michael
parents: 1556
diff changeset
565 AVCodecContext *stream = s->streams[n]->codec;
507177b7444c fix indention (dunno why it was messed up ...)
michael
parents: 1556
diff changeset
566 if (stream->codec_type == CODEC_TYPE_VIDEO) {
507177b7444c fix indention (dunno why it was messed up ...)
michael
parents: 1556
diff changeset
567 if (nb_frames < avi->packet_count[n])
507177b7444c fix indention (dunno why it was messed up ...)
michael
parents: 1556
diff changeset
568 nb_frames = avi->packet_count[n];
507177b7444c fix indention (dunno why it was messed up ...)
michael
parents: 1556
diff changeset
569 } else {
507177b7444c fix indention (dunno why it was messed up ...)
michael
parents: 1556
diff changeset
570 if (stream->codec_id == CODEC_ID_MP2 || stream->codec_id == CODEC_ID_MP3) {
507177b7444c fix indention (dunno why it was messed up ...)
michael
parents: 1556
diff changeset
571 nb_frames += avi->packet_count[n];
507177b7444c fix indention (dunno why it was messed up ...)
michael
parents: 1556
diff changeset
572 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
573 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
574 }
1676
507177b7444c fix indention (dunno why it was messed up ...)
michael
parents: 1556
diff changeset
575 put_le32(pb, nb_frames);
507177b7444c fix indention (dunno why it was messed up ...)
michael
parents: 1556
diff changeset
576 url_fseek(pb, file_size, SEEK_SET);
507177b7444c fix indention (dunno why it was messed up ...)
michael
parents: 1556
diff changeset
577
507177b7444c fix indention (dunno why it was messed up ...)
michael
parents: 1556
diff changeset
578 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
579 }
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
580 }
119
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
581 put_flush_packet(pb);
102
c48108fe538e AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 94
diff changeset
582
119
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
583 for (i=0; i<MAX_STREAMS; i++) {
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
584 for (j=0; j<avi->indexes[i].ents_allocated/AVI_INDEX_CLUSTER_SIZE; j++)
119
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
585 av_free(avi->indexes[i].cluster[j]);
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
586 av_free(avi->indexes[i].cluster);
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
587 avi->indexes[i].cluster = NULL;
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
588 avi->indexes[i].ents_allocated = avi->indexes[i].entry = 0;
119
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 106
diff changeset
589 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 876
diff changeset
590
102
c48108fe538e AVI > 2Gb (OpenDML) generation patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 94
diff changeset
591 return res;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
592 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
593
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
594 AVOutputFormat avi_muxer = {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
595 "avi",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 3177
diff changeset
596 NULL_IF_CONFIG_SMALL("AVI format"),
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
597 "video/x-msvideo",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
598 "avi",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
599 sizeof(AVIContext),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
600 CODEC_ID_MP2,
106
4da5d55b3690 we really shouldnt use M$* as default codec -> use MPEG4 as default
michaelni
parents: 105
diff changeset
601 CODEC_ID_MPEG4,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
602 avi_write_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
603 avi_write_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
604 avi_write_trailer,
3766
f062deeedb8d Change codec_tag type from const struct AVCodecTag ** to const struct AVCodecTag * const *
reimar
parents: 3759
diff changeset
605 .codec_tag= (const AVCodecTag* const []){codec_bmp_tags, codec_wav_tags, 0},
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
606 };
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
607 #endif //CONFIG_AVI_MUXER