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