FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 "internal.h"
27 #include "avformat.h"
28 #include "avio_internal.h"
29 
30 typedef enum {
34 
35 #define DEFAULT_SLAVE_FAILURE_POLICY ON_SLAVE_FAILURE_ABORT
36 
37 typedef struct {
39  AVBitStreamFilterContext **bsfs; ///< bitstream filters per stream
40 
42 
43  /** map from input to output streams indexes,
44  * disabled output streams are set to -1 */
45  int *stream_map;
47 } TeeSlave;
48 
49 typedef struct TeeContext {
50  const AVClass *class;
51  unsigned nb_slaves;
52  unsigned nb_alive;
54 } TeeContext;
55 
56 static const char *const slave_delim = "|";
57 static const char *const slave_opt_open = "[";
58 static const char *const slave_opt_close = "]";
59 static const char *const slave_opt_delim = ":]"; /* must have the close too */
60 static const char *const slave_bsfs_spec_sep = "/";
61 static const char *const slave_select_sep = ",";
62 
63 static const AVClass tee_muxer_class = {
64  .class_name = "Tee muxer",
65  .item_name = av_default_item_name,
66  .version = LIBAVUTIL_VERSION_INT,
67 };
68 
69 static int parse_slave_options(void *log, char *slave,
70  AVDictionary **options, char **filename)
71 {
72  const char *p;
73  char *key, *val;
74  int ret;
75 
76  if (!strspn(slave, slave_opt_open)) {
77  *filename = slave;
78  return 0;
79  }
80  p = slave + 1;
81  if (strspn(p, slave_opt_close)) {
82  *filename = (char *)p + 1;
83  return 0;
84  }
85  while (1) {
86  ret = av_opt_get_key_value(&p, "=", slave_opt_delim, 0, &key, &val);
87  if (ret < 0) {
88  av_log(log, AV_LOG_ERROR, "No option found near \"%s\"\n", p);
89  goto fail;
90  }
91  ret = av_dict_set(options, key, val,
93  if (ret < 0)
94  goto fail;
95  if (strspn(p, slave_opt_close))
96  break;
97  p++;
98  }
99  *filename = (char *)p + 1;
100  return 0;
101 
102 fail:
103  av_dict_free(options);
104  return ret;
105 }
106 
107 /**
108  * Parse list of bitstream filters and add them to the list of filters
109  * pointed to by bsfs.
110  *
111  * The list must be specified in the form:
112  * BSFS ::= BSF[,BSFS]
113  */
114 static int parse_bsfs(void *log_ctx, const char *bsfs_spec,
116 {
117  char *bsf_name, *buf, *dup, *saveptr;
118  int ret = 0;
119 
120  if (!(dup = buf = av_strdup(bsfs_spec)))
121  return AVERROR(ENOMEM);
122 
123  while (bsf_name = av_strtok(buf, ",", &saveptr)) {
125 
126  if (!bsf) {
127  av_log(log_ctx, AV_LOG_ERROR,
128  "Cannot initialize bitstream filter with name '%s', "
129  "unknown filter or internal error happened\n",
130  bsf_name);
131  ret = AVERROR_UNKNOWN;
132  goto end;
133  }
134 
135  /* append bsf context to the list of bsf contexts */
136  *bsfs = bsf;
137  bsfs = &bsf->next;
138 
139  buf = NULL;
140  }
141 
142 end:
143  av_free(dup);
144  return ret;
145 }
146 
147 static inline int parse_slave_failure_policy_option(const char *opt, TeeSlave *tee_slave)
148 {
149  if (!opt) {
151  return 0;
152  } else if (!av_strcasecmp("abort", opt)) {
153  tee_slave->on_fail = ON_SLAVE_FAILURE_ABORT;
154  return 0;
155  } else if (!av_strcasecmp("ignore", opt)) {
156  tee_slave->on_fail = ON_SLAVE_FAILURE_IGNORE;
157  return 0;
158  }
159  /* Set failure behaviour to abort, so invalid option error will not be ignored */
160  tee_slave->on_fail = ON_SLAVE_FAILURE_ABORT;
161  return AVERROR(EINVAL);
162 }
163 
164 static int close_slave(TeeSlave *tee_slave)
165 {
166  AVFormatContext *avf;
167  unsigned i;
168  int ret = 0;
169 
170  avf = tee_slave->avf;
171  if (!avf)
172  return 0;
173 
174  if (tee_slave->header_written)
175  ret = av_write_trailer(avf);
176 
177  if (tee_slave->bsfs) {
178  for (i = 0; i < avf->nb_streams; ++i) {
179  AVBitStreamFilterContext *bsf_next, *bsf = tee_slave->bsfs[i];
180  while (bsf) {
181  bsf_next = bsf->next;
183  bsf = bsf_next;
184  }
185  }
186  }
187  av_freep(&tee_slave->stream_map);
188  av_freep(&tee_slave->bsfs);
189 
190  ff_format_io_close(avf, &avf->pb);
192  tee_slave->avf = NULL;
193  return ret;
194 }
195 
196 static void close_slaves(AVFormatContext *avf)
197 {
198  TeeContext *tee = avf->priv_data;
199  unsigned i;
200 
201  for (i = 0; i < tee->nb_slaves; i++) {
202  close_slave(&tee->slaves[i]);
203  }
204  av_freep(&tee->slaves);
205 }
206 
207 static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
208 {
209  int i, ret;
211  AVDictionaryEntry *entry;
212  char *filename;
213  char *format = NULL, *select = NULL, *on_fail = NULL;
214  AVFormatContext *avf2 = NULL;
215  AVStream *st, *st2;
216  int stream_count;
217  int fullret;
218  char *subselect = NULL, *next_subselect = NULL, *first_subselect = NULL, *tmp_select = NULL;
219 
220  if ((ret = parse_slave_options(avf, slave, &options, &filename)) < 0)
221  return ret;
222 
223 #define STEAL_OPTION(option, field) do { \
224  if ((entry = av_dict_get(options, option, NULL, 0))) { \
225  field = entry->value; \
226  entry->value = NULL; /* prevent it from being freed */ \
227  av_dict_set(&options, option, NULL, 0); \
228  } \
229  } while (0)
230 
231  STEAL_OPTION("f", format);
232  STEAL_OPTION("select", select);
233  STEAL_OPTION("onfail", on_fail);
234 
235  ret = parse_slave_failure_policy_option(on_fail, tee_slave);
236  if (ret < 0) {
237  av_log(avf, AV_LOG_ERROR,
238  "Invalid onfail option value, valid options are 'abort' and 'ignore'\n");
239  goto end;
240  }
241 
242  ret = avformat_alloc_output_context2(&avf2, NULL, format, filename);
243  if (ret < 0)
244  goto end;
245  tee_slave->avf = avf2;
246  av_dict_copy(&avf2->metadata, avf->metadata, 0);
247  avf2->opaque = avf->opaque;
248  avf2->io_open = avf->io_open;
249  avf2->io_close = avf->io_close;
250 
251  tee_slave->stream_map = av_calloc(avf->nb_streams, sizeof(*tee_slave->stream_map));
252  if (!tee_slave->stream_map) {
253  ret = AVERROR(ENOMEM);
254  goto end;
255  }
256 
257  stream_count = 0;
258  for (i = 0; i < avf->nb_streams; i++) {
259  st = avf->streams[i];
260  if (select) {
261  tmp_select = av_strdup(select); // av_strtok is destructive so we regenerate it in each loop
262  if (!tmp_select) {
263  ret = AVERROR(ENOMEM);
264  goto end;
265  }
266  fullret = 0;
267  first_subselect = tmp_select;
268  next_subselect = NULL;
269  while (subselect = av_strtok(first_subselect, slave_select_sep, &next_subselect)) {
270  first_subselect = NULL;
271 
272  ret = avformat_match_stream_specifier(avf, avf->streams[i], subselect);
273  if (ret < 0) {
274  av_log(avf, AV_LOG_ERROR,
275  "Invalid stream specifier '%s' for output '%s'\n",
276  subselect, slave);
277  goto end;
278  }
279  if (ret != 0) {
280  fullret = 1; // match
281  break;
282  }
283  }
284  av_freep(&tmp_select);
285 
286  if (fullret == 0) { /* no match */
287  tee_slave->stream_map[i] = -1;
288  continue;
289  }
290  }
291  tee_slave->stream_map[i] = stream_count++;
292 
293  if (!(st2 = avformat_new_stream(avf2, NULL))) {
294  ret = AVERROR(ENOMEM);
295  goto end;
296  }
297  st2->id = st->id;
298  st2->r_frame_rate = st->r_frame_rate;
299  st2->time_base = st->time_base;
300  st2->start_time = st->start_time;
301  st2->duration = st->duration;
302  st2->nb_frames = st->nb_frames;
303  st2->disposition = st->disposition;
305  st2->avg_frame_rate = st->avg_frame_rate;
306  av_dict_copy(&st2->metadata, st->metadata, 0);
307  if ((ret = avcodec_parameters_copy(st2->codecpar, st->codecpar)) < 0)
308  goto end;
309  }
310 
311  if (!(avf2->oformat->flags & AVFMT_NOFILE)) {
312  if ((ret = avf2->io_open(avf2, &avf2->pb, filename, AVIO_FLAG_WRITE, NULL)) < 0) {
313  av_log(avf, AV_LOG_ERROR, "Slave '%s': error opening: %s\n",
314  slave, av_err2str(ret));
315  goto end;
316  }
317  }
318 
319  if ((ret = avformat_write_header(avf2, &options)) < 0) {
320  av_log(avf, AV_LOG_ERROR, "Slave '%s': error writing header: %s\n",
321  slave, av_err2str(ret));
322  goto end;
323  }
324  tee_slave->header_written = 1;
325 
326  tee_slave->bsfs = av_calloc(avf2->nb_streams, sizeof(*tee_slave->bsfs));
327  if (!tee_slave->bsfs) {
328  ret = AVERROR(ENOMEM);
329  goto end;
330  }
331 
332  entry = NULL;
333  while (entry = av_dict_get(options, "bsfs", NULL, AV_DICT_IGNORE_SUFFIX)) {
334  const char *spec = entry->key + strlen("bsfs");
335  if (*spec) {
336  if (strspn(spec, slave_bsfs_spec_sep) != 1) {
337  av_log(avf, AV_LOG_ERROR,
338  "Specifier separator in '%s' is '%c', but only characters '%s' "
339  "are allowed\n", entry->key, *spec, slave_bsfs_spec_sep);
340  ret = AVERROR(EINVAL);
341  goto end;
342  }
343  spec++; /* consume separator */
344  }
345 
346  for (i = 0; i < avf2->nb_streams; i++) {
347  ret = avformat_match_stream_specifier(avf2, avf2->streams[i], spec);
348  if (ret < 0) {
349  av_log(avf, AV_LOG_ERROR,
350  "Invalid stream specifier '%s' in bsfs option '%s' for slave "
351  "output '%s'\n", spec, entry->key, filename);
352  goto end;
353  }
354 
355  if (ret > 0) {
356  av_log(avf, AV_LOG_DEBUG, "spec:%s bsfs:%s matches stream %d of slave "
357  "output '%s'\n", spec, entry->value, i, filename);
358  if (tee_slave->bsfs[i]) {
359  av_log(avf, AV_LOG_WARNING,
360  "Duplicate bsfs specification associated to stream %d of slave "
361  "output '%s', filters will be ignored\n", i, filename);
362  continue;
363  }
364  ret = parse_bsfs(avf, entry->value, &tee_slave->bsfs[i]);
365  if (ret < 0) {
366  av_log(avf, AV_LOG_ERROR,
367  "Error parsing bitstream filter sequence '%s' associated to "
368  "stream %d of slave output '%s'\n", entry->value, i, filename);
369  goto end;
370  }
371  }
372  }
373 
374  av_dict_set(&options, entry->key, NULL, 0);
375  }
376 
377  if (options) {
378  entry = NULL;
379  while ((entry = av_dict_get(options, "", entry, AV_DICT_IGNORE_SUFFIX)))
380  av_log(avf2, AV_LOG_ERROR, "Unknown option '%s'\n", entry->key);
382  goto end;
383  }
384 
385 end:
386  av_free(format);
387  av_free(select);
388  av_free(on_fail);
389  av_dict_free(&options);
390  av_freep(&tmp_select);
391  return ret;
392 }
393 
394 static void log_slave(TeeSlave *slave, void *log_ctx, int log_level)
395 {
396  int i;
397  av_log(log_ctx, log_level, "filename:'%s' format:%s\n",
398  slave->avf->filename, slave->avf->oformat->name);
399  for (i = 0; i < slave->avf->nb_streams; i++) {
400  AVStream *st = slave->avf->streams[i];
401  AVBitStreamFilterContext *bsf = slave->bsfs[i];
402 
403  av_log(log_ctx, log_level, " stream:%d codec:%s type:%s",
406  if (bsf) {
407  av_log(log_ctx, log_level, " bsfs:");
408  while (bsf) {
409  av_log(log_ctx, log_level, "%s%s",
410  bsf->filter->name, bsf->next ? "," : "");
411  bsf = bsf->next;
412  }
413  }
414  av_log(log_ctx, log_level, "\n");
415  }
416 }
417 
418 static int tee_process_slave_failure(AVFormatContext *avf, unsigned slave_idx, int err_n)
419 {
420  TeeContext *tee = avf->priv_data;
421  TeeSlave *tee_slave = &tee->slaves[slave_idx];
422 
423  tee->nb_alive--;
424 
425  close_slave(tee_slave);
426 
427  if (!tee->nb_alive) {
428  av_log(avf, AV_LOG_ERROR, "All tee outputs failed.\n");
429  return err_n;
430  } else if (tee_slave->on_fail == ON_SLAVE_FAILURE_ABORT) {
431  av_log(avf, AV_LOG_ERROR, "Slave muxer #%u failed, aborting.\n", slave_idx);
432  return err_n;
433  } else {
434  av_log(avf, AV_LOG_ERROR, "Slave muxer #%u failed: %s, continuing with %u/%u slaves.\n",
435  slave_idx, av_err2str(err_n), tee->nb_alive, tee->nb_slaves);
436  return 0;
437  }
438 }
439 
441 {
442  TeeContext *tee = avf->priv_data;
443  unsigned nb_slaves = 0, i;
444  const char *filename = avf->filename;
445  char **slaves = NULL;
446  int ret;
447 
448  while (*filename) {
449  char *slave = av_get_token(&filename, slave_delim);
450  if (!slave) {
451  ret = AVERROR(ENOMEM);
452  goto fail;
453  }
454  ret = av_dynarray_add_nofree(&slaves, &nb_slaves, slave);
455  if (ret < 0) {
456  av_free(slave);
457  goto fail;
458  }
459  if (strspn(filename, slave_delim))
460  filename++;
461  }
462 
463  if (!(tee->slaves = av_mallocz_array(nb_slaves, sizeof(*tee->slaves)))) {
464  ret = AVERROR(ENOMEM);
465  goto fail;
466  }
467  tee->nb_slaves = tee->nb_alive = nb_slaves;
468 
469  for (i = 0; i < nb_slaves; i++) {
470  if ((ret = open_slave(avf, slaves[i], &tee->slaves[i])) < 0) {
471  ret = tee_process_slave_failure(avf, i, ret);
472  if (ret < 0)
473  goto fail;
474  } else {
475  log_slave(&tee->slaves[i], avf, AV_LOG_VERBOSE);
476  }
477  av_freep(&slaves[i]);
478  }
479 
480  for (i = 0; i < avf->nb_streams; i++) {
481  int j, mapped = 0;
482  for (j = 0; j < tee->nb_slaves; j++)
483  if (tee->slaves[j].avf)
484  mapped += tee->slaves[j].stream_map[i] >= 0;
485  if (!mapped)
486  av_log(avf, AV_LOG_WARNING, "Input stream #%d is not mapped "
487  "to any slave.\n", i);
488  }
489  av_free(slaves);
490  return 0;
491 
492 fail:
493  for (i = 0; i < nb_slaves; i++)
494  av_freep(&slaves[i]);
495  close_slaves(avf);
496  av_free(slaves);
497  return ret;
498 }
499 
501 {
502  TeeContext *tee = avf->priv_data;
503  int ret_all = 0, ret;
504  unsigned i;
505 
506  for (i = 0; i < tee->nb_slaves; i++) {
507  if ((ret = close_slave(&tee->slaves[i])) < 0) {
508  ret = tee_process_slave_failure(avf, i, ret);
509  if (!ret_all && ret < 0)
510  ret_all = ret;
511  }
512  }
513  av_freep(&tee->slaves);
514  return ret_all;
515 }
516 
518 {
519  TeeContext *tee = avf->priv_data;
520  AVFormatContext *avf2;
521  AVPacket pkt2;
522  int ret_all = 0, ret;
523  unsigned i, s;
524  int s2;
525  AVRational tb, tb2;
526 
527  for (i = 0; i < tee->nb_slaves; i++) {
528  if (!(avf2 = tee->slaves[i].avf))
529  continue;
530 
531  s = pkt->stream_index;
532  s2 = tee->slaves[i].stream_map[s];
533  if (s2 < 0)
534  continue;
535 
536  memset(&pkt2, 0, sizeof(AVPacket));
537  if ((ret = av_packet_ref(&pkt2, pkt)) < 0)
538  if (!ret_all) {
539  ret_all = ret;
540  continue;
541  }
542  tb = avf ->streams[s ]->time_base;
543  tb2 = avf2->streams[s2]->time_base;
544  pkt2.pts = av_rescale_q(pkt->pts, tb, tb2);
545  pkt2.dts = av_rescale_q(pkt->dts, tb, tb2);
546  pkt2.duration = av_rescale_q(pkt->duration, tb, tb2);
547  pkt2.stream_index = s2;
548 
549  if ((ret = av_apply_bitstream_filters(avf2->streams[s2]->codec, &pkt2,
550  tee->slaves[i].bsfs[s2])) < 0 ||
551  (ret = av_interleaved_write_frame(avf2, &pkt2)) < 0) {
552  ret = tee_process_slave_failure(avf, i, ret);
553  if (!ret_all && ret < 0)
554  ret_all = ret;
555  }
556  }
557  return ret_all;
558 }
559 
561  .name = "tee",
562  .long_name = NULL_IF_CONFIG_SMALL("Multiple muxer tee"),
563  .priv_data_size = sizeof(TeeContext),
567  .priv_class = &tee_muxer_class,
568  .flags = AVFMT_NOFILE,
569 };
#define NULL
Definition: coverity.c:32
const char const char void * val
Definition: avisynth_c.h:634
static int tee_write_packet(AVFormatContext *avf, AVPacket *pkt)
Definition: tee.c:517
const char * s
Definition: avisynth_c.h:631
SlaveFailurePolicy
Definition: tee.c:30
int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
Write a packet to an output media file ensuring correct interleaving.
Definition: mux.c:1083
AVBitStreamFilterContext ** bsfs
bitstream filters per stream
Definition: tee.c:39
static const char *const slave_opt_delim
Definition: tee.c:59
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
#define LIBAVUTIL_VERSION_INT
Definition: version.h:70
TeeSlave * slaves
Definition: tee.c:53
static int tee_write_trailer(AVFormatContext *avf)
Definition: tee.c:500
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:3922
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:943
#define AVIO_FLAG_WRITE
write-only
Definition: avio.h:607
static const char *const slave_bsfs_spec_sep
Definition: tee.c:60
external API header
static void log_slave(TeeSlave *slave, void *log_ctx, int log_level)
Definition: tee.c:394
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition: dict.c:216
static AVPacket pkt
int header_written
Definition: tee.c:46
SlaveFailurePolicy on_fail
Definition: tee.c:41
static int tee_process_slave_failure(AVFormatContext *avf, unsigned slave_idx, int err_n)
Definition: tee.c:418
static const char *const slave_delim
Definition: tee.c:56
#define AV_DICT_DONT_STRDUP_KEY
Take ownership of a key that's been allocated with av_malloc() or another memory allocation function...
Definition: dict.h:73
static const char *const slave_opt_close
Definition: tee.c:58
Format I/O context.
Definition: avformat.h:1325
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
AVOutputFormat ff_tee_muxer
Definition: tee.c:560
int flags
can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_GLOBALHEADER, AVFMT_NOTIMESTAMPS, AVFMT_VARIABLE_FPS, AVFMT_NODIMENSIONS, AVFMT_NOSTREAMS, AVFMT_ALLOW_FLUSH, AVFMT_TS_NONSTRICT, AVFMT_TS_NEGATIVE
Definition: avformat.h:541
static int close_slave(TeeSlave *tee_slave)
Definition: tee.c:164
AVOptions.
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: avcodec.h:1598
int id
Format-specific stream ID.
Definition: avformat.h:883
void ff_format_io_close(AVFormatContext *s, AVIOContext **pb)
Definition: utils.c:5106
static void close_slaves(AVFormatContext *avf)
Definition: tee.c:196
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: utils.c:4646
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:4065
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1393
const char * name
Definition: avcodec.h:5724
unsigned nb_alive
Definition: tee.c:52
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:39
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
const OptionDef options[]
Definition: ffserver.c:3969
struct AVBitStreamFilterContext * next
Definition: avcodec.h:5656
static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
Definition: tee.c:207
#define av_log(a,...)
static int parse_slave_options(void *log, char *slave, AVDictionary **options, char **filename)
Definition: tee.c:69
static const char *const slave_select_sep
Definition: tee.c:61
struct AVOutputFormat * oformat
The output container format.
Definition: avformat.h:1344
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
Definition: avpacket.c:572
int avformat_alloc_output_context2(AVFormatContext **ctx, AVOutputFormat *oformat, const char *format_name, const char *filename)
Allocate an AVFormatContext for an output format.
Definition: mux.c:148
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
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Copy the contents of src to dst.
Definition: utils.c:4059
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
AVDictionary * metadata
Metadata that applies to the whole file.
Definition: avformat.h:1539
#define s2
Definition: regdef.h:39
int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem)
Add an element to a dynamic array.
Definition: mem.c:310
av_default_item_name
#define DEFAULT_SLAVE_FAILURE_POLICY
Definition: tee.c:35
#define AVERROR(e)
Definition: error.h:43
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:176
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
unsigned nb_slaves
Definition: tee.c:51
int * stream_map
map from input to output streams indexes, disabled output streams are set to -1
Definition: tee.c:45
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
Definition: dict.c:202
attribute_deprecated AVBitStreamFilterContext * av_bitstream_filter_init(const char *name)
Create and initialize a bitstream filter context given a bitstream filter name.
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:3918
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:954
#define fail()
Definition: checkasm.h:81
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:149
void * opaque
User data.
Definition: avformat.h:1805
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1381
Definition: tee.c:37
char filename[1024]
input or output filename
Definition: avformat.h:1401
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:496
static const AVClass tee_muxer_class
Definition: tee.c:63
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
Definition: avstring.c:213
#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:76
attribute_deprecated void av_bitstream_filter_close(AVBitStreamFilterContext *bsf)
Release bitstream filter context.
static int write_trailer(AVFormatContext *s1)
Definition: v4l2enc.c:94
const char * name
Definition: avformat.h:522
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:119
AVDictionary * metadata
Definition: avformat.h:945
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
Definition: utils.c:3082
Stream structure.
Definition: avformat.h:876
Definition: tee.c:49
char * av_strdup(const char *s)
Duplicate the string s.
Definition: mem.c:267
AVIOContext * pb
I/O context.
Definition: avformat.h:1367
static const char *const slave_opt_open
Definition: tee.c:57
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
struct AVBitStreamFilter * filter
Definition: avcodec.h:5654
static const char * format
Definition: movenc.c:47
Describe the class of an AVClass context structure.
Definition: log.h:67
rational number numerator/denominator
Definition: rational.h:43
static int parse_bsfs(void *log_ctx, const char *bsfs_spec, AVBitStreamFilterContext **bsfs)
Parse list of bitstream filters and add them to the list of filters pointed to by bsfs...
Definition: tee.c:114
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
Definition: utils.c:4001
void * av_calloc(size_t nmemb, size_t size)
Allocate a block of nmemb * size bytes with alignment suitable for all memory accesses (including vec...
Definition: mem.c:260
const char * av_get_media_type_string(enum AVMediaType media_type)
Return a string describing the media_type enum, NULL if media_type is unknown.
Definition: utils.c:79
static int flags
Definition: cpu.c:47
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:184
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition: avformat.h:930
Main libavformat public API header.
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:476
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base...
Definition: avformat.h:923
int disposition
AV_DISPOSITION_* bit field.
Definition: avformat.h:934
int64_t nb_frames
number of frames in this stream if known or 0
Definition: avformat.h:932
char * key
Definition: dict.h:86
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:71
#define av_free(p)
#define AVERROR_OPTION_NOT_FOUND
Option not found.
Definition: error.h:61
char * value
Definition: dict.h:87
int av_opt_get_key_value(const char **ropts, const char *key_val_sep, const char *pairs_sep, unsigned flags, char **rkey, char **rval)
Extract a key-value pair from the beginning of a string.
Definition: opt.c:1442
void * priv_data
Format private data.
Definition: avformat.h:1353
static void write_header(FFV1Context *f)
Definition: ffv1enc.c:498
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: avcodec.h:1579
static void * av_mallocz_array(size_t nmemb, size_t size)
Definition: mem.h:229
int av_write_trailer(AVFormatContext *s)
Write the stream trailer to an output media file and free the file private data.
Definition: mux.c:1184
#define av_freep(p)
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key, ignoring the suffix of the found key string.
Definition: dict.h:70
AVCodecParameters * codecpar
Definition: avformat.h:1006
int stream_index
Definition: avcodec.h:1582
static int parse_slave_failure_policy_option(const char *opt, TeeSlave *tee_slave)
Definition: tee.c:147
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avformat.h:913
AVRational r_frame_rate
Real base framerate of the stream.
Definition: avformat.h:1101
int(* io_open)(struct AVFormatContext *s, AVIOContext **pb, const char *url, int flags, AVDictionary **options)
Definition: avformat.h:1883
This structure stores compressed data.
Definition: avcodec.h:1557
static int write_packet(AVFormatContext *s1, AVPacket *pkt)
Definition: v4l2enc.c:86
AVFormatContext * avf
Definition: tee.c:38
void(* io_close)(struct AVFormatContext *s, AVIOContext *pb)
A callback for closing the streams opened with AVFormatContext.io_open().
Definition: avformat.h:1889
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1573
static int tee_write_header(AVFormatContext *avf)
Definition: tee.c:440
#define STEAL_OPTION(option, field)
#define tb
Definition: regdef.h:68