FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
movenc-test.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Martin Storsjo
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "config.h"
22 
23 #include "libavutil/intreadwrite.h"
24 #include "libavutil/mathematics.h"
25 #include "libavutil/md5.h"
26 
27 #include "avformat.h"
28 
29 #if HAVE_UNISTD_H
30 #include <unistd.h>
31 #endif
32 
33 #if !HAVE_GETOPT
34 #include "compat/getopt.c"
35 #endif
36 
37 #define HASH_SIZE 16
38 
39 static const uint8_t h264_extradata[] = {
40  0x01, 0x4d, 0x40, 0x1e, 0xff, 0xe1, 0x00, 0x02, 0x67, 0x4d, 0x01, 0x00, 0x02, 0x68, 0xef
41 };
42 static const uint8_t aac_extradata[] = {
43  0x12, 0x10
44 };
45 
46 
47 static const char *format = "mp4";
49 uint8_t iobuf[32768];
51 
53 const char *cur_name;
54 FILE* out;
56 struct AVMD5* md5;
58 
61 
62 int bframes;
63 int64_t duration;
65 int frames;
67 int64_t next_p_pts;
72 
74 
76 
77 
78 static void count_warnings(void *avcl, int level, const char *fmt, va_list vl)
79 {
80  if (level == AV_LOG_WARNING)
81  num_warnings++;
82 }
83 
84 static void init_count_warnings(void)
85 {
87  num_warnings = 0;
88 }
89 
90 static void reset_count_warnings(void)
91 {
93 }
94 
95 static int io_write(void *opaque, uint8_t *buf, int size)
96 {
97  out_size += size;
98  av_md5_update(md5, buf, size);
99  if (out)
100  fwrite(buf, 1, size, out);
101  return size;
102 }
103 
104 static void init_out(const char *name)
105 {
106  char buf[100];
107  cur_name = name;
108  snprintf(buf, sizeof(buf), "%s.%s", cur_name, format);
109 
110  av_md5_init(md5);
111  if (write_file) {
112  out = fopen(buf, "wb");
113  if (!out)
114  perror(buf);
115  }
116  out_size = 0;
117 }
118 
119 static void close_out(void)
120 {
121  int i;
122  av_md5_final(md5, hash);
123  for (i = 0; i < HASH_SIZE; i++)
124  printf("%02x", hash[i]);
125  printf(" %d %s\n", out_size, cur_name);
126  if (out)
127  fclose(out);
128  out = NULL;
129 }
130 
131 static void check_func(int value, int line, const char *msg, ...)
132 {
133  if (!value) {
134  va_list ap;
135  va_start(ap, msg);
136  printf("%d: ", line);
137  vprintf(msg, ap);
138  printf("\n");
139  check_faults++;
140  va_end(ap);
141  }
142 }
143 #define check(value, ...) check_func(value, __LINE__, __VA_ARGS__)
144 
145 static void init_fps(int bf, int audio_preroll, int fps)
146 {
147  AVStream *st;
148  ctx = avformat_alloc_context();
149  if (!ctx)
150  exit(1);
152  if (!ctx->oformat)
153  exit(1);
155  if (!ctx->pb)
156  exit(1);
157  ctx->flags |= AVFMT_FLAG_BITEXACT;
158 
159  st = avformat_new_stream(ctx, NULL);
160  if (!st)
161  exit(1);
164  st->codecpar->width = 640;
165  st->codecpar->height = 480;
166  st->time_base.num = 1;
167  st->time_base.den = 30;
168  st->codecpar->extradata_size = sizeof(h264_extradata);
170  if (!st->codecpar->extradata)
171  exit(1);
172  memcpy(st->codecpar->extradata, h264_extradata, sizeof(h264_extradata));
173  video_st = st;
174 
175  st = avformat_new_stream(ctx, NULL);
176  if (!st)
177  exit(1);
180  st->codecpar->sample_rate = 44100;
181  st->codecpar->channels = 2;
182  st->time_base.num = 1;
183  st->time_base.den = 44100;
184  st->codecpar->extradata_size = sizeof(aac_extradata);
186  if (!st->codecpar->extradata)
187  exit(1);
188  memcpy(st->codecpar->extradata, aac_extradata, sizeof(aac_extradata));
189  audio_st = st;
190 
191  if (avformat_write_header(ctx, &opts) < 0)
192  exit(1);
193  av_dict_free(&opts);
194 
195  frames = 0;
196  gop_size = 30;
197  duration = video_st->time_base.den / fps;
198  audio_duration = 1024LL * audio_st->time_base.den / audio_st->codecpar->sample_rate;
199  if (audio_preroll)
200  audio_preroll = 2048LL * audio_st->time_base.den / audio_st->codecpar->sample_rate;
201 
202  bframes = bf;
203  video_dts = bframes ? -duration : 0;
204  audio_dts = -audio_preroll;
205 }
206 
207 static void init(int bf, int audio_preroll)
208 {
209  init_fps(bf, audio_preroll, 30);
210 }
211 
212 static void mux_frames(int n)
213 {
214  int end_frames = frames + n;
215  while (1) {
216  AVPacket pkt;
217  uint8_t pktdata[8] = { 0 };
218  av_init_packet(&pkt);
219 
220  if (av_compare_ts(audio_dts, audio_st->time_base, video_dts, video_st->time_base) < 0) {
221  pkt.dts = pkt.pts = audio_dts;
222  pkt.stream_index = 1;
223  pkt.duration = audio_duration;
225  } else {
226  if (frames == end_frames)
227  break;
228  pkt.dts = video_dts;
229  pkt.stream_index = 0;
230  pkt.duration = duration;
231  if ((frames % gop_size) == 0) {
232  pkt.flags |= AV_PKT_FLAG_KEY;
234  pkt.pts = pkt.dts + duration;
235  video_dts = pkt.pts;
236  } else {
239  pkt.pts = pkt.dts;
241  } else {
243  if (((frames + 1) % gop_size) == 0) {
244  pkt.pts = pkt.dts + duration;
245  video_dts = pkt.pts;
246  } else {
247  next_p_pts = pkt.pts = pkt.dts + 2 * duration;
248  video_dts += duration;
249  }
250  }
251  }
252  if (!bframes)
253  pkt.pts = pkt.dts;
254  frames++;
255  }
256 
257  if (clear_duration)
258  pkt.duration = 0;
259  AV_WB32(pktdata + 4, pkt.pts);
260  pkt.data = pktdata;
261  pkt.size = 8;
262  if (skip_write)
263  continue;
264  if (skip_write_audio && pkt.stream_index == 1)
265  continue;
266  av_write_frame(ctx, &pkt);
267  }
268 }
269 
270 static void mux_gops(int n)
271 {
272  mux_frames(gop_size * n);
273 }
274 
275 static void skip_gops(int n)
276 {
277  skip_write = 1;
278  mux_gops(n);
279  skip_write = 0;
280 }
281 
282 static void signal_init_ts(void)
283 {
284  AVPacket pkt;
285  av_init_packet(&pkt);
286  pkt.size = 0;
287  pkt.data = NULL;
288 
289  pkt.stream_index = 0;
290  pkt.dts = video_dts;
291  pkt.pts = 0;
292  av_write_frame(ctx, &pkt);
293 
294  pkt.stream_index = 1;
295  pkt.dts = pkt.pts = audio_dts;
296  av_write_frame(ctx, &pkt);
297 }
298 
299 static void finish(void)
300 {
301  av_write_trailer(ctx);
302  av_free(ctx->pb);
304  ctx = NULL;
305 }
306 
307 static void help(void)
308 {
309  printf("movenc-test [-w]\n"
310  "-w write output into files\n");
311 }
312 
313 int main(int argc, char **argv)
314 {
315  int c;
317  uint8_t content[HASH_SIZE];
318  int empty_moov_pos;
319  int prev_pos;
320 
321  for (;;) {
322  c = getopt(argc, argv, "wh");
323  if (c == -1)
324  break;
325  switch (c) {
326  case 'w':
327  write_file = 1;
328  break;
329  default:
330  case 'h':
331  help();
332  return 0;
333  }
334  }
335 
336  av_register_all();
337 
338  md5 = av_md5_alloc();
339  if (!md5)
340  return 1;
341 
342  // Write a fragmented file with an initial moov that actually contains some
343  // samples. One moov+mdat with 1 second of data and one moof+mdat with 1
344  // second of data.
345  init_out("non-empty-moov");
346  av_dict_set(&opts, "movflags", "frag_keyframe", 0);
347  init(0, 0);
348  mux_gops(2);
349  finish();
350  close_out();
351 
352  // Write a similar file, but with b-frames and audio preroll, handled
353  // via an edit list.
354  init_out("non-empty-moov-elst");
355  av_dict_set(&opts, "movflags", "frag_keyframe", 0);
356  av_dict_set(&opts, "use_editlist", "1", 0);
357  init(1, 1);
358  mux_gops(2);
359  finish();
360  close_out();
361 
362  // Use b-frames but no audio-preroll, but without an edit list.
363  // Due to avoid_negative_ts == AVFMT_AVOID_NEG_TS_MAKE_ZERO, the dts
364  // of the first audio packet is > 0, but it is set to zero since edit
365  // lists aren't used, increasing the duration of the first packet instead.
366  init_out("non-empty-moov-no-elst");
367  av_dict_set(&opts, "movflags", "frag_keyframe", 0);
368  av_dict_set(&opts, "use_editlist", "0", 0);
369  init(1, 0);
370  mux_gops(2);
371  finish();
372  close_out();
373 
374  format = "ismv";
375  // Write an ISMV, with b-frames and audio preroll.
376  init_out("ismv");
377  av_dict_set(&opts, "movflags", "frag_keyframe", 0);
378  init(1, 1);
379  mux_gops(2);
380  finish();
381  close_out();
382  format = "mp4";
383 
384  // An initial moov that doesn't contain any samples, followed by two
385  // moof+mdat pairs.
386  init_out("empty-moov");
387  av_dict_set(&opts, "movflags", "frag_keyframe+empty_moov", 0);
388  av_dict_set(&opts, "use_editlist", "0", 0);
389  init(0, 0);
390  mux_gops(2);
391  finish();
392  close_out();
393  memcpy(content, hash, HASH_SIZE);
394 
395  // Similar to the previous one, but with input that doesn't start at
396  // pts/dts 0. avoid_negative_ts behaves in the same way as
397  // in non-empty-moov-no-elst above.
398  init_out("empty-moov-no-elst");
399  av_dict_set(&opts, "movflags", "frag_keyframe+empty_moov", 0);
400  init(1, 0);
401  mux_gops(2);
402  finish();
403  close_out();
404 
405  // Same as the previous one, but disable avoid_negative_ts (which
406  // would require using an edit list, but with empty_moov, one can't
407  // write a sensible edit list, when the start timestamps aren't known).
408  // This should trigger a warning - we check that the warning is produced.
410  init_out("empty-moov-no-elst-no-adjust");
411  av_dict_set(&opts, "movflags", "frag_keyframe+empty_moov", 0);
412  av_dict_set(&opts, "avoid_negative_ts", "0", 0);
413  init(1, 0);
414  mux_gops(2);
415  finish();
416  close_out();
417 
419  check(num_warnings > 0, "No warnings printed for unhandled start offset");
420 
421  // Verify that delay_moov produces the same as empty_moov for
422  // simple input
423  init_out("delay-moov");
424  av_dict_set(&opts, "movflags", "frag_keyframe+delay_moov", 0);
425  av_dict_set(&opts, "use_editlist", "0", 0);
426  init(0, 0);
427  mux_gops(2);
428  finish();
429  close_out();
430  check(!memcmp(hash, content, HASH_SIZE), "delay_moov differs from empty_moov");
431 
432  // Test writing content that requires an edit list using delay_moov
433  init_out("delay-moov-elst");
434  av_dict_set(&opts, "movflags", "frag_keyframe+delay_moov", 0);
435  init(1, 1);
436  mux_gops(2);
437  finish();
438  close_out();
439 
440  // Test writing a file with one track lacking packets, with delay_moov.
441  skip_write_audio = 1;
442  init_out("delay-moov-empty-track");
443  av_dict_set(&opts, "movflags", "frag_keyframe+delay_moov", 0);
444  init(0, 0);
445  mux_gops(2);
446  // The automatic flushing shouldn't output anything, since we're still
447  // waiting for data for some tracks
448  check(out_size == 0, "delay_moov flushed prematurely");
449  // When closed (or manually flushed), all the written data should still
450  // be output.
451  finish();
452  close_out();
453  check(out_size > 0, "delay_moov didn't output anything");
454 
455  // Check that manually flushing still outputs things as expected. This
456  // produces two fragments, while the one above produces only one.
457  init_out("delay-moov-empty-track-flush");
458  av_dict_set(&opts, "movflags", "frag_custom+delay_moov", 0);
459  init(0, 0);
460  mux_gops(1);
461  av_write_frame(ctx, NULL); // Force writing the moov
462  check(out_size > 0, "No moov written");
463  av_write_frame(ctx, NULL);
464  mux_gops(1);
465  av_write_frame(ctx, NULL);
466  finish();
467  close_out();
468 
469  skip_write_audio = 0;
470 
471 
472 
473  // Verify that the header written by delay_moov when manually flushed
474  // is identical to the one by empty_moov.
475  init_out("empty-moov-header");
476  av_dict_set(&opts, "movflags", "frag_keyframe+empty_moov", 0);
477  av_dict_set(&opts, "use_editlist", "0", 0);
478  init(0, 0);
479  close_out();
480  memcpy(header, hash, HASH_SIZE);
481  init_out("empty-moov-content");
482  mux_gops(2);
483  // Written 2 seconds of content, with an automatic flush after 1 second.
484  check(out_size > 0, "No automatic flush?");
485  empty_moov_pos = prev_pos = out_size;
486  // Manually flush the second fragment
487  av_write_frame(ctx, NULL);
488  check(out_size > prev_pos, "No second fragment flushed?");
489  prev_pos = out_size;
490  // Check that an extra flush doesn't output any more data
491  av_write_frame(ctx, NULL);
492  check(out_size == prev_pos, "More data written?");
493  close_out();
494  memcpy(content, hash, HASH_SIZE);
495  // Ignore the trailer written here
496  finish();
497 
498  init_out("delay-moov-header");
499  av_dict_set(&opts, "movflags", "frag_custom+delay_moov", 0);
500  av_dict_set(&opts, "use_editlist", "0", 0);
501  init(0, 0);
502  check(out_size == 0, "Output written during init with delay_moov");
503  mux_gops(1); // Write 1 second of content
504  av_write_frame(ctx, NULL); // Force writing the moov
505  close_out();
506  check(!memcmp(hash, header, HASH_SIZE), "delay_moov header differs from empty_moov");
507  init_out("delay-moov-content");
508  av_write_frame(ctx, NULL); // Flush the first fragment
509  check(out_size == empty_moov_pos, "Manually flushed content differs from automatically flushed, %d vs %d", out_size, empty_moov_pos);
510  mux_gops(1); // Write the rest of the content
511  av_write_frame(ctx, NULL); // Flush the second fragment
512  close_out();
513  check(!memcmp(hash, content, HASH_SIZE), "delay_moov content differs from empty_moov");
514  finish();
515 
516 
517  // Verify that we can produce an identical second fragment without
518  // writing the first one. First write the reference fragments that
519  // we want to reproduce.
520  av_dict_set(&opts, "movflags", "frag_custom+empty_moov+dash", 0);
521  init(0, 0);
522  mux_gops(1);
523  av_write_frame(ctx, NULL); // Output the first fragment
524  init_out("empty-moov-second-frag");
525  mux_gops(1);
526  av_write_frame(ctx, NULL); // Output the second fragment
527  close_out();
528  memcpy(content, hash, HASH_SIZE);
529  finish();
530 
531  // Produce the same second fragment without actually writing the first
532  // one before.
533  av_dict_set(&opts, "movflags", "frag_custom+empty_moov+dash+frag_discont", 0);
534  av_dict_set(&opts, "fragment_index", "2", 0);
535  av_dict_set(&opts, "avoid_negative_ts", "0", 0);
536  av_dict_set(&opts, "use_editlist", "0", 0);
537  init(0, 0);
538  skip_gops(1);
539  init_out("empty-moov-second-frag-discont");
540  mux_gops(1);
541  av_write_frame(ctx, NULL); // Output the second fragment
542  close_out();
543  check(!memcmp(hash, content, HASH_SIZE), "discontinuously written fragment differs");
544  finish();
545 
546  // Produce the same thing by using delay_moov, which requires a slightly
547  // different call sequence.
548  av_dict_set(&opts, "movflags", "frag_custom+delay_moov+dash+frag_discont", 0);
549  av_dict_set(&opts, "fragment_index", "2", 0);
550  init(0, 0);
551  skip_gops(1);
552  mux_gops(1);
553  av_write_frame(ctx, NULL); // Output the moov
554  init_out("delay-moov-second-frag-discont");
555  av_write_frame(ctx, NULL); // Output the second fragment
556  close_out();
557  check(!memcmp(hash, content, HASH_SIZE), "discontinuously written fragment differs");
558  finish();
559 
560 
561  // Test discontinously written fragments with b-frames (where the
562  // assumption of starting at pts=0 works) but not with audio preroll
563  // (which can't be guessed).
564  av_dict_set(&opts, "movflags", "frag_custom+delay_moov+dash", 0);
565  init(1, 0);
566  mux_gops(1);
567  init_out("delay-moov-elst-init");
568  av_write_frame(ctx, NULL); // Output the moov
569  close_out();
570  memcpy(header, hash, HASH_SIZE);
571  av_write_frame(ctx, NULL); // Output the first fragment
572  init_out("delay-moov-elst-second-frag");
573  mux_gops(1);
574  av_write_frame(ctx, NULL); // Output the second fragment
575  close_out();
576  memcpy(content, hash, HASH_SIZE);
577  finish();
578 
579  av_dict_set(&opts, "movflags", "frag_custom+delay_moov+dash+frag_discont", 0);
580  av_dict_set(&opts, "fragment_index", "2", 0);
581  init(1, 0);
582  skip_gops(1);
583  mux_gops(1); // Write the second fragment
584  init_out("delay-moov-elst-init-discont");
585  av_write_frame(ctx, NULL); // Output the moov
586  close_out();
587  check(!memcmp(hash, header, HASH_SIZE), "discontinuously written header differs");
588  init_out("delay-moov-elst-second-frag-discont");
589  av_write_frame(ctx, NULL); // Output the second fragment
590  close_out();
591  check(!memcmp(hash, content, HASH_SIZE), "discontinuously written fragment differs");
592  finish();
593 
594 
595  // Test discontinously written fragments with b-frames and audio preroll,
596  // properly signaled.
597  av_dict_set(&opts, "movflags", "frag_custom+delay_moov+dash", 0);
598  init(1, 1);
599  mux_gops(1);
600  init_out("delay-moov-elst-signal-init");
601  av_write_frame(ctx, NULL); // Output the moov
602  close_out();
603  memcpy(header, hash, HASH_SIZE);
604  av_write_frame(ctx, NULL); // Output the first fragment
605  init_out("delay-moov-elst-signal-second-frag");
606  mux_gops(1);
607  av_write_frame(ctx, NULL); // Output the second fragment
608  close_out();
609  memcpy(content, hash, HASH_SIZE);
610  finish();
611 
612  av_dict_set(&opts, "movflags", "frag_custom+delay_moov+dash+frag_discont", 0);
613  av_dict_set(&opts, "fragment_index", "2", 0);
614  init(1, 1);
615  signal_init_ts();
616  skip_gops(1);
617  mux_gops(1); // Write the second fragment
618  init_out("delay-moov-elst-signal-init-discont");
619  av_write_frame(ctx, NULL); // Output the moov
620  close_out();
621  check(!memcmp(hash, header, HASH_SIZE), "discontinuously written header differs");
622  init_out("delay-moov-elst-signal-second-frag-discont");
623  av_write_frame(ctx, NULL); // Output the second fragment
624  close_out();
625  check(!memcmp(hash, content, HASH_SIZE), "discontinuously written fragment differs");
626  finish();
627 
628 
629  // Test VFR content, with sidx atoms (which declare the pts duration
630  // of a fragment, forcing overriding the start pts of the next one).
631  // Here, the fragment duration in pts is significantly different from
632  // the duration in dts. The video stream starts at dts=-10,pts=0, and
633  // the second fragment starts at dts=155,pts=156. The trun duration sum
634  // of the first fragment is 165, which also is written as
635  // baseMediaDecodeTime in the tfdt in the second fragment. The sidx for
636  // the first fragment says earliest_presentation_time = 0 and
637  // subsegment_duration = 156, which also matches the sidx in the second
638  // fragment. For the audio stream, the pts and dts durations also don't
639  // match - the input stream starts at pts=-2048, but that part is excluded
640  // by the edit list.
641  init_out("vfr");
642  av_dict_set(&opts, "movflags", "frag_keyframe+delay_moov+dash", 0);
643  init_fps(1, 1, 3);
644  mux_frames(gop_size/2);
645  duration /= 10;
646  mux_frames(gop_size/2);
647  mux_gops(1);
648  finish();
649  close_out();
650 
651  // Test VFR content, with cleared duration fields. In these cases,
652  // the muxer must guess the duration of the last packet of each
653  // fragment. As long as the framerate doesn't vary (too much) at the
654  // fragment edge, it works just fine. Additionally, when automatically
655  // cutting fragments, the muxer already know the timestamps of the next
656  // packet for one stream (in most cases the video stream), avoiding
657  // having to use guesses for that one.
659  clear_duration = 1;
660  init_out("vfr-noduration");
661  av_dict_set(&opts, "movflags", "frag_keyframe+delay_moov+dash", 0);
662  init_fps(1, 1, 3);
663  mux_frames(gop_size/2);
664  duration /= 10;
665  mux_frames(gop_size/2);
666  mux_gops(1);
667  finish();
668  close_out();
669  clear_duration = 0;
671  check(num_warnings > 0, "No warnings printed for filled in durations");
672 
673  av_free(md5);
674 
675  return check_faults > 0 ? 1 : 0;
676 }
int main(int argc, char **argv)
Definition: movenc-test.c:313
#define NULL
Definition: coverity.c:32
static void reset_count_warnings(void)
Definition: movenc-test.c:90
int av_write_frame(AVFormatContext *s, AVPacket *pkt)
Write a packet to an output media file.
Definition: mux.c:816
AVFormatContext * ctx
Definition: movenc-test.c:48
const char * fmt
Definition: avisynth_c.h:632
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
int skip_write
Definition: movenc-test.c:69
AVStream * video_st
Definition: movenc-test.c:59
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:3921
int num
numerator
Definition: rational.h:44
int size
Definition: avcodec.h:1580
#define AVIO_FLAG_WRITE
write-only
Definition: avio.h:543
int64_t audio_duration
Definition: movenc-test.c:64
static void skip_gops(int n)
Definition: movenc-test.c:275
static void init_out(const char *name)
Definition: movenc-test.c:104
int frames
Definition: movenc-test.c:65
static AVPacket pkt
void av_md5_update(AVMD5 *ctx, const uint8_t *src, int len)
Update hash value.
Definition: md5.c:157
Format I/O context.
Definition: avformat.h:1325
struct AVMD5 * av_md5_alloc(void)
Allocate an AVMD5 context.
Definition: md5.c:48
uint8_t
int width
Video only.
Definition: avcodec.h:3987
static void help(void)
Definition: movenc-test.c:307
int skip_write_audio
Definition: movenc-test.c:70
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: avcodec.h:1597
static void signal_init_ts(void)
Definition: movenc-test.c:282
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:4059
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
Definition: options.c:132
int flags
Flags modifying the (de)muxer behaviour.
Definition: avformat.h:1436
uint8_t * data
Definition: avcodec.h:1579
ptrdiff_t size
Definition: opengl_enc.c:101
static const uint8_t header[24]
Definition: sdr2.c:67
static void check_func(int value, int line, const char *msg,...)
Definition: movenc-test.c:131
static void count_warnings(void *avcl, int level, const char *fmt, va_list vl)
Definition: movenc-test.c:78
Definition: md5.c:40
#define AVFMT_FLAG_BITEXACT
When muxing, try to avoid writing any random/volatile data to the output.
Definition: avformat.h:1453
struct AVOutputFormat * oformat
The output container format.
Definition: avformat.h:1344
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1611
AVIOContext * avio_alloc_context(unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int(*read_packet)(void *opaque, uint8_t *buf, int buf_size), int(*write_packet)(void *opaque, uint8_t *buf, int buf_size), int64_t(*seek)(void *opaque, int64_t offset, int whence))
Allocate and initialize an AVIOContext for buffered I/O.
Definition: aviobuf.c:121
uint8_t hash[HASH_SIZE]
Definition: movenc-test.c:57
int write_file
Definition: movenc-test.c:52
int out_size
Definition: movenc-test.c:55
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
Definition: dict.c:202
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:3917
Definition: graph2dot.c:48
uint8_t iobuf[32768]
Definition: movenc-test.c:49
void av_log_default_callback(void *ptr, int level, const char *fmt, va_list vl)
Default logging callback.
Definition: log.c:302
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1585
int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b)
Compare 2 timestamps each in its own timebases.
Definition: mathematics.c:147
int extradata_size
Size of the extradata content in bytes.
Definition: avcodec.h:3939
static void mux_frames(int n)
Definition: movenc-test.c:212
av_warn_unused_result int avformat_write_header(AVFormatContext *s, AVDictionary **options)
Allocate the stream private data and write the stream header to an output media file.
Definition: mux.c:492
void av_log_set_callback(void(*callback)(void *, int, const char *, va_list))
Set the logging callback.
Definition: log.c:406
GLsizei GLboolean const GLfloat * value
Definition: opengl_enc.c:109
enum AVPictureType last_picture
Definition: movenc-test.c:68
int64_t duration
Definition: movenc-test.c:63
int clear_duration
Definition: movenc-test.c:71
int n
Definition: avisynth_c.h:547
AVOutputFormat * av_guess_format(const char *short_name, const char *filename, const char *mime_type)
Return the output format in the list of registered output formats which best matches the provided par...
Definition: format.c:94
FILE * out
Definition: movenc-test.c:54
Stream structure.
Definition: avformat.h:876
static void init_count_warnings(void)
Definition: movenc-test.c:84
int64_t audio_dts
Definition: movenc-test.c:60
AVIOContext * pb
I/O context.
Definition: avformat.h:1367
#define check(value,...)
Definition: movenc-test.c:143
static void finish(void)
Definition: movenc-test.c:299
const char * cur_name
Definition: movenc-test.c:53
static const char * format
Definition: movenc-test.c:47
static int getopt(int argc, char *argv[], char *opts)
Definition: getopt.c:41
void av_md5_init(AVMD5 *ctx)
Initialize MD5 hashing.
Definition: md5.c:147
void * buf
Definition: avisynth_c.h:553
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:69
#define AV_WB32(p, v)
Definition: intreadwrite.h:419
static void init(int bf, int audio_preroll)
Definition: movenc-test.c:207
AVPictureType
Definition: avutil.h:264
#define snprintf
Definition: snprintf.h:34
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
Definition: utils.c:3995
void av_md5_final(AVMD5 *ctx, uint8_t *dst)
Finish hashing and output digest value.
Definition: md5.c:192
int64_t video_dts
Definition: movenc-test.c:60
static void mux_gops(int n)
Definition: movenc-test.c:270
uint8_t level
Definition: svq3.c:193
int sample_rate
Audio only.
Definition: avcodec.h:4031
Main libavformat public API header.
static double c[64]
int64_t next_p_pts
Definition: movenc-test.c:67
Bi-dir predicted.
Definition: avutil.h:268
struct AVMD5 * md5
Definition: movenc-test.c:56
AVStream * audio_st
Definition: movenc-test.c:59
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
Definition: avpacket.c:33
int den
denominator
Definition: rational.h:45
static int io_write(void *opaque, uint8_t *buf, int size)
Definition: movenc-test.c:95
static void init_fps(int bf, int audio_preroll, int fps)
Definition: movenc-test.c:145
#define HASH_SIZE
Definition: movenc-test.c:37
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:730
static void close_out(void)
Definition: movenc-test.c:119
#define av_free(p)
int bframes
Definition: movenc-test.c:62
int gop_size
Definition: movenc-test.c:66
AVDictionary * opts
Definition: movenc-test.c:50
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: avcodec.h:3935
int channels
Audio only.
Definition: avcodec.h:4027
int check_faults
Definition: movenc-test.c:75
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: avcodec.h:1578
int av_write_trailer(AVFormatContext *s)
Write the stream trailer to an output media file and free the file private data.
Definition: mux.c:1136
static const uint8_t aac_extradata[]
Definition: movenc-test.c:42
static const uint8_t h264_extradata[]
Definition: movenc-test.c:39
AVCodecParameters * codecpar
Definition: avformat.h:1006
int stream_index
Definition: avcodec.h:1581
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avformat.h:913
This structure stores compressed data.
Definition: avcodec.h:1556
void av_register_all(void)
Initialize libavformat and register all the muxers, demuxers and protocols.
Definition: allformats.c:44
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:252
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1572
Predicted.
Definition: avutil.h:267
int num_warnings
Definition: movenc-test.c:73
const char * name
Definition: opengl_enc.c:103