FFmpeg
tee.c
Go to the documentation of this file.
1 /*
2  * Tee pseudo-muxer
3  * Copyright (c) 2012 Nicolas George
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 License
9  * 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
15  * GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with FFmpeg; if not, write to the Free Software * Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 
23 #include "libavutil/avutil.h"
24 #include "libavutil/avstring.h"
25 #include "libavutil/opt.h"
26 #include "libavcodec/bsf.h"
27 #include "internal.h"
28 #include "avformat.h"
29 #include "mux.h"
30 #include "tee_common.h"
31 
32 typedef enum {
36 
37 #define DEFAULT_SLAVE_FAILURE_POLICY ON_SLAVE_FAILURE_ABORT
38 
39 typedef struct {
41  AVBSFContext **bsfs; ///< bitstream filters per stream
42 
44  int use_fifo;
46 
47  /** map from input to output streams indexes,
48  * disabled output streams are set to -1 */
49  int *stream_map;
51 } TeeSlave;
52 
53 typedef struct TeeContext {
54  const AVClass *class;
55  unsigned nb_slaves;
56  unsigned nb_alive;
58  int use_fifo;
60 } TeeContext;
61 
62 static const char *const slave_delim = "|";
63 static const char *const slave_bsfs_spec_sep = "/";
64 static const char *const slave_select_sep = ",";
65 
66 #define OFFSET(x) offsetof(TeeContext, x)
67 static const AVOption options[] = {
68  {"use_fifo", "Use fifo pseudo-muxer to separate actual muxers from encoder",
69  OFFSET(use_fifo), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
70  {"fifo_options", "fifo pseudo-muxer options", OFFSET(fifo_options),
72  {NULL}
73 };
74 
75 static const AVClass tee_muxer_class = {
76  .class_name = "Tee muxer",
77  .item_name = av_default_item_name,
78  .option = options,
79  .version = LIBAVUTIL_VERSION_INT,
80 };
81 
82 static inline int parse_slave_failure_policy_option(const char *opt, TeeSlave *tee_slave)
83 {
84  if (!opt) {
86  return 0;
87  } else if (!av_strcasecmp("abort", opt)) {
88  tee_slave->on_fail = ON_SLAVE_FAILURE_ABORT;
89  return 0;
90  } else if (!av_strcasecmp("ignore", opt)) {
91  tee_slave->on_fail = ON_SLAVE_FAILURE_IGNORE;
92  return 0;
93  }
94  /* Set failure behaviour to abort, so invalid option error will not be ignored */
95  tee_slave->on_fail = ON_SLAVE_FAILURE_ABORT;
96  return AVERROR(EINVAL);
97 }
98 
99 static int parse_slave_fifo_policy(const char *use_fifo, TeeSlave *tee_slave)
100 {
101  /*TODO - change this to use proper function for parsing boolean
102  * options when there is one */
103  if (av_match_name(use_fifo, "true,y,yes,enable,enabled,on,1")) {
104  tee_slave->use_fifo = 1;
105  } else if (av_match_name(use_fifo, "false,n,no,disable,disabled,off,0")) {
106  tee_slave->use_fifo = 0;
107  } else {
108  return AVERROR(EINVAL);
109  }
110  return 0;
111 }
112 
113 static int parse_slave_fifo_options(const char *fifo_options, TeeSlave *tee_slave)
114 {
115  return av_dict_parse_string(&tee_slave->fifo_options, fifo_options, "=", ":", 0);
116 }
117 
118 static int close_slave(TeeSlave *tee_slave)
119 {
120  AVFormatContext *avf;
121  unsigned i;
122  int ret = 0;
123 
124  av_dict_free(&tee_slave->fifo_options);
125  avf = tee_slave->avf;
126  if (!avf)
127  return 0;
128 
129  if (tee_slave->header_written)
130  ret = av_write_trailer(avf);
131 
132  if (tee_slave->bsfs) {
133  for (i = 0; i < avf->nb_streams; ++i)
134  av_bsf_free(&tee_slave->bsfs[i]);
135  }
136  av_freep(&tee_slave->stream_map);
137  av_freep(&tee_slave->bsfs);
138 
139  ff_format_io_close(avf, &avf->pb);
141  tee_slave->avf = NULL;
142  return ret;
143 }
144 
145 static void close_slaves(AVFormatContext *avf)
146 {
147  TeeContext *tee = avf->priv_data;
148  unsigned i;
149 
150  for (i = 0; i < tee->nb_slaves; i++) {
151  close_slave(&tee->slaves[i]);
152  }
153  av_freep(&tee->slaves);
154 }
155 
156 static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
157 {
158  int i, ret;
159  AVDictionary *options = NULL, *bsf_options = NULL;
160  AVDictionaryEntry *entry;
161  char *filename;
162  char *format = NULL, *select = NULL, *on_fail = NULL;
163  char *use_fifo = NULL, *fifo_options_str = NULL;
164  AVFormatContext *avf2 = NULL;
165  AVStream *st, *st2;
166  int stream_count;
167  int fullret;
168  char *subselect = NULL, *next_subselect = NULL, *first_subselect = NULL, *tmp_select = NULL;
169 
170  if ((ret = ff_tee_parse_slave_options(avf, slave, &options, &filename)) < 0)
171  return ret;
172 
173 #define CONSUME_OPTION(option, field, action) do { \
174  if ((entry = av_dict_get(options, option, NULL, 0))) { \
175  field = entry->value; \
176  { action } \
177  av_dict_set(&options, option, NULL, 0); \
178  } \
179  } while (0)
180 #define STEAL_OPTION(option, field) \
181  CONSUME_OPTION(option, field, \
182  entry->value = NULL; /* prevent it from being freed */)
183 #define PROCESS_OPTION(option, field, function, on_error) \
184  CONSUME_OPTION(option, field, if ((ret = function) < 0) { { on_error } goto end; })
185 
186  STEAL_OPTION("f", format);
187  STEAL_OPTION("select", select);
188  PROCESS_OPTION("onfail", on_fail,
189  parse_slave_failure_policy_option(on_fail, tee_slave),
190  av_log(avf, AV_LOG_ERROR, "Invalid onfail option value, "
191  "valid options are 'abort' and 'ignore'\n"););
192  PROCESS_OPTION("use_fifo", use_fifo,
193  parse_slave_fifo_policy(use_fifo, tee_slave),
194  av_log(avf, AV_LOG_ERROR, "Error parsing fifo options: %s\n",
195  av_err2str(ret)););
196  PROCESS_OPTION("fifo_options", fifo_options_str,
197  parse_slave_fifo_options(fifo_options_str, tee_slave), ;);
198  entry = NULL;
199  while ((entry = av_dict_get(options, "bsfs", entry, AV_DICT_IGNORE_SUFFIX))) {
200  /* trim out strlen("bsfs") characters from key */
201  av_dict_set(&bsf_options, entry->key + 4, entry->value, 0);
202  av_dict_set(&options, entry->key, NULL, 0);
203  }
204 
205  if (tee_slave->use_fifo) {
206 
207  if (options) {
208  char *format_options_str = NULL;
209  ret = av_dict_get_string(options, &format_options_str, '=', ':');
210  if (ret < 0)
211  goto end;
212 
213  ret = av_dict_set(&tee_slave->fifo_options, "format_opts", format_options_str,
215  if (ret < 0)
216  goto end;
217  }
218 
219  if (format) {
220  ret = av_dict_set(&tee_slave->fifo_options, "fifo_format", format,
222  format = NULL;
223  if (ret < 0)
224  goto end;
225  }
226 
228  options = tee_slave->fifo_options;
229  tee_slave->fifo_options = NULL;
230  }
232  tee_slave->use_fifo ? "fifo" :format, filename);
233  if (ret < 0)
234  goto end;
235  tee_slave->avf = avf2;
236  av_dict_copy(&avf2->metadata, avf->metadata, 0);
237  avf2->opaque = avf->opaque;
238  avf2->io_open = avf->io_open;
239 #if FF_API_AVFORMAT_IO_CLOSE
241  avf2->io_close = avf->io_close;
243 #endif
244  avf2->io_close2 = avf->io_close2;
246  avf2->flags = avf->flags;
248 
249  tee_slave->stream_map = av_calloc(avf->nb_streams, sizeof(*tee_slave->stream_map));
250  if (!tee_slave->stream_map) {
251  ret = AVERROR(ENOMEM);
252  goto end;
253  }
254 
255  stream_count = 0;
256  for (i = 0; i < avf->nb_streams; i++) {
257  st = avf->streams[i];
258  if (select) {
259  tmp_select = av_strdup(select); // av_strtok is destructive so we regenerate it in each loop
260  if (!tmp_select) {
261  ret = AVERROR(ENOMEM);
262  goto end;
263  }
264  fullret = 0;
265  first_subselect = tmp_select;
266  next_subselect = NULL;
267  while (subselect = av_strtok(first_subselect, slave_select_sep, &next_subselect)) {
268  first_subselect = NULL;
269 
270  ret = avformat_match_stream_specifier(avf, avf->streams[i], subselect);
271  if (ret < 0) {
272  av_log(avf, AV_LOG_ERROR,
273  "Invalid stream specifier '%s' for output '%s'\n",
274  subselect, slave);
275  goto end;
276  }
277  if (ret != 0) {
278  fullret = 1; // match
279  break;
280  }
281  }
282  av_freep(&tmp_select);
283 
284  if (fullret == 0) { /* no match */
285  tee_slave->stream_map[i] = -1;
286  continue;
287  }
288  }
289  tee_slave->stream_map[i] = stream_count++;
290 
291  st2 = ff_stream_clone(avf2, st);
292  if (!st2) {
293  ret = AVERROR(ENOMEM);
294  goto end;
295  }
296  }
297 
298  ret = ff_format_output_open(avf2, filename, &options);
299  if (ret < 0) {
300  av_log(avf, AV_LOG_ERROR, "Slave '%s': error opening: %s\n", slave,
301  av_err2str(ret));
302  goto end;
303  }
304 
305  if ((ret = avformat_write_header(avf2, &options)) < 0) {
306  av_log(avf, AV_LOG_ERROR, "Slave '%s': error writing header: %s\n",
307  slave, av_err2str(ret));
308  goto end;
309  }
310  tee_slave->header_written = 1;
311 
312  tee_slave->bsfs = av_calloc(avf2->nb_streams, sizeof(*tee_slave->bsfs));
313  if (!tee_slave->bsfs) {
314  ret = AVERROR(ENOMEM);
315  goto end;
316  }
317 
318  entry = NULL;
319  while (entry = av_dict_get(bsf_options, "", NULL, AV_DICT_IGNORE_SUFFIX)) {
320  const char *spec = entry->key;
321  if (*spec) {
322  if (strspn(spec, slave_bsfs_spec_sep) != 1) {
323  av_log(avf, AV_LOG_ERROR,
324  "Specifier separator in '%s' is '%c', but only characters '%s' "
325  "are allowed\n", entry->key, *spec, slave_bsfs_spec_sep);
326  ret = AVERROR(EINVAL);
327  goto end;
328  }
329  spec++; /* consume separator */
330  }
331 
332  for (i = 0; i < avf2->nb_streams; i++) {
333  ret = avformat_match_stream_specifier(avf2, avf2->streams[i], spec);
334  if (ret < 0) {
335  av_log(avf, AV_LOG_ERROR,
336  "Invalid stream specifier '%s' in bsfs option '%s' for slave "
337  "output '%s'\n", spec, entry->key, filename);
338  goto end;
339  }
340 
341  if (ret > 0) {
342  av_log(avf, AV_LOG_DEBUG, "spec:%s bsfs:%s matches stream %d of slave "
343  "output '%s'\n", spec, entry->value, i, filename);
344  if (tee_slave->bsfs[i]) {
345  av_log(avf, AV_LOG_WARNING,
346  "Duplicate bsfs specification associated to stream %d of slave "
347  "output '%s', filters will be ignored\n", i, filename);
348  continue;
349  }
350  ret = av_bsf_list_parse_str(entry->value, &tee_slave->bsfs[i]);
351  if (ret < 0) {
352  av_log(avf, AV_LOG_ERROR,
353  "Error parsing bitstream filter sequence '%s' associated to "
354  "stream %d of slave output '%s'\n", entry->value, i, filename);
355  goto end;
356  }
357  }
358  }
359 
360  av_dict_set(&bsf_options, entry->key, NULL, 0);
361  }
362 
363  for (i = 0; i < avf->nb_streams; i++){
364  int target_stream = tee_slave->stream_map[i];
365  if (target_stream < 0)
366  continue;
367 
368  if (!tee_slave->bsfs[target_stream]) {
369  /* Add pass-through bitstream filter */
370  ret = av_bsf_get_null_filter(&tee_slave->bsfs[target_stream]);
371  if (ret < 0) {
372  av_log(avf, AV_LOG_ERROR,
373  "Failed to create pass-through bitstream filter: %s\n",
374  av_err2str(ret));
375  goto end;
376  }
377  }
378 
379  tee_slave->bsfs[target_stream]->time_base_in = avf->streams[i]->time_base;
380  ret = avcodec_parameters_copy(tee_slave->bsfs[target_stream]->par_in,
381  avf->streams[i]->codecpar);
382  if (ret < 0)
383  goto end;
384 
385  ret = av_bsf_init(tee_slave->bsfs[target_stream]);
386  if (ret < 0) {
387  av_log(avf, AV_LOG_ERROR,
388  "Failed to initialize bitstream filter(s): %s\n",
389  av_err2str(ret));
390  goto end;
391  }
392  }
393 
394  if (options) {
395  entry = NULL;
396  while ((entry = av_dict_get(options, "", entry, AV_DICT_IGNORE_SUFFIX)))
397  av_log(avf2, AV_LOG_ERROR, "Unknown option '%s'\n", entry->key);
399  goto end;
400  }
401 
402 end:
403  av_free(format);
404  av_free(select);
406  av_dict_free(&bsf_options);
407  av_freep(&tmp_select);
408  return ret;
409 }
410 
411 static void log_slave(TeeSlave *slave, void *log_ctx, int log_level)
412 {
413  int i;
414  av_log(log_ctx, log_level, "filename:'%s' format:%s\n",
415  slave->avf->url, slave->avf->oformat->name);
416  for (i = 0; i < slave->avf->nb_streams; i++) {
417  AVStream *st = slave->avf->streams[i];
418  AVBSFContext *bsf = slave->bsfs[i];
419  const char *bsf_name;
420 
421  av_log(log_ctx, log_level, " stream:%d codec:%s type:%s",
424 
425  bsf_name = bsf->filter->priv_class ?
426  bsf->filter->priv_class->item_name(bsf) : bsf->filter->name;
427  av_log(log_ctx, log_level, " bsfs: %s\n", bsf_name);
428  }
429 }
430 
431 static int tee_process_slave_failure(AVFormatContext *avf, unsigned slave_idx, int err_n)
432 {
433  TeeContext *tee = avf->priv_data;
434  TeeSlave *tee_slave = &tee->slaves[slave_idx];
435 
436  tee->nb_alive--;
437 
438  close_slave(tee_slave);
439 
440  if (!tee->nb_alive) {
441  av_log(avf, AV_LOG_ERROR, "All tee outputs failed.\n");
442  return err_n;
443  } else if (tee_slave->on_fail == ON_SLAVE_FAILURE_ABORT) {
444  av_log(avf, AV_LOG_ERROR, "Slave muxer #%u failed, aborting.\n", slave_idx);
445  return err_n;
446  } else {
447  av_log(avf, AV_LOG_ERROR, "Slave muxer #%u failed: %s, continuing with %u/%u slaves.\n",
448  slave_idx, av_err2str(err_n), tee->nb_alive, tee->nb_slaves);
449  return 0;
450  }
451 }
452 
454 {
455  TeeContext *tee = avf->priv_data;
456  unsigned nb_slaves = 0, i;
457  const char *filename = avf->url;
458  char **slaves = NULL;
459  int ret;
460 
461  while (*filename) {
462  char *slave = av_get_token(&filename, slave_delim);
463  if (!slave) {
464  ret = AVERROR(ENOMEM);
465  goto fail;
466  }
467  ret = av_dynarray_add_nofree(&slaves, &nb_slaves, slave);
468  if (ret < 0) {
469  av_free(slave);
470  goto fail;
471  }
472  if (strspn(filename, slave_delim))
473  filename++;
474  }
475 
476  if (!FF_ALLOCZ_TYPED_ARRAY(tee->slaves, nb_slaves)) {
477  ret = AVERROR(ENOMEM);
478  goto fail;
479  }
480  tee->nb_slaves = tee->nb_alive = nb_slaves;
481 
482  for (i = 0; i < nb_slaves; i++) {
483 
484  tee->slaves[i].use_fifo = tee->use_fifo;
485  ret = av_dict_copy(&tee->slaves[i].fifo_options, tee->fifo_options, 0);
486  if (ret < 0)
487  goto fail;
488 
489  if ((ret = open_slave(avf, slaves[i], &tee->slaves[i])) < 0) {
491  if (ret < 0)
492  goto fail;
493  } else {
494  log_slave(&tee->slaves[i], avf, AV_LOG_VERBOSE);
495  }
496  av_freep(&slaves[i]);
497  }
498 
499  for (i = 0; i < avf->nb_streams; i++) {
500  int j, mapped = 0;
501  for (j = 0; j < tee->nb_slaves; j++)
502  if (tee->slaves[j].avf)
503  mapped += tee->slaves[j].stream_map[i] >= 0;
504  if (!mapped)
505  av_log(avf, AV_LOG_WARNING, "Input stream #%d is not mapped "
506  "to any slave.\n", i);
507  }
508  av_free(slaves);
509  return 0;
510 
511 fail:
512  for (i = 0; i < nb_slaves; i++)
513  av_freep(&slaves[i]);
514  close_slaves(avf);
515  av_free(slaves);
516  return ret;
517 }
518 
520 {
521  TeeContext *tee = avf->priv_data;
522  int ret_all = 0, ret;
523  unsigned i;
524 
525  for (i = 0; i < tee->nb_slaves; i++) {
526  if ((ret = close_slave(&tee->slaves[i])) < 0) {
528  if (!ret_all && ret < 0)
529  ret_all = ret;
530  }
531  }
532  av_freep(&tee->slaves);
533  return ret_all;
534 }
535 
537 {
538  TeeContext *tee = avf->priv_data;
539  AVFormatContext *avf2;
540  AVBSFContext *bsfs;
541  AVPacket *const pkt2 = ffformatcontext(avf)->pkt;
542  int ret_all = 0, ret;
543  unsigned i, s;
544  int s2;
545 
546  for (i = 0; i < tee->nb_slaves; i++) {
547  if (!(avf2 = tee->slaves[i].avf))
548  continue;
549 
550  /* Flush slave if pkt is NULL*/
551  if (!pkt) {
553  if (ret < 0) {
555  if (!ret_all && ret < 0)
556  ret_all = ret;
557  }
558  continue;
559  }
560 
561  s = pkt->stream_index;
562  s2 = tee->slaves[i].stream_map[s];
563  if (s2 < 0)
564  continue;
565 
566  if ((ret = av_packet_ref(pkt2, pkt)) < 0) {
567  if (!ret_all)
568  ret_all = ret;
569  continue;
570  }
571  bsfs = tee->slaves[i].bsfs[s2];
572  pkt2->stream_index = s2;
573 
574  ret = av_bsf_send_packet(bsfs, pkt2);
575  if (ret < 0) {
576  av_packet_unref(pkt2);
577  av_log(avf, AV_LOG_ERROR, "Error while sending packet to bitstream filter: %s\n",
578  av_err2str(ret));
580  if (!ret_all && ret < 0)
581  ret_all = ret;
582  }
583 
584  while(1) {
585  ret = av_bsf_receive_packet(bsfs, pkt2);
586  if (ret == AVERROR(EAGAIN)) {
587  ret = 0;
588  break;
589  } else if (ret < 0) {
590  break;
591  }
592 
594  avf2->streams[s2]->time_base);
595  ret = av_interleaved_write_frame(avf2, pkt2);
596  if (ret < 0)
597  break;
598  };
599 
600  if (ret < 0) {
602  if (!ret_all && ret < 0)
603  ret_all = ret;
604  }
605  }
606  return ret_all;
607 }
608 
610  .p.name = "tee",
611  .p.long_name = NULL_IF_CONFIG_SMALL("Multiple muxer tee"),
612  .priv_data_size = sizeof(TeeContext),
616  .p.priv_class = &tee_muxer_class,
618  .p.flags = AVFMT_NOFILE | AVFMT_ALLOW_FLUSH | AVFMT_TS_NEGATIVE,
619 #else
620  .p.flags = AVFMT_NOFILE | AVFMT_TS_NEGATIVE,
621 #endif
622  .flags_internal = FF_FMT_ALLOW_FLUSH,
623 };
FF_ALLOCZ_TYPED_ARRAY
#define FF_ALLOCZ_TYPED_ARRAY(p, nelem)
Definition: internal.h:88
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:423
FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:73
AVBSFContext::par_in
AVCodecParameters * par_in
Parameters of the input stream.
Definition: bsf.h:90
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
ON_SLAVE_FAILURE_IGNORE
@ ON_SLAVE_FAILURE_IGNORE
Definition: tee.c:34
AVOutputFormat::name
const char * name
Definition: avformat.h:511
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
TeeSlave::bsfs
AVBSFContext ** bsfs
bitstream filters per stream
Definition: tee.c:41
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:51
TeeSlave::stream_map
int * stream_map
map from input to output streams indexes, disabled output streams are set to -1
Definition: tee.c:49
ffformatcontext
static av_always_inline FFFormatContext * ffformatcontext(AVFormatContext *s)
Definition: internal.h:194
AVBitStreamFilter::name
const char * name
Definition: bsf.h:112
av_strcasecmp
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
Definition: avstring.c:207
AVFormatContext::streams
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1183
AVFormatContext::strict_std_compliance
int strict_std_compliance
Allow non-standard and experimental extension.
Definition: avformat.h:1411
parse_slave_fifo_options
static int parse_slave_fifo_options(const char *fifo_options, TeeSlave *tee_slave)
Definition: tee.c:113
OFFSET
#define OFFSET(x)
Definition: tee.c:66
ff_tee_parse_slave_options
int ff_tee_parse_slave_options(void *log, char *slave, AVDictionary **options, char **filename)
Definition: tee_common.c:33
AVOption
AVOption.
Definition: opt.h:251
AV_DICT_IGNORE_SUFFIX
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key,...
Definition: dict.h:75
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
tee_write_trailer
static int tee_write_trailer(AVFormatContext *avf)
Definition: tee.c:519
AVDictionary
Definition: dict.c:34
tee_write_packet
static int tee_write_packet(AVFormatContext *avf, AVPacket *pkt)
Definition: tee.c:536
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
TeeContext::use_fifo
int use_fifo
Definition: tee.c:58
TeeContext::nb_slaves
unsigned nb_slaves
Definition: tee.c:55
AVBSFContext
The bitstream filter state.
Definition: bsf.h:68
FFOutputFormat::p
AVOutputFormat p
The public AVOutputFormat.
Definition: mux.h:36
ON_SLAVE_FAILURE_ABORT
@ ON_SLAVE_FAILURE_ABORT
Definition: tee.c:33
STEAL_OPTION
#define STEAL_OPTION(option, field)
tee_common.h
AVFormatContext::interrupt_callback
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
Definition: avformat.h:1381
bsf.h
FF_FMT_ALLOW_FLUSH
#define FF_FMT_ALLOW_FLUSH
Definition: mux.h:30
fail
#define fail()
Definition: checkasm.h:138
AVERROR_OPTION_NOT_FOUND
#define AVERROR_OPTION_NOT_FOUND
Option not found.
Definition: error.h:63
parse_slave_fifo_policy
static int parse_slave_fifo_policy(const char *use_fifo, TeeSlave *tee_slave)
Definition: tee.c:99
AV_DICT_DONT_STRDUP_VAL
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that's been allocated with av_malloc() or another memory allocation functio...
Definition: dict.h:79
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
AVFormatContext::metadata
AVDictionary * metadata
Metadata that applies to the whole file.
Definition: avformat.h:1343
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:62
s
#define s(width, name)
Definition: cbs_vp9.c:198
AV_OPT_FLAG_ENCODING_PARAM
#define AV_OPT_FLAG_ENCODING_PARAM
a generic parameter which can be set by the user for muxing or encoding
Definition: opt.h:281
tee_muxer_class
static const AVClass tee_muxer_class
Definition: tee.c:75
AVFormatContext::flags
int flags
Flags modifying the (de)muxer behaviour.
Definition: avformat.h:1233
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
slave_bsfs_spec_sep
static const char *const slave_bsfs_spec_sep
Definition: tee.c:63
av_strtok
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok().
Definition: avstring.c:178
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
TeeContext::slaves
TeeSlave * slaves
Definition: tee.c:57
AVBSFContext::time_base_in
AVRational time_base_in
The timebase used for the timestamps of the input packets.
Definition: bsf.h:102
TeeContext::fifo_options
AVDictionary * fifo_options
Definition: tee.c:59
slave_select_sep
static const char *const slave_select_sep
Definition: tee.c:64
AVFormatContext::opaque
void * opaque
User data.
Definition: avformat.h:1620
tee_process_slave_failure
static int tee_process_slave_failure(AVFormatContext *avf, unsigned slave_idx, int err_n)
Definition: tee.c:431
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:477
AVFormatContext
Format I/O context.
Definition: avformat.h:1115
internal.h
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:864
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
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
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:880
NULL
#define NULL
Definition: coverity.c:32
av_bsf_receive_packet
int av_bsf_receive_packet(AVBSFContext *ctx, AVPacket *pkt)
Retrieve a filtered packet.
Definition: bsf.c:230
write_trailer
static int write_trailer(AVFormatContext *s1)
Definition: v4l2enc.c:101
AV_OPT_TYPE_DICT
@ AV_OPT_TYPE_DICT
Definition: opt.h:232
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
close_slave
static int close_slave(TeeSlave *tee_slave)
Definition: tee.c:118
AVFormatContext::pb
AVIOContext * pb
I/O context.
Definition: avformat.h:1157
TeeContext::nb_alive
unsigned nb_alive
Definition: tee.c:56
ff_tee_muxer
const FFOutputFormat ff_tee_muxer
Definition: tee.c:609
AVBitStreamFilter::priv_class
const AVClass * priv_class
A class for the private data, used to declare bitstream filter private AVOptions.
Definition: bsf.h:130
FFOutputFormat
Definition: mux.h:32
av_packet_ref
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
Definition: avpacket.c:431
TeeSlave::on_fail
SlaveFailurePolicy on_fail
Definition: tee.c:43
AVFormatContext::nb_streams
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1171
s2
#define s2
Definition: regdef.h:39
TeeSlave
Definition: tee.c:39
avformat_match_stream_specifier
int avformat_match_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
Check if the stream st contained in s is matched by the stream specifier spec.
Definition: avformat.c:588
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:106
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
AVFormatContext::url
char * url
input or output URL.
Definition: avformat.h:1198
close_slaves
static void close_slaves(AVFormatContext *avf)
Definition: tee.c:145
AVFMT_NOFILE
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:469
ff_format_io_close
int ff_format_io_close(AVFormatContext *s, AVIOContext **pb)
Definition: avformat.c:843
TeeSlave::fifo_options
AVDictionary * fifo_options
Definition: tee.c:45
DEFAULT_SLAVE_FAILURE_POLICY
#define DEFAULT_SLAVE_FAILURE_POLICY
Definition: tee.c:37
TeeContext
Definition: tee.c:53
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:225
options
static const AVOption options[]
Definition: tee.c:67
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:527
TeeSlave::use_fifo
int use_fifo
Definition: tee.c:44
avcodec_get_name
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
Definition: utils.c:417
open_slave
static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
Definition: tee.c:156
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:1291
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
TeeSlave::header_written
int header_written
Definition: tee.c:50
else
else
Definition: snow.txt:125
AVBSFContext::time_base_out
AVRational time_base_out
The timebase used for the timestamps of the output packets.
Definition: bsf.h:108
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:262
FF_API_ALLOW_FLUSH
#define FF_API_ALLOW_FLUSH
Definition: version_major.h:50
write_packet
static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
Definition: ffmpeg_mux.c:61
AVFMT_TS_NEGATIVE
#define AVFMT_TS_NEGATIVE
Format allows muxing negative timestamps.
Definition: avformat.h:495
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:841
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
av_bsf_get_null_filter
int av_bsf_get_null_filter(AVBSFContext **bsf)
Get null/pass-through bitstream filter.
Definition: bsf.c:553
AVFormatContext::oformat
const struct AVOutputFormat * oformat
The output container format.
Definition: avformat.h:1134
avformat.h
parse_slave_failure_policy_option
static int parse_slave_failure_policy_option(const char *opt, TeeSlave *tee_slave)
Definition: tee.c:82
log_slave
static void log_slave(TeeSlave *slave, void *log_ctx, int log_level)
Definition: tee.c:411
av_dynarray_add_nofree
int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem)
Add an element to a dynamic array.
Definition: mem.c:313
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
SlaveFailurePolicy
SlaveFailurePolicy
Definition: tee.c:32
tee_write_header
static int tee_write_header(AVFormatContext *avf)
Definition: tee.c:453
av_get_token
char * av_get_token(const char **buf, const char *term)
Unescape the given string until a non escaped terminating char, and return the token corresponding to...
Definition: avstring.c:143
av_match_name
int av_match_name(const char *name, const char *names)
Match instances of a name in a comma-separated list of names.
Definition: avstring.c:345
avformat_free_context
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
Definition: avformat.c:102
av_dict_parse_string
int av_dict_parse_string(AVDictionary **pm, const char *str, const char *key_val_sep, const char *pairs_sep, int flags)
Parse the key/value pairs list and add the parsed entries to a dictionary.
Definition: dict.c:202
AVFormatContext::io_open
int(* io_open)(struct AVFormatContext *s, AVIOContext **pb, const char *url, int flags, AVDictionary **options)
A callback for opening new IO streams.
Definition: avformat.h:1674
slave_delim
static const char *const slave_delim
Definition: tee.c:62
PROCESS_OPTION
#define PROCESS_OPTION(option, field, function, on_error)
AVPacket::stream_index
int stream_index
Definition: packet.h:493
FF_DISABLE_DEPRECATION_WARNINGS
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:72
AVBSFContext::filter
const struct AVBitStreamFilter * filter
The bitstream filter this context is an instance of.
Definition: bsf.h:77
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:270
av_bsf_list_parse_str
int av_bsf_list_parse_str(const char *str, AVBSFContext **bsf_lst)
Parse string describing list of bitstream filters and create single AVBSFContext describing the whole...
Definition: bsf.c:526
avutil.h
TeeSlave::avf
AVFormatContext * avf
Definition: tee.c:40
FFFormatContext::pkt
AVPacket * pkt
Used to hold temporary packets for the generic demuxing code.
Definition: internal.h:140
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
AVDictionaryEntry
Definition: dict.h:89
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:55
ff_stream_clone
AVStream * ff_stream_clone(AVFormatContext *dst_ctx, const AVStream *src)
Create a new stream and copy to it all parameters from a source stream, with the exception of the ind...
Definition: avformat.c:263
AVPacket
This structure stores compressed data.
Definition: packet.h:468
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:244
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:1276
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
av_dict_set
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:88
av_dict_get_string
int av_dict_get_string(const AVDictionary *m, char **buffer, const char key_val_sep, const char pairs_sep)
Get dictionary entries as a string.
Definition: dict.c:252
av_dict_copy
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition: dict.c:239
AVFormatContext::io_close2
int(* io_close2)(struct AVFormatContext *s, AVIOContext *pb)
A callback for closing the streams opened with AVFormatContext.io_open().
Definition: avformat.h:1726
ff_format_output_open
int ff_format_output_open(AVFormatContext *s, const char *url, AVDictionary **options)
Utility function to open IO stream of output format.
Definition: mux_utils.c:116
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
avstring.h
AVClass::item_name
const char *(* item_name)(void *ctx)
A pointer to a function which returns the name of a context instance ctx associated with the class.
Definition: log.h:77
write_header
static void write_header(FFV1Context *f)
Definition: ffv1enc.c:346
avformat_alloc_output_context2
int avformat_alloc_output_context2(AVFormatContext **ctx, const AVOutputFormat *oformat, const char *format_name, const char *filename)
Allocate an AVFormatContext for an output format.
Definition: mux.c:93
AVFormatContext::priv_data
void * priv_data
Format private data.
Definition: avformat.h:1143
avcodec_parameters_copy
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Copy the contents of src to dst.
Definition: codec_par.c:106
mux.h