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