avienc.c
Go to the documentation of this file.
1 /*
2  * AVI muxer
3  * Copyright (c) 2000 Fabrice Bellard
4  *
5  * This file is part of Libav.
6  *
7  * Libav is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * Libav is distributed in the hope that it will be useful,
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
18  * License along with Libav; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 #include "avformat.h"
22 #include "internal.h"
23 #include "avi.h"
24 #include "avio_internal.h"
25 #include "riff.h"
26 #include "libavutil/intreadwrite.h"
27 #include "libavutil/dict.h"
28 
29 /*
30  * TODO:
31  * - fill all fields if non streamed (nb_frames for example)
32  */
33 
34 typedef struct AVIIentry {
35  unsigned int flags, pos, len;
36 } AVIIentry;
37 
38 #define AVI_INDEX_CLUSTER_SIZE 16384
39 
40 typedef struct AVIIndex {
41  int64_t indx_start;
42  int entry;
45 } AVIIndex;
46 
47 typedef struct {
48  int64_t riff_start, movi_list, odml_list;
49  int64_t frames_hdr_all;
50  int riff_id;
51 } AVIContext;
52 
53 typedef struct {
54  int64_t frames_hdr_strm;
57  int entry;
58 
60 } AVIStream ;
61 
62 static inline AVIIentry* avi_get_ientry(AVIIndex* idx, int ent_id)
63 {
64  int cl = ent_id / AVI_INDEX_CLUSTER_SIZE;
65  int id = ent_id % AVI_INDEX_CLUSTER_SIZE;
66  return &idx->cluster[cl][id];
67 }
68 
70  const char* riff_tag, const char* list_tag)
71 {
72  AVIContext *avi= s->priv_data;
73  int64_t loff;
74  int i;
75 
76  avi->riff_id++;
77  for (i=0; i<s->nb_streams; i++){
78  AVIStream *avist= s->streams[i]->priv_data;
79  avist->indexes.entry = 0;
80  }
81 
82  avi->riff_start = ff_start_tag(pb, "RIFF");
83  ffio_wfourcc(pb, riff_tag);
84  loff = ff_start_tag(pb, "LIST");
85  ffio_wfourcc(pb, list_tag);
86  return loff;
87 }
88 
89 static char* avi_stream2fourcc(char* tag, int index, enum AVMediaType type)
90 {
91  tag[0] = '0' + index/10;
92  tag[1] = '0' + index%10;
93  if (type == AVMEDIA_TYPE_VIDEO) {
94  tag[2] = 'd';
95  tag[3] = 'c';
96  } else if (type == AVMEDIA_TYPE_SUBTITLE) {
97  // note: this is not an official code
98  tag[2] = 's';
99  tag[3] = 'b';
100  } else {
101  tag[2] = 'w';
102  tag[3] = 'b';
103  }
104  tag[4] = '\0';
105  return tag;
106 }
107 
108 static void avi_write_info_tag(AVIOContext *pb, const char *tag, const char *str)
109 {
110  int len = strlen(str);
111  if (len > 0) {
112  len++;
113  ffio_wfourcc(pb, tag);
114  avio_wl32(pb, len);
115  avio_put_str(pb, str);
116  if (len & 1)
117  avio_w8(pb, 0);
118  }
119 }
120 
121 static int avi_write_counters(AVFormatContext* s, int riff_id)
122 {
123  AVIOContext *pb = s->pb;
124  AVIContext *avi = s->priv_data;
125  int n, au_byterate, au_ssize, au_scale, nb_frames = 0;
126  int64_t file_size;
127  AVCodecContext* stream;
128 
129  file_size = avio_tell(pb);
130  for(n = 0; n < s->nb_streams; n++) {
131  AVIStream *avist= s->streams[n]->priv_data;
132 
133  assert(avist->frames_hdr_strm);
134  stream = s->streams[n]->codec;
135  avio_seek(pb, avist->frames_hdr_strm, SEEK_SET);
136  ff_parse_specific_params(stream, &au_byterate, &au_ssize, &au_scale);
137  if(au_ssize == 0) {
138  avio_wl32(pb, avist->packet_count);
139  } else {
140  avio_wl32(pb, avist->audio_strm_length / au_ssize);
141  }
142  if(stream->codec_type == AVMEDIA_TYPE_VIDEO)
143  nb_frames = FFMAX(nb_frames, avist->packet_count);
144  }
145  if(riff_id == 1) {
146  assert(avi->frames_hdr_all);
147  avio_seek(pb, avi->frames_hdr_all, SEEK_SET);
148  avio_wl32(pb, nb_frames);
149  }
150  avio_seek(pb, file_size, SEEK_SET);
151 
152  return 0;
153 }
154 
156 {
157  AVIContext *avi = s->priv_data;
158  AVIOContext *pb = s->pb;
159  int bitrate, n, i, nb_frames, au_byterate, au_ssize, au_scale;
160  AVCodecContext *stream, *video_enc;
161  int64_t list1, list2, strh, strf;
163 
164  if (s->nb_streams > AVI_MAX_STREAM_COUNT) {
165  av_log(s, AV_LOG_ERROR, "AVI does not support >%d streams\n",
167  return -1;
168  }
169 
170  for(n=0;n<s->nb_streams;n++) {
171  s->streams[n]->priv_data= av_mallocz(sizeof(AVIStream));
172  if(!s->streams[n]->priv_data)
173  return AVERROR(ENOMEM);
174  }
175 
176  /* header list */
177  avi->riff_id = 0;
178  list1 = avi_start_new_riff(s, pb, "AVI ", "hdrl");
179 
180  /* avi header */
181  ffio_wfourcc(pb, "avih");
182  avio_wl32(pb, 14 * 4);
183  bitrate = 0;
184 
185  video_enc = NULL;
186  for(n=0;n<s->nb_streams;n++) {
187  stream = s->streams[n]->codec;
188  bitrate += stream->bit_rate;
189  if (stream->codec_type == AVMEDIA_TYPE_VIDEO)
190  video_enc = stream;
191  }
192 
193  nb_frames = 0;
194 
195  if(video_enc){
196  avio_wl32(pb, (uint32_t)(INT64_C(1000000) * video_enc->time_base.num / video_enc->time_base.den));
197  } else {
198  avio_wl32(pb, 0);
199  }
200  avio_wl32(pb, bitrate / 8); /* XXX: not quite exact */
201  avio_wl32(pb, 0); /* padding */
202  if (!pb->seekable)
203  avio_wl32(pb, AVIF_TRUSTCKTYPE | AVIF_ISINTERLEAVED); /* flags */
204  else
206  avi->frames_hdr_all = avio_tell(pb); /* remember this offset to fill later */
207  avio_wl32(pb, nb_frames); /* nb frames, filled later */
208  avio_wl32(pb, 0); /* initial frame */
209  avio_wl32(pb, s->nb_streams); /* nb streams */
210  avio_wl32(pb, 1024 * 1024); /* suggested buffer size */
211  if(video_enc){
212  avio_wl32(pb, video_enc->width);
213  avio_wl32(pb, video_enc->height);
214  } else {
215  avio_wl32(pb, 0);
216  avio_wl32(pb, 0);
217  }
218  avio_wl32(pb, 0); /* reserved */
219  avio_wl32(pb, 0); /* reserved */
220  avio_wl32(pb, 0); /* reserved */
221  avio_wl32(pb, 0); /* reserved */
222 
223  /* stream list */
224  for(i=0;i<n;i++) {
225  AVIStream *avist= s->streams[i]->priv_data;
226  list2 = ff_start_tag(pb, "LIST");
227  ffio_wfourcc(pb, "strl");
228 
229  stream = s->streams[i]->codec;
230 
231  /* stream generic header */
232  strh = ff_start_tag(pb, "strh");
233  switch(stream->codec_type) {
235  // XSUB subtitles behave like video tracks, other subtitles
236  // are not (yet) supported.
237  if (stream->codec_id != CODEC_ID_XSUB) {
238  av_log(s, AV_LOG_ERROR, "Subtitle streams other than DivX XSUB are not supported by the AVI muxer.\n");
239  return AVERROR_PATCHWELCOME;
240  }
241  case AVMEDIA_TYPE_VIDEO: ffio_wfourcc(pb, "vids"); break;
242  case AVMEDIA_TYPE_AUDIO: ffio_wfourcc(pb, "auds"); break;
243 // case AVMEDIA_TYPE_TEXT : ffio_wfourcc(pb, "txts"); break;
244  case AVMEDIA_TYPE_DATA : ffio_wfourcc(pb, "dats"); break;
245  }
246  if(stream->codec_type == AVMEDIA_TYPE_VIDEO ||
247  stream->codec_id == CODEC_ID_XSUB)
248  avio_wl32(pb, stream->codec_tag);
249  else
250  avio_wl32(pb, 1);
251  avio_wl32(pb, 0); /* flags */
252  avio_wl16(pb, 0); /* priority */
253  avio_wl16(pb, 0); /* language */
254  avio_wl32(pb, 0); /* initial frame */
255 
256  ff_parse_specific_params(stream, &au_byterate, &au_ssize, &au_scale);
257 
258  avio_wl32(pb, au_scale); /* scale */
259  avio_wl32(pb, au_byterate); /* rate */
260  avpriv_set_pts_info(s->streams[i], 64, au_scale, au_byterate);
261 
262  avio_wl32(pb, 0); /* start */
263  avist->frames_hdr_strm = avio_tell(pb); /* remember this offset to fill later */
264  if (!pb->seekable)
265  avio_wl32(pb, AVI_MAX_RIFF_SIZE); /* FIXME: this may be broken, but who cares */
266  else
267  avio_wl32(pb, 0); /* length, XXX: filled later */
268 
269  /* suggested buffer size */ //FIXME set at the end to largest chunk
270  if(stream->codec_type == AVMEDIA_TYPE_VIDEO)
271  avio_wl32(pb, 1024 * 1024);
272  else if(stream->codec_type == AVMEDIA_TYPE_AUDIO)
273  avio_wl32(pb, 12 * 1024);
274  else
275  avio_wl32(pb, 0);
276  avio_wl32(pb, -1); /* quality */
277  avio_wl32(pb, au_ssize); /* sample size */
278  avio_wl32(pb, 0);
279  avio_wl16(pb, stream->width);
280  avio_wl16(pb, stream->height);
281  ff_end_tag(pb, strh);
282 
283  if(stream->codec_type != AVMEDIA_TYPE_DATA){
284  strf = ff_start_tag(pb, "strf");
285  switch(stream->codec_type) {
287  // XSUB subtitles behave like video tracks, other subtitles
288  // are not (yet) supported.
289  if (stream->codec_id != CODEC_ID_XSUB) break;
290  case AVMEDIA_TYPE_VIDEO:
291  ff_put_bmp_header(pb, stream, ff_codec_bmp_tags, 0);
292  break;
293  case AVMEDIA_TYPE_AUDIO:
294  if (ff_put_wav_header(pb, stream) < 0) {
295  return -1;
296  }
297  break;
298  default:
299  return -1;
300  }
301  ff_end_tag(pb, strf);
302  if ((t = av_dict_get(s->streams[i]->metadata, "title", NULL, 0))) {
303  avi_write_info_tag(s->pb, "strn", t->value);
304  t = NULL;
305  }
306  }
307 
308  if (pb->seekable) {
309  unsigned char tag[5];
310  int j;
311 
312  /* Starting to lay out AVI OpenDML master index.
313  * We want to make it JUNK entry for now, since we'd
314  * like to get away without making AVI an OpenDML one
315  * for compatibility reasons.
316  */
317  avist->indexes.entry = avist->indexes.ents_allocated = 0;
318  avist->indexes.indx_start = ff_start_tag(pb, "JUNK");
319  avio_wl16(pb, 4); /* wLongsPerEntry */
320  avio_w8(pb, 0); /* bIndexSubType (0 == frame index) */
321  avio_w8(pb, 0); /* bIndexType (0 == AVI_INDEX_OF_INDEXES) */
322  avio_wl32(pb, 0); /* nEntriesInUse (will fill out later on) */
323  ffio_wfourcc(pb, avi_stream2fourcc(tag, i, stream->codec_type));
324  /* dwChunkId */
325  avio_wl64(pb, 0); /* dwReserved[3]
326  avio_wl32(pb, 0); Must be 0. */
327  for (j=0; j < AVI_MASTER_INDEX_SIZE * 2; j++)
328  avio_wl64(pb, 0);
329  ff_end_tag(pb, avist->indexes.indx_start);
330  }
331 
332  if( stream->codec_type == AVMEDIA_TYPE_VIDEO
333  && s->streams[i]->sample_aspect_ratio.num>0
334  && s->streams[i]->sample_aspect_ratio.den>0){
335  int vprp= ff_start_tag(pb, "vprp");
337  (AVRational){stream->width, stream->height});
338  int num, den;
339  av_reduce(&num, &den, dar.num, dar.den, 0xFFFF);
340 
341  avio_wl32(pb, 0); //video format = unknown
342  avio_wl32(pb, 0); //video standard= unknown
343  avio_wl32(pb, lrintf(1.0/av_q2d(stream->time_base)));
344  avio_wl32(pb, stream->width );
345  avio_wl32(pb, stream->height);
346  avio_wl16(pb, den);
347  avio_wl16(pb, num);
348  avio_wl32(pb, stream->width );
349  avio_wl32(pb, stream->height);
350  avio_wl32(pb, 1); //progressive FIXME
351 
352  avio_wl32(pb, stream->height);
353  avio_wl32(pb, stream->width );
354  avio_wl32(pb, stream->height);
355  avio_wl32(pb, stream->width );
356  avio_wl32(pb, 0);
357  avio_wl32(pb, 0);
358 
359  avio_wl32(pb, 0);
360  avio_wl32(pb, 0);
361  ff_end_tag(pb, vprp);
362  }
363 
364  ff_end_tag(pb, list2);
365  }
366 
367  if (pb->seekable) {
368  /* AVI could become an OpenDML one, if it grows beyond 2Gb range */
369  avi->odml_list = ff_start_tag(pb, "JUNK");
370  ffio_wfourcc(pb, "odml");
371  ffio_wfourcc(pb, "dmlh");
372  avio_wl32(pb, 248);
373  for (i = 0; i < 248; i+= 4)
374  avio_wl32(pb, 0);
375  ff_end_tag(pb, avi->odml_list);
376  }
377 
378  ff_end_tag(pb, list1);
379 
380  list2 = ff_start_tag(pb, "LIST");
381  ffio_wfourcc(pb, "INFO");
383  for (i = 0; *ff_riff_tags[i]; i++) {
385  avi_write_info_tag(s->pb, t->key, t->value);
386  }
387  ff_end_tag(pb, list2);
388 
389  /* some padding for easier tag editing */
390  list2 = ff_start_tag(pb, "JUNK");
391  for (i = 0; i < 1016; i += 4)
392  avio_wl32(pb, 0);
393  ff_end_tag(pb, list2);
394 
395  avi->movi_list = ff_start_tag(pb, "LIST");
396  ffio_wfourcc(pb, "movi");
397 
398  avio_flush(pb);
399 
400  return 0;
401 }
402 
404 {
405  AVIOContext *pb = s->pb;
406  AVIContext *avi = s->priv_data;
407  char tag[5];
408  char ix_tag[] = "ix00";
409  int i, j;
410 
411  assert(pb->seekable);
412 
413  if (avi->riff_id > AVI_MASTER_INDEX_SIZE)
414  return -1;
415 
416  for (i=0;i<s->nb_streams;i++) {
417  AVIStream *avist= s->streams[i]->priv_data;
418  int64_t ix, pos;
419 
420  avi_stream2fourcc(tag, i, s->streams[i]->codec->codec_type);
421  ix_tag[3] = '0' + i;
422 
423  /* Writing AVI OpenDML leaf index chunk */
424  ix = avio_tell(pb);
425  ffio_wfourcc(pb, ix_tag); /* ix?? */
426  avio_wl32(pb, avist->indexes.entry * 8 + 24);
427  /* chunk size */
428  avio_wl16(pb, 2); /* wLongsPerEntry */
429  avio_w8(pb, 0); /* bIndexSubType (0 == frame index) */
430  avio_w8(pb, 1); /* bIndexType (1 == AVI_INDEX_OF_CHUNKS) */
431  avio_wl32(pb, avist->indexes.entry);
432  /* nEntriesInUse */
433  ffio_wfourcc(pb, tag); /* dwChunkId */
434  avio_wl64(pb, avi->movi_list);/* qwBaseOffset */
435  avio_wl32(pb, 0); /* dwReserved_3 (must be 0) */
436 
437  for (j=0; j<avist->indexes.entry; j++) {
438  AVIIentry* ie = avi_get_ientry(&avist->indexes, j);
439  avio_wl32(pb, ie->pos + 8);
440  avio_wl32(pb, ((uint32_t)ie->len & ~0x80000000) |
441  (ie->flags & 0x10 ? 0 : 0x80000000));
442  }
443  avio_flush(pb);
444  pos = avio_tell(pb);
445 
446  /* Updating one entry in the AVI OpenDML master index */
447  avio_seek(pb, avist->indexes.indx_start - 8, SEEK_SET);
448  ffio_wfourcc(pb, "indx"); /* enabling this entry */
449  avio_skip(pb, 8);
450  avio_wl32(pb, avi->riff_id); /* nEntriesInUse */
451  avio_skip(pb, 16*avi->riff_id);
452  avio_wl64(pb, ix); /* qwOffset */
453  avio_wl32(pb, pos - ix); /* dwSize */
454  avio_wl32(pb, avist->indexes.entry); /* dwDuration */
455 
456  avio_seek(pb, pos, SEEK_SET);
457  }
458  return 0;
459 }
460 
462 {
463  AVIOContext *pb = s->pb;
464  AVIContext *avi = s->priv_data;
465  int64_t idx_chunk;
466  int i;
467  char tag[5];
468 
469  if (pb->seekable) {
470  AVIStream *avist;
471  AVIIentry* ie = 0, *tie;
472  int empty, stream_id = -1;
473 
474  idx_chunk = ff_start_tag(pb, "idx1");
475  for(i=0; i<s->nb_streams; i++){
476  avist= s->streams[i]->priv_data;
477  avist->entry=0;
478  }
479 
480  do {
481  empty = 1;
482  for (i=0; i<s->nb_streams; i++) {
483  avist= s->streams[i]->priv_data;
484  if (avist->indexes.entry <= avist->entry)
485  continue;
486 
487  tie = avi_get_ientry(&avist->indexes, avist->entry);
488  if (empty || tie->pos < ie->pos) {
489  ie = tie;
490  stream_id = i;
491  }
492  empty = 0;
493  }
494  if (!empty) {
495  avist= s->streams[stream_id]->priv_data;
496  avi_stream2fourcc(tag, stream_id,
497  s->streams[stream_id]->codec->codec_type);
498  ffio_wfourcc(pb, tag);
499  avio_wl32(pb, ie->flags);
500  avio_wl32(pb, ie->pos);
501  avio_wl32(pb, ie->len);
502  avist->entry++;
503  }
504  } while (!empty);
505  ff_end_tag(pb, idx_chunk);
506 
507  avi_write_counters(s, avi->riff_id);
508  }
509  return 0;
510 }
511 
513 {
514  AVIContext *avi = s->priv_data;
515  AVIOContext *pb = s->pb;
516  unsigned char tag[5];
517  unsigned int flags=0;
518  const int stream_index= pkt->stream_index;
519  AVIStream *avist= s->streams[stream_index]->priv_data;
520  AVCodecContext *enc= s->streams[stream_index]->codec;
521  int size= pkt->size;
522 
523 // av_log(s, AV_LOG_DEBUG, "%"PRId64" %d %d\n", pkt->dts, avi->packet_count[stream_index], stream_index);
524  while(enc->block_align==0 && pkt->dts != AV_NOPTS_VALUE && pkt->dts > avist->packet_count){
525  AVPacket empty_packet;
526 
527  av_init_packet(&empty_packet);
528  empty_packet.size= 0;
529  empty_packet.data= NULL;
530  empty_packet.stream_index= stream_index;
531  avi_write_packet(s, &empty_packet);
532 // av_log(s, AV_LOG_DEBUG, "dup %"PRId64" %d\n", pkt->dts, avi->packet_count[stream_index]);
533  }
534  avist->packet_count++;
535 
536  // Make sure to put an OpenDML chunk when the file size exceeds the limits
537  if (pb->seekable &&
538  (avio_tell(pb) - avi->riff_start > AVI_MAX_RIFF_SIZE)) {
539 
540  avi_write_ix(s);
541  ff_end_tag(pb, avi->movi_list);
542 
543  if (avi->riff_id == 1)
544  avi_write_idx1(s);
545 
546  ff_end_tag(pb, avi->riff_start);
547  avi->movi_list = avi_start_new_riff(s, pb, "AVIX", "movi");
548  }
549 
550  avi_stream2fourcc(tag, stream_index, enc->codec_type);
551  if(pkt->flags&AV_PKT_FLAG_KEY)
552  flags = 0x10;
553  if (enc->codec_type == AVMEDIA_TYPE_AUDIO) {
554  avist->audio_strm_length += size;
555  }
556 
557  if (s->pb->seekable) {
558  AVIIndex* idx = &avist->indexes;
559  int cl = idx->entry / AVI_INDEX_CLUSTER_SIZE;
560  int id = idx->entry % AVI_INDEX_CLUSTER_SIZE;
561  if (idx->ents_allocated <= idx->entry) {
562  idx->cluster = av_realloc(idx->cluster, (cl+1)*sizeof(void*));
563  if (!idx->cluster)
564  return -1;
566  if (!idx->cluster[cl])
567  return -1;
569  }
570 
571  idx->cluster[cl][id].flags = flags;
572  idx->cluster[cl][id].pos = avio_tell(pb) - avi->movi_list;
573  idx->cluster[cl][id].len = size;
574  idx->entry++;
575  }
576 
577  avio_write(pb, tag, 4);
578  avio_wl32(pb, size);
579  avio_write(pb, pkt->data, size);
580  if (size & 1)
581  avio_w8(pb, 0);
582 
583  avio_flush(pb);
584  return 0;
585 }
586 
588 {
589  AVIContext *avi = s->priv_data;
590  AVIOContext *pb = s->pb;
591  int res = 0;
592  int i, j, n, nb_frames;
593  int64_t file_size;
594 
595  if (pb->seekable){
596  if (avi->riff_id == 1) {
597  ff_end_tag(pb, avi->movi_list);
598  res = avi_write_idx1(s);
599  ff_end_tag(pb, avi->riff_start);
600  } else {
601  avi_write_ix(s);
602  ff_end_tag(pb, avi->movi_list);
603  ff_end_tag(pb, avi->riff_start);
604 
605  file_size = avio_tell(pb);
606  avio_seek(pb, avi->odml_list - 8, SEEK_SET);
607  ffio_wfourcc(pb, "LIST"); /* Making this AVI OpenDML one */
608  avio_skip(pb, 16);
609 
610  for (n=nb_frames=0;n<s->nb_streams;n++) {
611  AVCodecContext *stream = s->streams[n]->codec;
612  AVIStream *avist= s->streams[n]->priv_data;
613 
614  if (stream->codec_type == AVMEDIA_TYPE_VIDEO) {
615  if (nb_frames < avist->packet_count)
616  nb_frames = avist->packet_count;
617  } else {
618  if (stream->codec_id == CODEC_ID_MP2 || stream->codec_id == CODEC_ID_MP3) {
619  nb_frames += avist->packet_count;
620  }
621  }
622  }
623  avio_wl32(pb, nb_frames);
624  avio_seek(pb, file_size, SEEK_SET);
625 
626  avi_write_counters(s, avi->riff_id);
627  }
628  }
629  avio_flush(pb);
630 
631  for (i=0; i<s->nb_streams; i++) {
632  AVIStream *avist= s->streams[i]->priv_data;
633  for (j=0; j<avist->indexes.ents_allocated/AVI_INDEX_CLUSTER_SIZE; j++)
634  av_free(avist->indexes.cluster[j]);
635  av_freep(&avist->indexes.cluster);
636  avist->indexes.ents_allocated = avist->indexes.entry = 0;
637  }
638 
639  return res;
640 }
641 
643  .name = "avi",
644  .long_name = NULL_IF_CONFIG_SMALL("AVI format"),
645  .mime_type = "video/x-msvideo",
646  .extensions = "avi",
647  .priv_data_size = sizeof(AVIContext),
649  .audio_codec = CODEC_ID_MP3,
650 #else
651  .audio_codec = CODEC_ID_AC3,
652 #endif
653  .video_codec = CODEC_ID_MPEG4,
657  .codec_tag= (const AVCodecTag* const []){ff_codec_bmp_tags, ff_codec_wav_tags, 0},
658  .flags= AVFMT_VARIABLE_FPS,
659 };
static int write_header(AVFormatContext *s)
Definition: assenc.c:28
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:154
void avio_wl16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:527
Bytestream IO Context.
Definition: avio.h:68
int size
void ff_end_tag(AVIOContext *pb, int64_t start)
int64_t ff_start_tag(AVIOContext *pb, const char *tag)
unsigned int pos
Definition: avienc.c:35
int ents_allocated
Definition: avienc.c:43
void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the pts for a given stream.
Definition: utils.c:3828
#define AVI_MAX_RIFF_SIZE
Definition: avi.h:31
static int write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: assenc.c:58
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:716
int num
numerator
Definition: rational.h:44
int size
Definition: avcodec.h:909
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:211
#define AVI_MASTER_INDEX_SIZE
Definition: avi.h:32
static char * avi_stream2fourcc(char *tag, int index, enum AVMediaType type)
Definition: avienc.c:89
void * priv_data
Definition: avformat.h:633
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
Definition: mem.c:117
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:954
AVDictionaryEntry * av_dict_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:27
AVOutputFormat ff_avi_muxer
Definition: avienc.c:642
int64_t frames_hdr_strm
Definition: avienc.c:54
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
Definition: avcodec.h:1751
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avcodec.h:1398
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:147
static void avi_write_info_tag(AVIOContext *pb, const char *tag, const char *str)
Definition: avienc.c:108
Format I/O context.
Definition: avformat.h:863
int64_t odml_list
Definition: avienc.c:48
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
Definition: avpacket.c:46
#define AVIF_ISINTERLEAVED
Definition: avi.h:26
Public dictionary API.
void avio_wl32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:316
#define CONFIG_LIBMP3LAME_ENCODER
Definition: config.h:815
Opaque data information usually continuous.
Definition: avutil.h:232
int64_t movi_list
Definition: avidec.c:63
AVStream ** streams
Definition: avformat.h:908
static double av_q2d(AVRational a)
Convert rational to double.
Definition: rational.h:69
struct AVIIndex AVIIndex
uint8_t * data
Definition: avcodec.h:908
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:80
int64_t riff_start
Definition: avienc.c:48
static int flags
Definition: log.c:34
uint32_t tag
Definition: movenc.c:670
void ff_parse_specific_params(AVCodecContext *stream, int *au_rate, int *au_ssize, int *au_scale)
Definition: riff.c:623
static int64_t avi_start_new_riff(AVFormatContext *s, AVIOContext *pb, const char *riff_tag, const char *list_tag)
Definition: avienc.c:69
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:492
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:190
static av_always_inline void ffio_wfourcc(AVIOContext *pb, const uint8_t *s)
Definition: avio_internal.h:50
static int write_trailer(AVFormatContext *s)
Definition: assenc.c:67
static float t
void avio_wl64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:515
#define AVI_MAX_STREAM_COUNT
Definition: avi.h:33
void ff_metadata_conv(AVDictionary **pm, const AVMetadataConv *d_conv, const AVMetadataConv *s_conv)
Definition: metadata.c:55
#define AV_DICT_MATCH_CASE
Definition: dict.h:61
AVDictionary * metadata
Definition: avformat.h:1085
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:137
static int avi_write_idx1(AVFormatContext *s)
Definition: avienc.c:461
#define AVERROR(e)
Definition: error.h:43
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:191
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:140
unsigned int flags
Definition: avienc.c:35
const AVCodecTag ff_codec_wav_tags[]
Definition: riff.c:289
#define FFMAX(a, b)
Definition: common.h:53
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:914
int packet_count
Definition: avienc.c:56
AVCodecContext * codec
codec context
Definition: avformat.h:623
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition: rational.c:36
unsigned int len
Definition: avienc.c:35
unsigned int nb_streams
A list of all streams in the file.
Definition: avformat.h:907
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:122
int bit_rate
the average bitrate
Definition: avcodec.h:1340
int void avio_flush(AVIOContext *s)
Definition: aviobuf.c:205
const AVCodecTag ff_codec_bmp_tags[]
Definition: riff.c:31
int width
picture width / height.
Definition: avcodec.h:1408
static av_always_inline int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: avio.h:483
const char * name
Definition: avformat.h:390
internal header for RIFF based (de)muxers do NOT include this in end user applications ...
static av_always_inline av_const long int lrintf(float x)
Definition: libm.h:69
static int avi_write_trailer(AVFormatContext *s)
Definition: avienc.c:587
AVDictionary * metadata
Definition: avformat.h:718
int64_t indx_start
Definition: avienc.c:41
const char ff_riff_tags[][5]
Definition: riff.c:361
static int avi_write_header(AVFormatContext *s)
Definition: avienc.c:155
#define AVIF_HASINDEX
Definition: avi.h:24
int avio_put_str(AVIOContext *s, const char *str)
Write a NULL-terminated string.
Definition: aviobuf.c:469
#define AVERROR_PATCHWELCOME
Not yet implemented in Libav, patches welcome.
Definition: error.h:57
static int avi_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: avienc.c:512
NULL
Definition: eval.c:50
struct AVIStream AVIStream
enum AVMediaType codec_type
Definition: avcodec.h:1574
AVIOContext * pb
Definition: avformat.h:896
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:169
main external API structure.
Definition: avcodec.h:1329
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:111
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:1590
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:64
#define AVI_INDEX_CLUSTER_SIZE
Definition: avienc.c:38
int index
Definition: gxfenc.c:73
rational number numerator/denominator
Definition: rational.h:43
int audio_strm_length
Definition: avienc.c:55
AVMediaType
Definition: avutil.h:228
enum CodecID id
Definition: mxfenc.c:85
void ff_put_bmp_header(AVIOContext *pb, AVCodecContext *enc, const AVCodecTag *tags, int for_asf)
const AVMetadataConv ff_riff_info_conv[]
Definition: riff.c:346
AVIIentry ** cluster
Definition: avienc.c:44
Main libavformat public API header.
int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc)
char * key
Definition: dict.h:75
int den
denominator
Definition: rational.h:45
static AVIIentry * avi_get_ientry(AVIIndex *idx, int ent_id)
Definition: avienc.c:62
#define AVFMT_VARIABLE_FPS
Format allows variable fps.
Definition: avformat.h:378
char * value
Definition: dict.h:76
struct AVIIentry AVIIentry
int64_t frames_hdr_all
Definition: avienc.c:49
int len
void * priv_data
Format private data.
Definition: avformat.h:883
int entry
Definition: avienc.c:57
AVIIndex indexes
Definition: avienc.c:59
static int avi_write_counters(AVFormatContext *s, int riff_id)
Definition: avienc.c:121
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: avcodec.h:907
#define AVIF_TRUSTCKTYPE
Definition: avi.h:27
int entry
Definition: avienc.c:42
int stream_index
Definition: avcodec.h:910
static int avi_write_ix(AVFormatContext *s)
Definition: avienc.c:403
int riff_id
Definition: avienc.c:50
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:271
preferred ID for decoding MPEG audio layer 1, 2 or 3
Definition: avcodec.h:336
enum CodecID codec_id
Definition: avcodec.h:1575