Libav
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 int avi_write_counters(AVFormatContext *s, int riff_id)
109 {
110  AVIOContext *pb = s->pb;
111  AVIContext *avi = s->priv_data;
112  int n, au_byterate, au_ssize, au_scale, nb_frames = 0;
113  int64_t file_size;
114  AVCodecContext *stream;
115 
116  file_size = avio_tell(pb);
117  for (n = 0; n < s->nb_streams; n++) {
118  AVIStream *avist = s->streams[n]->priv_data;
119 
120  assert(avist->frames_hdr_strm);
121  stream = s->streams[n]->codec;
122  avio_seek(pb, avist->frames_hdr_strm, SEEK_SET);
123  ff_parse_specific_params(s->streams[n], &au_byterate, &au_ssize, &au_scale);
124  if (au_ssize == 0)
125  avio_wl32(pb, avist->packet_count);
126  else
127  avio_wl32(pb, avist->audio_strm_length / au_ssize);
128  if (stream->codec_type == AVMEDIA_TYPE_VIDEO)
129  nb_frames = FFMAX(nb_frames, avist->packet_count);
130  }
131  if (riff_id == 1) {
132  assert(avi->frames_hdr_all);
133  avio_seek(pb, avi->frames_hdr_all, SEEK_SET);
134  avio_wl32(pb, nb_frames);
135  }
136  avio_seek(pb, file_size, SEEK_SET);
137 
138  return 0;
139 }
140 
142 {
143  AVIContext *avi = s->priv_data;
144  AVIOContext *pb = s->pb;
145  int bitrate, n, i, nb_frames, au_byterate, au_ssize, au_scale;
146  AVCodecContext *video_enc;
147  AVStream *video_st = NULL;
148  int64_t list1, list2, strh, strf;
149  AVDictionaryEntry *t = NULL;
150 
151  if (s->nb_streams > AVI_MAX_STREAM_COUNT) {
152  av_log(s, AV_LOG_ERROR, "AVI does not support >%d streams\n",
154  return -1;
155  }
156 
157  for (n = 0; n < s->nb_streams; n++) {
158  s->streams[n]->priv_data = av_mallocz(sizeof(AVIStream));
159  if (!s->streams[n]->priv_data)
160  return AVERROR(ENOMEM);
161  }
162 
163  /* header list */
164  avi->riff_id = 0;
165  list1 = avi_start_new_riff(s, pb, "AVI ", "hdrl");
166 
167  /* avi header */
168  ffio_wfourcc(pb, "avih");
169  avio_wl32(pb, 14 * 4);
170  bitrate = 0;
171 
172  video_enc = NULL;
173  for (n = 0; n < s->nb_streams; n++) {
174  AVCodecContext *codec = s->streams[n]->codec;
175  bitrate += codec->bit_rate;
176  if (codec->codec_type == AVMEDIA_TYPE_VIDEO) {
177  video_enc = codec;
178  video_st = s->streams[n];
179  }
180  }
181 
182  nb_frames = 0;
183 
184  // TODO: should be avg_frame_rate
185  if (video_st)
186  avio_wl32(pb, (uint32_t) (INT64_C(1000000) * video_st->time_base.num /
187  video_st->time_base.den));
188  else
189  avio_wl32(pb, 0);
190  avio_wl32(pb, bitrate / 8); /* XXX: not quite exact */
191  avio_wl32(pb, 0); /* padding */
192  if (!pb->seekable)
193  avio_wl32(pb, AVIF_TRUSTCKTYPE | AVIF_ISINTERLEAVED); /* flags */
194  else
196  avi->frames_hdr_all = avio_tell(pb); /* remember this offset to fill later */
197  avio_wl32(pb, nb_frames); /* nb frames, filled later */
198  avio_wl32(pb, 0); /* initial frame */
199  avio_wl32(pb, s->nb_streams); /* nb streams */
200  avio_wl32(pb, 1024 * 1024); /* suggested buffer size */
201  if (video_enc) {
202  avio_wl32(pb, video_enc->width);
203  avio_wl32(pb, video_enc->height);
204  } else {
205  avio_wl32(pb, 0);
206  avio_wl32(pb, 0);
207  }
208  avio_wl32(pb, 0); /* reserved */
209  avio_wl32(pb, 0); /* reserved */
210  avio_wl32(pb, 0); /* reserved */
211  avio_wl32(pb, 0); /* reserved */
212 
213  /* stream list */
214  for (i = 0; i < n; i++) {
215  AVStream *st = s->streams[i];
216  AVCodecContext *enc = st->codec;
217  AVIStream *avist = st->priv_data;
218  list2 = ff_start_tag(pb, "LIST");
219  ffio_wfourcc(pb, "strl");
220 
221  /* stream generic header */
222  strh = ff_start_tag(pb, "strh");
223  switch (enc->codec_type) {
225  // XSUB subtitles behave like video tracks, other subtitles
226  // are not (yet) supported.
227  if (enc->codec_id != AV_CODEC_ID_XSUB) {
228  av_log(s, AV_LOG_ERROR,
229  "Subtitle streams other than DivX XSUB are not supported by the AVI muxer.\n");
230  return AVERROR_PATCHWELCOME;
231  }
232  case AVMEDIA_TYPE_VIDEO:
233  ffio_wfourcc(pb, "vids");
234  break;
235  case AVMEDIA_TYPE_AUDIO:
236  ffio_wfourcc(pb, "auds");
237  break;
238 // case AVMEDIA_TYPE_TEXT:
239 // ffio_wfourcc(pb, "txts");
240 // break;
241  case AVMEDIA_TYPE_DATA:
242  ffio_wfourcc(pb, "dats");
243  break;
244  }
245  if (enc->codec_type == AVMEDIA_TYPE_VIDEO ||
246  enc->codec_id == AV_CODEC_ID_XSUB)
247  avio_wl32(pb, enc->codec_tag);
248  else
249  avio_wl32(pb, 1);
250  avio_wl32(pb, 0); /* flags */
251  avio_wl16(pb, 0); /* priority */
252  avio_wl16(pb, 0); /* language */
253  avio_wl32(pb, 0); /* initial frame */
254 
255  ff_parse_specific_params(st, &au_byterate, &au_ssize, &au_scale);
256 
257  avio_wl32(pb, au_scale); /* scale */
258  avio_wl32(pb, au_byterate); /* rate */
259  avpriv_set_pts_info(st, 64, au_scale, au_byterate);
260 
261  avio_wl32(pb, 0); /* start */
262  /* remember this offset to fill later */
263  avist->frames_hdr_strm = avio_tell(pb);
264  if (!pb->seekable)
265  /* FIXME: this may be broken, but who cares */
267  else
268  avio_wl32(pb, 0); /* length, XXX: filled later */
269 
270  /* suggested buffer size */ //FIXME set at the end to largest chunk
271  if (enc->codec_type == AVMEDIA_TYPE_VIDEO)
272  avio_wl32(pb, 1024 * 1024);
273  else if (enc->codec_type == AVMEDIA_TYPE_AUDIO)
274  avio_wl32(pb, 12 * 1024);
275  else
276  avio_wl32(pb, 0);
277  avio_wl32(pb, -1); /* quality */
278  avio_wl32(pb, au_ssize); /* sample size */
279  avio_wl32(pb, 0);
280  avio_wl16(pb, enc->width);
281  avio_wl16(pb, enc->height);
282  ff_end_tag(pb, strh);
283 
284  if (enc->codec_type != AVMEDIA_TYPE_DATA) {
285  strf = ff_start_tag(pb, "strf");
286  switch (enc->codec_type) {
288  /* XSUB subtitles behave like video tracks, other subtitles
289  * are not (yet) supported. */
290  if (enc->codec_id != AV_CODEC_ID_XSUB)
291  break;
292  case AVMEDIA_TYPE_VIDEO:
294  break;
295  case AVMEDIA_TYPE_AUDIO:
296  if (ff_put_wav_header(pb, enc) < 0)
297  return -1;
298  break;
299  default:
300  return -1;
301  }
302  ff_end_tag(pb, strf);
303  if ((t = av_dict_get(st->metadata, "title", NULL, 0))) {
304  ff_riff_write_info_tag(s->pb, "strn", t->value);
305  t = NULL;
306  }
307  }
308 
309  if (pb->seekable) {
310  unsigned char tag[5];
311  int j;
312 
313  /* Starting to lay out AVI OpenDML master index.
314  * We want to make it JUNK entry for now, since we'd
315  * like to get away without making AVI an OpenDML one
316  * for compatibility reasons. */
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, enc->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 (enc->codec_type == AVMEDIA_TYPE_VIDEO &&
333  st->sample_aspect_ratio.num > 0 &&
334  st->sample_aspect_ratio.den > 0) {
335  int vprp = ff_start_tag(pb, "vprp");
337  (AVRational) { enc->width,
338  enc->height });
339  int num, den;
340  av_reduce(&num, &den, dar.num, dar.den, 0xFFFF);
341 
342  avio_wl32(pb, 0); // video format = unknown
343  avio_wl32(pb, 0); // video standard = unknown
344  // TODO: should be avg_frame_rate
345  avio_wl32(pb, lrintf(1.0 / av_q2d(st->time_base)));
346  avio_wl32(pb, enc->width);
347  avio_wl32(pb, enc->height);
348  avio_wl16(pb, den);
349  avio_wl16(pb, num);
350  avio_wl32(pb, enc->width);
351  avio_wl32(pb, enc->height);
352  avio_wl32(pb, 1); // progressive FIXME
353 
354  avio_wl32(pb, enc->height);
355  avio_wl32(pb, enc->width);
356  avio_wl32(pb, enc->height);
357  avio_wl32(pb, enc->width);
358  avio_wl32(pb, 0);
359  avio_wl32(pb, 0);
360 
361  avio_wl32(pb, 0);
362  avio_wl32(pb, 0);
363  ff_end_tag(pb, vprp);
364  }
365 
366  ff_end_tag(pb, list2);
367  }
368 
369  if (pb->seekable) {
370  /* AVI could become an OpenDML one, if it grows beyond 2Gb range */
371  avi->odml_list = ff_start_tag(pb, "JUNK");
372  ffio_wfourcc(pb, "odml");
373  ffio_wfourcc(pb, "dmlh");
374  avio_wl32(pb, 248);
375  for (i = 0; i < 248; i += 4)
376  avio_wl32(pb, 0);
377  ff_end_tag(pb, avi->odml_list);
378  }
379 
380  ff_end_tag(pb, list1);
381 
383 
384  /* some padding for easier tag editing */
385  list2 = ff_start_tag(pb, "JUNK");
386  for (i = 0; i < 1016; i += 4)
387  avio_wl32(pb, 0);
388  ff_end_tag(pb, list2);
389 
390  avi->movi_list = ff_start_tag(pb, "LIST");
391  ffio_wfourcc(pb, "movi");
392 
393  avio_flush(pb);
394 
395  return 0;
396 }
397 
399 {
400  AVIOContext *pb = s->pb;
401  AVIContext *avi = s->priv_data;
402  char tag[5];
403  char ix_tag[] = "ix00";
404  int i, j;
405 
406  assert(pb->seekable);
407 
408  if (avi->riff_id > AVI_MASTER_INDEX_SIZE)
409  return -1;
410 
411  for (i = 0; i < s->nb_streams; i++) {
412  AVIStream *avist = s->streams[i]->priv_data;
413  int64_t ix, pos;
414 
415  avi_stream2fourcc(tag, i, s->streams[i]->codec->codec_type);
416  ix_tag[3] = '0' + i;
417 
418  /* Writing AVI OpenDML leaf index chunk */
419  ix = avio_tell(pb);
420  ffio_wfourcc(pb, ix_tag); /* ix?? */
421  avio_wl32(pb, avist->indexes.entry * 8 + 24);
422  /* chunk size */
423  avio_wl16(pb, 2); /* wLongsPerEntry */
424  avio_w8(pb, 0); /* bIndexSubType (0 == frame index) */
425  avio_w8(pb, 1); /* bIndexType (1 == AVI_INDEX_OF_CHUNKS) */
426  avio_wl32(pb, avist->indexes.entry);
427  /* nEntriesInUse */
428  ffio_wfourcc(pb, tag); /* dwChunkId */
429  avio_wl64(pb, avi->movi_list); /* qwBaseOffset */
430  avio_wl32(pb, 0); /* dwReserved_3 (must be 0) */
431 
432  for (j = 0; j < avist->indexes.entry; j++) {
433  AVIIentry *ie = avi_get_ientry(&avist->indexes, j);
434  avio_wl32(pb, ie->pos + 8);
435  avio_wl32(pb, ((uint32_t) ie->len & ~0x80000000) |
436  (ie->flags & 0x10 ? 0 : 0x80000000));
437  }
438  avio_flush(pb);
439  pos = avio_tell(pb);
440 
441  /* Updating one entry in the AVI OpenDML master index */
442  avio_seek(pb, avist->indexes.indx_start - 8, SEEK_SET);
443  ffio_wfourcc(pb, "indx"); /* enabling this entry */
444  avio_skip(pb, 8);
445  avio_wl32(pb, avi->riff_id); /* nEntriesInUse */
446  avio_skip(pb, 16 * avi->riff_id);
447  avio_wl64(pb, ix); /* qwOffset */
448  avio_wl32(pb, pos - ix); /* dwSize */
449  avio_wl32(pb, avist->indexes.entry); /* dwDuration */
450 
451  avio_seek(pb, pos, SEEK_SET);
452  }
453  return 0;
454 }
455 
457 {
458  AVIOContext *pb = s->pb;
459  AVIContext *avi = s->priv_data;
460  int64_t idx_chunk;
461  int i;
462  char tag[5];
463 
464  if (pb->seekable) {
465  AVIStream *avist;
466  AVIIentry *ie = 0, *tie;
467  int empty, stream_id = -1;
468 
469  idx_chunk = ff_start_tag(pb, "idx1");
470  for (i = 0; i < s->nb_streams; i++) {
471  avist = s->streams[i]->priv_data;
472  avist->entry = 0;
473  }
474 
475  do {
476  empty = 1;
477  for (i = 0; i < s->nb_streams; i++) {
478  avist = s->streams[i]->priv_data;
479  if (avist->indexes.entry <= avist->entry)
480  continue;
481 
482  tie = avi_get_ientry(&avist->indexes, avist->entry);
483  if (empty || tie->pos < ie->pos) {
484  ie = tie;
485  stream_id = i;
486  }
487  empty = 0;
488  }
489  if (!empty) {
490  avist = s->streams[stream_id]->priv_data;
491  avi_stream2fourcc(tag, stream_id,
492  s->streams[stream_id]->codec->codec_type);
493  ffio_wfourcc(pb, tag);
494  avio_wl32(pb, ie->flags);
495  avio_wl32(pb, ie->pos);
496  avio_wl32(pb, ie->len);
497  avist->entry++;
498  }
499  } while (!empty);
500  ff_end_tag(pb, idx_chunk);
501 
502  avi_write_counters(s, avi->riff_id);
503  }
504  return 0;
505 }
506 
508 {
509  unsigned char tag[5];
510  unsigned int flags = 0;
511  const int stream_index = pkt->stream_index;
512  int size = pkt->size;
513  AVIContext *avi = s->priv_data;
514  AVIOContext *pb = s->pb;
515  AVIStream *avist = s->streams[stream_index]->priv_data;
516  AVCodecContext *enc = s->streams[stream_index]->codec;
517 
518  while (enc->block_align == 0 && pkt->dts != AV_NOPTS_VALUE &&
519  pkt->dts > avist->packet_count) {
520  AVPacket empty_packet;
521 
522  av_init_packet(&empty_packet);
523  empty_packet.size = 0;
524  empty_packet.data = NULL;
525  empty_packet.stream_index = stream_index;
526  avi_write_packet(s, &empty_packet);
527  }
528  avist->packet_count++;
529 
530  // Make sure to put an OpenDML chunk when the file size exceeds the limits
531  if (pb->seekable &&
532  (avio_tell(pb) - avi->riff_start > AVI_MAX_RIFF_SIZE)) {
533  avi_write_ix(s);
534  ff_end_tag(pb, avi->movi_list);
535 
536  if (avi->riff_id == 1)
537  avi_write_idx1(s);
538 
539  ff_end_tag(pb, avi->riff_start);
540  avi->movi_list = avi_start_new_riff(s, pb, "AVIX", "movi");
541  }
542 
543  avi_stream2fourcc(tag, stream_index, enc->codec_type);
544  if (pkt->flags & AV_PKT_FLAG_KEY)
545  flags = 0x10;
546  if (enc->codec_type == AVMEDIA_TYPE_AUDIO)
547  avist->audio_strm_length += size;
548 
549  if (s->pb->seekable) {
550  int err;
551  AVIIndex *idx = &avist->indexes;
552  int cl = idx->entry / AVI_INDEX_CLUSTER_SIZE;
553  int id = idx->entry % AVI_INDEX_CLUSTER_SIZE;
554  if (idx->ents_allocated <= idx->entry) {
555  if ((err = av_reallocp(&idx->cluster,
556  (cl + 1) * sizeof(*idx->cluster))) < 0) {
557  idx->ents_allocated = 0;
558  idx->entry = 0;
559  return err;
560  }
561  idx->cluster[cl] =
563  if (!idx->cluster[cl])
564  return -1;
566  }
567 
568  idx->cluster[cl][id].flags = flags;
569  idx->cluster[cl][id].pos = avio_tell(pb) - avi->movi_list;
570  idx->cluster[cl][id].len = size;
571  idx->entry++;
572  }
573 
574  avio_write(pb, tag, 4);
575  avio_wl32(pb, size);
576  avio_write(pb, pkt->data, size);
577  if (size & 1)
578  avio_w8(pb, 0);
579 
580  return 0;
581 }
582 
584 {
585  AVIContext *avi = s->priv_data;
586  AVIOContext *pb = s->pb;
587  int res = 0;
588  int i, j, n, nb_frames;
589  int64_t file_size;
590 
591  if (pb->seekable) {
592  if (avi->riff_id == 1) {
593  ff_end_tag(pb, avi->movi_list);
594  res = avi_write_idx1(s);
595  ff_end_tag(pb, avi->riff_start);
596  } else {
597  avi_write_ix(s);
598  ff_end_tag(pb, avi->movi_list);
599  ff_end_tag(pb, avi->riff_start);
600 
601  file_size = avio_tell(pb);
602  avio_seek(pb, avi->odml_list - 8, SEEK_SET);
603  ffio_wfourcc(pb, "LIST"); /* Making this AVI OpenDML one */
604  avio_skip(pb, 16);
605 
606  for (n = nb_frames = 0; n < s->nb_streams; n++) {
607  AVCodecContext *stream = s->streams[n]->codec;
608  AVIStream *avist = s->streams[n]->priv_data;
609 
610  if (stream->codec_type == AVMEDIA_TYPE_VIDEO) {
611  if (nb_frames < avist->packet_count)
612  nb_frames = avist->packet_count;
613  } else {
614  if (stream->codec_id == AV_CODEC_ID_MP2 ||
615  stream->codec_id == AV_CODEC_ID_MP3)
616  nb_frames += avist->packet_count;
617  }
618  }
619  avio_wl32(pb, nb_frames);
620  avio_seek(pb, file_size, SEEK_SET);
621 
622  avi_write_counters(s, avi->riff_id);
623  }
624  }
625 
626  for (i = 0; i < s->nb_streams; i++) {
627  AVIStream *avist = s->streams[i]->priv_data;
628  for (j = 0; j < avist->indexes.ents_allocated / AVI_INDEX_CLUSTER_SIZE; j++)
629  av_free(avist->indexes.cluster[j]);
630  av_freep(&avist->indexes.cluster);
631  avist->indexes.ents_allocated = avist->indexes.entry = 0;
632  }
633 
634  return res;
635 }
636 
638  .name = "avi",
639  .long_name = NULL_IF_CONFIG_SMALL("AVI (Audio Video Interleaved)"),
640  .mime_type = "video/x-msvideo",
641  .extensions = "avi",
642  .priv_data_size = sizeof(AVIContext),
644  .video_codec = AV_CODEC_ID_MPEG4,
648  .codec_tag = (const AVCodecTag * const []) {
650  },
651 };
#define FFMAX(a, b)
Definition: common.h:55
Bytestream IO Context.
Definition: avio.h:68
int size
void ff_end_tag(AVIOContext *pb, int64_t start)
Definition: riffenc.c:38
int64_t ff_start_tag(AVIOContext *pb, const char *tag)
Definition: riffenc.c:31
enum AVCodecID id
Definition: mxfenc.c:84
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 time base and wrapping info for a given stream.
Definition: utils.c:2821
#define AVI_MAX_RIFF_SIZE
Definition: avi.h:31
static int write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: assenc.c:58
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:718
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:769
int num
numerator
Definition: rational.h:44
int size
Definition: avcodec.h:974
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
#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 avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:165
int void avio_flush(AVIOContext *s)
Definition: aviobuf.c:180
AVOutputFormat ff_avi_muxer
Definition: avienc.c:637
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:1828
#define CONFIG_LIBMP3LAME
Definition: config.h:315
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:198
AVDictionary * metadata
Definition: avformat.h:771
Format I/O context.
Definition: avformat.h:922
int64_t odml_list
Definition: avienc.c:48
#define AVIF_ISINTERLEAVED
Definition: avi.h:26
Opaque data information usually continuous.
Definition: avutil.h:189
int64_t movi_list
Definition: avidec.c:67
void avio_wl32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:260
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:219
static double av_q2d(AVRational a)
Convert rational to double.
Definition: rational.h:69
int av_reallocp(void *ptr, size_t size)
Allocate or reallocate a block of memory.
Definition: mem.c:140
AVRational av_mul_q(AVRational b, AVRational c) av_const
Multiply two rationals.
Definition: rational.c:79
int64_t riff_start
Definition: avienc.c:48
static int flags
Definition: log.c:44
uint32_t tag
Definition: movenc.c:844
void * priv_data
Definition: avformat.h:719
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 void ffio_wfourcc(AVIOContext *pb, const uint8_t *s)
Definition: avio_internal.h:67
static int write_trailer(AVFormatContext *s)
Definition: assenc.c:64
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1019
#define AVI_MAX_STREAM_COUNT
Definition: avi.h:33
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:123
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:186
static int avi_write_idx1(AVFormatContext *s)
Definition: avienc.c:456
void ff_parse_specific_params(AVStream *st, int *au_rate, int *au_ssize, int *au_scale)
Definition: riffenc.c:212
void * priv_data
Format private data.
Definition: avformat.h:950
#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:150
void ff_riff_write_info_tag(AVIOContext *pb, const char *tag, const char *str)
Write a single RIFF info tag.
Definition: riffenc.c:245
preferred ID for decoding MPEG audio layer 1, 2 or 3
Definition: avcodec.h:379
unsigned int flags
Definition: avienc.c:35
const AVCodecTag ff_codec_wav_tags[]
Definition: riff.c:353
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:979
int packet_count
Definition: avienc.c:56
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition: rational.c:35
unsigned int len
Definition: avienc.c:35
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:978
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:117
int bit_rate
the average bitrate
Definition: avcodec.h:1114
const AVCodecTag ff_codec_bmp_tags[]
Definition: riff.c:29
int width
picture width / height.
Definition: avcodec.h:1224
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:990
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:62
internal header for RIFF based (de)muxers do NOT include this in end user applications ...
char * value
Definition: dict.h:76
static av_always_inline av_const long int lrintf(float x)
Definition: libm.h:144
const char * name
Definition: avformat.h:446
static int avi_write_trailer(AVFormatContext *s)
Definition: avienc.c:583
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:186
void avio_wl64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:324
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:144
int64_t indx_start
Definition: avienc.c:41
static int avi_write_header(AVFormatContext *s)
Definition: avienc.c:141
#define AVIF_HASINDEX
Definition: avi.h:24
Stream structure.
Definition: avformat.h:699
#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:507
NULL
Definition: eval.c:55
enum AVMediaType codec_type
Definition: avcodec.h:1058
enum AVCodecID codec_id
Definition: avcodec.h:1067
main external API structure.
Definition: avcodec.h:1050
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:1082
AVIOContext * pb
I/O context.
Definition: avformat.h:964
void ff_riff_write_info(AVFormatContext *s)
Write all recognized RIFF tags from s->metadata.
Definition: riffenc.c:276
#define AVI_INDEX_CLUSTER_SIZE
Definition: avienc.c:38
int index
Definition: gxfenc.c:72
rational number numerator/denominator
Definition: rational.h:43
uint8_t * data
Definition: avcodec.h:973
int audio_strm_length
Definition: avienc.c:55
AVMediaType
Definition: avutil.h:185
void ff_put_bmp_header(AVIOContext *pb, AVCodecContext *enc, const AVCodecTag *tags, int for_asf)
Definition: riffenc.c:186
AVIIentry ** cluster
Definition: avienc.c:44
Main libavformat public API header.
int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc)
Definition: riffenc.c:50
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:38
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
Definition: avpacket.c:47
int den
denominator
Definition: rational.h:45
static AVIIentry * avi_get_ientry(AVIIndex *idx, int ent_id)
Definition: avienc.c:62
int64_t frames_hdr_all
Definition: avienc.c:49
static void write_header(FFV1Context *f)
Definition: ffv1enc.c:380
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:108
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: avcodec.h:972
#define AVIF_TRUSTCKTYPE
Definition: avi.h:27
int entry
Definition: avienc.c:42
int stream_index
Definition: avcodec.h:975
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avformat.h:741
static av_always_inline int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: avio.h:210
This structure stores compressed data.
Definition: avcodec.h:950
static int avi_write_ix(AVFormatContext *s)
Definition: avienc.c:398
int riff_id
Definition: avienc.c:50
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:228
void avio_wl16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:336
void * av_mallocz(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:205