FFmpeg
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 #include <math.h>
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/avutil.h"
33 #include "libavutil/internal.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 #define AVI_MASTER_INDEX_PREFIX_SIZE (8+2+1+1+4+8+4+4)
55 #define AVI_MASTER_INDEX_ENTRY_SIZE 16 /* bytes per entry */
56 #define AVI_MASTER_INDEX_SIZE_DEFAULT 256 /* number of entries */
57 
58 typedef struct AVIIndex {
59  int64_t indx_start;
61  int entry;
65 } AVIIndex;
66 
67 typedef struct AVIContext {
68  const AVClass *class;
69  int64_t riff_start, movi_list, odml_list;
70  int64_t frames_hdr_all;
71  int riff_id;
75 } AVIContext;
76 
77 typedef struct AVIStream {
78  int64_t frames_hdr_strm;
81  int entry;
82  int max_size;
84 
85  int64_t last_dts;
86 
88 
90 
91  uint32_t palette[AVPALETTE_COUNT];
92  uint32_t old_palette[AVPALETTE_COUNT];
93  int64_t pal_offset;
94 } AVIStream;
95 
97 
98 static inline AVIIentry *avi_get_ientry(const AVIIndex *idx, int ent_id)
99 {
100  int cl = ent_id / AVI_INDEX_CLUSTER_SIZE;
101  int id = ent_id % AVI_INDEX_CLUSTER_SIZE;
102  return &idx->cluster[cl][id];
103 }
104 
105 static int avi_add_ientry(AVFormatContext *s, int stream_index, char *tag,
106  unsigned int flags, unsigned int size)
107 {
108  AVIContext *avi = s->priv_data;
109  AVIOContext *pb = s->pb;
110  AVIStream *avist = s->streams[stream_index]->priv_data;
111  AVIIndex *idx = &avist->indexes;
112  int cl = idx->entry / AVI_INDEX_CLUSTER_SIZE;
113  int id = idx->entry % AVI_INDEX_CLUSTER_SIZE;
114 
115  if (idx->ents_allocated <= idx->entry) {
116  idx->cluster = av_realloc_f(idx->cluster, sizeof(void*), cl+1);
117  if (!idx->cluster) {
118  idx->ents_allocated = 0;
119  idx->entry = 0;
120  return AVERROR(ENOMEM);
121  }
122  idx->cluster[cl] =
124  if (!idx->cluster[cl])
125  return AVERROR(ENOMEM);
127  }
128 
129  if (tag)
130  memcpy(idx->cluster[cl][id].tag, tag, 4);
131  else
132  memset(idx->cluster[cl][id].tag, 0, 4);
133  idx->cluster[cl][id].flags = flags;
134  idx->cluster[cl][id].pos = avio_tell(pb) - avi->movi_list;
135  idx->cluster[cl][id].len = size;
136  avist->max_size = FFMAX(avist->max_size, size);
137  idx->entry++;
138 
139  return 0;
140 }
141 
142 static av_cold int avi_init(struct AVFormatContext *s)
143 {
144  AVIContext *avi = s->priv_data;
145 
146  if (avi->reserve_index_space > 0) {
149  } else
151  av_log(s, AV_LOG_DEBUG, "reserve_index_space:%d master_index_max_size:%d\n",
153 
154  return 1; /* stream initialization continues in avi_write_header */
155 }
156 
158  const char *riff_tag, const char *list_tag)
159 {
160  AVIContext *avi = s->priv_data;
161  int64_t loff;
162  int i;
163 
164  avi->riff_id++;
165  for (i = 0; i < s->nb_streams; i++) {
166  AVIStream *avist = s->streams[i]->priv_data;
168  avist->indexes.entry = 0;
169  }
170 
171  avi->riff_start = ff_start_tag(pb, "RIFF");
172  ffio_wfourcc(pb, riff_tag);
173  loff = ff_start_tag(pb, "LIST");
174  ffio_wfourcc(pb, list_tag);
175  return loff;
176 }
177 
178 static char *avi_stream2fourcc(char *tag, int index, enum AVMediaType type)
179 {
180  tag[0] = '0' + index / 10;
181  tag[1] = '0' + index % 10;
182  if (type == AVMEDIA_TYPE_VIDEO) {
183  tag[2] = 'd';
184  tag[3] = 'c';
185  } else if (type == AVMEDIA_TYPE_SUBTITLE) {
186  // note: this is not an official code
187  tag[2] = 's';
188  tag[3] = 'b';
189  } else {
190  tag[2] = 'w';
191  tag[3] = 'b';
192  }
193  tag[4] = '\0';
194  return tag;
195 }
196 
197 static int avi_write_counters(AVFormatContext *s, int riff_id)
198 {
199  AVIOContext *pb = s->pb;
200  AVIContext *avi = s->priv_data;
201  int n, au_byterate, au_ssize, au_scale, nb_frames = 0;
202  int64_t file_size;
203  AVCodecParameters *par;
204 
205  file_size = avio_tell(pb);
206  for (n = 0; n < s->nb_streams; n++) {
207  AVIStream *avist = s->streams[n]->priv_data;
208 
209  av_assert0(avist->frames_hdr_strm);
210  par = s->streams[n]->codecpar;
211  avio_seek(pb, avist->frames_hdr_strm, SEEK_SET);
212  ff_parse_specific_params(s->streams[n], &au_byterate, &au_ssize, &au_scale);
213  if (au_ssize == 0)
214  avio_wl32(pb, avist->packet_count);
215  else
216  avio_wl32(pb, avist->audio_strm_length / au_ssize);
217  if (par->codec_type == AVMEDIA_TYPE_VIDEO)
218  nb_frames = FFMAX(nb_frames, avist->packet_count);
219  }
220  if (riff_id == 1) {
222  avio_seek(pb, avi->frames_hdr_all, SEEK_SET);
223  avio_wl32(pb, nb_frames);
224  }
225  avio_seek(pb, file_size, SEEK_SET);
226 
227  return 0;
228 }
229 
230 static void write_odml_master(AVFormatContext *s, int stream_index)
231 {
232  AVIOContext *pb = s->pb;
233  AVIContext *avi = s->priv_data;
234  AVStream *st = s->streams[stream_index];
235  AVCodecParameters *par = st->codecpar;
236  AVIStream *avist = st->priv_data;
237  unsigned char tag[5];
238  int j;
239 
240  /* Starting to lay out AVI OpenDML master index.
241  * We want to make it JUNK entry for now, since we'd
242  * like to get away without making AVI an OpenDML one
243  * for compatibility reasons. */
244  avist->indexes.indx_start = ff_start_tag(pb, "JUNK");
245  avio_wl16(pb, 4); /* wLongsPerEntry */
246  avio_w8(pb, 0); /* bIndexSubType (0 == frame index) */
247  avio_w8(pb, 0); /* bIndexType (0 == AVI_INDEX_OF_INDEXES) */
248  avio_wl32(pb, 0); /* nEntriesInUse (will fill out later on) */
249  ffio_wfourcc(pb, avi_stream2fourcc(tag, stream_index, par->codec_type));
250  /* dwChunkId */
251  avio_wl64(pb, 0); /* dwReserved[3] */
252  avio_wl32(pb, 0); /* Must be 0. */
253  for (j = 0; j < avi->master_index_max_size * 2; j++)
254  avio_wl64(pb, 0);
255  ff_end_tag(pb, avist->indexes.indx_start);
256 }
257 
259 {
260  AVIContext *avi = s->priv_data;
261  AVIOContext *pb = s->pb;
262  int bitrate, n, i, nb_frames, au_byterate, au_ssize, au_scale;
263  int64_t max_stream_duration = 0;
264  AVCodecParameters *video_par;
266  int64_t list1, list2, strh, strf;
267  AVDictionaryEntry *t = NULL;
268  int padding;
269 
270  if (s->nb_streams > AVI_MAX_STREAM_COUNT) {
271  av_log(s, AV_LOG_ERROR, "AVI does not support >%d streams\n",
273  return AVERROR(EINVAL);
274  }
275 
276  for (n = 0; n < s->nb_streams; n++) {
277  s->streams[n]->priv_data = av_mallocz(sizeof(AVIStream));
278  if (!s->streams[n]->priv_data)
279  return AVERROR(ENOMEM);
280  }
281 
282  /* header list */
283  avi->riff_id = 0;
284  list1 = avi_start_new_riff(s, pb, "AVI ", "hdrl");
285 
286  /* avi header */
287  ffio_wfourcc(pb, "avih");
288  avio_wl32(pb, 14 * 4);
289  bitrate = 0;
290 
291  video_par = NULL;
292  for (n = 0; n < s->nb_streams; n++) {
293  AVCodecParameters *par = s->streams[n]->codecpar;
294  AVStream *st = s->streams[n];
295  bitrate = FFMIN(bitrate + par->bit_rate, INT32_MAX);
296  if (st->duration > 0) {
297  int64_t stream_duration = av_rescale_q(st->duration, st->time_base, AV_TIME_BASE_Q);
298  max_stream_duration = FFMAX(stream_duration, max_stream_duration);
299  }
300  if (par->codec_type == AVMEDIA_TYPE_VIDEO) {
301  video_par = par;
302  video_st = st;
303  }
304  }
305 
306  /* guess master index size based on bitrate and duration */
307  if (!avi->reserve_index_space) {
308  double duration_est, filesize_est;
309  if (s->duration > 0)
310  duration_est = (double)s->duration / AV_TIME_BASE;
311  else if (max_stream_duration > 0)
312  duration_est = (double)max_stream_duration / AV_TIME_BASE;
313  else
314  duration_est = 10 * 60 * 60; /* default to 10 hours */
315  filesize_est = duration_est * (bitrate / 8) * 1.10; /* add 10% safety margin for muxer+bitrate */
316  avi->master_index_max_size = FFMAX((int)ceil(filesize_est / AVI_MAX_RIFF_SIZE) + 1,
317  avi->master_index_max_size);
318  av_log(s, AV_LOG_DEBUG, "duration_est:%0.3f, filesize_est:%0.1fGiB, master_index_max_size:%d\n",
319  duration_est, filesize_est / (1024*1024*1024), avi->master_index_max_size);
320  }
321 
322  nb_frames = 0;
323 
324  // TODO: should be avg_frame_rate
325  if (video_st)
326  avio_wl32(pb, (uint32_t) (INT64_C(1000000) * video_st->time_base.num /
327  video_st->time_base.den));
328  else
329  avio_wl32(pb, 0);
330  avio_wl32(pb, bitrate / 8); /* XXX: not quite exact */
331  avio_wl32(pb, 0); /* padding */
332  if (!(pb->seekable & AVIO_SEEKABLE_NORMAL))
333  avio_wl32(pb, AVIF_TRUSTCKTYPE | AVIF_ISINTERLEAVED); /* flags */
334  else
336  avi->frames_hdr_all = avio_tell(pb); /* remember this offset to fill later */
337  avio_wl32(pb, nb_frames); /* nb frames, filled later */
338  avio_wl32(pb, 0); /* initial frame */
339  avio_wl32(pb, s->nb_streams); /* nb streams */
340  avio_wl32(pb, 1024 * 1024); /* suggested buffer size */
341  if (video_par) {
342  avio_wl32(pb, video_par->width);
343  avio_wl32(pb, video_par->height);
344  } else {
345  avio_wl32(pb, 0);
346  avio_wl32(pb, 0);
347  }
348  avio_wl32(pb, 0); /* reserved */
349  avio_wl32(pb, 0); /* reserved */
350  avio_wl32(pb, 0); /* reserved */
351  avio_wl32(pb, 0); /* reserved */
352 
353  /* stream list */
354  for (i = 0; i < n; i++) {
355  AVStream *st = s->streams[i];
356  AVCodecParameters *par = st->codecpar;
357  AVIStream *avist = st->priv_data;
358  list2 = ff_start_tag(pb, "LIST");
359  ffio_wfourcc(pb, "strl");
360 
361  /* stream generic header */
362  strh = ff_start_tag(pb, "strh");
363  switch (par->codec_type) {
365  // XSUB subtitles behave like video tracks, other subtitles
366  // are not (yet) supported.
367  if (par->codec_id != AV_CODEC_ID_XSUB) {
368  avpriv_report_missing_feature(s, "Subtitle streams other than DivX XSUB");
369  return AVERROR_PATCHWELCOME;
370  }
371  case AVMEDIA_TYPE_VIDEO:
372  ffio_wfourcc(pb, "vids");
373  break;
374  case AVMEDIA_TYPE_AUDIO:
375  ffio_wfourcc(pb, "auds");
376  break;
377 // case AVMEDIA_TYPE_TEXT:
378 // ffio_wfourcc(pb, "txts");
379 // break;
380  case AVMEDIA_TYPE_DATA:
381  ffio_wfourcc(pb, "dats");
382  break;
383  }
384  if (par->codec_type == AVMEDIA_TYPE_VIDEO ||
385  par->codec_id == AV_CODEC_ID_XSUB)
386  avio_wl32(pb, par->codec_tag);
387  else
388  avio_wl32(pb, 1);
389  avist->strh_flags_offset = avio_tell(pb);
390  avio_wl32(pb, 0); /* flags */
391  avio_wl16(pb, 0); /* priority */
392  avio_wl16(pb, 0); /* language */
393  avio_wl32(pb, 0); /* initial frame */
394 
395  ff_parse_specific_params(st, &au_byterate, &au_ssize, &au_scale);
396 
397  if ( par->codec_type == AVMEDIA_TYPE_VIDEO
398  && par->codec_id != AV_CODEC_ID_XSUB
399  && au_byterate > 1000LL*au_scale) {
400  au_byterate = 600;
401  au_scale = 1;
402  }
403  avpriv_set_pts_info(st, 64, au_scale, au_byterate);
404  if (par->codec_id == AV_CODEC_ID_XSUB)
405  au_scale = au_byterate = 0;
406 
407  avio_wl32(pb, au_scale); /* scale */
408  avio_wl32(pb, au_byterate); /* rate */
409 
410  avio_wl32(pb, 0); /* start */
411  /* remember this offset to fill later */
412  avist->frames_hdr_strm = avio_tell(pb);
413  if (!(pb->seekable & AVIO_SEEKABLE_NORMAL))
414  /* FIXME: this may be broken, but who cares */
416  else
417  avio_wl32(pb, 0); /* length, XXX: filled later */
418 
419  /* suggested buffer size, is set to largest chunk size in avi_write_trailer */
420  if (par->codec_type == AVMEDIA_TYPE_VIDEO)
421  avio_wl32(pb, 1024 * 1024);
422  else if (par->codec_type == AVMEDIA_TYPE_AUDIO)
423  avio_wl32(pb, 12 * 1024);
424  else
425  avio_wl32(pb, 0);
426  avio_wl32(pb, -1); /* quality */
427  avio_wl32(pb, au_ssize); /* sample size */
428  avio_wl32(pb, 0);
429  avio_wl16(pb, par->width);
430  avio_wl16(pb, par->height);
431  ff_end_tag(pb, strh);
432 
433  if (par->codec_type != AVMEDIA_TYPE_DATA) {
434  int ret, flags;
435  enum AVPixelFormat pix_fmt;
436 
437  strf = ff_start_tag(pb, "strf");
438  switch (par->codec_type) {
440  /* XSUB subtitles behave like video tracks, other subtitles
441  * are not (yet) supported. */
442  if (par->codec_id != AV_CODEC_ID_XSUB)
443  break;
444  case AVMEDIA_TYPE_VIDEO:
445  /* WMP expects RGB 5:5:5 rawvideo in avi to have bpp set to 16. */
446  if ( !par->codec_tag
447  && par->codec_id == AV_CODEC_ID_RAWVIDEO
448  && par->format == AV_PIX_FMT_RGB555LE
449  && par->bits_per_coded_sample == 15)
450  par->bits_per_coded_sample = 16;
451  avist->pal_offset = avio_tell(pb) + 40;
452  ff_put_bmp_header(pb, par, 0, 0);
454  par->bits_per_coded_sample);
455  if ( !par->codec_tag
456  && par->codec_id == AV_CODEC_ID_RAWVIDEO
457  && par->format != pix_fmt
458  && par->format != AV_PIX_FMT_NONE)
459  av_log(s, AV_LOG_ERROR, "%s rawvideo cannot be written to avi, output file will be unreadable\n",
461  break;
462  case AVMEDIA_TYPE_AUDIO:
463  flags = (avi->write_channel_mask == 0) ? FF_PUT_WAV_HEADER_SKIP_CHANNELMASK : 0;
464  if ((ret = ff_put_wav_header(s, pb, par, flags)) < 0)
465  return ret;
466  break;
467  default:
468  av_log(s, AV_LOG_ERROR,
469  "Invalid or not supported codec type '%s' found in the input\n",
470  (char *)av_x_if_null(av_get_media_type_string(par->codec_type), "?"));
471  return AVERROR(EINVAL);
472  }
473  ff_end_tag(pb, strf);
474  if ((t = av_dict_get(st->metadata, "title", NULL, 0))) {
475  ff_riff_write_info_tag(s->pb, "strn", t->value);
476  t = NULL;
477  }
478  if (par->codec_id == AV_CODEC_ID_XSUB
479  && (t = av_dict_get(s->streams[i]->metadata, "language", NULL, 0))) {
480  const char* langstr = ff_convert_lang_to(t->value, AV_LANG_ISO639_1);
481  t = NULL;
482  if (langstr) {
483  char* str = av_asprintf("Subtitle - %s-xx;02", langstr);
484  if (!str)
485  return AVERROR(ENOMEM);
486  ff_riff_write_info_tag(s->pb, "strn", str);
487  av_free(str);
488  }
489  }
490  }
491 
492  if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
493  write_odml_master(s, i);
494  }
495 
496  if (par->codec_type == AVMEDIA_TYPE_VIDEO &&
497  st->sample_aspect_ratio.num > 0 &&
498  st->sample_aspect_ratio.den > 0) {
499  int vprp = ff_start_tag(pb, "vprp");
501  (AVRational) { par->width,
502  par->height });
503  int num, den, fields, i;
504  av_reduce(&num, &den, dar.num, dar.den, 0xFFFF);
505  if (par->field_order == AV_FIELD_TT || par->field_order == AV_FIELD_BB ||
506  par->field_order == AV_FIELD_TB || par->field_order == AV_FIELD_BT) {
507  fields = 2; // interlaced
508  } else {
509  fields = 1; // progressive
510  }
511 
512  avio_wl32(pb, 0); // video format = unknown
513  avio_wl32(pb, 0); // video standard = unknown
514  // TODO: should be avg_frame_rate
515  avio_wl32(pb, (2LL*st->time_base.den + st->time_base.num - 1) / (2LL * st->time_base.num));
516  avio_wl32(pb, par->width);
517  avio_wl32(pb, par->height);
518  avio_wl16(pb, den);
519  avio_wl16(pb, num);
520  avio_wl32(pb, par->width);
521  avio_wl32(pb, par->height);
522  avio_wl32(pb, fields); // fields per frame
523 
524  for (i = 0; i < fields; i++) {
525  int start_line;
526  // OpenDML v1.02 is not very specific on what value to use for
527  // start_line when frame data is not coming from a capturing device,
528  // so just use 0/1 depending on the field order for interlaced frames
529  if (par->field_order == AV_FIELD_TT || par->field_order == AV_FIELD_TB) {
530  start_line = (i == 0) ? 0 : 1;
531  } else if (par->field_order == AV_FIELD_BB || par->field_order == AV_FIELD_BT) {
532  start_line = (i == 0) ? 1 : 0;
533  } else {
534  start_line = 0;
535  }
536 
537  avio_wl32(pb, par->height / fields); // compressed bitmap height
538  avio_wl32(pb, par->width); // compressed bitmap width
539  avio_wl32(pb, par->height / fields); // valid bitmap height
540  avio_wl32(pb, par->width); // valid bitmap width
541  avio_wl32(pb, 0); // valid bitmap X offset
542  avio_wl32(pb, 0); // valid bitmap Y offset
543  avio_wl32(pb, 0); // valid X offset in T
544  avio_wl32(pb, start_line); // valid Y start line
545  }
546  ff_end_tag(pb, vprp);
547  }
548 
549  ff_end_tag(pb, list2);
550  }
551 
552  if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
553  /* AVI could become an OpenDML one, if it grows beyond 2Gb range */
554  avi->odml_list = ff_start_tag(pb, "JUNK");
555  ffio_wfourcc(pb, "odml");
556  ffio_wfourcc(pb, "dmlh");
557  avio_wl32(pb, 248);
558  for (i = 0; i < 248; i += 4)
559  avio_wl32(pb, 0);
560  ff_end_tag(pb, avi->odml_list);
561  }
562 
563  ff_end_tag(pb, list1);
564 
566 
567 
568  padding = s->metadata_header_padding;
569  if (padding < 0)
570  padding = 1016;
571 
572  /* some padding for easier tag editing */
573  if (padding) {
574  list2 = ff_start_tag(pb, "JUNK");
575  for (i = padding; i > 0; i -= 4)
576  avio_wl32(pb, 0);
577  ff_end_tag(pb, list2);
578  }
579 
580  avi->movi_list = ff_start_tag(pb, "LIST");
581  ffio_wfourcc(pb, "movi");
582 
583  avio_flush(pb);
584 
585  return 0;
586 }
587 
588 static void update_odml_entry(AVFormatContext *s, int stream_index, int64_t ix, int size)
589 {
590  AVIOContext *pb = s->pb;
591  AVIContext *avi = s->priv_data;
592  AVIStream *avist = s->streams[stream_index]->priv_data;
593  int64_t pos;
594  int au_byterate, au_ssize, au_scale;
595 
596  avio_flush(pb);
597  pos = avio_tell(pb);
598 
599  /* Updating one entry in the AVI OpenDML master index */
600  avio_seek(pb, avist->indexes.indx_start - 8, SEEK_SET);
601  ffio_wfourcc(pb, "indx"); /* enabling this entry */
602  avio_skip(pb, 8);
603  avio_wl32(pb, avi->riff_id - avist->indexes.master_odml_riff_id_base); /* nEntriesInUse */
604  avio_skip(pb, 16 * (avi->riff_id - avist->indexes.master_odml_riff_id_base));
605  avio_wl64(pb, ix); /* qwOffset */
606  avio_wl32(pb, size); /* dwSize */
607  ff_parse_specific_params(s->streams[stream_index], &au_byterate, &au_ssize, &au_scale);
608  if (s->streams[stream_index]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && au_ssize > 0) {
609  uint32_t audio_segm_size = (avist->audio_strm_length - avist->indexes.audio_strm_offset);
610  if ((audio_segm_size % au_ssize > 0) && !avist->sample_requested) {
611  avpriv_request_sample(s, "OpenDML index duration for audio packets with partial frames");
612  avist->sample_requested = 1;
613  }
614  avio_wl32(pb, audio_segm_size / au_ssize); /* dwDuration (sample count) */
615  } else
616  avio_wl32(pb, avist->indexes.entry); /* dwDuration (packet count) */
617 
618  avio_seek(pb, pos, SEEK_SET);
619 }
620 
622 {
623  AVIOContext *pb = s->pb;
624  AVIContext *avi = s->priv_data;
625  char tag[5];
626  char ix_tag[] = "ix00";
627  int i, j;
628 
630 
631  for (i = 0; i < s->nb_streams; i++) {
632  AVIStream *avist = s->streams[i]->priv_data;
634  int64_t pos;
636 
637  pos = avio_tell(pb);
638  update_odml_entry(s, i, pos, size);
639  write_odml_master(s, i);
640  av_assert1(avio_tell(pb) - pos == size);
641  avist->indexes.master_odml_riff_id_base = avi->riff_id - 1;
642  }
644  }
645 
646  for (i = 0; i < s->nb_streams; i++) {
647  AVIStream *avist = s->streams[i]->priv_data;
648  int64_t ix;
649 
650  avi_stream2fourcc(tag, i, s->streams[i]->codecpar->codec_type);
651  ix_tag[3] = '0' + i;
652 
653  /* Writing AVI OpenDML leaf index chunk */
654  ix = avio_tell(pb);
655  ffio_wfourcc(pb, ix_tag); /* ix?? */
656  avio_wl32(pb, avist->indexes.entry * 8 + 24);
657  /* chunk size */
658  avio_wl16(pb, 2); /* wLongsPerEntry */
659  avio_w8(pb, 0); /* bIndexSubType (0 == frame index) */
660  avio_w8(pb, 1); /* bIndexType (1 == AVI_INDEX_OF_CHUNKS) */
661  avio_wl32(pb, avist->indexes.entry);
662  /* nEntriesInUse */
663  ffio_wfourcc(pb, tag); /* dwChunkId */
664  avio_wl64(pb, avi->movi_list); /* qwBaseOffset */
665  avio_wl32(pb, 0); /* dwReserved_3 (must be 0) */
666 
667  for (j = 0; j < avist->indexes.entry; j++) {
668  AVIIentry *ie = avi_get_ientry(&avist->indexes, j);
669  avio_wl32(pb, ie->pos + 8);
670  avio_wl32(pb, ((uint32_t) ie->len & ~0x80000000) |
671  (ie->flags & 0x10 ? 0 : 0x80000000));
672  }
673 
674  update_odml_entry(s, i, ix, avio_tell(pb) - ix);
675  }
676  return 0;
677 }
678 
680 {
681  AVIOContext *pb = s->pb;
682  AVIContext *avi = s->priv_data;
683  int64_t idx_chunk;
684  int i;
685  char tag[5];
686 
687  if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
688  AVIStream *avist;
689  AVIIentry *ie = 0, *tie;
690  int empty, stream_id = -1;
691 
692  idx_chunk = ff_start_tag(pb, "idx1");
693  for (i = 0; i < s->nb_streams; i++) {
694  avist = s->streams[i]->priv_data;
695  avist->entry = 0;
696  }
697 
698  do {
699  empty = 1;
700  for (i = 0; i < s->nb_streams; i++) {
701  avist = s->streams[i]->priv_data;
702  if (avist->indexes.entry <= avist->entry)
703  continue;
704 
705  tie = avi_get_ientry(&avist->indexes, avist->entry);
706  if (empty || tie->pos < ie->pos) {
707  ie = tie;
708  stream_id = i;
709  }
710  empty = 0;
711  }
712  if (!empty) {
713  avist = s->streams[stream_id]->priv_data;
714  if (*ie->tag)
715  ffio_wfourcc(pb, ie->tag);
716  else {
717  avi_stream2fourcc(tag, stream_id,
718  s->streams[stream_id]->codecpar->codec_type);
719  ffio_wfourcc(pb, tag);
720  }
721  avio_wl32(pb, ie->flags);
722  avio_wl32(pb, ie->pos);
723  avio_wl32(pb, ie->len);
724  avist->entry++;
725  }
726  } while (!empty);
727  ff_end_tag(pb, idx_chunk);
728 
729  avi_write_counters(s, avi->riff_id);
730  }
731  return 0;
732 }
733 
734 static int write_skip_frames(AVFormatContext *s, int stream_index, int64_t dts)
735 {
736  AVIStream *avist = s->streams[stream_index]->priv_data;
737  AVCodecParameters *par = s->streams[stream_index]->codecpar;
738 
739  ff_dlog(s, "dts:%s packet_count:%d stream_index:%d\n", av_ts2str(dts), avist->packet_count, stream_index);
740  while (par->block_align == 0 && dts != AV_NOPTS_VALUE &&
741  dts > avist->packet_count && par->codec_id != AV_CODEC_ID_XSUB && avist->packet_count) {
742  AVPacket empty_packet;
743 
744  if (dts - avist->packet_count > 60000) {
745  av_log(s, AV_LOG_ERROR, "Too large number of skipped frames %"PRId64" > 60000\n", dts - avist->packet_count);
746  return AVERROR(EINVAL);
747  }
748 
749  av_init_packet(&empty_packet);
750  empty_packet.size = 0;
751  empty_packet.data = NULL;
752  empty_packet.stream_index = stream_index;
753  avi_write_packet_internal(s, &empty_packet);
754  ff_dlog(s, "dup dts:%s packet_count:%d\n", av_ts2str(dts), avist->packet_count);
755  }
756 
757  return 0;
758 }
759 
761 {
762  const int stream_index = pkt->stream_index;
763  AVCodecParameters *par = s->streams[stream_index]->codecpar;
764  int ret;
765 
766  if (par->codec_id == AV_CODEC_ID_H264 && par->codec_tag == MKTAG('H','2','6','4') && pkt->size) {
767  ret = ff_check_h264_startcode(s, s->streams[stream_index], pkt);
768  if (ret < 0)
769  return ret;
770  }
771 
772  if ((ret = write_skip_frames(s, stream_index, pkt->dts)) < 0)
773  return ret;
774 
775  if (!pkt->size)
776  return avi_write_packet_internal(s, pkt); /* Passthrough */
777 
778  if (par->codec_type == AVMEDIA_TYPE_VIDEO) {
779  AVIStream *avist = s->streams[stream_index]->priv_data;
780  AVIOContext *pb = s->pb;
781  AVPacket *opkt = pkt;
782  int reshuffle_ret;
783  if (par->codec_id == AV_CODEC_ID_RAWVIDEO && par->codec_tag == 0) {
784  int64_t bpc = par->bits_per_coded_sample != 15 ? par->bits_per_coded_sample : 16;
785  int expected_stride = ((par->width * bpc + 31) >> 5)*4;
786  reshuffle_ret = ff_reshuffle_raw_rgb(s, &pkt, par, expected_stride);
787  if (reshuffle_ret < 0)
788  return reshuffle_ret;
789  } else
790  reshuffle_ret = 0;
791  if (par->format == AV_PIX_FMT_PAL8) {
792  ret = ff_get_packet_palette(s, opkt, reshuffle_ret, avist->palette);
793  if (ret < 0)
794  goto fail;
795  if (ret) {
796  int pal_size = 1 << par->bits_per_coded_sample;
797  int pc_tag, i;
798 
800 
801  if ((pb->seekable & AVIO_SEEKABLE_NORMAL) && avist->pal_offset) {
802  int64_t cur_offset = avio_tell(pb);
803  avio_seek(pb, avist->pal_offset, SEEK_SET);
804  for (i = 0; i < pal_size; i++) {
805  uint32_t v = avist->palette[i];
806  avio_wl32(pb, v & 0xffffff);
807  }
808  avio_seek(pb, cur_offset, SEEK_SET);
809  memcpy(avist->old_palette, avist->palette, pal_size * 4);
810  avist->pal_offset = 0;
811  }
812  if (memcmp(avist->palette, avist->old_palette, pal_size * 4)) {
813  unsigned char tag[5];
814  avi_stream2fourcc(tag, stream_index, par->codec_type);
815  tag[2] = 'p'; tag[3] = 'c';
816  if (s->pb->seekable & AVIO_SEEKABLE_NORMAL) {
817  if (avist->strh_flags_offset) {
818  int64_t cur_offset = avio_tell(pb);
819  avio_seek(pb, avist->strh_flags_offset, SEEK_SET);
821  avio_seek(pb, cur_offset, SEEK_SET);
822  avist->strh_flags_offset = 0;
823  }
824  ret = avi_add_ientry(s, stream_index, tag, AVIIF_NO_TIME,
825  pal_size * 4 + 4);
826  if (ret < 0)
827  goto fail;
828  }
829  pc_tag = ff_start_tag(pb, tag);
830  avio_w8(pb, 0);
831  avio_w8(pb, pal_size & 0xFF);
832  avio_wl16(pb, 0); // reserved
833  for (i = 0; i < pal_size; i++) {
834  uint32_t v = avist->palette[i];
835  avio_wb32(pb, v<<8);
836  }
837  ff_end_tag(pb, pc_tag);
838  memcpy(avist->old_palette, avist->palette, pal_size * 4);
839  }
840  }
841  }
842  if (reshuffle_ret) {
843  ret = avi_write_packet_internal(s, pkt);
844 
845 fail:
846  if (reshuffle_ret)
847  av_packet_free(&pkt);
848  return ret;
849  }
850  }
851 
852  return avi_write_packet_internal(s, pkt);
853 }
854 
856 {
857  unsigned char tag[5];
858  unsigned int flags = 0;
859  const int stream_index = pkt->stream_index;
860  int size = pkt->size;
861  AVIContext *avi = s->priv_data;
862  AVIOContext *pb = s->pb;
863  AVIStream *avist = s->streams[stream_index]->priv_data;
864  AVCodecParameters *par = s->streams[stream_index]->codecpar;
865 
866  if (pkt->dts != AV_NOPTS_VALUE)
867  avist->last_dts = pkt->dts + pkt->duration;
868 
869  avist->packet_count++;
870 
871  // Make sure to put an OpenDML chunk when the file size exceeds the limits
872  if ((pb->seekable & AVIO_SEEKABLE_NORMAL) &&
873  (avio_tell(pb) - avi->riff_start > AVI_MAX_RIFF_SIZE)) {
874  avi_write_ix(s);
875  ff_end_tag(pb, avi->movi_list);
876 
877  if (avi->riff_id == 1)
878  avi_write_idx1(s);
879 
880  ff_end_tag(pb, avi->riff_start);
881  avi->movi_list = avi_start_new_riff(s, pb, "AVIX", "movi");
882  }
883 
884  avi_stream2fourcc(tag, stream_index, par->codec_type);
885  if (pkt->flags & AV_PKT_FLAG_KEY)
886  flags = 0x10;
887  if (par->codec_type == AVMEDIA_TYPE_AUDIO)
888  avist->audio_strm_length += size;
889 
890  if (s->pb->seekable & AVIO_SEEKABLE_NORMAL) {
891  int ret;
892  ret = avi_add_ientry(s, stream_index, NULL, flags, size);
893  if (ret < 0)
894  return ret;
895  }
896 
897  avio_write(pb, tag, 4);
898  avio_wl32(pb, size);
899  avio_write(pb, pkt->data, size);
900  if (size & 1)
901  avio_w8(pb, 0);
902 
903  return 0;
904 }
905 
907 {
908  AVIContext *avi = s->priv_data;
909  AVIOContext *pb = s->pb;
910  int res = 0;
911  int i, n, nb_frames;
912  int64_t file_size;
913 
914  for (i = 0; i < s->nb_streams; i++) {
915  AVIStream *avist = s->streams[i]->priv_data;
916  write_skip_frames(s, i, avist->last_dts);
917  }
918 
919  if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
920  if (avi->riff_id == 1) {
921  ff_end_tag(pb, avi->movi_list);
922  res = avi_write_idx1(s);
923  ff_end_tag(pb, avi->riff_start);
924  } else {
925  avi_write_ix(s);
926  ff_end_tag(pb, avi->movi_list);
927  ff_end_tag(pb, avi->riff_start);
928 
929  file_size = avio_tell(pb);
930  avio_seek(pb, avi->odml_list - 8, SEEK_SET);
931  ffio_wfourcc(pb, "LIST"); /* Making this AVI OpenDML one */
932  avio_skip(pb, 16);
933 
934  for (n = nb_frames = 0; n < s->nb_streams; n++) {
935  AVCodecParameters *par = s->streams[n]->codecpar;
936  AVIStream *avist = s->streams[n]->priv_data;
937 
938  if (par->codec_type == AVMEDIA_TYPE_VIDEO) {
939  if (nb_frames < avist->packet_count)
940  nb_frames = avist->packet_count;
941  } else {
942  if (par->codec_id == AV_CODEC_ID_MP2 ||
943  par->codec_id == AV_CODEC_ID_MP3)
944  nb_frames += avist->packet_count;
945  }
946  }
947  avio_wl32(pb, nb_frames);
948  avio_seek(pb, file_size, SEEK_SET);
949 
950  avi_write_counters(s, avi->riff_id);
951  }
952  }
953 
954  if (avi->riff_id >= avi->master_index_max_size) {
955  int index_space = AVI_MASTER_INDEX_PREFIX_SIZE +
957  av_log(s, AV_LOG_WARNING, "Output file not strictly OpenDML compliant, "
958  "consider re-muxing with 'reserve_index_space' option value >= %d\n",
959  index_space);
960  }
961 
962  for (i = 0; i < s->nb_streams; i++) {
963  AVIStream *avist = s->streams[i]->priv_data;
964  if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
965  avio_seek(pb, avist->frames_hdr_strm + 4, SEEK_SET);
966  avio_wl32(pb, avist->max_size);
967  }
968  }
969 
970  return res;
971 }
972 
974 {
975  for (int i = 0; i < s->nb_streams; i++) {
976  AVIStream *avist = s->streams[i]->priv_data;
977  if (!avist)
978  continue;
979  for (int j = 0; j < avist->indexes.ents_allocated / AVI_INDEX_CLUSTER_SIZE; j++)
980  av_freep(&avist->indexes.cluster[j]);
981  av_freep(&avist->indexes.cluster);
982  avist->indexes.ents_allocated = avist->indexes.entry = 0;
983  }
984 }
985 
986 #define OFFSET(x) offsetof(AVIContext, x)
987 #define ENC AV_OPT_FLAG_ENCODING_PARAM
988 static const AVOption options[] = {
989  { "reserve_index_space", "reserve space (in bytes) at the beginning of the file for each stream index", OFFSET(reserve_index_space), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, ENC },
990  { "write_channel_mask", "write channel mask into wave format header", OFFSET(write_channel_mask), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, ENC },
991  { NULL },
992 };
993 
994 static const AVClass avi_muxer_class = {
995  .class_name = "AVI muxer",
996  .item_name = av_default_item_name,
997  .option = options,
998  .version = LIBAVUTIL_VERSION_INT,
999 };
1000 
1002  .name = "avi",
1003  .long_name = NULL_IF_CONFIG_SMALL("AVI (Audio Video Interleaved)"),
1004  .mime_type = "video/x-msvideo",
1005  .extensions = "avi",
1006  .priv_data_size = sizeof(AVIContext),
1007  .audio_codec = CONFIG_LIBMP3LAME ? AV_CODEC_ID_MP3 : AV_CODEC_ID_AC3,
1008  .video_codec = AV_CODEC_ID_MPEG4,
1009  .init = avi_init,
1010  .deinit = avi_deinit,
1014  .codec_tag = (const AVCodecTag * const []) {
1016  },
1017  .priv_class = &avi_muxer_class,
1018 };
#define AVI_MASTER_INDEX_PREFIX_SIZE
Definition: avienc.c:54
static int write_skip_frames(AVFormatContext *s, int stream_index, int64_t dts)
Definition: avienc.c:734
static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue)
Definition: ffmpeg.c:690
#define NULL
Definition: coverity.c:32
enum AVFieldOrder field_order
Video only.
Definition: avcodec.h:4049
void avio_wl16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:472
Bytestream IO Context.
Definition: avio.h:161
static enum AVPixelFormat pix_fmt
#define AVI_MASTER_INDEX_SIZE_DEFAULT
Definition: avienc.c:56
#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:246
void ff_put_bmp_header(AVIOContext *pb, AVCodecParameters *par, int for_asf, int ignore_extradata)
Definition: riffenc.c:209
int ff_put_wav_header(AVFormatContext *s, AVIOContext *pb, AVCodecParameters *par, int flags)
Write WAVEFORMAT header structure.
Definition: riffenc.c:54
int master_odml_riff_id_base
Definition: avienc.c:63
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
unsigned int pos
Definition: avienc.c:49
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
int ents_allocated
Definition: avienc.c:62
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:4929
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
#define AVI_MAX_RIFF_SIZE
Definition: avi.h:31
#define avpriv_request_sample(...)
int64_t audio_strm_offset
Definition: avienc.c:60
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:3968
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:943
int num
Numerator.
Definition: rational.h:59
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), little-endian, X=unused/undefined ...
Definition: pixfmt.h:108
int size
Definition: avcodec.h:1481
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:246
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:191
Convenience header that includes libavutil&#39;s core.
static char * avi_stream2fourcc(char *tag, int index, enum AVMediaType type)
Definition: avienc.c:178
GLint GLenum type
Definition: opengl_enc.c:104
void * priv_data
Definition: avformat.h:896
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:334
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:236
static AVPacket pkt
AVOutputFormat ff_avi_muxer
Definition: avienc.c:1001
int64_t frames_hdr_strm
Definition: avienc.c:78
This struct describes the properties of an encoded stream.
Definition: avcodec.h:3960
Format I/O context.
Definition: avformat.h:1358
int64_t odml_list
Definition: avienc.c:69
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 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:372
#define av_cold
Definition: attributes.h:82
#define av_malloc(s)
Opaque data information usually continuous.
Definition: avutil.h:203
int width
Video only.
Definition: avcodec.h:4034
8 bits with AV_PIX_FMT_RGB32 palette
Definition: pixfmt.h:77
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:105
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: avcodec.h:1498
int64_t movi_list
Definition: avidec.c:74
#define OFFSET(x)
Definition: avienc.c:986
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1426
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:40
uint8_t * data
Definition: avcodec.h:1480
int64_t riff_start
Definition: avienc.c:69
#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:157
ptrdiff_t size
Definition: opengl_enc.c:100
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:557
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
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:218
static av_always_inline void ffio_wfourcc(AVIOContext *pb, const uint8_t *s)
Definition: avio_internal.h:58
#define av_log(a,...)
static const AVClass avi_muxer_class
Definition: avienc.c:994
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
Definition: avcodec.h:3997
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1512
void avio_wl64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:460
static void * av_x_if_null(const void *p, const void *x)
Return x default pointer in case p is NULL.
Definition: avutil.h:308
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
uint32_t old_palette[AVPALETTE_COUNT]
Definition: avienc.c:92
#define ENC
Definition: avienc.c:987
#define AVI_MAX_STREAM_COUNT
Definition: avi.h:32
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
#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:679
int master_index_max_size
Definition: avienc.c:73
void ff_parse_specific_params(AVStream *st, int *au_rate, int *au_ssize, int *au_scale)
Definition: riffenc.c:265
int ff_check_h264_startcode(AVFormatContext *s, const AVStream *st, const AVPacket *pkt)
Check presence of H264 startcode.
Definition: mpegtsenc.c:1441
const char * ff_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:186
void ff_riff_write_info_tag(AVIOContext *pb, const char *tag, const char *str)
Write a single RIFF info tag.
Definition: riffenc.c:295
char tag[4]
Definition: avienc.c:47
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
AVStream * video_st
Definition: movenc.c:59
preferred ID for decoding MPEG audio layer 1, 2 or 3
Definition: avcodec.h:566
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:3964
simple assert() macros that are a bit more flexible than ISO C assert().
unsigned int flags
Definition: avienc.c:48
const AVCodecTag ff_codec_wav_tags[]
Definition: riff.c:500
#define FFMAX(a, b)
Definition: common.h:94
#define fail()
Definition: checkasm.h:122
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1486
int packet_count
Definition: avienc.c:80
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:1414
static void update_odml_entry(AVFormatContext *s, int stream_index, int64_t ix, int size)
Definition: avienc.c:588
int block_align
Audio only.
Definition: avcodec.h:4085
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:260
the definition of that something depends on the semantic of the filter The callback must examine the status of the filter s links and proceed accordingly The status of output links is stored in the status_in and status_out fields and tested by the then the processing requires a frame on this link and the filter is expected to make efforts in that direction The status of input links is stored by the fifo and status_out fields
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:53
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:254
#define FFMIN(a, b)
Definition: common.h:96
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:505
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:5722
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:906
#define s(width, name)
Definition: cbs_vp9.c:257
int n
Definition: avisynth_c.h:760
AVDictionary * metadata
Definition: avformat.h:945
int64_t indx_start
Definition: avienc.c:59
int64_t audio_strm_length
Definition: avienc.c:79
static int avi_write_header(AVFormatContext *s)
Definition: avienc.c:258
#define AVIF_HASINDEX
Definition: avi.h:24
if(ret)
int metadata_header_padding
Number of bytes to be written as padding in a metadata header.
Definition: avformat.h:1858
Stream structure.
Definition: avformat.h:881
int64_t pal_offset
Definition: avienc.c:93
#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:760
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
Definition: avio.h:40
enum AVPixelFormat avpriv_find_pix_fmt(const PixelFormatTag *tags, unsigned int fourcc)
Definition: utils.c:467
static av_cold int avi_init(struct AVFormatContext *s)
Definition: avienc.c:142
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:260
AVIOContext * pb
I/O context.
Definition: avformat.h:1400
static const AVOption options[]
Definition: avienc.c:988
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:196
int sample_requested
Definition: avienc.c:83
#define AVIIF_NO_TIME
Definition: avi.h:39
void ff_riff_write_info(AVFormatContext *s)
Write all recognized RIFF tags from s->metadata.
Definition: riffenc.c:327
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 (pair of numerator and denominator).
Definition: rational.h:58
#define AVI_MASTER_INDEX_ENTRY_SIZE
Definition: avienc.c:55
void avio_flush(AVIOContext *s)
Force flushing of buffered data.
Definition: aviobuf.c:238
AVMediaType
Definition: avutil.h:199
static void avi_deinit(AVFormatContext *s)
Definition: avienc.c:973
static AVIIentry * avi_get_ientry(const AVIIndex *idx, int ent_id)
Definition: avienc.c:98
#define AVPALETTE_COUNT
Definition: pixfmt.h:33
int64_t strh_flags_offset
Definition: avienc.c:89
static void write_odml_master(AVFormatContext *s, int stream_index)
Definition: avienc.c:230
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
AVIIentry ** cluster
Definition: avienc.c:64
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:76
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition: avformat.h:930
int64_t bitrate
Definition: h264_levels.c:131
static int avi_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
Definition: avienc.c:855
Main libavformat public API header.
int write_channel_mask
Definition: avienc.c:74
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:60
#define av_free(p)
int reserve_index_space
Definition: avienc.c:72
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:70
const PixelFormatTag avpriv_pix_fmt_bps_avi[]
Definition: raw.c:315
void * priv_data
Format private data.
Definition: avformat.h:1386
#define FF_PUT_WAV_HEADER_SKIP_CHANNELMASK
Tell ff_put_wav_header() to write an empty channel mask.
Definition: riff.h:59
static void write_header(FFV1Context *f)
Definition: ffv1enc.c:349
int entry
Definition: avienc.c:81
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:87
int bits_per_coded_sample
The number of bits per sample in the codedwords.
Definition: avcodec.h:4010
static int avi_write_counters(AVFormatContext *s, int riff_id)
Definition: avienc.c:197
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: avcodec.h:1479
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:80
void avio_wb32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:380
int64_t duration
Duration of the stream, in AV_TIME_BASE fractional seconds.
Definition: avformat.h:1473
#define AVIF_TRUSTCKTYPE
Definition: avi.h:27
#define av_freep(p)
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1028
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: avcodec.h:3972
int entry
Definition: avienc.c:61
uint32_t palette[AVPALETTE_COUNT]
Definition: avienc.c:91
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:2438
int stream_index
Definition: avcodec.h:1482
int max_size
Definition: avienc.c:82
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avformat.h:910
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Frame references ownership and permissions
int64_t last_dts
Definition: avienc.c:85
#define MKTAG(a, b, c, d)
Definition: common.h:366
enum AVCodecID id
#define AVISF_VIDEO_PALCHANGES
Definition: avi.h:35
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
This structure stores compressed data.
Definition: avcodec.h:1457
static int avi_write_ix(AVFormatContext *s)
Definition: avienc.c:621
3-char terminological language codes as per ISO-IEC 639-2
Definition: avlanguage.h:33
int riff_id
Definition: avienc.c:71
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248