FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 FFmpeg.
6  *
7  * FFmpeg 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  * FFmpeg 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 FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 //#define DEBUG
23 
24 #include "avformat.h"
25 #include "internal.h"
26 #include "avi.h"
27 #include "avio_internal.h"
28 #include "riff.h"
29 #include "mpegts.h"
30 #include "libavformat/avlanguage.h"
31 #include "libavutil/avstring.h"
32 #include "libavutil/internal.h"
33 #include "libavutil/intreadwrite.h"
34 #include "libavutil/dict.h"
35 #include "libavutil/avassert.h"
36 #include "libavutil/timestamp.h"
37 #include "libavutil/opt.h"
38 #include "libavutil/pixdesc.h"
39 #include "libavcodec/raw.h"
40 
41 /*
42  * TODO:
43  * - fill all fields if non streamed (nb_frames for example)
44  */
45 
46 typedef struct AVIIentry {
47  char tag[4];
48  unsigned int flags;
49  unsigned int pos;
50  unsigned int len;
51 } AVIIentry;
52 
53 #define AVI_INDEX_CLUSTER_SIZE 16384
54 
55 typedef struct AVIIndex {
56  int64_t indx_start;
58  int entry;
62 } AVIIndex;
63 
64 typedef struct AVIContext {
65  const AVClass *class;
67  int64_t frames_hdr_all;
68  int riff_id;
70 } AVIContext;
71 
72 typedef struct AVIStream {
73  int64_t frames_hdr_strm;
76  int entry;
77  int max_size;
79 
80  int64_t last_dts;
81 
83 
85 
88  int64_t pal_offset;
89 } AVIStream;
90 
92 
93 static inline AVIIentry *avi_get_ientry(const AVIIndex *idx, int ent_id)
94 {
95  int cl = ent_id / AVI_INDEX_CLUSTER_SIZE;
96  int id = ent_id % AVI_INDEX_CLUSTER_SIZE;
97  return &idx->cluster[cl][id];
98 }
99 
100 static int avi_add_ientry(AVFormatContext *s, int stream_index, char *tag,
101  unsigned int flags, unsigned int size)
102 {
103  AVIContext *avi = s->priv_data;
104  AVIOContext *pb = s->pb;
105  AVIStream *avist = s->streams[stream_index]->priv_data;
106  AVIIndex *idx = &avist->indexes;
107  int cl = idx->entry / AVI_INDEX_CLUSTER_SIZE;
108  int id = idx->entry % AVI_INDEX_CLUSTER_SIZE;
109 
110  if (idx->ents_allocated <= idx->entry) {
111  idx->cluster = av_realloc_f(idx->cluster, sizeof(void*), cl+1);
112  if (!idx->cluster) {
113  idx->ents_allocated = 0;
114  idx->entry = 0;
115  return AVERROR(ENOMEM);
116  }
117  idx->cluster[cl] =
119  if (!idx->cluster[cl])
120  return AVERROR(ENOMEM);
122  }
123 
124  if (tag)
125  memcpy(idx->cluster[cl][id].tag, tag, 4);
126  else
127  memset(idx->cluster[cl][id].tag, 0, 4);
128  idx->cluster[cl][id].flags = flags;
129  idx->cluster[cl][id].pos = avio_tell(pb) - avi->movi_list;
130  idx->cluster[cl][id].len = size;
131  avist->max_size = FFMAX(avist->max_size, size);
132  idx->entry++;
133 
134  return 0;
135 }
136 
138  const char *riff_tag, const char *list_tag)
139 {
140  AVIContext *avi = s->priv_data;
141  int64_t loff;
142  int i;
143 
144  avi->riff_id++;
145  for (i = 0; i < s->nb_streams; i++) {
146  AVIStream *avist = s->streams[i]->priv_data;
148  avist->indexes.entry = 0;
149  }
150 
151  avi->riff_start = ff_start_tag(pb, "RIFF");
152  ffio_wfourcc(pb, riff_tag);
153  loff = ff_start_tag(pb, "LIST");
154  ffio_wfourcc(pb, list_tag);
155  return loff;
156 }
157 
158 static char *avi_stream2fourcc(char *tag, int index, enum AVMediaType type)
159 {
160  tag[0] = '0' + index / 10;
161  tag[1] = '0' + index % 10;
162  if (type == AVMEDIA_TYPE_VIDEO) {
163  tag[2] = 'd';
164  tag[3] = 'c';
165  } else if (type == AVMEDIA_TYPE_SUBTITLE) {
166  // note: this is not an official code
167  tag[2] = 's';
168  tag[3] = 'b';
169  } else {
170  tag[2] = 'w';
171  tag[3] = 'b';
172  }
173  tag[4] = '\0';
174  return tag;
175 }
176 
177 static int avi_write_counters(AVFormatContext *s, int riff_id)
178 {
179  AVIOContext *pb = s->pb;
180  AVIContext *avi = s->priv_data;
181  int n, au_byterate, au_ssize, au_scale, nb_frames = 0;
182  int64_t file_size;
183  AVCodecParameters *par;
184 
185  file_size = avio_tell(pb);
186  for (n = 0; n < s->nb_streams; n++) {
187  AVIStream *avist = s->streams[n]->priv_data;
188 
189  av_assert0(avist->frames_hdr_strm);
190  par = s->streams[n]->codecpar;
191  avio_seek(pb, avist->frames_hdr_strm, SEEK_SET);
192  ff_parse_specific_params(s->streams[n], &au_byterate, &au_ssize, &au_scale);
193  if (au_ssize == 0)
194  avio_wl32(pb, avist->packet_count);
195  else
196  avio_wl32(pb, avist->audio_strm_length / au_ssize);
197  if (par->codec_type == AVMEDIA_TYPE_VIDEO)
198  nb_frames = FFMAX(nb_frames, avist->packet_count);
199  }
200  if (riff_id == 1) {
202  avio_seek(pb, avi->frames_hdr_all, SEEK_SET);
203  avio_wl32(pb, nb_frames);
204  }
205  avio_seek(pb, file_size, SEEK_SET);
206 
207  return 0;
208 }
209 
210 static void write_odml_master(AVFormatContext *s, int stream_index)
211 {
212  AVIOContext *pb = s->pb;
213  AVStream *st = s->streams[stream_index];
214  AVCodecParameters *par = st->codecpar;
215  AVIStream *avist = st->priv_data;
216  unsigned char tag[5];
217  int j;
218 
219  /* Starting to lay out AVI OpenDML master index.
220  * We want to make it JUNK entry for now, since we'd
221  * like to get away without making AVI an OpenDML one
222  * for compatibility reasons. */
223  avist->indexes.indx_start = ff_start_tag(pb, "JUNK");
224  avio_wl16(pb, 4); /* wLongsPerEntry */
225  avio_w8(pb, 0); /* bIndexSubType (0 == frame index) */
226  avio_w8(pb, 0); /* bIndexType (0 == AVI_INDEX_OF_INDEXES) */
227  avio_wl32(pb, 0); /* nEntriesInUse (will fill out later on) */
228  ffio_wfourcc(pb, avi_stream2fourcc(tag, stream_index, par->codec_type));
229  /* dwChunkId */
230  avio_wl64(pb, 0); /* dwReserved[3] */
231  avio_wl32(pb, 0); /* Must be 0. */
232  for (j = 0; j < AVI_MASTER_INDEX_SIZE * 2; j++)
233  avio_wl64(pb, 0);
234  ff_end_tag(pb, avist->indexes.indx_start);
235 }
236 
238 {
239  AVIContext *avi = s->priv_data;
240  AVIOContext *pb = s->pb;
241  int bitrate, n, i, nb_frames, au_byterate, au_ssize, au_scale;
242  AVCodecParameters *video_par;
244  int64_t list1, list2, strh, strf;
245  AVDictionaryEntry *t = NULL;
246  int padding;
247 
248  if (s->nb_streams > AVI_MAX_STREAM_COUNT) {
249  av_log(s, AV_LOG_ERROR, "AVI does not support >%d streams\n",
251  return AVERROR(EINVAL);
252  }
253 
254  for (n = 0; n < s->nb_streams; n++) {
255  s->streams[n]->priv_data = av_mallocz(sizeof(AVIStream));
256  if (!s->streams[n]->priv_data)
257  return AVERROR(ENOMEM);
258  }
259 
260  /* header list */
261  avi->riff_id = 0;
262  list1 = avi_start_new_riff(s, pb, "AVI ", "hdrl");
263 
264  /* avi header */
265  ffio_wfourcc(pb, "avih");
266  avio_wl32(pb, 14 * 4);
267  bitrate = 0;
268 
269  video_par = NULL;
270  for (n = 0; n < s->nb_streams; n++) {
271  AVCodecParameters *par = s->streams[n]->codecpar;
272  bitrate += par->bit_rate;
273  if (par->codec_type == AVMEDIA_TYPE_VIDEO) {
274  video_par = par;
275  video_st = s->streams[n];
276  }
277  }
278 
279  nb_frames = 0;
280 
281  // TODO: should be avg_frame_rate
282  if (video_st)
283  avio_wl32(pb, (uint32_t) (INT64_C(1000000) * video_st->time_base.num /
284  video_st->time_base.den));
285  else
286  avio_wl32(pb, 0);
287  avio_wl32(pb, bitrate / 8); /* XXX: not quite exact */
288  avio_wl32(pb, 0); /* padding */
289  if (!pb->seekable)
290  avio_wl32(pb, AVIF_TRUSTCKTYPE | AVIF_ISINTERLEAVED); /* flags */
291  else
293  avi->frames_hdr_all = avio_tell(pb); /* remember this offset to fill later */
294  avio_wl32(pb, nb_frames); /* nb frames, filled later */
295  avio_wl32(pb, 0); /* initial frame */
296  avio_wl32(pb, s->nb_streams); /* nb streams */
297  avio_wl32(pb, 1024 * 1024); /* suggested buffer size */
298  if (video_par) {
299  avio_wl32(pb, video_par->width);
300  avio_wl32(pb, video_par->height);
301  } else {
302  avio_wl32(pb, 0);
303  avio_wl32(pb, 0);
304  }
305  avio_wl32(pb, 0); /* reserved */
306  avio_wl32(pb, 0); /* reserved */
307  avio_wl32(pb, 0); /* reserved */
308  avio_wl32(pb, 0); /* reserved */
309 
310  /* stream list */
311  for (i = 0; i < n; i++) {
312  AVStream *st = s->streams[i];
313  AVCodecParameters *par = st->codecpar;
314  AVIStream *avist = st->priv_data;
315  list2 = ff_start_tag(pb, "LIST");
316  ffio_wfourcc(pb, "strl");
317 
318  /* stream generic header */
319  strh = ff_start_tag(pb, "strh");
320  switch (par->codec_type) {
322  // XSUB subtitles behave like video tracks, other subtitles
323  // are not (yet) supported.
324  if (par->codec_id != AV_CODEC_ID_XSUB) {
325  av_log(s, AV_LOG_ERROR,
326  "Subtitle streams other than DivX XSUB are not supported by the AVI muxer.\n");
327  return AVERROR_PATCHWELCOME;
328  }
329  case AVMEDIA_TYPE_VIDEO:
330  ffio_wfourcc(pb, "vids");
331  break;
332  case AVMEDIA_TYPE_AUDIO:
333  ffio_wfourcc(pb, "auds");
334  break;
335 // case AVMEDIA_TYPE_TEXT:
336 // ffio_wfourcc(pb, "txts");
337 // break;
338  case AVMEDIA_TYPE_DATA:
339  ffio_wfourcc(pb, "dats");
340  break;
341  }
342  if (par->codec_type == AVMEDIA_TYPE_VIDEO ||
343  par->codec_id == AV_CODEC_ID_XSUB)
344  avio_wl32(pb, par->codec_tag);
345  else
346  avio_wl32(pb, 1);
347  avist->strh_flags_offset = avio_tell(pb);
348  avio_wl32(pb, 0); /* flags */
349  avio_wl16(pb, 0); /* priority */
350  avio_wl16(pb, 0); /* language */
351  avio_wl32(pb, 0); /* initial frame */
352 
353  ff_parse_specific_params(st, &au_byterate, &au_ssize, &au_scale);
354 
355  if ( par->codec_type == AVMEDIA_TYPE_VIDEO
356  && par->codec_id != AV_CODEC_ID_XSUB
357  && au_byterate > 1000LL*au_scale) {
358  au_byterate = 600;
359  au_scale = 1;
360  }
361  avpriv_set_pts_info(st, 64, au_scale, au_byterate);
362  if (par->codec_id == AV_CODEC_ID_XSUB)
363  au_scale = au_byterate = 0;
364 
365  avio_wl32(pb, au_scale); /* scale */
366  avio_wl32(pb, au_byterate); /* rate */
367 
368  avio_wl32(pb, 0); /* start */
369  /* remember this offset to fill later */
370  avist->frames_hdr_strm = avio_tell(pb);
371  if (!pb->seekable)
372  /* FIXME: this may be broken, but who cares */
374  else
375  avio_wl32(pb, 0); /* length, XXX: filled later */
376 
377  /* suggested buffer size, is set to largest chunk size in avi_write_trailer */
378  if (par->codec_type == AVMEDIA_TYPE_VIDEO)
379  avio_wl32(pb, 1024 * 1024);
380  else if (par->codec_type == AVMEDIA_TYPE_AUDIO)
381  avio_wl32(pb, 12 * 1024);
382  else
383  avio_wl32(pb, 0);
384  avio_wl32(pb, -1); /* quality */
385  avio_wl32(pb, au_ssize); /* sample size */
386  avio_wl32(pb, 0);
387  avio_wl16(pb, par->width);
388  avio_wl16(pb, par->height);
389  ff_end_tag(pb, strh);
390 
391  if (par->codec_type != AVMEDIA_TYPE_DATA) {
392  int ret, flags;
393  enum AVPixelFormat pix_fmt;
394 
395  strf = ff_start_tag(pb, "strf");
396  switch (par->codec_type) {
398  /* XSUB subtitles behave like video tracks, other subtitles
399  * are not (yet) supported. */
400  if (par->codec_id != AV_CODEC_ID_XSUB)
401  break;
402  case AVMEDIA_TYPE_VIDEO:
403  /* WMP expects RGB 5:5:5 rawvideo in avi to have bpp set to 16. */
404  if ( !par->codec_tag
405  && par->codec_id == AV_CODEC_ID_RAWVIDEO
406  && par->format == AV_PIX_FMT_RGB555LE
407  && par->bits_per_coded_sample == 15)
408  par->bits_per_coded_sample = 16;
409  avist->pal_offset = avio_tell(pb) + 40;
410  ff_put_bmp_header(pb, par, ff_codec_bmp_tags, 0, 0);
412  par->bits_per_coded_sample);
413  if ( !par->codec_tag
414  && par->codec_id == AV_CODEC_ID_RAWVIDEO
415  && par->format != pix_fmt
416  && par->format != AV_PIX_FMT_NONE)
417  av_log(s, AV_LOG_ERROR, "%s rawvideo cannot be written to avi, output file will be unreadable\n",
419  break;
420  case AVMEDIA_TYPE_AUDIO:
421  flags = (avi->write_channel_mask == 0) ? FF_PUT_WAV_HEADER_SKIP_CHANNELMASK : 0;
422  if ((ret = ff_put_wav_header(s, pb, par, flags)) < 0)
423  return ret;
424  break;
425  default:
426  av_log(s, AV_LOG_ERROR,
427  "Invalid or not supported codec type '%s' found in the input\n",
428  (char *)av_x_if_null(av_get_media_type_string(par->codec_type), "?"));
429  return AVERROR(EINVAL);
430  }
431  ff_end_tag(pb, strf);
432  if ((t = av_dict_get(st->metadata, "title", NULL, 0))) {
433  ff_riff_write_info_tag(s->pb, "strn", t->value);
434  t = NULL;
435  }
436  if (par->codec_id == AV_CODEC_ID_XSUB
437  && (t = av_dict_get(s->streams[i]->metadata, "language", NULL, 0))) {
438  const char* langstr = av_convert_lang_to(t->value, AV_LANG_ISO639_1);
439  t = NULL;
440  if (langstr) {
441  char* str = av_asprintf("Subtitle - %s-xx;02", langstr);
442  if (!str)
443  return AVERROR(ENOMEM);
444  ff_riff_write_info_tag(s->pb, "strn", str);
445  av_free(str);
446  }
447  }
448  }
449 
450  if (pb->seekable) {
451  write_odml_master(s, i);
452  }
453 
454  if (par->codec_type == AVMEDIA_TYPE_VIDEO &&
455  st->sample_aspect_ratio.num > 0 &&
456  st->sample_aspect_ratio.den > 0) {
457  int vprp = ff_start_tag(pb, "vprp");
459  (AVRational) { par->width,
460  par->height });
461  int num, den;
462  av_reduce(&num, &den, dar.num, dar.den, 0xFFFF);
463 
464  avio_wl32(pb, 0); // video format = unknown
465  avio_wl32(pb, 0); // video standard = unknown
466  // TODO: should be avg_frame_rate
467  avio_wl32(pb, (2LL*st->time_base.den + st->time_base.num - 1) / (2LL * st->time_base.num));
468  avio_wl32(pb, par->width);
469  avio_wl32(pb, par->height);
470  avio_wl16(pb, den);
471  avio_wl16(pb, num);
472  avio_wl32(pb, par->width);
473  avio_wl32(pb, par->height);
474  avio_wl32(pb, 1); // progressive FIXME
475 
476  avio_wl32(pb, par->height);
477  avio_wl32(pb, par->width);
478  avio_wl32(pb, par->height);
479  avio_wl32(pb, par->width);
480  avio_wl32(pb, 0);
481  avio_wl32(pb, 0);
482 
483  avio_wl32(pb, 0);
484  avio_wl32(pb, 0);
485  ff_end_tag(pb, vprp);
486  }
487 
488  ff_end_tag(pb, list2);
489  }
490 
491  if (pb->seekable) {
492  /* AVI could become an OpenDML one, if it grows beyond 2Gb range */
493  avi->odml_list = ff_start_tag(pb, "JUNK");
494  ffio_wfourcc(pb, "odml");
495  ffio_wfourcc(pb, "dmlh");
496  avio_wl32(pb, 248);
497  for (i = 0; i < 248; i += 4)
498  avio_wl32(pb, 0);
499  ff_end_tag(pb, avi->odml_list);
500  }
501 
502  ff_end_tag(pb, list1);
503 
505 
506 
507  padding = s->metadata_header_padding;
508  if (padding < 0)
509  padding = 1016;
510 
511  /* some padding for easier tag editing */
512  if (padding) {
513  list2 = ff_start_tag(pb, "JUNK");
514  for (i = padding; i > 0; i -= 4)
515  avio_wl32(pb, 0);
516  ff_end_tag(pb, list2);
517  }
518 
519  avi->movi_list = ff_start_tag(pb, "LIST");
520  ffio_wfourcc(pb, "movi");
521 
522  avio_flush(pb);
523 
524  return 0;
525 }
526 
527 static void update_odml_entry(AVFormatContext *s, int stream_index, int64_t ix, int size)
528 {
529  AVIOContext *pb = s->pb;
530  AVIContext *avi = s->priv_data;
531  AVIStream *avist = s->streams[stream_index]->priv_data;
532  int64_t pos;
533  int au_byterate, au_ssize, au_scale;
534 
535  avio_flush(pb);
536  pos = avio_tell(pb);
537 
538  /* Updating one entry in the AVI OpenDML master index */
539  avio_seek(pb, avist->indexes.indx_start - 8, SEEK_SET);
540  ffio_wfourcc(pb, "indx"); /* enabling this entry */
541  avio_skip(pb, 8);
542  avio_wl32(pb, avi->riff_id - avist->indexes.master_odml_riff_id_base); /* nEntriesInUse */
543  avio_skip(pb, 16 * (avi->riff_id - avist->indexes.master_odml_riff_id_base));
544  avio_wl64(pb, ix); /* qwOffset */
545  avio_wl32(pb, size); /* dwSize */
546  ff_parse_specific_params(s->streams[stream_index], &au_byterate, &au_ssize, &au_scale);
547  if (s->streams[stream_index]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && au_ssize > 0) {
548  uint32_t audio_segm_size = (avist->audio_strm_length - avist->indexes.audio_strm_offset);
549  if ((audio_segm_size % au_ssize > 0) && !avist->sample_requested) {
550  avpriv_request_sample(s, "OpenDML index duration for audio packets with partial frames");
551  avist->sample_requested = 1;
552  }
553  avio_wl32(pb, audio_segm_size / au_ssize); /* dwDuration (sample count) */
554  } else
555  avio_wl32(pb, avist->indexes.entry); /* dwDuration (packet count) */
556 
557  avio_seek(pb, pos, SEEK_SET);
558 }
559 
561 {
562  AVIOContext *pb = s->pb;
563  AVIContext *avi = s->priv_data;
564  char tag[5];
565  char ix_tag[] = "ix00";
566  int i, j;
567 
568  av_assert0(pb->seekable);
569 
570  for (i = 0; i < s->nb_streams; i++) {
571  AVIStream *avist = s->streams[i]->priv_data;
573  int64_t pos;
574  int size = 8+2+1+1+4+8+4+4+16*AVI_MASTER_INDEX_SIZE;
575 
576  pos = avio_tell(pb);
577  update_odml_entry(s, i, pos, size);
578  write_odml_master(s, i);
579  av_assert1(avio_tell(pb) - pos == size);
580  avist->indexes.master_odml_riff_id_base = avi->riff_id - 1;
581  }
583  }
584 
585  for (i = 0; i < s->nb_streams; i++) {
586  AVIStream *avist = s->streams[i]->priv_data;
587  int64_t ix;
588 
589  avi_stream2fourcc(tag, i, s->streams[i]->codecpar->codec_type);
590  ix_tag[3] = '0' + i;
591 
592  /* Writing AVI OpenDML leaf index chunk */
593  ix = avio_tell(pb);
594  ffio_wfourcc(pb, ix_tag); /* ix?? */
595  avio_wl32(pb, avist->indexes.entry * 8 + 24);
596  /* chunk size */
597  avio_wl16(pb, 2); /* wLongsPerEntry */
598  avio_w8(pb, 0); /* bIndexSubType (0 == frame index) */
599  avio_w8(pb, 1); /* bIndexType (1 == AVI_INDEX_OF_CHUNKS) */
600  avio_wl32(pb, avist->indexes.entry);
601  /* nEntriesInUse */
602  ffio_wfourcc(pb, tag); /* dwChunkId */
603  avio_wl64(pb, avi->movi_list); /* qwBaseOffset */
604  avio_wl32(pb, 0); /* dwReserved_3 (must be 0) */
605 
606  for (j = 0; j < avist->indexes.entry; j++) {
607  AVIIentry *ie = avi_get_ientry(&avist->indexes, j);
608  avio_wl32(pb, ie->pos + 8);
609  avio_wl32(pb, ((uint32_t) ie->len & ~0x80000000) |
610  (ie->flags & 0x10 ? 0 : 0x80000000));
611  }
612 
613  update_odml_entry(s, i, ix, avio_tell(pb) - ix);
614  }
615  return 0;
616 }
617 
619 {
620  AVIOContext *pb = s->pb;
621  AVIContext *avi = s->priv_data;
622  int64_t idx_chunk;
623  int i;
624  char tag[5];
625 
626  if (pb->seekable) {
627  AVIStream *avist;
628  AVIIentry *ie = 0, *tie;
629  int empty, stream_id = -1;
630 
631  idx_chunk = ff_start_tag(pb, "idx1");
632  for (i = 0; i < s->nb_streams; i++) {
633  avist = s->streams[i]->priv_data;
634  avist->entry = 0;
635  }
636 
637  do {
638  empty = 1;
639  for (i = 0; i < s->nb_streams; i++) {
640  avist = s->streams[i]->priv_data;
641  if (avist->indexes.entry <= avist->entry)
642  continue;
643 
644  tie = avi_get_ientry(&avist->indexes, avist->entry);
645  if (empty || tie->pos < ie->pos) {
646  ie = tie;
647  stream_id = i;
648  }
649  empty = 0;
650  }
651  if (!empty) {
652  avist = s->streams[stream_id]->priv_data;
653  if (*ie->tag)
654  ffio_wfourcc(pb, ie->tag);
655  else {
656  avi_stream2fourcc(tag, stream_id,
657  s->streams[stream_id]->codecpar->codec_type);
658  ffio_wfourcc(pb, tag);
659  }
660  avio_wl32(pb, ie->flags);
661  avio_wl32(pb, ie->pos);
662  avio_wl32(pb, ie->len);
663  avist->entry++;
664  }
665  } while (!empty);
666  ff_end_tag(pb, idx_chunk);
667 
668  avi_write_counters(s, avi->riff_id);
669  }
670  return 0;
671 }
672 
673 static int write_skip_frames(AVFormatContext *s, int stream_index, int64_t dts)
674 {
675  AVIStream *avist = s->streams[stream_index]->priv_data;
676  AVCodecParameters *par = s->streams[stream_index]->codecpar;
677 
678  ff_dlog(s, "dts:%s packet_count:%d stream_index:%d\n", av_ts2str(dts), avist->packet_count, stream_index);
679  while (par->block_align == 0 && dts != AV_NOPTS_VALUE &&
680  dts > avist->packet_count && par->codec_id != AV_CODEC_ID_XSUB && avist->packet_count) {
681  AVPacket empty_packet;
682 
683  if (dts - avist->packet_count > 60000) {
684  av_log(s, AV_LOG_ERROR, "Too large number of skipped frames %"PRId64" > 60000\n", dts - avist->packet_count);
685  return AVERROR(EINVAL);
686  }
687 
688  av_init_packet(&empty_packet);
689  empty_packet.size = 0;
690  empty_packet.data = NULL;
691  empty_packet.stream_index = stream_index;
692  avi_write_packet_internal(s, &empty_packet);
693  ff_dlog(s, "dup dts:%s packet_count:%d\n", av_ts2str(dts), avist->packet_count);
694  }
695 
696  return 0;
697 }
698 
700 {
701  const int stream_index = pkt->stream_index;
702  AVCodecParameters *par = s->streams[stream_index]->codecpar;
703  int ret;
704 
705  if (par->codec_id == AV_CODEC_ID_H264 && par->codec_tag == MKTAG('H','2','6','4') && pkt->size) {
706  ret = ff_check_h264_startcode(s, s->streams[stream_index], pkt);
707  if (ret < 0)
708  return ret;
709  }
710 
711  if ((ret = write_skip_frames(s, stream_index, pkt->dts)) < 0)
712  return ret;
713 
714  if (!pkt->size)
715  return avi_write_packet_internal(s, pkt); /* Passthrough */
716 
717  if (par->codec_type == AVMEDIA_TYPE_VIDEO) {
718  AVIStream *avist = s->streams[stream_index]->priv_data;
719  AVIOContext *pb = s->pb;
720  AVPacket *opkt = pkt;
721  int reshuffle_ret;
722  if (par->codec_id == AV_CODEC_ID_RAWVIDEO && par->codec_tag == 0) {
723  int64_t bpc = par->bits_per_coded_sample != 15 ? par->bits_per_coded_sample : 16;
724  int expected_stride = ((par->width * bpc + 31) >> 5)*4;
725  reshuffle_ret = ff_reshuffle_raw_rgb(s, &pkt, par, expected_stride);
726  if (reshuffle_ret < 0)
727  return reshuffle_ret;
728  } else
729  reshuffle_ret = 0;
730  if (par->format == AV_PIX_FMT_PAL8) {
731  ret = ff_get_packet_palette(s, opkt, reshuffle_ret, avist->palette);
732  if (ret < 0)
733  goto fail;
734  if (ret) {
735  int pal_size = 1 << par->bits_per_coded_sample;
736  int pc_tag, i;
737 
739 
740  if (pb->seekable && avist->pal_offset) {
741  int64_t cur_offset = avio_tell(pb);
742  avio_seek(pb, avist->pal_offset, SEEK_SET);
743  for (i = 0; i < pal_size; i++) {
744  uint32_t v = avist->palette[i];
745  avio_wl32(pb, v & 0xffffff);
746  }
747  avio_seek(pb, cur_offset, SEEK_SET);
748  memcpy(avist->old_palette, avist->palette, pal_size * 4);
749  avist->pal_offset = 0;
750  }
751  if (memcmp(avist->palette, avist->old_palette, pal_size * 4)) {
752  unsigned char tag[5];
753  avi_stream2fourcc(tag, stream_index, par->codec_type);
754  tag[2] = 'p'; tag[3] = 'c';
755  if (s->pb->seekable) {
756  if (avist->strh_flags_offset) {
757  int64_t cur_offset = avio_tell(pb);
758  avio_seek(pb, avist->strh_flags_offset, SEEK_SET);
760  avio_seek(pb, cur_offset, SEEK_SET);
761  avist->strh_flags_offset = 0;
762  }
763  ret = avi_add_ientry(s, stream_index, tag, AVIIF_NO_TIME,
764  pal_size * 4 + 4);
765  if (ret < 0)
766  goto fail;
767  }
768  pc_tag = ff_start_tag(pb, tag);
769  avio_w8(pb, 0);
770  avio_w8(pb, pal_size & 0xFF);
771  avio_wl16(pb, 0); // reserved
772  for (i = 0; i < pal_size; i++) {
773  uint32_t v = avist->palette[i];
774  avio_wb32(pb, v<<8);
775  }
776  ff_end_tag(pb, pc_tag);
777  memcpy(avist->old_palette, avist->palette, pal_size * 4);
778  }
779  }
780  }
781  if (reshuffle_ret) {
782  ret = avi_write_packet_internal(s, pkt);
783 
784 fail:
785  if (reshuffle_ret)
786  av_packet_free(&pkt);
787  return ret;
788  }
789  }
790 
791  return avi_write_packet_internal(s, pkt);
792 }
793 
795 {
796  unsigned char tag[5];
797  unsigned int flags = 0;
798  const int stream_index = pkt->stream_index;
799  int size = pkt->size;
800  AVIContext *avi = s->priv_data;
801  AVIOContext *pb = s->pb;
802  AVIStream *avist = s->streams[stream_index]->priv_data;
803  AVCodecParameters *par = s->streams[stream_index]->codecpar;
804 
805  if (pkt->dts != AV_NOPTS_VALUE)
806  avist->last_dts = pkt->dts + pkt->duration;
807 
808  avist->packet_count++;
809 
810  // Make sure to put an OpenDML chunk when the file size exceeds the limits
811  if (pb->seekable &&
812  (avio_tell(pb) - avi->riff_start > AVI_MAX_RIFF_SIZE)) {
813  avi_write_ix(s);
814  ff_end_tag(pb, avi->movi_list);
815 
816  if (avi->riff_id == 1)
817  avi_write_idx1(s);
818 
819  ff_end_tag(pb, avi->riff_start);
820  avi->movi_list = avi_start_new_riff(s, pb, "AVIX", "movi");
821  }
822 
823  avi_stream2fourcc(tag, stream_index, par->codec_type);
824  if (pkt->flags & AV_PKT_FLAG_KEY)
825  flags = 0x10;
826  if (par->codec_type == AVMEDIA_TYPE_AUDIO)
827  avist->audio_strm_length += size;
828 
829  if (s->pb->seekable) {
830  int ret;
831  ret = avi_add_ientry(s, stream_index, NULL, flags, size);
832  if (ret < 0)
833  return ret;
834  }
835 
836  avio_write(pb, tag, 4);
837  avio_wl32(pb, size);
838  avio_write(pb, pkt->data, size);
839  if (size & 1)
840  avio_w8(pb, 0);
841 
842  return 0;
843 }
844 
846 {
847  AVIContext *avi = s->priv_data;
848  AVIOContext *pb = s->pb;
849  int res = 0;
850  int i, j, n, nb_frames;
851  int64_t file_size;
852 
853  for (i = 0; i < s->nb_streams; i++) {
854  AVIStream *avist = s->streams[i]->priv_data;
855  write_skip_frames(s, i, avist->last_dts);
856  }
857 
858  if (pb->seekable) {
859  if (avi->riff_id == 1) {
860  ff_end_tag(pb, avi->movi_list);
861  res = avi_write_idx1(s);
862  ff_end_tag(pb, avi->riff_start);
863  } else {
864  avi_write_ix(s);
865  ff_end_tag(pb, avi->movi_list);
866  ff_end_tag(pb, avi->riff_start);
867 
868  file_size = avio_tell(pb);
869  avio_seek(pb, avi->odml_list - 8, SEEK_SET);
870  ffio_wfourcc(pb, "LIST"); /* Making this AVI OpenDML one */
871  avio_skip(pb, 16);
872 
873  for (n = nb_frames = 0; n < s->nb_streams; n++) {
874  AVCodecParameters *par = s->streams[n]->codecpar;
875  AVIStream *avist = s->streams[n]->priv_data;
876 
877  if (par->codec_type == AVMEDIA_TYPE_VIDEO) {
878  if (nb_frames < avist->packet_count)
879  nb_frames = avist->packet_count;
880  } else {
881  if (par->codec_id == AV_CODEC_ID_MP2 ||
882  par->codec_id == AV_CODEC_ID_MP3)
883  nb_frames += avist->packet_count;
884  }
885  }
886  avio_wl32(pb, nb_frames);
887  avio_seek(pb, file_size, SEEK_SET);
888 
889  avi_write_counters(s, avi->riff_id);
890  }
891  }
892 
893  for (i = 0; i < s->nb_streams; i++) {
894  AVIStream *avist = s->streams[i]->priv_data;
895  for (j = 0; j < avist->indexes.ents_allocated / AVI_INDEX_CLUSTER_SIZE; j++)
896  av_freep(&avist->indexes.cluster[j]);
897  av_freep(&avist->indexes.cluster);
898  avist->indexes.ents_allocated = avist->indexes.entry = 0;
899  if (pb->seekable) {
900  avio_seek(pb, avist->frames_hdr_strm + 4, SEEK_SET);
901  avio_wl32(pb, avist->max_size);
902  }
903  }
904 
905  return res;
906 }
907 
908 #define OFFSET(x) offsetof(AVIContext, x)
909 #define ENC AV_OPT_FLAG_ENCODING_PARAM
910 static const AVOption options[] = {
911  { "write_channel_mask", "write channel mask into wave format header", OFFSET(write_channel_mask), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, ENC },
912  { NULL },
913 };
914 
915 static const AVClass avi_muxer_class = {
916  .class_name = "AVI muxer",
917  .item_name = av_default_item_name,
918  .option = options,
919  .version = LIBAVUTIL_VERSION_INT,
920 };
921 
923  .name = "avi",
924  .long_name = NULL_IF_CONFIG_SMALL("AVI (Audio Video Interleaved)"),
925  .mime_type = "video/x-msvideo",
926  .extensions = "avi",
927  .priv_data_size = sizeof(AVIContext),
928  .audio_codec = CONFIG_LIBMP3LAME ? AV_CODEC_ID_MP3 : AV_CODEC_ID_AC3,
929  .video_codec = AV_CODEC_ID_MPEG4,
933  .codec_tag = (const AVCodecTag * const []) {
935  },
936  .priv_class = &avi_muxer_class,
937 };
static int write_skip_frames(AVFormatContext *s, int stream_index, int64_t dts)
Definition: avienc.c:673
#define NULL
Definition: coverity.c:32
void avio_wl16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:446
const char * s
Definition: avisynth_c.h:631
Bytestream IO Context.
Definition: avio.h:147
static enum AVPixelFormat pix_fmt
#define av_realloc_f(p, o, n)
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
AVOption.
Definition: opt.h:245
int ff_put_wav_header(AVFormatContext *s, AVIOContext *pb, AVCodecParameters *par, int flags)
Write WAVEFORMAT header structure.
Definition: riffenc.c:54
enum AVCodecID id
Definition: mxfenc.c:104
int master_odml_riff_id_base
Definition: avienc.c:60
unsigned int pos
Definition: avienc.c:49
#define LIBAVUTIL_VERSION_INT
Definition: version.h:70
int ents_allocated
Definition: avienc.c:59
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:4427
#define AVI_MAX_RIFF_SIZE
Definition: avi.h:31
int64_t audio_strm_offset
Definition: avienc.c:57
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:3922
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:943
int num
numerator
Definition: rational.h:44
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), little-endian, X=unused/undefined ...
Definition: pixfmt.h:116
int size
Definition: avcodec.h:1581
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:230
#define AVI_MASTER_INDEX_SIZE
Definition: avi.h:32
static char * avi_stream2fourcc(char *tag, int index, enum AVMediaType type)
Definition: avienc.c:158
void * priv_data
Definition: avformat.h:891
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:304
static AVPacket pkt
AVOutputFormat ff_avi_muxer
Definition: avienc.c:922
int64_t frames_hdr_strm
Definition: avienc.c:73
This struct describes the properties of an encoded stream.
Definition: avcodec.h:3914
Format I/O context.
Definition: avformat.h:1325
int64_t odml_list
Definition: avienc.c:66
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
#define AVIF_ISINTERLEAVED
Definition: avi.h:26
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
Public dictionary API.
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition: avpacket.c:62
void avio_wl32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:346
#define av_malloc(s)
Opaque data information usually continuous.
Definition: avutil.h:195
int width
Video only.
Definition: avcodec.h:3988
8 bits with AV_PIX_FMT_RGB32 palette
Definition: pixfmt.h:73
AVOptions.
timestamp utils, mostly useful for debugging/logging purposes
static int avi_add_ientry(AVFormatContext *s, int stream_index, char *tag, unsigned int flags, unsigned int size)
Definition: avienc.c:100
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: avcodec.h:1598
int64_t movi_list
Definition: avidec.c:75
#define OFFSET(x)
Definition: avienc.c:908
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1393
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:39
uint8_t * data
Definition: avcodec.h:1580
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:80
int64_t riff_start
Definition: avienc.c:66
uint32_t tag
Definition: movenc.c:1367
#define ff_dlog(a,...)
static int64_t avi_start_new_riff(AVFormatContext *s, AVIOContext *pb, const char *riff_tag, const char *list_tag)
Definition: avienc.c:137
ptrdiff_t size
Definition: opengl_enc.c:101
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:511
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:204
static av_always_inline void ffio_wfourcc(AVIOContext *pb, const uint8_t *s)
Definition: avio_internal.h:66
#define av_log(a,...)
static const AVClass avi_muxer_class
Definition: avienc.c:915
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
Definition: avcodec.h:3951
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1612
void avio_wl64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:434
static void * av_x_if_null(const void *p, const void *x)
Return x default pointer in case p is NULL.
Definition: avutil.h:300
uint32_t old_palette[AVPALETTE_COUNT]
Definition: avienc.c:87
#define ENC
Definition: avienc.c:909
#define AVI_MAX_STREAM_COUNT
Definition: avi.h:33
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
static int avi_write_idx1(AVFormatContext *s)
Definition: avienc.c:618
void ff_parse_specific_params(AVStream *st, int *au_rate, int *au_ssize, int *au_scale)
Definition: riffenc.c:263
int ff_check_h264_startcode(AVFormatContext *s, const AVStream *st, const AVPacket *pkt)
Check presence of H264 startcode.
Definition: mpegtsenc.c:1396
av_default_item_name
#define AVERROR(e)
Definition: error.h:43
const char * av_convert_lang_to(const char *lang, enum AVLangCodespace target_codespace)
Convert a language code to a target codespace.
Definition: avlanguage.c:736
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:176
void ff_riff_write_info_tag(AVIOContext *pb, const char *tag, const char *str)
Write a single RIFF info tag.
Definition: riffenc.c:293
char tag[4]
Definition: avienc.c:47
AVStream * video_st
Definition: movenc.c:59
preferred ID for decoding MPEG audio layer 1, 2 or 3
Definition: avcodec.h:515
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:3918
simple assert() macros that are a bit more flexible than ISO C assert().
unsigned int flags
Definition: avienc.c:48
void ff_put_bmp_header(AVIOContext *pb, AVCodecParameters *par, const AVCodecTag *tags, int for_asf, int ignore_extradata)
Definition: riffenc.c:207
const AVCodecTag ff_codec_wav_tags[]
Definition: riff.c:432
#define FFMAX(a, b)
Definition: common.h:94
#define fail()
Definition: checkasm.h:81
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1586
int packet_count
Definition: avienc.c:75
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
char * av_asprintf(const char *fmt,...)
Definition: avstring.c:113
unsigned int len
Definition: avienc.c:50
common internal API header
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1381
static void update_odml_entry(AVFormatContext *s, int stream_index, int64_t ix, int size)
Definition: avienc.c:527
int block_align
Audio only.
Definition: avcodec.h:4039
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:243
int void avio_flush(AVIOContext *s)
Force flushing of buffered data.
Definition: aviobuf.c:224
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:53
Raw Video Codec.
const AVCodecTag ff_codec_bmp_tags[]
Definition: riff.c:32
static int write_trailer(AVFormatContext *s1)
Definition: v4l2enc.c:94
const char * name
Definition: avformat.h:522
int ff_get_packet_palette(AVFormatContext *s, AVPacket *pkt, int ret, uint32_t *palette)
Retrieves the palette from a packet, either from side data, or appended to the video data in the pack...
Definition: utils.c:5151
internal header for RIFF based (de)muxers do NOT include this in end user applications ...
static int avi_write_trailer(AVFormatContext *s)
Definition: avienc.c:845
int n
Definition: avisynth_c.h:547
AVDictionary * metadata
Definition: avformat.h:945
int64_t indx_start
Definition: avienc.c:56
int64_t audio_strm_length
Definition: avienc.c:74
static int avi_write_header(AVFormatContext *s)
Definition: avienc.c:237
#define AVIF_HASINDEX
Definition: avi.h:24
Stream structure.
Definition: avformat.h:876
int64_t pal_offset
Definition: avienc.c:88
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
static int avi_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: avienc.c:699
enum AVPixelFormat avpriv_find_pix_fmt(const PixelFormatTag *tags, unsigned int fourcc)
Definition: utils.c:1009
AVIOContext * pb
I/O context.
Definition: avformat.h:1367
static const AVOption options[]
Definition: avienc.c:910
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:182
int sample_requested
Definition: avienc.c:78
#define AVIIF_NO_TIME
Definition: avi.h:40
GLint GLenum type
Definition: opengl_enc.c:105
void ff_riff_write_info(AVFormatContext *s)
Write all recognized RIFF tags from s->metadata.
Definition: riffenc.c:324
Describe the class of an AVClass context structure.
Definition: log.h:67
#define AVI_INDEX_CLUSTER_SIZE
Definition: avienc.c:53
int index
Definition: gxfenc.c:89
rational number numerator/denominator
Definition: rational.h:43
AVMediaType
Definition: avutil.h:191
static AVIIentry * avi_get_ientry(const AVIIndex *idx, int ent_id)
Definition: avienc.c:93
#define AVPALETTE_COUNT
Definition: pixfmt.h:33
int64_t strh_flags_offset
Definition: avienc.c:84
static void write_odml_master(AVFormatContext *s, int stream_index)
Definition: avienc.c:210
AVIIentry ** cluster
Definition: avienc.c:61
const char * av_get_media_type_string(enum AVMediaType media_type)
Return a string describing the media_type enum, NULL if media_type is unknown.
Definition: utils.c:79
static int flags
Definition: cpu.c:47
static int avi_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
Definition: avienc.c:794
Main libavformat public API header.
int write_channel_mask
Definition: avienc.c:69
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
Definition: avpacket.c:33
int den
denominator
Definition: rational.h:45
#define av_free(p)
char * value
Definition: dict.h:87
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: timestamp.h:54
int64_t frames_hdr_all
Definition: avienc.c:67
const PixelFormatTag avpriv_pix_fmt_bps_avi[]
Definition: raw.c:285
void * priv_data
Format private data.
Definition: avformat.h:1353
#define FF_PUT_WAV_HEADER_SKIP_CHANNELMASK
Tell ff_put_wav_header() to write an empty channel mask.
Definition: riff.h:58
static void write_header(FFV1Context *f)
Definition: ffv1enc.c:498
int entry
Definition: avienc.c:76
int ff_reshuffle_raw_rgb(AVFormatContext *s, AVPacket **ppkt, AVCodecParameters *par, int expected_stride)
Reshuffles the lines to use the user specified stride.
Definition: rawutils.c:25
AVIIndex indexes
Definition: avienc.c:82
int bits_per_coded_sample
The number of bits per sample in the codedwords.
Definition: avcodec.h:3964
static int avi_write_counters(AVFormatContext *s, int riff_id)
Definition: avienc.c:177
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: avcodec.h:1579
void avio_wb32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:354
#define AVIF_TRUSTCKTYPE
Definition: avi.h:27
#define av_freep(p)
AVCodecParameters * codecpar
Definition: avformat.h:1006
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: avcodec.h:3926
int entry
Definition: avienc.c:58
uint32_t palette[AVPALETTE_COUNT]
Definition: avienc.c:86
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:2138
int stream_index
Definition: avcodec.h:1582
int max_size
Definition: avienc.c:77
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avformat.h:913
int64_t last_dts
Definition: avienc.c:80
#define MKTAG(a, b, c, d)
Definition: common.h:342
#define AVISF_VIDEO_PALCHANGES
Definition: avi.h:36
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60
This structure stores compressed data.
Definition: avcodec.h:1557
static int write_packet(AVFormatContext *s1, AVPacket *pkt)
Definition: v4l2enc.c:86
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:252
static int avi_write_ix(AVFormatContext *s)
Definition: avienc.c:560
3-char terminological language codes as per ISO-IEC 639-2
Definition: avlanguage.h:30
int riff_id
Definition: avienc.c:68
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:240