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 #define MAX_SLAVES 16
31 
32 typedef enum {
36 
37 #define DEFAULT_SLAVE_FAILURE_POLICY ON_SLAVE_FAILURE_ABORT
38 
39 typedef struct {
41  AVBitStreamFilterContext **bsfs; ///< bitstream filters per stream
42 
44 
45  /** map from input to output streams indexes,
46  * disabled output streams are set to -1 */
47  int *stream_map;
49 } TeeSlave;
50 
51 typedef struct TeeContext {
52  const AVClass *class;
53  unsigned nb_slaves;
54  unsigned nb_alive;
56 } TeeContext;
57 
58 static const char *const slave_delim = "|";
59 static const char *const slave_opt_open = "[";
60 static const char *const slave_opt_close = "]";
61 static const char *const slave_opt_delim = ":]"; /* must have the close too */
62 static const char *const slave_bsfs_spec_sep = "/";
63 static const char *const slave_select_sep = ",";
64 
65 static const AVClass tee_muxer_class = {
66  .class_name = "Tee muxer",
67  .item_name = av_default_item_name,
68  .version = LIBAVUTIL_VERSION_INT,
69 };
70 
71 static int parse_slave_options(void *log, char *slave,
72  AVDictionary **options, char **filename)
73 {
74  const char *p;
75  char *key, *val;
76  int ret;
77 
78  if (!strspn(slave, slave_opt_open)) {
79  *filename = slave;
80  return 0;
81  }
82  p = slave + 1;
83  if (strspn(p, slave_opt_close)) {
84  *filename = (char *)p + 1;
85  return 0;
86  }
87  while (1) {
88  ret = av_opt_get_key_value(&p, "=", slave_opt_delim, 0, &key, &val);
89  if (ret < 0) {
90  av_log(log, AV_LOG_ERROR, "No option found near \"%s\"\n", p);
91  goto fail;
92  }
93  ret = av_dict_set(options, key, val,
95  if (ret < 0)
96  goto fail;
97  if (strspn(p, slave_opt_close))
98  break;
99  p++;
100  }
101  *filename = (char *)p + 1;
102  return 0;
103 
104 fail:
105  av_dict_free(options);
106  return ret;
107 }
108 
109 /**
110  * Parse list of bitstream filters and add them to the list of filters
111  * pointed to by bsfs.
112  *
113  * The list must be specified in the form:
114  * BSFS ::= BSF[,BSFS]
115  */
116 static int parse_bsfs(void *log_ctx, const char *bsfs_spec,
118 {
119  char *bsf_name, *buf, *dup, *saveptr;
120  int ret = 0;
121 
122  if (!(dup = buf = av_strdup(bsfs_spec)))
123  return AVERROR(ENOMEM);
124 
125  while (bsf_name = av_strtok(buf, ",", &saveptr)) {
127 
128  if (!bsf) {
129  av_log(log_ctx, AV_LOG_ERROR,
130  "Cannot initialize bitstream filter with name '%s', "
131  "unknown filter or internal error happened\n",
132  bsf_name);
133  ret = AVERROR_UNKNOWN;
134  goto end;
135  }
136 
137  /* append bsf context to the list of bsf contexts */
138  *bsfs = bsf;
139  bsfs = &bsf->next;
140 
141  buf = NULL;
142  }
143 
144 end:
145  av_free(dup);
146  return ret;
147 }
148 
149 static inline int parse_slave_failure_policy_option(const char *opt, TeeSlave *tee_slave)
150 {
151  if (!opt) {
153  return 0;
154  } else if (!av_strcasecmp("abort", opt)) {
155  tee_slave->on_fail = ON_SLAVE_FAILURE_ABORT;
156  return 0;
157  } else if (!av_strcasecmp("ignore", opt)) {
158  tee_slave->on_fail = ON_SLAVE_FAILURE_IGNORE;
159  return 0;
160  }
161  /* Set failure behaviour to abort, so invalid option error will not be ignored */
162  tee_slave->on_fail = ON_SLAVE_FAILURE_ABORT;
163  return AVERROR(EINVAL);
164 }
165 
166 static int close_slave(TeeSlave *tee_slave)
167 {
168  AVFormatContext *avf;
169  unsigned i;
170  int ret = 0;
171 
172  avf = tee_slave->avf;
173  if (!avf)
174  return 0;
175 
176  if (tee_slave->header_written)
177  ret = av_write_trailer(avf);
178 
179  if (tee_slave->bsfs) {
180  for (i = 0; i < avf->nb_streams; ++i) {
181  AVBitStreamFilterContext *bsf_next, *bsf = tee_slave->bsfs[i];
182  while (bsf) {
183  bsf_next = bsf->next;
185  bsf = bsf_next;
186  }
187  }
188  }
189  av_freep(&tee_slave->stream_map);
190  av_freep(&tee_slave->bsfs);
191 
192  ff_format_io_close(avf, &avf->pb);
194  tee_slave->avf = NULL;
195  return ret;
196 }
197 
198 static void close_slaves(AVFormatContext *avf)
199 {
200  TeeContext *tee = avf->priv_data;
201  unsigned i;
202 
203  for (i = 0; i < tee->nb_slaves; i++) {
204  close_slave(&tee->slaves[i]);
205  }
206 }
207 
208 static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
209 {
210  int i, ret;
212  AVDictionaryEntry *entry;
213  char *filename;
214  char *format = NULL, *select = NULL, *on_fail = NULL;
215  AVFormatContext *avf2 = NULL;
216  AVStream *st, *st2;
217  int stream_count;
218  int fullret;
219  char *subselect = NULL, *next_subselect = NULL, *first_subselect = NULL, *tmp_select = NULL;
220 
221  if ((ret = parse_slave_options(avf, slave, &options, &filename)) < 0)
222  return ret;
223 
224 #define STEAL_OPTION(option, field) do { \
225  if ((entry = av_dict_get(options, option, NULL, 0))) { \
226  field = entry->value; \
227  entry->value = NULL; /* prevent it from being freed */ \
228  av_dict_set(&options, option, NULL, 0); \
229  } \
230  } while (0)
231 
232  STEAL_OPTION("f", format);
233  STEAL_OPTION("select", select);
234  STEAL_OPTION("onfail", on_fail);
235 
236  ret = parse_slave_failure_policy_option(on_fail, tee_slave);
237  if (ret < 0) {
238  av_log(avf, AV_LOG_ERROR,
239  "Invalid onfail option value, valid options are 'abort' and 'ignore'\n");
240  goto end;
241  }
242 
243  ret = avformat_alloc_output_context2(&avf2, NULL, format, filename);
244  if (ret < 0)
245  goto end;
246  tee_slave->avf = avf2;
247  av_dict_copy(&avf2->metadata, avf->metadata, 0);
248  avf2->opaque = avf->opaque;
249  avf2->io_open = avf->io_open;
250  avf2->io_close = avf->io_close;
251 
252  tee_slave->stream_map = av_calloc(avf->nb_streams, sizeof(*tee_slave->stream_map));
253  if (!tee_slave->stream_map) {
254  ret = AVERROR(ENOMEM);
255  goto end;
256  }
257 
258  stream_count = 0;
259  for (i = 0; i < avf->nb_streams; i++) {
260  st = avf->streams[i];
261  if (select) {
262  tmp_select = av_strdup(select); // av_strtok is destructive so we regenerate it in each loop
263  if (!tmp_select) {
264  ret = AVERROR(ENOMEM);
265  goto end;
266  }
267  fullret = 0;
268  first_subselect = tmp_select;
269  next_subselect = NULL;
270  while (subselect = av_strtok(first_subselect, slave_select_sep, &next_subselect)) {
271  first_subselect = NULL;
272 
273  ret = avformat_match_stream_specifier(avf, avf->streams[i], subselect);
274  if (ret < 0) {
275  av_log(avf, AV_LOG_ERROR,
276  "Invalid stream specifier '%s' for output '%s'\n",
277  subselect, slave);
278  goto end;
279  }
280  if (ret != 0) {
281  fullret = 1; // match
282  break;
283  }
284  }
285  av_freep(&tmp_select);
286 
287  if (fullret == 0) { /* no match */
288  tee_slave->stream_map[i] = -1;
289  continue;
290  }
291  }
292  tee_slave->stream_map[i] = stream_count++;
293 
294  if (!(st2 = avformat_new_stream(avf2, NULL))) {
295  ret = AVERROR(ENOMEM);
296  goto end;
297  }
298  st2->id = st->id;
299  st2->r_frame_rate = st->r_frame_rate;
300  st2->time_base = st->time_base;
301  st2->start_time = st->start_time;
302  st2->duration = st->duration;
303  st2->nb_frames = st->nb_frames;
304  st2->disposition = st->disposition;
306  st2->avg_frame_rate = st->avg_frame_rate;
307  av_dict_copy(&st2->metadata, st->metadata, 0);
308  if ((ret = avcodec_parameters_copy(st2->codecpar, st->codecpar)) < 0)
309  goto end;
310  }
311 
312  if (!(avf2->oformat->flags & AVFMT_NOFILE)) {
313  if ((ret = avf2->io_open(avf2, &avf2->pb, filename, AVIO_FLAG_WRITE, NULL)) < 0) {
314  av_log(avf, AV_LOG_ERROR, "Slave '%s': error opening: %s\n",
315  slave, av_err2str(ret));
316  goto end;
317  }
318  }
319 
320  if ((ret = avformat_write_header(avf2, &options)) < 0) {
321  av_log(avf, AV_LOG_ERROR, "Slave '%s': error writing header: %s\n",
322  slave, av_err2str(ret));
323  goto end;
324  }
325  tee_slave->header_written = 1;
326 
327  tee_slave->bsfs = av_calloc(avf2->nb_streams, sizeof(TeeSlave));
328  if (!tee_slave->bsfs) {
329  ret = AVERROR(ENOMEM);
330  goto end;
331  }
332 
333  entry = NULL;
334  while (entry = av_dict_get(options, "bsfs", NULL, AV_DICT_IGNORE_SUFFIX)) {
335  const char *spec = entry->key + strlen("bsfs");
336  if (*spec) {
337  if (strspn(spec, slave_bsfs_spec_sep) != 1) {
338  av_log(avf, AV_LOG_ERROR,
339  "Specifier separator in '%s' is '%c', but only characters '%s' "
340  "are allowed\n", entry->key, *spec, slave_bsfs_spec_sep);
341  ret = AVERROR(EINVAL);
342  goto end;
343  }
344  spec++; /* consume separator */
345  }
346 
347  for (i = 0; i < avf2->nb_streams; i++) {
348  ret = avformat_match_stream_specifier(avf2, avf2->streams[i], spec);
349  if (ret < 0) {
350  av_log(avf, AV_LOG_ERROR,
351  "Invalid stream specifier '%s' in bsfs option '%s' for slave "
352  "output '%s'\n", spec, entry->key, filename);
353  goto end;
354  }
355 
356  if (ret > 0) {
357  av_log(avf, AV_LOG_DEBUG, "spec:%s bsfs:%s matches stream %d of slave "
358  "output '%s'\n", spec, entry->value, i, filename);
359  if (tee_slave->bsfs[i]) {
360  av_log(avf, AV_LOG_WARNING,
361  "Duplicate bsfs specification associated to stream %d of slave "
362  "output '%s', filters will be ignored\n", i, filename);
363  continue;
364  }
365  ret = parse_bsfs(avf, entry->value, &tee_slave->bsfs[i]);
366  if (ret < 0) {
367  av_log(avf, AV_LOG_ERROR,
368  "Error parsing bitstream filter sequence '%s' associated to "
369  "stream %d of slave output '%s'\n", entry->value, i, filename);
370  goto end;
371  }
372  }
373  }
374 
375  av_dict_set(&options, entry->key, NULL, 0);
376  }
377 
378  if (options) {
379  entry = NULL;
380  while ((entry = av_dict_get(options, "", entry, AV_DICT_IGNORE_SUFFIX)))
381  av_log(avf2, AV_LOG_ERROR, "Unknown option '%s'\n", entry->key);
383  goto end;
384  }
385 
386 end:
387  av_free(format);
388  av_free(select);
389  av_free(on_fail);
390  av_dict_free(&options);
391  av_freep(&tmp_select);
392  return ret;
393 }
394 
395 static void log_slave(TeeSlave *slave, void *log_ctx, int log_level)
396 {
397  int i;
398  av_log(log_ctx, log_level, "filename:'%s' format:%s\n",
399  slave->avf->filename, slave->avf->oformat->name);
400  for (i = 0; i < slave->avf->nb_streams; i++) {
401  AVStream *st = slave->avf->streams[i];
402  AVBitStreamFilterContext *bsf = slave->bsfs[i];
403 
404  av_log(log_ctx, log_level, " stream:%d codec:%s type:%s",
407  if (bsf) {
408  av_log(log_ctx, log_level, " bsfs:");
409  while (bsf) {
410  av_log(log_ctx, log_level, "%s%s",
411  bsf->filter->name, bsf->next ? "," : "");
412  bsf = bsf->next;
413  }
414  }
415  av_log(log_ctx, log_level, "\n");
416  }
417 }
418 
419 static int tee_process_slave_failure(AVFormatContext *avf, unsigned slave_idx, int err_n)
420 {
421  TeeContext *tee = avf->priv_data;
422  TeeSlave *tee_slave = &tee->slaves[slave_idx];
423 
424  tee->nb_alive--;
425 
426  close_slave(tee_slave);
427 
428  if (!tee->nb_alive) {
429  av_log(avf, AV_LOG_ERROR, "All tee outputs failed.\n");
430  return err_n;
431  } else if (tee_slave->on_fail == ON_SLAVE_FAILURE_ABORT) {
432  av_log(avf, AV_LOG_ERROR, "Slave muxer #%u failed, aborting.\n", slave_idx);
433  return err_n;
434  } else {
435  av_log(avf, AV_LOG_ERROR, "Slave muxer #%u failed: %s, continuing with %u/%u slaves.\n",
436  slave_idx, av_err2str(err_n), tee->nb_alive, tee->nb_slaves);
437  return 0;
438  }
439 }
440 
442 {
443  TeeContext *tee = avf->priv_data;
444  unsigned nb_slaves = 0, i;
445  const char *filename = avf->filename;
446  char *slaves[MAX_SLAVES];
447  int ret;
448 
449  while (*filename) {
450  if (nb_slaves == MAX_SLAVES) {
451  av_log(avf, AV_LOG_ERROR, "Maximum %d slave muxers reached.\n",
452  MAX_SLAVES);
453  ret = AVERROR_PATCHWELCOME;
454  goto fail;
455  }
456  if (!(slaves[nb_slaves++] = av_get_token(&filename, slave_delim))) {
457  ret = AVERROR(ENOMEM);
458  goto fail;
459  }
460  if (strspn(filename, slave_delim))
461  filename++;
462  }
463 
464  tee->nb_slaves = tee->nb_alive = nb_slaves;
465 
466  for (i = 0; i < nb_slaves; i++) {
467  if ((ret = open_slave(avf, slaves[i], &tee->slaves[i])) < 0) {
468  ret = tee_process_slave_failure(avf, i, ret);
469  if (ret < 0)
470  goto fail;
471  } else {
472  log_slave(&tee->slaves[i], avf, AV_LOG_VERBOSE);
473  }
474  av_freep(&slaves[i]);
475  }
476 
477  for (i = 0; i < avf->nb_streams; i++) {
478  int j, mapped = 0;
479  for (j = 0; j < tee->nb_slaves; j++)
480  if (tee->slaves[j].avf)
481  mapped += tee->slaves[j].stream_map[i] >= 0;
482  if (!mapped)
483  av_log(avf, AV_LOG_WARNING, "Input stream #%d is not mapped "
484  "to any slave.\n", i);
485  }
486  return 0;
487 
488 fail:
489  for (i = 0; i < nb_slaves; i++)
490  av_freep(&slaves[i]);
491  close_slaves(avf);
492  return ret;
493 }
494 
496 {
497  TeeContext *tee = avf->priv_data;
498  int ret_all = 0, ret;
499  unsigned i;
500 
501  for (i = 0; i < tee->nb_slaves; i++) {
502  if ((ret = close_slave(&tee->slaves[i])) < 0) {
503  ret = tee_process_slave_failure(avf, i, ret);
504  if (!ret_all && ret < 0)
505  ret_all = ret;
506  }
507  }
508  return ret_all;
509 }
510 
512 {
513  TeeContext *tee = avf->priv_data;
514  AVFormatContext *avf2;
515  AVPacket pkt2;
516  int ret_all = 0, ret;
517  unsigned i, s;
518  int s2;
519  AVRational tb, tb2;
520 
521  for (i = 0; i < tee->nb_slaves; i++) {
522  if (!(avf2 = tee->slaves[i].avf))
523  continue;
524 
525  s = pkt->stream_index;
526  s2 = tee->slaves[i].stream_map[s];
527  if (s2 < 0)
528  continue;
529 
530  if ((ret = av_copy_packet(&pkt2, pkt)) < 0 ||
531  (ret = av_dup_packet(&pkt2))< 0)
532  if (!ret_all) {
533  ret_all = ret;
534  continue;
535  }
536  tb = avf ->streams[s ]->time_base;
537  tb2 = avf2->streams[s2]->time_base;
538  pkt2.pts = av_rescale_q(pkt->pts, tb, tb2);
539  pkt2.dts = av_rescale_q(pkt->dts, tb, tb2);
540  pkt2.duration = av_rescale_q(pkt->duration, tb, tb2);
541  pkt2.stream_index = s2;
542 
543  if ((ret = av_apply_bitstream_filters(avf2->streams[s2]->codec, &pkt2,
544  tee->slaves[i].bsfs[s2])) < 0 ||
545  (ret = av_interleaved_write_frame(avf2, &pkt2)) < 0) {
546  ret = tee_process_slave_failure(avf, i, ret);
547  if (!ret_all && ret < 0)
548  ret_all = ret;
549  }
550  }
551  return ret_all;
552 }
553 
555  .name = "tee",
556  .long_name = NULL_IF_CONFIG_SMALL("Multiple muxer tee"),
557  .priv_data_size = sizeof(TeeContext),
561  .priv_class = &tee_muxer_class,
562  .flags = AVFMT_NOFILE,
563 };
#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:511
const char * s
Definition: avisynth_c.h:631
SlaveFailurePolicy
Definition: tee.c:32
int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
Write a packet to an output media file ensuring correct interleaving.
Definition: mux.c:1044
AVBitStreamFilterContext ** bsfs
bitstream filters per stream
Definition: tee.c:41
static const char *const slave_opt_delim
Definition: tee.c:61
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
#define LIBAVUTIL_VERSION_INT
Definition: version.h:70
static int tee_write_trailer(AVFormatContext *avf)
Definition: tee.c:495
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:3911
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:943
#define AVIO_FLAG_WRITE
write-only
Definition: avio.h:543
static const char *const slave_bsfs_spec_sep
Definition: tee.c:62
external API header
static void log_slave(TeeSlave *slave, void *log_ctx, int log_level)
Definition: tee.c:395
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:48
SlaveFailurePolicy on_fail
Definition: tee.c:43
static int tee_process_slave_failure(AVFormatContext *avf, unsigned slave_idx, int err_n)
Definition: tee.c:419
static const char *const slave_delim
Definition: tee.c:58
#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:60
Format I/O context.
Definition: avformat.h:1319
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:554
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
Definition: avformat.h:541
static int close_slave(TeeSlave *tee_slave)
Definition: tee.c:166
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:1592
int id
Format-specific stream ID.
Definition: avformat.h:883
void ff_format_io_close(AVFormatContext *s, AVIOContext **pb)
Definition: utils.c:5042
static void close_slaves(AVFormatContext *avf)
Definition: tee.c:198
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:4621
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:4040
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1387
const char * name
Definition: avcodec.h:5698
unsigned nb_alive
Definition: tee.c:54
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:3967
struct AVBitStreamFilterContext * next
Definition: avcodec.h:5630
static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
Definition: tee.c:208
#define av_log(a,...)
static int parse_slave_options(void *log, char *slave, AVDictionary **options, char **filename)
Definition: tee.c:71
static const char *const slave_select_sep
Definition: tee.c:63
struct AVOutputFormat * oformat
The output container format.
Definition: avformat.h:1338
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:4047
#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:1533
#define s2
Definition: regdef.h:39
av_default_item_name
#define DEFAULT_SLAVE_FAILURE_POLICY
Definition: tee.c:37
#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
attribute_deprecated int av_dup_packet(AVPacket *pkt)
Definition: avpacket.c:235
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
unsigned nb_slaves
Definition: tee.c:53
int * stream_map
map from input to output streams indexes, disabled output streams are set to -1
Definition: tee.c:47
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:3907
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:1799
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1375
Definition: tee.c:39
char filename[1024]
input or output filename
Definition: avformat.h:1395
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:476
static const AVClass tee_muxer_class
Definition: tee.c:65
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
TeeSlave slaves[MAX_SLAVES]
Definition: tee.c:55
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
Definition: utils.c:3074
Stream structure.
Definition: avformat.h:876
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
Definition: tee.c:51
char * av_strdup(const char *s)
Duplicate the string s.
Definition: mem.c:267
AVIOContext * pb
I/O context.
Definition: avformat.h:1361
static const char *const slave_opt_open
Definition: tee.c:59
static const char * format
Definition: movenc-test.c:47
int av_copy_packet(AVPacket *dst, const AVPacket *src)
Copy packet, including contents.
Definition: avpacket.c:246
void * buf
Definition: avisynth_c.h:553
int av_apply_bitstream_filters(AVCodecContext *codec, AVPacket *pkt, AVBitStreamFilterContext *bsfc)
Apply a list of bitstream filters to a packet.
Definition: utils.c:4988
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:5628
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:116
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
Definition: utils.c:3976
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 MAX_SLAVES
Definition: tee.c:30
#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:1436
void * priv_data
Format private data.
Definition: avformat.h:1347
static void write_header(FFV1Context *f)
Definition: ffv1enc.c:497
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: avcodec.h:1573
int av_write_trailer(AVFormatContext *s)
Write the stream trailer to an output media file and free the file private data.
Definition: mux.c:1120
#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:1576
static int parse_slave_failure_policy_option(const char *opt, TeeSlave *tee_slave)
Definition: tee.c:149
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:1877
This structure stores compressed data.
Definition: avcodec.h:1551
static int write_packet(AVFormatContext *s1, AVPacket *pkt)
Definition: v4l2enc.c:86
AVFormatContext * avf
Definition: tee.c:40
void(* io_close)(struct AVFormatContext *s, AVIOContext *pb)
A callback for closing the streams opened with AVFormatContext.io_open().
Definition: avformat.h:1883
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1567
static int tee_write_header(AVFormatContext *avf)
Definition: tee.c:441
#define STEAL_OPTION(option, field)
#define tb
Definition: regdef.h:68