FFmpeg
ffmpeg_mux.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include <stdatomic.h>
20 #include <stdio.h>
21 #include <string.h>
22 
23 #include "ffmpeg.h"
24 #include "ffmpeg_mux.h"
25 #include "ffmpeg_utils.h"
26 #include "sync_queue.h"
27 
28 #include "libavutil/avstring.h"
29 #include "libavutil/fifo.h"
30 #include "libavutil/intreadwrite.h"
31 #include "libavutil/log.h"
32 #include "libavutil/mem.h"
33 #include "libavutil/time.h"
34 #include "libavutil/timestamp.h"
35 
36 #include "libavcodec/packet.h"
37 
38 #include "libavformat/avformat.h"
39 #include "libavformat/avio.h"
40 
41 typedef struct MuxThreadContext {
45 
47 {
48  return (Muxer*)of;
49 }
50 
51 static int64_t filesize(AVIOContext *pb)
52 {
53  int64_t ret = -1;
54 
55  if (pb) {
56  ret = avio_size(pb);
57  if (ret <= 0) // FIXME improve avio_size() so it works with non seekable output too
58  ret = avio_tell(pb);
59  }
60 
61  return ret;
62 }
63 
65 {
66  static const char *desc[] = {
67  [LATENCY_PROBE_DEMUX] = "demux",
68  [LATENCY_PROBE_DEC_PRE] = "decode",
69  [LATENCY_PROBE_DEC_POST] = "decode",
70  [LATENCY_PROBE_FILTER_PRE] = "filter",
71  [LATENCY_PROBE_FILTER_POST] = "filter",
72  [LATENCY_PROBE_ENC_PRE] = "encode",
73  [LATENCY_PROBE_ENC_POST] = "encode",
74  [LATENCY_PROBE_NB] = "mux",
75  };
76 
77  char latency[512];
78 
79  *latency = 0;
80  if (pkt->opaque_ref) {
81  const FrameData *fd = (FrameData*)pkt->opaque_ref->data;
82  int64_t now = av_gettime_relative();
83  int64_t total = INT64_MIN;
84 
85  int next;
86 
87  for (unsigned i = 0; i < FF_ARRAY_ELEMS(fd->wallclock); i = next) {
88  int64_t val = fd->wallclock[i];
89 
90  next = i + 1;
91 
92  if (val == INT64_MIN)
93  continue;
94 
95  if (total == INT64_MIN) {
96  total = now - val;
97  snprintf(latency, sizeof(latency), "total:%gms", total / 1e3);
98  }
99 
100  // find the next valid entry
101  for (; next <= FF_ARRAY_ELEMS(fd->wallclock); next++) {
102  int64_t val_next = (next == FF_ARRAY_ELEMS(fd->wallclock)) ?
103  now : fd->wallclock[next];
104  int64_t diff;
105 
106  if (val_next == INT64_MIN)
107  continue;
108  diff = val_next - val;
109 
110  // print those stages that take at least 5% of total
111  if (100. * diff > 5. * total) {
112  av_strlcat(latency, ", ", sizeof(latency));
113 
114  if (!strcmp(desc[i], desc[next]))
115  av_strlcat(latency, desc[i], sizeof(latency));
116  else
117  av_strlcatf(latency, sizeof(latency), "%s-%s:",
118  desc[i], desc[next]);
119 
120  av_strlcatf(latency, sizeof(latency), " %gms/%d%%",
121  diff / 1e3, (int)(100. * diff / total));
122  }
123 
124  break;
125  }
126 
127  }
128  }
129 
130  av_log(ost, AV_LOG_INFO, "muxer <- pts:%s pts_time:%s dts:%s dts_time:%s "
131  "duration:%s duration_time:%s size:%d latency(%s)\n",
135  pkt->size, *latency ? latency : "N/A");
136 }
137 
138 static int mux_fixup_ts(Muxer *mux, MuxStream *ms, AVPacket *pkt)
139 {
140  OutputStream *ost = &ms->ost;
141 
142 #if FFMPEG_OPT_VSYNC_DROP
143  if (ost->type == AVMEDIA_TYPE_VIDEO && ost->vsync_method == VSYNC_DROP)
144  pkt->pts = pkt->dts = AV_NOPTS_VALUE;
145 #endif
146 
147  // rescale timestamps to the stream timebase
148  if (ost->type == AVMEDIA_TYPE_AUDIO && !ost->enc) {
149  // use av_rescale_delta() for streamcopying audio, to preserve
150  // accuracy with coarse input timebases
152 
153  if (!duration)
155 
157  (AVRational){1, ost->st->codecpar->sample_rate}, duration,
158  &ms->ts_rescale_delta_last, ost->st->time_base);
159  pkt->pts = pkt->dts;
160 
162  } else
164  pkt->time_base = ost->st->time_base;
165 
166  if (!(mux->fc->oformat->flags & AVFMT_NOTIMESTAMPS)) {
167  if (pkt->dts != AV_NOPTS_VALUE &&
168  pkt->pts != AV_NOPTS_VALUE &&
169  pkt->dts > pkt->pts) {
170  av_log(ost, AV_LOG_WARNING, "Invalid DTS: %"PRId64" PTS: %"PRId64", replacing by guess\n",
171  pkt->dts, pkt->pts);
172  pkt->pts =
173  pkt->dts = pkt->pts + pkt->dts + ms->last_mux_dts + 1
174  - FFMIN3(pkt->pts, pkt->dts, ms->last_mux_dts + 1)
175  - FFMAX3(pkt->pts, pkt->dts, ms->last_mux_dts + 1);
176  }
177  if ((ost->type == AVMEDIA_TYPE_AUDIO || ost->type == AVMEDIA_TYPE_VIDEO || ost->type == AVMEDIA_TYPE_SUBTITLE) &&
178  pkt->dts != AV_NOPTS_VALUE &&
179  ms->last_mux_dts != AV_NOPTS_VALUE) {
180  int64_t max = ms->last_mux_dts + !(mux->fc->oformat->flags & AVFMT_TS_NONSTRICT);
181  if (pkt->dts < max) {
182  int loglevel = max - pkt->dts > 2 || ost->type == AVMEDIA_TYPE_VIDEO ? AV_LOG_WARNING : AV_LOG_DEBUG;
183  if (exit_on_error)
184  loglevel = AV_LOG_ERROR;
185  av_log(ost, loglevel, "Non-monotonic DTS; "
186  "previous: %"PRId64", current: %"PRId64"; ",
187  ms->last_mux_dts, pkt->dts);
188  if (exit_on_error) {
189  return AVERROR(EINVAL);
190  }
191 
192  av_log(ost, loglevel, "changing to %"PRId64". This may result "
193  "in incorrect timestamps in the output file.\n",
194  max);
195  if (pkt->pts >= pkt->dts)
196  pkt->pts = FFMAX(pkt->pts, max);
197  pkt->dts = max;
198  }
199  }
200  }
201  ms->last_mux_dts = pkt->dts;
202 
203  if (debug_ts)
205 
206  return 0;
207 }
208 
210 {
211  MuxStream *ms = ms_from_ost(ost);
212  AVFormatContext *s = mux->fc;
213  int64_t fs;
214  uint64_t frame_num;
215  int ret;
216 
217  fs = filesize(s->pb);
218  atomic_store(&mux->last_filesize, fs);
219  if (fs >= mux->limit_filesize) {
220  ret = AVERROR_EOF;
221  goto fail;
222  }
223 
224  ret = mux_fixup_ts(mux, ms, pkt);
225  if (ret < 0)
226  goto fail;
227 
228  ms->data_size_mux += pkt->size;
229  frame_num = atomic_fetch_add(&ost->packets_written, 1);
230 
232 
233  if (ms->stats.io)
234  enc_stats_write(ost, &ms->stats, NULL, pkt, frame_num);
235 
237  if (ret < 0) {
239  "Error submitting a packet to the muxer: %s\n",
240  av_err2str(ret));
241  goto fail;
242  }
243 
244  return 0;
245 fail:
247  return ret;
248 }
249 
250 static int sync_queue_process(Muxer *mux, MuxStream *ms, AVPacket *pkt, int *stream_eof)
251 {
252  OutputFile *of = &mux->of;
253 
254  if (ms->sq_idx_mux >= 0) {
255  int ret = sq_send(mux->sq_mux, ms->sq_idx_mux, SQPKT(pkt));
256  if (ret < 0) {
257  if (ret == AVERROR_EOF)
258  *stream_eof = 1;
259 
260  return ret;
261  }
262 
263  while (1) {
264  ret = sq_receive(mux->sq_mux, -1, SQPKT(mux->sq_pkt));
265  if (ret < 0) {
266  /* n.b.: We forward EOF from the sync queue, terminating muxing.
267  * This assumes that if a muxing sync queue is present, then all
268  * the streams use it. That is true currently, but may change in
269  * the future, then this code needs to be revisited.
270  */
271  return ret == AVERROR(EAGAIN) ? 0 : ret;
272  }
273 
274  ret = write_packet(mux, of->streams[ret],
275  mux->sq_pkt);
276  if (ret < 0)
277  return ret;
278  }
279  } else if (pkt)
280  return write_packet(mux, &ms->ost, pkt);
281 
282  return 0;
283 }
284 
286 
287 /* apply the output bitstream filters */
289  OutputStream *ost, AVPacket *pkt, int *stream_eof)
290 {
291  MuxStream *ms = ms_from_ost(ost);
292  const char *err_msg;
293  int ret = 0;
294 
295  if (pkt && !ost->enc) {
296  ret = of_streamcopy(&mux->of, ost, pkt);
297  if (ret == AVERROR(EAGAIN))
298  return 0;
299  else if (ret == AVERROR_EOF) {
301  pkt = NULL;
302  ret = 0;
303  *stream_eof = 1;
304  } else if (ret < 0)
305  goto fail;
306  }
307 
308  // emit heartbeat for -fix_sub_duration;
309  // we are only interested in heartbeats on on random access points.
310  if (pkt && (pkt->flags & AV_PKT_FLAG_KEY)) {
314 
315  ret = sch_mux_sub_heartbeat(mux->sch, mux->sch_idx, ms->sch_idx,
317  if (ret < 0)
318  goto fail;
319  }
320 
321  if (ms->bsf_ctx) {
322  int bsf_eof = 0;
323 
324  if (pkt)
326 
328  if (ret < 0) {
329  err_msg = "submitting a packet for bitstream filtering";
330  goto fail;
331  }
332 
333  while (!bsf_eof) {
335  if (ret == AVERROR(EAGAIN))
336  return 0;
337  else if (ret == AVERROR_EOF)
338  bsf_eof = 1;
339  else if (ret < 0) {
341  "Error applying bitstream filters to a packet: %s",
342  av_err2str(ret));
343  if (exit_on_error)
344  return ret;
345  continue;
346  }
347 
348  if (!bsf_eof)
350 
351  ret = sync_queue_process(mux, ms, bsf_eof ? NULL : ms->bsf_pkt, stream_eof);
352  if (ret < 0)
353  goto mux_fail;
354  }
355  *stream_eof = 1;
356  } else {
357  ret = sync_queue_process(mux, ms, pkt, stream_eof);
358  if (ret < 0)
359  goto mux_fail;
360  }
361 
362  return *stream_eof ? AVERROR_EOF : 0;
363 
364 mux_fail:
365  err_msg = "submitting a packet to the muxer";
366 
367 fail:
368  if (ret != AVERROR_EOF)
369  av_log(ost, AV_LOG_ERROR, "Error %s: %s\n", err_msg, av_err2str(ret));
370  return ret;
371 }
372 
373 static void thread_set_name(OutputFile *of)
374 {
375  char name[16];
376  snprintf(name, sizeof(name), "mux%d:%s", of->index, of->format->name);
378 }
379 
381 {
382  av_packet_free(&mt->pkt);
384 
385  memset(mt, 0, sizeof(*mt));
386 }
387 
389 {
390  memset(mt, 0, sizeof(*mt));
391 
392  mt->pkt = av_packet_alloc();
393  if (!mt->pkt)
394  goto fail;
395 
397  if (!mt->fix_sub_duration_pkt)
398  goto fail;
399 
400  return 0;
401 
402 fail:
403  mux_thread_uninit(mt);
404  return AVERROR(ENOMEM);
405 }
406 
407 int muxer_thread(void *arg)
408 {
409  Muxer *mux = arg;
410  OutputFile *of = &mux->of;
411 
412  MuxThreadContext mt;
413 
414  int ret = 0;
415 
416  ret = mux_thread_init(&mt);
417  if (ret < 0)
418  goto finish;
419 
420  thread_set_name(of);
421 
422  while (1) {
423  OutputStream *ost;
424  int stream_idx, stream_eof = 0;
425 
426  ret = sch_mux_receive(mux->sch, of->index, mt.pkt);
427  stream_idx = mt.pkt->stream_index;
428  if (stream_idx < 0) {
429  av_log(mux, AV_LOG_VERBOSE, "All streams finished\n");
430  ret = 0;
431  break;
432  }
433 
434  ost = of->streams[mux->sch_stream_idx[stream_idx]];
435  mt.pkt->stream_index = ost->index;
436  mt.pkt->flags &= ~AV_PKT_FLAG_TRUSTED;
437 
438  ret = mux_packet_filter(mux, &mt, ost, ret < 0 ? NULL : mt.pkt, &stream_eof);
439  av_packet_unref(mt.pkt);
440  if (ret == AVERROR_EOF) {
441  if (stream_eof) {
442  sch_mux_receive_finish(mux->sch, of->index, stream_idx);
443  } else {
444  av_log(mux, AV_LOG_VERBOSE, "Muxer returned EOF\n");
445  ret = 0;
446  break;
447  }
448  } else if (ret < 0) {
449  av_log(mux, AV_LOG_ERROR, "Error muxing a packet\n");
450  break;
451  }
452  }
453 
454 finish:
455  mux_thread_uninit(&mt);
456 
457  return ret;
458 }
459 
461 {
462  MuxStream *ms = ms_from_ost(ost);
464  int64_t dts = fd ? fd->dts_est : AV_NOPTS_VALUE;
465  int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time;
466  int64_t ts_offset;
467 
468  if (of->recording_time != INT64_MAX &&
469  dts >= of->recording_time + start_time)
470  return AVERROR_EOF;
471 
472  if (!ms->streamcopy_started && !(pkt->flags & AV_PKT_FLAG_KEY) &&
474  return AVERROR(EAGAIN);
475 
476  if (!ms->streamcopy_started) {
477  if (!ms->copy_prior_start &&
478  (pkt->pts == AV_NOPTS_VALUE ?
479  dts < ms->ts_copy_start :
481  return AVERROR(EAGAIN);
482 
483  if (of->start_time != AV_NOPTS_VALUE && dts < of->start_time)
484  return AVERROR(EAGAIN);
485  }
486 
488 
489  if (pkt->pts != AV_NOPTS_VALUE)
490  pkt->pts -= ts_offset;
491 
492  if (pkt->dts == AV_NOPTS_VALUE) {
494  } else if (ost->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
495  pkt->pts = pkt->dts - ts_offset;
496  }
497 
498  pkt->dts -= ts_offset;
499 
500  ms->streamcopy_started = 1;
501 
502  return 0;
503 }
504 
505 int print_sdp(const char *filename);
506 
507 int print_sdp(const char *filename)
508 {
509  char sdp[16384];
510  int j = 0, ret;
511  AVIOContext *sdp_pb;
512  AVFormatContext **avc;
513 
514  avc = av_malloc_array(nb_output_files, sizeof(*avc));
515  if (!avc)
516  return AVERROR(ENOMEM);
517  for (int i = 0; i < nb_output_files; i++) {
518  if (!strcmp(output_files[i]->format->name, "rtp")) {
519  avc[j] = mux_from_of(output_files[i])->fc;
520  j++;
521  }
522  }
523 
524  if (!j) {
525  av_log(NULL, AV_LOG_ERROR, "No output streams in the SDP.\n");
526  ret = AVERROR(EINVAL);
527  goto fail;
528  }
529 
530  ret = av_sdp_create(avc, j, sdp, sizeof(sdp));
531  if (ret < 0)
532  goto fail;
533 
534  if (!filename) {
535  printf("SDP:\n%s\n", sdp);
536  fflush(stdout);
537  } else {
538  ret = avio_open2(&sdp_pb, filename, AVIO_FLAG_WRITE, &int_cb, NULL);
539  if (ret < 0) {
540  av_log(NULL, AV_LOG_ERROR, "Failed to open sdp file '%s'\n", filename);
541  goto fail;
542  }
543 
544  avio_print(sdp_pb, sdp);
545  avio_closep(&sdp_pb);
546  }
547 
548 fail:
549  av_freep(&avc);
550  return ret;
551 }
552 
553 int mux_check_init(void *arg)
554 {
555  Muxer *mux = arg;
556  OutputFile *of = &mux->of;
557  AVFormatContext *fc = mux->fc;
558  int ret;
559 
560  ret = avformat_write_header(fc, &mux->opts);
561  if (ret < 0) {
562  av_log(mux, AV_LOG_ERROR, "Could not write header (incorrect codec "
563  "parameters ?): %s\n", av_err2str(ret));
564  return ret;
565  }
566  //assert_avoptions(of->opts);
567  mux->header_written = 1;
568 
569  av_dump_format(fc, of->index, fc->url, 1);
571 
572  return 0;
573 }
574 
575 static int bsf_init(MuxStream *ms)
576 {
577  OutputStream *ost = &ms->ost;
578  AVBSFContext *ctx = ms->bsf_ctx;
579  int ret;
580 
581  if (!ctx)
582  return avcodec_parameters_copy(ost->st->codecpar, ost->par_in);
583 
584  ret = avcodec_parameters_copy(ctx->par_in, ost->par_in);
585  if (ret < 0)
586  return ret;
587 
588  ctx->time_base_in = ost->st->time_base;
589 
590  ret = av_bsf_init(ctx);
591  if (ret < 0) {
592  av_log(ms, AV_LOG_ERROR, "Error initializing bitstream filter: %s\n",
593  ctx->filter->name);
594  return ret;
595  }
596 
597  ret = avcodec_parameters_copy(ost->st->codecpar, ctx->par_out);
598  if (ret < 0)
599  return ret;
600  ost->st->time_base = ctx->time_base_out;
601 
602  ms->bsf_pkt = av_packet_alloc();
603  if (!ms->bsf_pkt)
604  return AVERROR(ENOMEM);
605 
606  return 0;
607 }
608 
610 {
611  Muxer *mux = mux_from_of(of);
612  MuxStream *ms = ms_from_ost(ost);
613  int ret;
614 
615  /* initialize bitstream filters for the output stream
616  * needs to be done here, because the codec id for streamcopy is not
617  * known until now */
618  ret = bsf_init(ms);
619  if (ret < 0)
620  return ret;
621 
622  if (ms->stream_duration) {
624  ost->st->time_base);
625  }
626 
627  if (ms->sch_idx >= 0)
628  return sch_mux_stream_ready(mux->sch, of->index, ms->sch_idx);
629 
630  return 0;
631 }
632 
633 static int check_written(OutputFile *of)
634 {
635  int64_t total_packets_written = 0;
636  int pass1_used = 1;
637  int ret = 0;
638 
639  for (int i = 0; i < of->nb_streams; i++) {
640  OutputStream *ost = of->streams[i];
641  uint64_t packets_written = atomic_load(&ost->packets_written);
642 
643  total_packets_written += packets_written;
644 
645  if (ost->enc_ctx &&
646  (ost->enc_ctx->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2))
648  pass1_used = 0;
649 
650  if (!packets_written &&
652  av_log(ost, AV_LOG_FATAL, "Empty output stream\n");
653  ret = err_merge(ret, AVERROR(EINVAL));
654  }
655  }
656 
657  if (!total_packets_written) {
658  int level = AV_LOG_WARNING;
659 
661  ret = err_merge(ret, AVERROR(EINVAL));
663  }
664 
665  av_log(of, level, "Output file is empty, nothing was encoded%s\n",
666  pass1_used ? "" : "(check -ss / -t / -frames parameters if used)");
667  }
668 
669  return ret;
670 }
671 
672 static void mux_final_stats(Muxer *mux)
673 {
674  OutputFile *of = &mux->of;
675  uint64_t total_packets = 0, total_size = 0;
676  uint64_t video_size = 0, audio_size = 0, subtitle_size = 0,
677  extra_size = 0, other_size = 0;
678 
679  uint8_t overhead[16] = "unknown";
680  int64_t file_size = of_filesize(of);
681 
682  av_log(of, AV_LOG_VERBOSE, "Output file #%d (%s):\n",
683  of->index, of->url);
684 
685  for (int j = 0; j < of->nb_streams; j++) {
686  OutputStream *ost = of->streams[j];
687  MuxStream *ms = ms_from_ost(ost);
688  const AVCodecParameters *par = ost->st->codecpar;
689  const enum AVMediaType type = par->codec_type;
690  const uint64_t s = ms->data_size_mux;
691 
692  switch (type) {
693  case AVMEDIA_TYPE_VIDEO: video_size += s; break;
694  case AVMEDIA_TYPE_AUDIO: audio_size += s; break;
695  case AVMEDIA_TYPE_SUBTITLE: subtitle_size += s; break;
696  default: other_size += s; break;
697  }
698 
699  extra_size += par->extradata_size;
700  total_size += s;
701  total_packets += atomic_load(&ost->packets_written);
702 
703  av_log(of, AV_LOG_VERBOSE, " Output stream #%d:%d (%s): ",
705  if (ost->enc) {
706  av_log(of, AV_LOG_VERBOSE, "%"PRIu64" frames encoded",
707  ost->frames_encoded);
708  if (type == AVMEDIA_TYPE_AUDIO)
709  av_log(of, AV_LOG_VERBOSE, " (%"PRIu64" samples)", ost->samples_encoded);
710  av_log(of, AV_LOG_VERBOSE, "; ");
711  }
712 
713  av_log(of, AV_LOG_VERBOSE, "%"PRIu64" packets muxed (%"PRIu64" bytes); ",
714  atomic_load(&ost->packets_written), s);
715 
716  av_log(of, AV_LOG_VERBOSE, "\n");
717  }
718 
719  av_log(of, AV_LOG_VERBOSE, " Total: %"PRIu64" packets (%"PRIu64" bytes) muxed\n",
720  total_packets, total_size);
721 
722  if (total_size && file_size > 0 && file_size >= total_size) {
723  snprintf(overhead, sizeof(overhead), "%f%%",
724  100.0 * (file_size - total_size) / total_size);
725  }
726 
727  av_log(of, AV_LOG_INFO,
728  "video:%1.0fKiB audio:%1.0fKiB subtitle:%1.0fKiB other streams:%1.0fKiB "
729  "global headers:%1.0fKiB muxing overhead: %s\n",
730  video_size / 1024.0,
731  audio_size / 1024.0,
732  subtitle_size / 1024.0,
733  other_size / 1024.0,
734  extra_size / 1024.0,
735  overhead);
736 }
737 
739 {
740  Muxer *mux = mux_from_of(of);
741  AVFormatContext *fc = mux->fc;
742  int ret, mux_result = 0;
743 
744  if (!mux->header_written) {
745  av_log(mux, AV_LOG_ERROR,
746  "Nothing was written into output file, because "
747  "at least one of its streams received no packets.\n");
748  return AVERROR(EINVAL);
749  }
750 
752  if (ret < 0) {
753  av_log(mux, AV_LOG_ERROR, "Error writing trailer: %s\n", av_err2str(ret));
754  mux_result = err_merge(mux_result, ret);
755  }
756 
757  mux->last_filesize = filesize(fc->pb);
758 
759  if (!(of->format->flags & AVFMT_NOFILE)) {
760  ret = avio_closep(&fc->pb);
761  if (ret < 0) {
762  av_log(mux, AV_LOG_ERROR, "Error closing file: %s\n", av_err2str(ret));
763  mux_result = err_merge(mux_result, ret);
764  }
765  }
766 
767  mux_final_stats(mux);
768 
769  // check whether anything was actually written
770  ret = check_written(of);
771  mux_result = err_merge(mux_result, ret);
772 
773  return mux_result;
774 }
775 
776 static void enc_stats_uninit(EncStats *es)
777 {
778  for (int i = 0; i < es->nb_components; i++)
779  av_freep(&es->components[i].str);
780  av_freep(&es->components);
781 
782  if (es->lock_initialized)
784  es->lock_initialized = 0;
785 }
786 
787 static void ost_free(OutputStream **post)
788 {
789  OutputStream *ost = *post;
790  MuxStream *ms;
791 
792  if (!ost)
793  return;
794  ms = ms_from_ost(ost);
795 
796  enc_free(&ost->enc);
797 
798  if (ost->logfile) {
799  if (fclose(ost->logfile))
800  av_log(ms, AV_LOG_ERROR,
801  "Error closing logfile, loss of information possible: %s\n",
802  av_err2str(AVERROR(errno)));
803  ost->logfile = NULL;
804  }
805 
806  avcodec_parameters_free(&ost->par_in);
807 
808  av_bsf_free(&ms->bsf_ctx);
809  av_packet_free(&ms->bsf_pkt);
810 
811  av_packet_free(&ms->pkt);
812  av_dict_free(&ost->encoder_opts);
813 
814  av_freep(&ost->kf.pts);
815  av_expr_free(ost->kf.pexpr);
816 
817  av_freep(&ost->logfile_prefix);
818  av_freep(&ost->apad);
819 
820  av_freep(&ost->attachment_filename);
821 
822  av_dict_free(&ost->sws_dict);
823  av_dict_free(&ost->swr_opts);
824 
825  if (ost->enc_ctx)
826  av_freep(&ost->enc_ctx->stats_in);
827  avcodec_free_context(&ost->enc_ctx);
828 
829  enc_stats_uninit(&ost->enc_stats_pre);
830  enc_stats_uninit(&ost->enc_stats_post);
831  enc_stats_uninit(&ms->stats);
832 
833  av_freep(post);
834 }
835 
836 static void fc_close(AVFormatContext **pfc)
837 {
838  AVFormatContext *fc = *pfc;
839 
840  if (!fc)
841  return;
842 
843  if (!(fc->oformat->flags & AVFMT_NOFILE))
844  avio_closep(&fc->pb);
846 
847  *pfc = NULL;
848 }
849 
850 void of_free(OutputFile **pof)
851 {
852  OutputFile *of = *pof;
853  Muxer *mux;
854 
855  if (!of)
856  return;
857  mux = mux_from_of(of);
858 
859  sq_free(&mux->sq_mux);
860 
861  for (int i = 0; i < of->nb_streams; i++)
862  ost_free(&of->streams[i]);
863  av_freep(&of->streams);
864 
865  av_freep(&mux->sch_stream_idx);
866 
867  av_dict_free(&mux->opts);
868 
869  av_packet_free(&mux->sq_pkt);
870 
871  fc_close(&mux->fc);
872 
873  av_freep(pof);
874 }
875 
877 {
878  Muxer *mux = mux_from_of(of);
879  return atomic_load(&mux->last_filesize);
880 }
MuxStream::ost
OutputStream ost
Definition: ffmpeg_mux.h:37
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:427
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:204
av_gettime_relative
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
Definition: time.c:56
MuxStream::copy_initial_nonkeyframes
int copy_initial_nonkeyframes
Definition: ffmpeg_mux.h:75
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
Muxer::fc
AVFormatContext * fc
Definition: ffmpeg_mux.h:86
name
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 default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
level
uint8_t level
Definition: svq3.c:204
atomic_store
#define atomic_store(object, desired)
Definition: stdatomic.h:85
err_merge
static int err_merge(int err0, int err1)
Merge two return codes - return one of the error codes if at least one of them was negative,...
Definition: ffmpeg_utils.h:41
ms_from_ost
static MuxStream * ms_from_ost(OutputStream *ost)
Definition: ffmpeg_mux.h:108
AVOutputFormat::name
const char * name
Definition: avformat.h:510
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
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:51
mux_from_of
static Muxer * mux_from_of(OutputFile *of)
Definition: ffmpeg_mux.c:46
MuxStream::sch_idx
int sch_idx
Definition: ffmpeg_mux.h:49
FrameData
Definition: ffmpeg.h:593
sch_mux_receive_finish
void sch_mux_receive_finish(Scheduler *sch, unsigned mux_idx, unsigned stream_idx)
Called by muxer tasks to signal that a stream will no longer accept input.
Definition: ffmpeg_sched.c:2057
Muxer::sch_stream_idx
int * sch_stream_idx
Definition: ffmpeg_mux.h:92
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:47
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
FrameData::dts_est
int64_t dts_est
Definition: ffmpeg.h:596
LATENCY_PROBE_DEC_POST
@ LATENCY_PROBE_DEC_POST
Definition: ffmpeg.h:101
AVFMT_NOTIMESTAMPS
#define AVFMT_NOTIMESTAMPS
Format does not need / have any timestamps.
Definition: avformat.h:479
AV_TIME_BASE_Q
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:264
OutputFile::start_time
int64_t start_time
start time in microseconds == AV_TIME_BASE units
Definition: ffmpeg.h:586
sync_queue.h
fc_close
static void fc_close(AVFormatContext **pfc)
Definition: ffmpeg_mux.c:836
enc_stats_uninit
static void enc_stats_uninit(EncStats *es)
Definition: ffmpeg_mux.c:776
Muxer::of
OutputFile of
Definition: ffmpeg_mux.h:81
mux_thread_init
static int mux_thread_init(MuxThreadContext *mt)
Definition: ffmpeg_mux.c:388
MuxStream::ts_rescale_delta_last
int64_t ts_rescale_delta_last
Definition: ffmpeg_mux.h:70
ffmpeg.h
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
fc
#define fc(width, name, range_min, range_max)
Definition: cbs_av1.c:464
AVPacket::duration
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: packet.h:540
max
#define max(a, b)
Definition: cuda_runtime.h:33
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
enc_stats_write
void enc_stats_write(OutputStream *ost, EncStats *es, const AVFrame *frame, const AVPacket *pkt, uint64_t frame_num)
Definition: ffmpeg_enc.c:480
MuxStream::copy_prior_start
int copy_prior_start
Definition: ffmpeg_mux.h:76
LATENCY_PROBE_ENC_POST
@ LATENCY_PROBE_ENC_POST
Definition: ffmpeg.h:105
av_bsf_free
void av_bsf_free(AVBSFContext **pctx)
Free a bitstream filter context and everything associated with it; write NULL into the supplied point...
Definition: bsf.c:52
avio_size
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:322
av_strlcatf
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
Definition: avstring.c:103
ost
static AVStream * ost
Definition: vaapi_transcode.c:42
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:577
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:74
AVBSFContext
The bitstream filter state.
Definition: bsf.h:68
MuxStream::ts_copy_start
int64_t ts_copy_start
Definition: ffmpeg_mux.h:60
MuxStream::stream_duration_tb
AVRational stream_duration_tb
Definition: ffmpeg_mux.h:67
sch_mux_stream_ready
int sch_mux_stream_ready(Scheduler *sch, unsigned mux_idx, unsigned stream_idx)
Signal to the scheduler that the specified muxed stream is initialized and ready.
Definition: ffmpeg_sched.c:1186
OutputFile::nb_streams
int nb_streams
Definition: ffmpeg.h:583
Muxer
Definition: ffmpeg_mux.h:80
debug_ts
int debug_ts
Definition: ffmpeg_opt.c:76
of_filesize
int64_t of_filesize(OutputFile *of)
Definition: ffmpeg_mux.c:876
fifo.h
mux_final_stats
static void mux_final_stats(Muxer *mux)
Definition: ffmpeg_mux.c:672
finish
static void finish(void)
Definition: movenc.c:342
AVPacket::opaque_ref
AVBufferRef * opaque_ref
AVBufferRef for free use by the API user.
Definition: packet.h:558
mux_log_debug_ts
static void mux_log_debug_ts(OutputStream *ost, const AVPacket *pkt)
Definition: ffmpeg_mux.c:64
muxer_thread
int muxer_thread(void *arg)
Definition: ffmpeg_mux.c:407
fail
#define fail()
Definition: checkasm.h:179
avio_tell
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:494
val
static double val(void *priv, double ch)
Definition: aeval.c:78
sq_receive
int sq_receive(SyncQueue *sq, int stream_idx, SyncQueueFrame frame)
Read a frame from the queue.
Definition: sync_queue.c:608
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
Muxer::sq_pkt
AVPacket * sq_pkt
Definition: ffmpeg_mux.h:103
AVStream::duration
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition: avformat.h:802
av_expr_free
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
Definition: eval.c:359
LATENCY_PROBE_FILTER_PRE
@ LATENCY_PROBE_FILTER_PRE
Definition: ffmpeg.h:102
SQPKT
#define SQPKT(pkt)
Definition: sync_queue.h:39
LATENCY_PROBE_DEMUX
@ LATENCY_PROBE_DEMUX
Definition: ffmpeg.h:99
of_streamcopy
static int of_streamcopy(OutputFile *of, OutputStream *ost, AVPacket *pkt)
Definition: ffmpeg_mux.c:460
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
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
ABORT_ON_FLAG_EMPTY_OUTPUT_STREAM
#define ABORT_ON_FLAG_EMPTY_OUTPUT_STREAM
Definition: ffmpeg.h:422
av_dump_format
void av_dump_format(AVFormatContext *ic, int index, const char *url, int is_output)
Print detailed information about the input or output format, such as duration, bitrate,...
Definition: dump.c:760
duration
int64_t duration
Definition: movenc.c:64
AVCodecParameters::frame_size
int frame_size
Audio only.
Definition: codec_par.h:195
EncStats::components
EncStatsComponent * components
Definition: ffmpeg.h:454
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:198
MuxStream::pkt
AVPacket * pkt
Definition: ffmpeg_mux.h:45
format
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 format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AVIO_FLAG_WRITE
#define AVIO_FLAG_WRITE
write-only
Definition: avio.h:618
LATENCY_PROBE_ENC_PRE
@ LATENCY_PROBE_ENC_PRE
Definition: ffmpeg.h:104
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
ctx
AVFormatContext * ctx
Definition: movenc.c:48
AVBSFContext::time_base_in
AVRational time_base_in
The timebase used for the timestamps of the input packets.
Definition: bsf.h:102
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:142
ffmpeg_utils.h
sync_queue_process
static int sync_queue_process(Muxer *mux, MuxStream *ms, AVPacket *pkt, int *stream_eof)
Definition: ffmpeg_mux.c:250
atomic_load
#define atomic_load(object)
Definition: stdatomic.h:93
AVPacket::opaque
void * opaque
for some private data of the user
Definition: packet.h:547
av_rescale_delta
int64_t av_rescale_delta(AVRational in_tb, int64_t in_ts, AVRational fs_tb, int duration, int64_t *last, AVRational out_tb)
Rescale a timestamp while preserving known durations.
Definition: mathematics.c:168
avformat_write_header
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:456
Muxer::limit_filesize
int64_t limit_filesize
Definition: ffmpeg_mux.h:98
arg
const char * arg
Definition: jacosubdec.c:67
if
if(ret)
Definition: filter_design.txt:179
AVFormatContext
Format I/O context.
Definition: avformat.h:1255
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:766
av_bsf_init
int av_bsf_init(AVBSFContext *ctx)
Prepare the filter for use, after all the parameters and options have been set.
Definition: bsf.c:149
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:782
NULL
#define NULL
Definition: coverity.c:32
of_free
void of_free(OutputFile **pof)
Definition: ffmpeg_mux.c:850
avcodec_parameters_free
void avcodec_parameters_free(AVCodecParameters **ppar)
Free an AVCodecParameters instance and everything associated with it and write NULL to the supplied p...
Definition: codec_par.c:66
fs
#define fs(width, name, subs,...)
Definition: cbs_vp9.c:200
av_bsf_receive_packet
int av_bsf_receive_packet(AVBSFContext *ctx, AVPacket *pkt)
Retrieve a filtered packet.
Definition: bsf.c:230
avio_print
#define avio_print(s,...)
Write strings (const char *) to the context.
Definition: avio.h:537
nb_output_dumped
atomic_uint nb_output_dumped
Definition: ffmpeg.c:120
avcodec_free_context
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer.
Definition: options.c:164
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
EncStats::lock
pthread_mutex_t lock
Definition: ffmpeg.h:459
EncStats
Definition: ffmpeg.h:453
MuxStream::bsf_ctx
AVBSFContext * bsf_ctx
Definition: ffmpeg_mux.h:42
FrameData::wallclock
int64_t wallclock[LATENCY_PROBE_NB]
Definition: ffmpeg.h:610
MuxStream::streamcopy_started
int streamcopy_started
Definition: ffmpeg_mux.h:77
time.h
OutputFile::index
int index
Definition: ffmpeg.h:577
Muxer::last_filesize
atomic_int_least64_t last_filesize
Definition: ffmpeg_mux.h:99
OutputFile::streams
OutputStream ** streams
Definition: ffmpeg.h:582
MuxStream::data_size_mux
uint64_t data_size_mux
Definition: ffmpeg_mux.h:73
AVCodecParameters::extradata_size
int extradata_size
Size of the extradata content in bytes.
Definition: codec_par.h:73
AVOutputFormat::flags
int flags
can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_GLOBALHEADER, AVFMT_NOTIMESTAMPS,...
Definition: avformat.h:529
AVIOContext
Bytestream IO Context.
Definition: avio.h:160
of_write_trailer
int of_write_trailer(OutputFile *of)
Definition: ffmpeg_mux.c:738
av_ts2timestr
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: timestamp.h:77
AVMediaType
AVMediaType
Definition: avutil.h:199
Muxer::sq_mux
SyncQueue * sq_mux
Definition: ffmpeg_mux.h:102
AVPacket::size
int size
Definition: packet.h:523
mux_thread_uninit
static void mux_thread_uninit(MuxThreadContext *mt)
Definition: ffmpeg_mux.c:380
output_files
OutputFile ** output_files
Definition: ffmpeg.c:128
av_bsf_send_packet
int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt)
Submit a packet for filtering.
Definition: bsf.c:202
av_err2str
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:121
start_time
static int64_t start_time
Definition: ffplay.c:329
Muxer::sch
Scheduler * sch
Definition: ffmpeg_mux.h:88
sq_send
int sq_send(SyncQueue *sq, unsigned int stream_idx, SyncQueueFrame frame)
Submit a frame for the stream with index stream_idx.
Definition: sync_queue.c:343
sq_free
void sq_free(SyncQueue **psq)
Definition: sync_queue.c:699
avio.h
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
LATENCY_PROBE_NB
@ LATENCY_PROBE_NB
Definition: ffmpeg.h:106
av_get_audio_frame_duration2
int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
This function is the same as av_get_audio_frame_duration(), except it works with AVCodecParameters in...
Definition: utils.c:796
OutputFile::url
const char * url
Definition: ffmpeg.h:580
AVFMT_NOFILE
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:468
printf
printf("static const uint8_t my_array[100] = {\n")
Muxer::opts
AVDictionary * opts
Definition: ffmpeg_mux.h:95
LATENCY_PROBE_DEC_PRE
@ LATENCY_PROBE_DEC_PRE
Definition: ffmpeg.h:100
diff
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
Definition: vf_paletteuse.c:164
MuxStream::bsf_pkt
AVPacket * bsf_pkt
Definition: ffmpeg_mux.h:43
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:521
MuxStream
Definition: ffmpeg_mux.h:36
AV_CODEC_FLAG_PASS2
#define AV_CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
Definition: avcodec.h:314
av_sdp_create
int av_sdp_create(AVFormatContext *ac[], int n_files, char *buf, int size)
Generate an SDP for an RTP session.
Definition: sdp.c:911
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:528
av_packet_alloc
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition: avpacket.c:63
av_dict_free
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
Definition: dict.c:223
Muxer::sch_idx
unsigned sch_idx
Definition: ffmpeg_mux.h:89
av_packet_rescale_ts
void av_packet_rescale_ts(AVPacket *pkt, AVRational src_tb, AVRational dst_tb)
Convert valid timing fields (timestamps / durations) in a packet from one timebase to another.
Definition: avpacket.c:531
MuxThreadContext::fix_sub_duration_pkt
AVPacket * fix_sub_duration_pkt
Definition: ffmpeg_mux.c:43
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
mux_check_init
int mux_check_init(void *arg)
Definition: ffmpeg_mux.c:553
filesize
static int64_t filesize(AVIOContext *pb)
Definition: ffmpeg_mux.c:51
pthread_mutex_destroy
static av_always_inline int pthread_mutex_destroy(pthread_mutex_t *mutex)
Definition: os2threads.h:112
av_write_trailer
int av_write_trailer(AVFormatContext *s)
Write the stream trailer to an output media file and free the file private data.
Definition: mux.c:1270
log.h
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:515
packet.h
MuxStream::stats
EncStats stats
Definition: ffmpeg_mux.h:47
FFMIN3
#define FFMIN3(a, b, c)
Definition: macros.h:50
check_written
static int check_written(OutputFile *of)
Definition: ffmpeg_mux.c:633
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:31
exit_on_error
int exit_on_error
Definition: ffmpeg_opt.c:77
int_cb
const AVIOInterruptCB int_cb
Definition: ffmpeg.c:327
AVBSFContext::time_base_out
AVRational time_base_out
The timebase used for the timestamps of the output packets.
Definition: bsf.h:108
nb_output_files
int nb_output_files
Definition: ffmpeg.c:129
write_packet
static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
Definition: ffmpeg_mux.c:209
AVFMT_TS_NONSTRICT
#define AVFMT_TS_NONSTRICT
Format does not require strictly increasing timestamps, but they must still be monotonic.
Definition: avformat.h:491
Muxer::header_written
int header_written
Definition: ffmpeg_mux.h:100
ret
ret
Definition: filter_design.txt:187
AV_LOG_FATAL
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
Definition: log.h:174
enc_free
void enc_free(Encoder **penc)
Definition: ffmpeg_enc.c:64
abort_on_flags
int abort_on_flags
Definition: ffmpeg_opt.c:78
AVFormatContext::oformat
const struct AVOutputFormat * oformat
The output container format.
Definition: avformat.h:1274
av_strlcat
size_t av_strlcat(char *dst, const char *src, size_t size)
Append the string src to the string dst, but to a total length of no more than size - 1 bytes,...
Definition: avstring.c:95
VSYNC_DROP
@ VSYNC_DROP
Definition: ffmpeg.h:72
avformat.h
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:28
AVStream::index
int index
stream index in AVFormatContext
Definition: avformat.h:749
atomic_fetch_add
#define atomic_fetch_add(object, operand)
Definition: stdatomic.h:131
avformat_free_context
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
Definition: avformat.c:141
EncStats::lock_initialized
int lock_initialized
Definition: ffmpeg.h:460
AVPacket::stream_index
int stream_index
Definition: packet.h:524
desc
const char * desc
Definition: libsvtav1.c:73
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
mem.h
MuxStream::sq_idx_mux
int sq_idx_mux
Definition: ffmpeg_mux.h:53
avio_open2
int avio_open2(AVIOContext **s, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options)
Create and initialize a AVIOContext for accessing the resource indicated by url.
Definition: avio.c:490
ffmpeg_mux.h
ost_free
static void ost_free(OutputStream **post)
Definition: ffmpeg_mux.c:787
AVPacket
This structure stores compressed data.
Definition: packet.h:499
avio_closep
int avio_closep(AVIOContext **s)
Close the resource accessed by the AVIOContext *s, free it and set the pointer pointing to it to NULL...
Definition: avio.c:648
av_interleaved_write_frame
int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
Write a packet to an output media file ensuring correct interleaving.
Definition: mux.c:1255
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
EncStats::nb_components
int nb_components
Definition: ffmpeg.h:455
print_sdp
int print_sdp(const char *filename)
Definition: ffmpeg_mux.c:507
FFMAX3
#define FFMAX3(a, b, c)
Definition: macros.h:48
mux_fixup_ts
static int mux_fixup_ts(Muxer *mux, MuxStream *ms, AVPacket *pkt)
Definition: ffmpeg_mux.c:138
of_stream_init
int of_stream_init(OutputFile *of, OutputStream *ost)
Definition: ffmpeg_mux.c:609
timestamp.h
OutputStream
Definition: mux.c:53
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
sch_mux_sub_heartbeat
int sch_mux_sub_heartbeat(Scheduler *sch, unsigned mux_idx, unsigned stream_idx, const AVPacket *pkt)
Definition: ffmpeg_sched.c:2075
EncStatsComponent::str
uint8_t * str
Definition: ffmpeg.h:449
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
MuxThreadContext
Definition: ffmpeg_mux.c:41
OutputFile::format
const AVOutputFormat * format
Definition: ffmpeg.h:579
avstring.h
OutputFile::recording_time
int64_t recording_time
desired length of the resulting file in microseconds == AV_TIME_BASE units
Definition: ffmpeg.h:585
AV_PKT_FLAG_TRUSTED
#define AV_PKT_FLAG_TRUSTED
The packet comes from a trusted source.
Definition: packet.h:591
PKT_OPAQUE_FIX_SUB_DURATION
@ PKT_OPAQUE_FIX_SUB_DURATION
Definition: ffmpeg.h:95
snprintf
#define snprintf
Definition: snprintf.h:34
EncStats::io
AVIOContext * io
Definition: ffmpeg.h:457
ABORT_ON_FLAG_EMPTY_OUTPUT
#define ABORT_ON_FLAG_EMPTY_OUTPUT
Definition: ffmpeg.h:421
thread_set_name
static void thread_set_name(OutputFile *of)
Definition: ffmpeg_mux.c:373
MuxStream::last_mux_dts
int64_t last_mux_dts
Definition: ffmpeg_mux.h:64
avcodec_parameters_copy
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Copy the contents of src to dst.
Definition: codec_par.c:106
AVPacket::time_base
AVRational time_base
Time base of the packet's timestamps.
Definition: packet.h:566
mux_packet_filter
static int mux_packet_filter(Muxer *mux, MuxThreadContext *mt, OutputStream *ost, AVPacket *pkt, int *stream_eof)
Definition: ffmpeg_mux.c:288
MuxStream::stream_duration
int64_t stream_duration
Definition: ffmpeg_mux.h:66
MuxThreadContext::pkt
AVPacket * pkt
Definition: ffmpeg_mux.c:42
sch_mux_receive
int sch_mux_receive(Scheduler *sch, unsigned mux_idx, AVPacket *pkt)
Called by muxer tasks to obtain packets for muxing.
Definition: ffmpeg_sched.c:2044
AV_CODEC_FLAG_PASS1
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
Definition: avcodec.h:310
OutputFile
Definition: ffmpeg.h:574
bsf_init
static int bsf_init(MuxStream *ms)
Definition: ffmpeg_mux.c:575
ff_thread_setname
static int ff_thread_setname(const char *name)
Definition: thread.h:216
LATENCY_PROBE_FILTER_POST
@ LATENCY_PROBE_FILTER_POST
Definition: ffmpeg.h:103