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;
71  int64_t frames_hdr_all;
72  int riff_id;
77 } AVIContext;
78 
79 typedef struct AVIStream {
80  int64_t frames_hdr_strm;
83  int entry;
84  int max_size;
86 
87  int64_t last_dts;
88 
90 
92 
95  int64_t pal_offset;
96 } AVIStream;
97 
99 
100 static inline AVIIentry *avi_get_ientry(const AVIIndex *idx, int ent_id)
101 {
102  int cl = ent_id / AVI_INDEX_CLUSTER_SIZE;
103  int id = ent_id % AVI_INDEX_CLUSTER_SIZE;
104  return &idx->cluster[cl][id];
105 }
106 
107 static int avi_add_ientry(AVFormatContext *s, int stream_index, char *tag,
108  unsigned int flags, unsigned int size)
109 {
110  AVIContext *avi = s->priv_data;
111  AVIOContext *pb = s->pb;
112  AVIStream *avist = s->streams[stream_index]->priv_data;
113  AVIIndex *idx = &avist->indexes;
114  int cl = idx->entry / AVI_INDEX_CLUSTER_SIZE;
115  int id = idx->entry % AVI_INDEX_CLUSTER_SIZE;
116 
117  if (idx->ents_allocated <= idx->entry) {
118  idx->cluster = av_realloc_f(idx->cluster, sizeof(void*), cl+1);
119  if (!idx->cluster) {
120  idx->ents_allocated = 0;
121  idx->entry = 0;
122  return AVERROR(ENOMEM);
123  }
124  idx->cluster[cl] =
126  if (!idx->cluster[cl])
127  return AVERROR(ENOMEM);
129  }
130 
131  if (tag)
132  memcpy(idx->cluster[cl][id].tag, tag, 4);
133  else
134  memset(idx->cluster[cl][id].tag, 0, 4);
135  idx->cluster[cl][id].flags = flags;
136  idx->cluster[cl][id].pos = avio_tell(pb) - avi->movi_list;
137  idx->cluster[cl][id].len = size;
138  avist->max_size = FFMAX(avist->max_size, size);
139  idx->entry++;
140 
141  return 0;
142 }
143 
144 static av_cold int avi_init(struct AVFormatContext *s)
145 {
146  AVIContext *avi = s->priv_data;
147 
148  if (avi->reserve_index_space > 0) {
151  } else
153  av_log(s, AV_LOG_DEBUG, "reserve_index_space:%d master_index_max_size:%d\n",
155 
156  return 1; /* stream initialization continues in avi_write_header */
157 }
158 
160  const char *riff_tag, const char *list_tag)
161 {
162  AVIContext *avi = s->priv_data;
163  int64_t loff;
164  int i;
165 
166  avi->riff_id++;
167  for (i = 0; i < s->nb_streams; i++) {
168  AVIStream *avist = s->streams[i]->priv_data;
170  avist->indexes.entry = 0;
171  }
172 
173  avi->riff_start = ff_start_tag(pb, "RIFF");
174  ffio_wfourcc(pb, riff_tag);
175  loff = ff_start_tag(pb, "LIST");
176  ffio_wfourcc(pb, list_tag);
177  return loff;
178 }
179 
180 static char *avi_stream2fourcc(char *tag, int index, enum AVMediaType type)
181 {
182  tag[0] = '0' + index / 10;
183  tag[1] = '0' + index % 10;
184  if (type == AVMEDIA_TYPE_VIDEO) {
185  tag[2] = 'd';
186  tag[3] = 'c';
187  } else if (type == AVMEDIA_TYPE_SUBTITLE) {
188  // note: this is not an official code
189  tag[2] = 's';
190  tag[3] = 'b';
191  } else {
192  tag[2] = 'w';
193  tag[3] = 'b';
194  }
195  tag[4] = '\0';
196  return tag;
197 }
198 
199 static int avi_write_counters(AVFormatContext *s, int riff_id)
200 {
201  AVIOContext *pb = s->pb;
202  AVIContext *avi = s->priv_data;
203  int n, au_byterate, au_ssize, au_scale, nb_frames = 0;
204  int64_t file_size;
205  AVCodecParameters *par;
206 
207  file_size = avio_tell(pb);
208  for (n = 0; n < s->nb_streams; n++) {
209  AVIStream *avist = s->streams[n]->priv_data;
210 
211  av_assert0(avist->frames_hdr_strm);
212  par = s->streams[n]->codecpar;
213  avio_seek(pb, avist->frames_hdr_strm, SEEK_SET);
214  ff_parse_specific_params(s->streams[n], &au_byterate, &au_ssize, &au_scale);
215  if (au_ssize == 0)
216  avio_wl32(pb, avist->packet_count);
217  else
218  avio_wl32(pb, avist->audio_strm_length / au_ssize);
219  if (par->codec_type == AVMEDIA_TYPE_VIDEO)
220  nb_frames = FFMAX(nb_frames, avist->packet_count);
221  }
222  if (riff_id == 1) {
224  avio_seek(pb, avi->frames_hdr_all, SEEK_SET);
225  avio_wl32(pb, nb_frames);
226  }
227  avio_seek(pb, file_size, SEEK_SET);
228 
229  return 0;
230 }
231 
232 static void write_odml_master(AVFormatContext *s, int stream_index)
233 {
234  AVIOContext *pb = s->pb;
235  AVIContext *avi = s->priv_data;
236  AVStream *st = s->streams[stream_index];
237  AVCodecParameters *par = st->codecpar;
238  AVIStream *avist = st->priv_data;
239  unsigned char tag[5];
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  ffio_fill(pb, 0, 3 * 4 /* dwReserved[3] */
253  + 16LL * avi->master_index_max_size);
254  ff_end_tag(pb, avist->indexes.indx_start);
255 }
256 
258 {
259  AVIContext *avi = s->priv_data;
260  AVIOContext *pb = s->pb;
261  int bitrate, n, i, nb_frames, au_byterate, au_ssize, au_scale;
262  int64_t max_stream_duration = 0;
263  AVCodecParameters *video_par;
265  int64_t list1, list2, strh, strf;
266  AVDictionaryEntry *t = NULL;
267  int padding;
268 
269  if (s->nb_streams > AVI_MAX_STREAM_COUNT) {
270  av_log(s, AV_LOG_ERROR, "AVI does not support "
271  ">"AV_STRINGIFY(AVI_MAX_STREAM_COUNT)" streams\n");
272  return AVERROR(EINVAL);
273  }
274 
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 /
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  ffio_fill(pb, 0, 4 * 4); /* reserved */
350 
351  /* stream list */
352  for (i = 0; i < n; i++) {
353  AVStream *st = s->streams[i];
354  AVCodecParameters *par = st->codecpar;
355  AVIStream *avist = st->priv_data;
356  list2 = ff_start_tag(pb, "LIST");
357  ffio_wfourcc(pb, "strl");
358 
359  /* stream generic header */
360  strh = ff_start_tag(pb, "strh");
361  switch (par->codec_type) {
363  // XSUB subtitles behave like video tracks, other subtitles
364  // are not (yet) supported.
365  if (par->codec_id != AV_CODEC_ID_XSUB) {
366  avpriv_report_missing_feature(s, "Subtitle streams other than DivX XSUB");
367  return AVERROR_PATCHWELCOME;
368  }
369  case AVMEDIA_TYPE_VIDEO:
370  ffio_wfourcc(pb, "vids");
371  break;
372  case AVMEDIA_TYPE_AUDIO:
373  ffio_wfourcc(pb, "auds");
374  break;
375 // case AVMEDIA_TYPE_TEXT:
376 // ffio_wfourcc(pb, "txts");
377 // break;
378  case AVMEDIA_TYPE_DATA:
379  ffio_wfourcc(pb, "dats");
380  break;
381  }
382  if (par->codec_type == AVMEDIA_TYPE_VIDEO ||
383  par->codec_id == AV_CODEC_ID_XSUB)
384  avio_wl32(pb, par->codec_tag);
385  else
386  avio_wl32(pb, 1);
387  avist->strh_flags_offset = avio_tell(pb);
388  avio_wl32(pb, 0); /* flags */
389  avio_wl16(pb, 0); /* priority */
390  avio_wl16(pb, 0); /* language */
391  avio_wl32(pb, 0); /* initial frame */
392 
393  ff_parse_specific_params(st, &au_byterate, &au_ssize, &au_scale);
394 
395  if ( par->codec_type == AVMEDIA_TYPE_VIDEO
396  && par->codec_id != AV_CODEC_ID_XSUB
397  && au_byterate > 1000LL*au_scale) {
398  au_byterate = 600;
399  au_scale = 1;
400  }
401  avpriv_set_pts_info(st, 64, au_scale, au_byterate);
402  if (par->codec_id == AV_CODEC_ID_XSUB)
403  au_scale = au_byterate = 0;
404 
405  avio_wl32(pb, au_scale); /* scale */
406  avio_wl32(pb, au_byterate); /* rate */
407 
408  avio_wl32(pb, 0); /* start */
409  /* remember this offset to fill later */
410  avist->frames_hdr_strm = avio_tell(pb);
411  if (!(pb->seekable & AVIO_SEEKABLE_NORMAL))
412  /* FIXME: this may be broken, but who cares */
414  else
415  avio_wl32(pb, 0); /* length, XXX: filled later */
416 
417  /* suggested buffer size, is set to largest chunk size in avi_write_trailer */
418  if (par->codec_type == AVMEDIA_TYPE_VIDEO)
419  avio_wl32(pb, 1024 * 1024);
420  else if (par->codec_type == AVMEDIA_TYPE_AUDIO)
421  avio_wl32(pb, 12 * 1024);
422  else
423  avio_wl32(pb, 0);
424  avio_wl32(pb, -1); /* quality */
425  avio_wl32(pb, au_ssize); /* sample size */
426  avio_wl32(pb, 0);
427  avio_wl16(pb, par->width);
428  avio_wl16(pb, par->height);
429  ff_end_tag(pb, strh);
430 
431  if (par->codec_type != AVMEDIA_TYPE_DATA) {
432  int ret, flags;
433  enum AVPixelFormat pix_fmt;
434 
435  strf = ff_start_tag(pb, "strf");
436  switch (par->codec_type) {
438  /* XSUB subtitles behave like video tracks, other subtitles
439  * are not (yet) supported. */
440  if (par->codec_id != AV_CODEC_ID_XSUB)
441  break;
442  case AVMEDIA_TYPE_VIDEO:
443  /* WMP expects RGB 5:5:5 rawvideo in avi to have bpp set to 16. */
444  if ( !par->codec_tag
445  && par->codec_id == AV_CODEC_ID_RAWVIDEO
446  && par->format == AV_PIX_FMT_RGB555LE
447  && par->bits_per_coded_sample == 15)
448  par->bits_per_coded_sample = 16;
449  avist->pal_offset = avio_tell(pb) + 40;
450  ff_put_bmp_header(pb, par, 0, 0, avi->flipped_raw_rgb);
452  par->bits_per_coded_sample);
453  if ( !par->codec_tag
454  && par->codec_id == AV_CODEC_ID_RAWVIDEO
455  && par->format != pix_fmt
456  && par->format != AV_PIX_FMT_NONE)
457  av_log(s, AV_LOG_ERROR, "%s rawvideo cannot be written to avi, output file will be unreadable\n",
459 
460  if (par->format == AV_PIX_FMT_PAL8) {
461  if (par->bits_per_coded_sample < 0 || par->bits_per_coded_sample > 8) {
462  av_log(s, AV_LOG_ERROR, "PAL8 with %d bps is not allowed\n", par->bits_per_coded_sample);
463  return AVERROR(EINVAL);
464  }
465  }
466 
467  break;
468  case AVMEDIA_TYPE_AUDIO:
470  if ((ret = ff_put_wav_header(s, pb, par, flags)) < 0)
471  return ret;
472  break;
473  default:
475  "Invalid or not supported codec type '%s' found in the input\n",
476  (char *)av_x_if_null(av_get_media_type_string(par->codec_type), "?"));
477  return AVERROR(EINVAL);
478  }
479  ff_end_tag(pb, strf);
480  if ((t = av_dict_get(st->metadata, "title", NULL, 0))) {
481  ff_riff_write_info_tag(s->pb, "strn", t->value);
482  t = NULL;
483  }
484  if (par->codec_id == AV_CODEC_ID_XSUB
485  && (t = av_dict_get(s->streams[i]->metadata, "language", NULL, 0))) {
486  const char* langstr = ff_convert_lang_to(t->value, AV_LANG_ISO639_1);
487  t = NULL;
488  if (langstr) {
489  char* str = av_asprintf("Subtitle - %s-xx;02", langstr);
490  if (!str)
491  return AVERROR(ENOMEM);
492  ff_riff_write_info_tag(s->pb, "strn", str);
493  av_free(str);
494  }
495  }
496  }
497 
498  if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
500  }
501 
502  if (par->codec_type == AVMEDIA_TYPE_VIDEO &&
503  st->sample_aspect_ratio.num > 0 &&
504  st->sample_aspect_ratio.den > 0) {
505  int vprp = ff_start_tag(pb, "vprp");
507  (AVRational) { par->width,
508  par->height });
509  int num, den, fields, i;
510  av_reduce(&num, &den, dar.num, dar.den, 0xFFFF);
511  if (par->field_order == AV_FIELD_TT || par->field_order == AV_FIELD_BB ||
512  par->field_order == AV_FIELD_TB || par->field_order == AV_FIELD_BT) {
513  fields = 2; // interlaced
514  } else {
515  fields = 1; // progressive
516  }
517 
518  avio_wl32(pb, 0); // video format = unknown
519  avio_wl32(pb, 0); // video standard = unknown
520  // TODO: should be avg_frame_rate
521  avio_wl32(pb, (2LL*st->time_base.den + st->time_base.num - 1) / (2LL * st->time_base.num));
522  avio_wl32(pb, par->width);
523  avio_wl32(pb, par->height);
524  avio_wl16(pb, den);
525  avio_wl16(pb, num);
526  avio_wl32(pb, par->width);
527  avio_wl32(pb, par->height);
528  avio_wl32(pb, fields); // fields per frame
529 
530  for (i = 0; i < fields; i++) {
531  int start_line;
532  // OpenDML v1.02 is not very specific on what value to use for
533  // start_line when frame data is not coming from a capturing device,
534  // so just use 0/1 depending on the field order for interlaced frames
535  if (par->field_order == AV_FIELD_TT || par->field_order == AV_FIELD_TB) {
536  start_line = (i == 0) ? 0 : 1;
537  } else if (par->field_order == AV_FIELD_BB || par->field_order == AV_FIELD_BT) {
538  start_line = (i == 0) ? 1 : 0;
539  } else {
540  start_line = 0;
541  }
542 
543  avio_wl32(pb, par->height / fields); // compressed bitmap height
544  avio_wl32(pb, par->width); // compressed bitmap width
545  avio_wl32(pb, par->height / fields); // valid bitmap height
546  avio_wl32(pb, par->width); // valid bitmap width
547  avio_wl32(pb, 0); // valid bitmap X offset
548  avio_wl32(pb, 0); // valid bitmap Y offset
549  avio_wl32(pb, 0); // valid X offset in T
550  avio_wl32(pb, start_line); // valid Y start line
551  }
552  ff_end_tag(pb, vprp);
553  }
554 
555  ff_end_tag(pb, list2);
556  }
557 
558  if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
559  /* AVI could become an OpenDML one, if it grows beyond 2Gb range */
560  avi->odml_list = ff_start_tag(pb, "JUNK");
561  ffio_wfourcc(pb, "odml");
562  ffio_wfourcc(pb, "dmlh");
563  avio_wl32(pb, 248);
564  ffio_fill(pb, 0, 248);
565  ff_end_tag(pb, avi->odml_list);
566  }
567 
568  ff_end_tag(pb, list1);
569 
571 
572 
573  padding = s->metadata_header_padding;
574  if (padding < 0)
575  padding = 1016;
576 
577  /* some padding for easier tag editing */
578  if (padding) {
579  list2 = ff_start_tag(pb, "JUNK");
580  ffio_fill(pb, 0, FFALIGN((uint32_t)padding, 4));
581  ff_end_tag(pb, list2);
582  }
583 
584  avi->movi_list = ff_start_tag(pb, "LIST");
585  ffio_wfourcc(pb, "movi");
586 
587  return 0;
588 }
589 
590 static void update_odml_entry(AVFormatContext *s, int stream_index, int64_t ix, int size)
591 {
592  AVIOContext *pb = s->pb;
593  AVIContext *avi = s->priv_data;
594  AVIStream *avist = s->streams[stream_index]->priv_data;
595  int64_t pos;
596  int au_byterate, au_ssize, au_scale;
597 
598  pos = avio_tell(pb);
599 
600  /* Updating one entry in the AVI OpenDML master index */
601  avio_seek(pb, avist->indexes.indx_start - 8, SEEK_SET);
602  ffio_wfourcc(pb, "indx"); /* enabling this entry */
603  avio_skip(pb, 8);
604  avio_wl32(pb, avi->riff_id - avist->indexes.master_odml_riff_id_base); /* nEntriesInUse */
605  avio_skip(pb, 16 * (avi->riff_id - avist->indexes.master_odml_riff_id_base));
606  avio_wl64(pb, ix); /* qwOffset */
607  avio_wl32(pb, size); /* dwSize */
608  ff_parse_specific_params(s->streams[stream_index], &au_byterate, &au_ssize, &au_scale);
609  if (s->streams[stream_index]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && au_ssize > 0) {
610  uint32_t audio_segm_size = (avist->audio_strm_length - avist->indexes.audio_strm_offset);
611  if ((audio_segm_size % au_ssize > 0) && !avist->sample_requested) {
612  avpriv_request_sample(s, "OpenDML index duration for audio packets with partial frames");
613  avist->sample_requested = 1;
614  }
615  avio_wl32(pb, audio_segm_size / au_ssize); /* dwDuration (sample count) */
616  } else
617  avio_wl32(pb, avist->indexes.entry); /* dwDuration (packet count) */
618 
619  avio_seek(pb, pos, SEEK_SET);
620 }
621 
623 {
624  AVIOContext *pb = s->pb;
625  AVIContext *avi = s->priv_data;
626  char tag[5];
627  char ix_tag[] = "ix00";
628  int i, j;
629 
631 
632  for (i = 0; i < s->nb_streams; i++) {
633  AVIStream *avist = s->streams[i]->priv_data;
635  int64_t pos;
637 
638  pos = avio_tell(pb);
641  av_assert1(avio_tell(pb) - pos == size);
642  avist->indexes.master_odml_riff_id_base = avi->riff_id - 1;
643  }
645  }
646 
647  for (i = 0; i < s->nb_streams; i++) {
648  AVIStream *avist = s->streams[i]->priv_data;
649  int64_t ix;
650 
651  avi_stream2fourcc(tag, i, s->streams[i]->codecpar->codec_type);
652  ix_tag[3] = '0' + i;
653 
654  /* Writing AVI OpenDML leaf index chunk */
655  ix = avio_tell(pb);
656  ffio_wfourcc(pb, ix_tag); /* ix?? */
657  avio_wl32(pb, avist->indexes.entry * 8 + 24);
658  /* chunk size */
659  avio_wl16(pb, 2); /* wLongsPerEntry */
660  avio_w8(pb, 0); /* bIndexSubType (0 == frame index) */
661  avio_w8(pb, 1); /* bIndexType (1 == AVI_INDEX_OF_CHUNKS) */
662  avio_wl32(pb, avist->indexes.entry);
663  /* nEntriesInUse */
664  ffio_wfourcc(pb, tag); /* dwChunkId */
665  avio_wl64(pb, avi->movi_list); /* qwBaseOffset */
666  avio_wl32(pb, 0); /* dwReserved_3 (must be 0) */
667 
668  for (j = 0; j < avist->indexes.entry; j++) {
669  AVIIentry *ie = avi_get_ientry(&avist->indexes, j);
670  avio_wl32(pb, ie->pos + 8);
671  avio_wl32(pb, ((uint32_t) ie->len & ~0x80000000) |
672  (ie->flags & 0x10 ? 0 : 0x80000000));
673  }
674 
675  update_odml_entry(s, i, ix, avio_tell(pb) - ix);
676  }
677  return 0;
678 }
679 
681 {
682  AVIOContext *pb = s->pb;
683  AVIContext *avi = s->priv_data;
684  int64_t idx_chunk;
685  int i;
686  char tag[5];
687 
688  if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
689  AVIStream *avist;
690  AVIIentry *ie = 0, *tie;
691  int empty, stream_id = -1;
692 
693  idx_chunk = ff_start_tag(pb, "idx1");
694  for (i = 0; i < s->nb_streams; i++) {
695  avist = s->streams[i]->priv_data;
696  avist->entry = 0;
697  }
698 
699  do {
700  empty = 1;
701  for (i = 0; i < s->nb_streams; i++) {
702  avist = s->streams[i]->priv_data;
703  if (avist->indexes.entry <= avist->entry)
704  continue;
705 
706  tie = avi_get_ientry(&avist->indexes, avist->entry);
707  if (empty || tie->pos < ie->pos) {
708  ie = tie;
709  stream_id = i;
710  }
711  empty = 0;
712  }
713  if (!empty) {
714  avist = s->streams[stream_id]->priv_data;
715  if (*ie->tag)
716  ffio_wfourcc(pb, ie->tag);
717  else {
718  avi_stream2fourcc(tag, stream_id,
719  s->streams[stream_id]->codecpar->codec_type);
720  ffio_wfourcc(pb, tag);
721  }
722  avio_wl32(pb, ie->flags);
723  avio_wl32(pb, ie->pos);
724  avio_wl32(pb, ie->len);
725  avist->entry++;
726  }
727  } while (!empty);
728  ff_end_tag(pb, idx_chunk);
729 
731  }
732  return 0;
733 }
734 
735 static int write_skip_frames(AVFormatContext *s, int stream_index, int64_t dts)
736 {
737  AVIContext *avi = s->priv_data;
738  AVIStream *avist = s->streams[stream_index]->priv_data;
739  AVCodecParameters *par = s->streams[stream_index]->codecpar;
740 
741  ff_dlog(s, "dts:%s packet_count:%d stream_index:%d\n", av_ts2str(dts), avist->packet_count, stream_index);
742  while (par->block_align == 0 && dts != AV_NOPTS_VALUE &&
743  dts > avist->packet_count && par->codec_id != AV_CODEC_ID_XSUB && avist->packet_count) {
744 
745  if (dts - avist->packet_count > 60000) {
746  av_log(s, AV_LOG_ERROR, "Too large number of skipped frames %"PRId64" > 60000\n", dts - avist->packet_count);
747  return AVERROR(EINVAL);
748  }
749 
750  avi->empty_packet->stream_index = stream_index;
752  ff_dlog(s, "dup dts:%s packet_count:%d\n", av_ts2str(dts), avist->packet_count);
753  }
754 
755  return 0;
756 }
757 
759 {
760  const int stream_index = pkt->stream_index;
761  AVCodecParameters *par = s->streams[stream_index]->codecpar;
762  int ret;
763 
764  if (par->codec_id == AV_CODEC_ID_H264 && par->codec_tag == MKTAG('H','2','6','4') && pkt->size) {
765  ret = ff_check_h264_startcode(s, s->streams[stream_index], pkt);
766  if (ret < 0)
767  return ret;
768  }
769 
770  if ((ret = write_skip_frames(s, stream_index, pkt->dts)) < 0)
771  return ret;
772 
773  if (!pkt->size)
774  return avi_write_packet_internal(s, pkt); /* Passthrough */
775 
776  if (par->codec_type == AVMEDIA_TYPE_VIDEO) {
777  AVIStream *avist = s->streams[stream_index]->priv_data;
778  AVIOContext *pb = s->pb;
779  AVPacket *opkt = pkt;
780  int reshuffle_ret;
781  if (par->codec_id == AV_CODEC_ID_RAWVIDEO && par->codec_tag == 0) {
782  int64_t bpc = par->bits_per_coded_sample != 15 ? par->bits_per_coded_sample : 16;
783  int expected_stride = ((par->width * bpc + 31) >> 5)*4;
784  reshuffle_ret = ff_reshuffle_raw_rgb(s, &pkt, par, expected_stride);
785  if (reshuffle_ret < 0)
786  return reshuffle_ret;
787  } else
788  reshuffle_ret = 0;
789  if (par->format == AV_PIX_FMT_PAL8) {
790  ret = ff_get_packet_palette(s, opkt, reshuffle_ret, avist->palette);
791  if (ret < 0)
792  goto fail;
793  if (ret) {
794  int pal_size = 1 << par->bits_per_coded_sample;
795  int pc_tag, i;
796 
798 
799  if ((pb->seekable & AVIO_SEEKABLE_NORMAL) && avist->pal_offset) {
800  int64_t cur_offset = avio_tell(pb);
801  avio_seek(pb, avist->pal_offset, SEEK_SET);
802  for (i = 0; i < pal_size; i++) {
803  uint32_t v = avist->palette[i];
804  avio_wl32(pb, v & 0xffffff);
805  }
806  avio_seek(pb, cur_offset, SEEK_SET);
807  memcpy(avist->old_palette, avist->palette, pal_size * 4);
808  avist->pal_offset = 0;
809  }
810  if (memcmp(avist->palette, avist->old_palette, pal_size * 4)) {
811  unsigned char tag[5];
812  avi_stream2fourcc(tag, stream_index, par->codec_type);
813  tag[2] = 'p'; tag[3] = 'c';
814  if (s->pb->seekable & AVIO_SEEKABLE_NORMAL) {
815  if (avist->strh_flags_offset) {
816  int64_t cur_offset = avio_tell(pb);
817  avio_seek(pb, avist->strh_flags_offset, SEEK_SET);
819  avio_seek(pb, cur_offset, SEEK_SET);
820  avist->strh_flags_offset = 0;
821  }
822  ret = avi_add_ientry(s, stream_index, tag, AVIIF_NO_TIME,
823  pal_size * 4 + 4);
824  if (ret < 0)
825  goto fail;
826  }
827  pc_tag = ff_start_tag(pb, tag);
828  avio_w8(pb, 0);
829  avio_w8(pb, pal_size & 0xFF);
830  avio_wl16(pb, 0); // reserved
831  for (i = 0; i < pal_size; i++) {
832  uint32_t v = avist->palette[i];
833  avio_wb32(pb, v<<8);
834  }
835  ff_end_tag(pb, pc_tag);
836  memcpy(avist->old_palette, avist->palette, pal_size * 4);
837  }
838  }
839  }
840  if (reshuffle_ret) {
842 
843 fail:
844  if (reshuffle_ret)
846  return ret;
847  }
848  }
849 
851 }
852 
854 {
855  unsigned char tag[5];
856  unsigned int flags = 0;
857  const int stream_index = pkt->stream_index;
858  int size = pkt->size;
859  AVIContext *avi = s->priv_data;
860  AVIOContext *pb = s->pb;
861  AVIStream *avist = s->streams[stream_index]->priv_data;
862  AVCodecParameters *par = s->streams[stream_index]->codecpar;
863 
864  if (pkt->dts != AV_NOPTS_VALUE)
865  avist->last_dts = pkt->dts + pkt->duration;
866 
867  avist->packet_count++;
868 
869  // Make sure to put an OpenDML chunk when the file size exceeds the limits
870  if ((pb->seekable & AVIO_SEEKABLE_NORMAL) &&
871  (avio_tell(pb) - avi->riff_start > AVI_MAX_RIFF_SIZE)) {
872  avi_write_ix(s);
873  ff_end_tag(pb, avi->movi_list);
874 
875  if (avi->riff_id == 1)
876  avi_write_idx1(s);
877 
878  ff_end_tag(pb, avi->riff_start);
879  avi->movi_list = avi_start_new_riff(s, pb, "AVIX", "movi");
880  }
881 
882  avi_stream2fourcc(tag, stream_index, par->codec_type);
883  if (pkt->flags & AV_PKT_FLAG_KEY)
884  flags = 0x10;
885  if (par->codec_type == AVMEDIA_TYPE_AUDIO)
886  avist->audio_strm_length += size;
887 
888  if (s->pb->seekable & AVIO_SEEKABLE_NORMAL) {
889  int ret;
890  ret = avi_add_ientry(s, stream_index, NULL, flags, size);
891  if (ret < 0)
892  return ret;
893  }
894 
895  avio_write(pb, tag, 4);
896  avio_wl32(pb, size);
897  avio_write(pb, pkt->data, size);
898  if (size & 1)
899  avio_w8(pb, 0);
900 
901  return 0;
902 }
903 
905 {
906  AVIContext *avi = s->priv_data;
907  AVIOContext *pb = s->pb;
908  int res = 0;
909  int i, n, nb_frames;
910  int64_t file_size;
911 
912  for (i = 0; i < s->nb_streams; i++) {
913  AVIStream *avist = s->streams[i]->priv_data;
914  write_skip_frames(s, i, avist->last_dts);
915  }
916 
917  if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
918  if (avi->riff_id == 1) {
919  ff_end_tag(pb, avi->movi_list);
920  res = avi_write_idx1(s);
921  ff_end_tag(pb, avi->riff_start);
922  } else {
923  avi_write_ix(s);
924  ff_end_tag(pb, avi->movi_list);
925  ff_end_tag(pb, avi->riff_start);
926 
927  file_size = avio_tell(pb);
928  avio_seek(pb, avi->odml_list - 8, SEEK_SET);
929  ffio_wfourcc(pb, "LIST"); /* Making this AVI OpenDML one */
930  avio_skip(pb, 16);
931 
932  for (n = nb_frames = 0; n < s->nb_streams; n++) {
933  AVCodecParameters *par = s->streams[n]->codecpar;
934  AVIStream *avist = s->streams[n]->priv_data;
935 
936  if (par->codec_type == AVMEDIA_TYPE_VIDEO) {
937  if (nb_frames < avist->packet_count)
938  nb_frames = avist->packet_count;
939  } else {
940  if (par->codec_id == AV_CODEC_ID_MP2 ||
941  par->codec_id == AV_CODEC_ID_MP3)
942  nb_frames += avist->packet_count;
943  }
944  }
945  avio_wl32(pb, nb_frames);
946  avio_seek(pb, file_size, SEEK_SET);
947 
949  }
950  }
951 
952  if (avi->riff_id >= avi->master_index_max_size) {
953  int index_space = AVI_MASTER_INDEX_PREFIX_SIZE +
955  av_log(s, AV_LOG_WARNING, "Output file not strictly OpenDML compliant, "
956  "consider re-muxing with 'reserve_index_space' option value >= %d\n",
957  index_space);
958  }
959 
960  for (i = 0; i < s->nb_streams; i++) {
961  AVIStream *avist = s->streams[i]->priv_data;
962  if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
963  avio_seek(pb, avist->frames_hdr_strm + 4, SEEK_SET);
964  avio_wl32(pb, avist->max_size);
965  }
966  }
967 
968  return res;
969 }
970 
972 {
973  for (int i = 0; i < s->nb_streams; i++) {
974  AVIStream *avist = s->streams[i]->priv_data;
975  if (!avist)
976  continue;
977  for (int j = 0; j < avist->indexes.ents_allocated / AVI_INDEX_CLUSTER_SIZE; j++)
978  av_freep(&avist->indexes.cluster[j]);
979  av_freep(&avist->indexes.cluster);
980  avist->indexes.ents_allocated = avist->indexes.entry = 0;
981  }
982 }
983 
984 #define OFFSET(x) offsetof(AVIContext, x)
985 #define ENC AV_OPT_FLAG_ENCODING_PARAM
986 static const AVOption options[] = {
987  { "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 },
988  { "write_channel_mask", "write channel mask into wave format header", OFFSET(write_channel_mask), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, ENC },
989  { "flipped_raw_rgb", "Raw RGB bitmaps are stored bottom-up", OFFSET(flipped_raw_rgb), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, ENC },
990  { NULL },
991 };
992 
993 static const AVClass avi_muxer_class = {
994  .class_name = "AVI muxer",
995  .item_name = av_default_item_name,
996  .option = options,
997  .version = LIBAVUTIL_VERSION_INT,
998 };
999 
1001  .name = "avi",
1002  .long_name = NULL_IF_CONFIG_SMALL("AVI (Audio Video Interleaved)"),
1003  .mime_type = "video/x-msvideo",
1004  .extensions = "avi",
1005  .priv_data_size = sizeof(AVIContext),
1006  .audio_codec = CONFIG_LIBMP3LAME ? AV_CODEC_ID_MP3 : AV_CODEC_ID_AC3,
1007  .video_codec = AV_CODEC_ID_MPEG4,
1008  .init = avi_init,
1009  .deinit = avi_deinit,
1013  .codec_tag = ff_riff_codec_tags_list,
1014  .priv_class = &avi_muxer_class,
1015 };
AVIContext::flipped_raw_rgb
int flipped_raw_rgb
Definition: avienc.c:76
AVIStream::strh_flags_offset
int64_t strh_flags_offset
Definition: avienc.c:91
options
static const AVOption options[]
Definition: avienc.c:986
AV_LANG_ISO639_1
@ AV_LANG_ISO639_1
3-char terminological language codes as per ISO-IEC 639-2
Definition: avlanguage.h:30
avi_stream2fourcc
static char * avi_stream2fourcc(char *tag, int index, enum AVMediaType type)
Definition: avienc.c:180
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:204
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
AVIIentry::len
unsigned int len
Definition: avienc.c:50
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
AV_CODEC_ID_AC3
@ AV_CODEC_ID_AC3
Definition: codec_id.h:426
AVOutputFormat::name
const char * name
Definition: avformat.h:504
AVERROR
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
opt.h
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:56
mpegts.h
ffio_wfourcc
static av_always_inline void ffio_wfourcc(AVIOContext *pb, const uint8_t *s)
Definition: avio_internal.h:116
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:52
avi_start_new_riff
static int64_t avi_start_new_riff(AVFormatContext *s, AVIOContext *pb, const char *riff_tag, const char *list_tag)
Definition: avienc.c:159
ffformatcontext
static av_always_inline FFFormatContext * ffformatcontext(AVFormatContext *s)
Definition: internal.h:189
AVI_MASTER_INDEX_SIZE_DEFAULT
#define AVI_MASTER_INDEX_SIZE_DEFAULT
Definition: avienc.c:56
AVStream::priv_data
void * priv_data
Definition: avformat.h:951
ff_put_bmp_header
void ff_put_bmp_header(AVIOContext *pb, AVCodecParameters *par, int for_asf, int ignore_extradata, int rgb_frame_is_flipped)
Definition: riffenc.c:216
AV_TIME_BASE_Q
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:260
av_asprintf
char * av_asprintf(const char *fmt,...)
Definition: avstring.c:113
AVIStream
Definition: avidec.c:41
avlanguage.h
avi_get_ientry
static AVIIentry * avi_get_ientry(const AVIIndex *idx, int ent_id)
Definition: avienc.c:100
AV_CODEC_ID_RAWVIDEO
@ AV_CODEC_ID_RAWVIDEO
Definition: codec_id.h:63
AV_CODEC_ID_MPEG4
@ AV_CODEC_ID_MPEG4
Definition: codec_id.h:62
pixdesc.h
deinit
static void deinit(AVFormatContext *s)
Definition: chromaprint.c:50
index
fg index
Definition: ffmpeg_filter.c:167
AVPacket::data
uint8_t * data
Definition: packet.h:373
AVOption
AVOption.
Definition: opt.h:247
avio_wl64
void avio_wl64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:454
AVPacket::duration
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: packet.h:391
AVCodecParameters::codec_tag
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: codec_par.h:64
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
avi_write_counters
static int avi_write_counters(AVFormatContext *s, int riff_id)
Definition: avienc.c:199
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:428
av_packet_free
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition: avpacket.c:75
AVIIndex::audio_strm_offset
int64_t audio_strm_offset
Definition: avienc.c:60
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
AVIStream::palette
uint32_t palette[AVPALETTE_COUNT]
Definition: avienc.c:93
init
static int init
Definition: av_tx.c:47
avio_wl16
void avio_wl16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:466
avi_muxer_class
static const AVClass avi_muxer_class
Definition: avienc.c:993
AV_FIELD_TT
@ AV_FIELD_TT
Definition: codec_par.h:39
AVIIndex::indx_start
int64_t indx_start
Definition: avienc.c:59
fail
#define fail()
Definition: checkasm.h:127
AVIContext::frames_hdr_all
int64_t frames_hdr_all
Definition: avienc.c:71
avio_tell
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:504
AVIStream::entry
int entry
Definition: avienc.c:83
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
avi_add_ientry
static int avi_add_ientry(AVFormatContext *s, int stream_index, char *tag, unsigned int flags, unsigned int size)
Definition: avienc.c:107
AV_CODEC_ID_MP3
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
Definition: codec_id.h:424
AVStream::duration
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition: avformat.h:985
AV_FIELD_TB
@ AV_FIELD_TB
Definition: codec_par.h:41
avi_write_trailer
static int avi_write_trailer(AVFormatContext *s)
Definition: avienc.c:904
av_reduce
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
AVRational::num
int num
Numerator.
Definition: rational.h:59
raw.h
ff_start_tag
int64_t ff_start_tag(AVIOContext *pb, const char *tag)
Definition: riffenc.c:32
avassert.h
ceil
static __device__ float ceil(float a)
Definition: cuda_runtime.h:176
AVIStream::last_dts
int64_t last_dts
Definition: avienc.c:87
pkt
AVPacket * pkt
Definition: movenc.c:59
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
av_cold
#define av_cold
Definition: attributes.h:90
AVIStream::old_palette
uint32_t old_palette[AVPALETTE_COUNT]
Definition: avienc.c:94
av_dict_get
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
AVIContext::odml_list
int64_t odml_list
Definition: avienc.c:70
AVIContext
Definition: avidec.c:68
avi_write_header
static int avi_write_header(AVFormatContext *s)
Definition: avienc.c:257
s
#define s(width, name)
Definition: cbs_vp9.c:257
avi_write_packet
static int avi_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: avienc.c:758
AVIContext::movi_list
int64_t movi_list
Definition: avidec.c:74
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AVCodecParameters::width
int width
Video only.
Definition: codec_par.h:126
AV_CODEC_ID_MP2
@ AV_CODEC_ID_MP2
Definition: codec_id.h:423
avi_init
static av_cold int avi_init(struct AVFormatContext *s)
Definition: avienc.c:144
AVI_MASTER_INDEX_PREFIX_SIZE
#define AVI_MASTER_INDEX_PREFIX_SIZE
Definition: avienc.c:54
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
av_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:141
pix_fmt
static enum AVPixelFormat pix_fmt
Definition: demuxing_decoding.c:41
AVMEDIA_TYPE_DATA
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
Definition: avutil.h:203
AVIIF_NO_TIME
#define AVIIF_NO_TIME
Definition: avi.h:39
AV_FIELD_BT
@ AV_FIELD_BT
Definition: codec_par.h:42
AV_CODEC_ID_H264
@ AV_CODEC_ID_H264
Definition: codec_id.h:77
avi_write_idx1
static int avi_write_idx1(AVFormatContext *s)
Definition: avienc.c:680
fields
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
Definition: filter_design.txt:155
if
if(ret)
Definition: filter_design.txt:179
AVIContext::write_channel_mask
int write_channel_mask
Definition: avienc.c:75
AVFormatContext
Format I/O context.
Definition: avformat.h:1200
PIX_FMT_LIST_AVI
@ PIX_FMT_LIST_AVI
Definition: raw.h:41
av_realloc_f
#define av_realloc_f(p, o, n)
Definition: tableprint_vlc.h:33
internal.h
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1095
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVISF_VIDEO_PALCHANGES
#define AVISF_VIDEO_PALCHANGES
Definition: avi.h:35
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
AVStream::time_base
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition: avformat.h:965
NULL
#define NULL
Definition: coverity.c:32
ff_put_wav_header
int ff_put_wav_header(AVFormatContext *s, AVIOContext *pb, AVCodecParameters *par, int flags)
Write WAVEFORMAT header structure.
Definition: riffenc.c:55
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
update_odml_entry
static void update_odml_entry(AVFormatContext *s, int stream_index, int64_t ix, int size)
Definition: avienc.c:590
write_trailer
static int write_trailer(AVFormatContext *s1)
Definition: v4l2enc.c:98
AVI_MAX_RIFF_SIZE
#define AVI_MAX_RIFF_SIZE
Definition: avi.h:31
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
avi_deinit
static void avi_deinit(AVFormatContext *s)
Definition: avienc.c:971
AVI_MAX_STREAM_COUNT
#define AVI_MAX_STREAM_COUNT
Definition: avi.h:32
AVStream::metadata
AVDictionary * metadata
Definition: avformat.h:1006
AVIStream::packet_count
int packet_count
Definition: avienc.c:82
AVIStream::pal_offset
int64_t pal_offset
Definition: avienc.c:95
ff_reshuffle_raw_rgb
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
avio_w8
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:210
ffio_fill
void ffio_fill(AVIOContext *s, int b, int64_t count)
Definition: aviobuf.c:218
AVPALETTE_COUNT
#define AVPALETTE_COUNT
Definition: pixfmt.h:33
OFFSET
#define OFFSET(x)
Definition: avienc.c:984
avi.h
ff_dlog
#define ff_dlog(a,...)
Definition: tableprint_vlc.h:29
AVIOContext
Bytestream IO Context.
Definition: avio.h:161
AVMediaType
AVMediaType
Definition: avutil.h:199
AVPacket::size
int size
Definition: packet.h:374
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
avpriv_pix_fmt_find
enum AVPixelFormat avpriv_pix_fmt_find(enum PixelFormatTagLists list, unsigned fourcc)
Definition: raw.c:352
id
enum AVCodecID id
Definition: extract_extradata_bsf.c:325
ff_riff_write_info_tag
void ff_riff_write_info_tag(AVIOContext *pb, const char *tag, const char *str)
Write a single RIFF info tag.
Definition: riffenc.c:303
AVIOContext::seekable
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:262
ff_convert_lang_to
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
AVIIndex::cluster
AVIIentry ** cluster
Definition: avienc.c:64
size
int size
Definition: twinvq_data.h:10344
video_st
AVStream * video_st
Definition: movenc.c:60
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
avpriv_report_missing_feature
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
FF_PUT_WAV_HEADER_SKIP_CHANNELMASK
#define FF_PUT_WAV_HEADER_SKIP_CHANNELMASK
Tell ff_put_wav_header() to write an empty channel mask.
Definition: riff.h:58
ff_avi_muxer
const AVOutputFormat ff_avi_muxer
Definition: avienc.c:1000
AVStream::sample_aspect_ratio
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:1004
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:372
avio_write
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:232
avio_wb32
void avio_wb32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:394
avio_wl32
void avio_wl32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:386
ENC
#define ENC
Definition: avienc.c:985
AVIIentry::pos
unsigned int pos
Definition: avienc.c:49
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:379
bitrate
int64_t bitrate
Definition: h264_levels.c:131
ff_end_tag
void ff_end_tag(AVIOContext *pb, int64_t start)
Definition: riffenc.c:39
write_packet
static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue)
Definition: ffmpeg.c:727
AV_FIELD_BB
@ AV_FIELD_BB
Definition: codec_par.h:40
avi_write_packet_internal
static int avi_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
Definition: avienc.c:853
AV_PIX_FMT_RGB555LE
@ AV_PIX_FMT_RGB555LE
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), little-endian, X=unused/undefined
Definition: pixfmt.h:108
AVOutputFormat
Definition: avformat.h:503
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:271
AVIStream::max_size
int max_size
Definition: avienc.c:84
avio_internal.h
AVI_MASTER_INDEX_ENTRY_SIZE
#define AVI_MASTER_INDEX_ENTRY_SIZE
Definition: avienc.c:55
internal.h
AVIF_TRUSTCKTYPE
#define AVIF_TRUSTCKTYPE
Definition: avi.h:27
AVCodecParameters::height
int height
Definition: codec_par.h:127
AV_TIME_BASE
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:254
AVCodecParameters::block_align
int block_align
Audio only.
Definition: codec_par.h:177
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:53
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
AV_STRINGIFY
#define AV_STRINGIFY(s)
Definition: macros.h:66
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:263
AVI_INDEX_CLUSTER_SIZE
#define AVI_INDEX_CLUSTER_SIZE
Definition: avienc.c:53
AVCodecParameters::field_order
enum AVFieldOrder field_order
Video only.
Definition: codec_par.h:141
ff_check_h264_startcode
int ff_check_h264_startcode(AVFormatContext *s, const AVStream *st, const AVPacket *pkt)
Check presence of H264 startcode.
Definition: mpegtsenc.c:1748
AV_CODEC_ID_XSUB
@ AV_CODEC_ID_XSUB
Definition: codec_id.h:525
AV_PIX_FMT_PAL8
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
Definition: pixfmt.h:77
tag
uint32_t tag
Definition: movenc.c:1596
ret
ret
Definition: filter_design.txt:187
ff_get_packet_palette
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:1892
AVStream
Stream structure.
Definition: avformat.h:935
avio_seek
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:260
AVClass::class_name
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:71
AVIContext::riff_id
int riff_id
Definition: avienc.c:72
ff_parse_specific_params
void ff_parse_specific_params(AVStream *st, int *au_rate, int *au_ssize, int *au_scale)
Definition: riffenc.c:273
pos
unsigned int pos
Definition: spdifenc.c:412
avformat.h
AVIStream::sample_requested
int sample_requested
Definition: avienc.c:85
dict.h
write_odml_master
static void write_odml_master(AVFormatContext *s, int stream_index)
Definition: avienc.c:232
AVIContext::reserve_index_space
int reserve_index_space
Definition: avienc.c:73
AVIIndex::master_odml_riff_id_base
int master_odml_riff_id_base
Definition: avienc.c:63
av_get_media_type_string
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:71
AVIO_SEEKABLE_NORMAL
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
Definition: avio.h:40
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:224
ff_riff_write_info
void ff_riff_write_info(AVFormatContext *s)
Write all recognized RIFF tags from s->metadata.
Definition: riffenc.c:335
AVIIentry
Definition: avienc.c:46
avpriv_set_pts_info
void avpriv_set_pts_info(AVStream *st, 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:1196
av_mul_q
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:80
AVPacket::stream_index
int stream_index
Definition: packet.h:375
avio_skip
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:347
AVIF_HASINDEX
#define AVIF_HASINDEX
Definition: avi.h:24
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
avutil.h
AVCodecParameters::bits_per_coded_sample
int bits_per_coded_sample
The number of bits per sample in the codedwords.
Definition: codec_par.h:102
FFFormatContext::pkt
AVPacket * pkt
Used to hold temporary packets for the generic demuxing code.
Definition: internal.h:132
avpriv_request_sample
#define avpriv_request_sample(...)
Definition: tableprint_vlc.h:37
AVCodecParameters::format
int format
Definition: codec_par.h:84
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
AVDictionaryEntry
Definition: dict.h:79
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:60
AVPacket
This structure stores compressed data.
Definition: packet.h:350
AVIF_ISINTERLEAVED
#define AVIF_ISINTERLEAVED
Definition: avi.h:26
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:241
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
riff.h
AVIStream::frames_hdr_strm
int64_t frames_hdr_strm
Definition: avienc.c:80
convert_header.str
string str
Definition: convert_header.py:20
timestamp.h
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
AVCodecParameters::bit_rate
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
Definition: codec_par.h:89
AVIIndex::entry
int entry
Definition: avienc.c:61
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
AVIIndex
Definition: avienc.c:58
av_ts2str
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: timestamp.h:54
AVIStream::indexes
AVIIndex indexes
Definition: avienc.c:89
MKTAG
#define MKTAG(a, b, c, d)
Definition: macros.h:55
AVDictionaryEntry::value
char * value
Definition: dict.h:81
avstring.h
AVIContext::empty_packet
AVPacket * empty_packet
Definition: avienc.c:69
write_header
static void write_header(FFV1Context *f)
Definition: ffv1enc.c:347
AVIStream::audio_strm_length
int64_t audio_strm_length
Definition: avienc.c:81
AVIIentry::tag
char tag[4]
Definition: avienc.c:47
ff_riff_codec_tags_list
const AVCodecTag *const ff_riff_codec_tags_list[]
AVIContext::riff_start
int64_t riff_start
Definition: avienc.c:70
write_skip_frames
static int write_skip_frames(AVFormatContext *s, int stream_index, int64_t dts)
Definition: avienc.c:735
AVIIentry::flags
unsigned int flags
Definition: avienc.c:48
av_x_if_null
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
av_get_pix_fmt_name
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:2580
AVIContext::master_index_max_size
int master_index_max_size
Definition: avienc.c:74
AVIIndex::ents_allocated
int ents_allocated
Definition: avienc.c:62
avi_write_ix
static int avi_write_ix(AVFormatContext *s)
Definition: avienc.c:622