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 #include "tee_common.h"
30 
31 typedef enum {
35 
36 #define DEFAULT_SLAVE_FAILURE_POLICY ON_SLAVE_FAILURE_ABORT
37 
38 typedef struct {
40  AVBSFContext **bsfs; ///< bitstream filters per stream
41 
43 
44  /** map from input to output streams indexes,
45  * disabled output streams are set to -1 */
46  int *stream_map;
48 } TeeSlave;
49 
50 typedef struct TeeContext {
51  const AVClass *class;
52  unsigned nb_slaves;
53  unsigned nb_alive;
55 } TeeContext;
56 
57 static const char *const slave_delim = "|";
58 static const char *const slave_bsfs_spec_sep = "/";
59 static const char *const slave_select_sep = ",";
60 
61 static const AVClass tee_muxer_class = {
62  .class_name = "Tee muxer",
63  .item_name = av_default_item_name,
64  .version = LIBAVUTIL_VERSION_INT,
65 };
66 
67 static inline int parse_slave_failure_policy_option(const char *opt, TeeSlave *tee_slave)
68 {
69  if (!opt) {
71  return 0;
72  } else if (!av_strcasecmp("abort", opt)) {
73  tee_slave->on_fail = ON_SLAVE_FAILURE_ABORT;
74  return 0;
75  } else if (!av_strcasecmp("ignore", opt)) {
76  tee_slave->on_fail = ON_SLAVE_FAILURE_IGNORE;
77  return 0;
78  }
79  /* Set failure behaviour to abort, so invalid option error will not be ignored */
80  tee_slave->on_fail = ON_SLAVE_FAILURE_ABORT;
81  return AVERROR(EINVAL);
82 }
83 
84 static int close_slave(TeeSlave *tee_slave)
85 {
86  AVFormatContext *avf;
87  unsigned i;
88  int ret = 0;
89 
90  avf = tee_slave->avf;
91  if (!avf)
92  return 0;
93 
94  if (tee_slave->header_written)
95  ret = av_write_trailer(avf);
96 
97  if (tee_slave->bsfs) {
98  for (i = 0; i < avf->nb_streams; ++i)
99  av_bsf_free(&tee_slave->bsfs[i]);
100  }
101  av_freep(&tee_slave->stream_map);
102  av_freep(&tee_slave->bsfs);
103 
104  ff_format_io_close(avf, &avf->pb);
106  tee_slave->avf = NULL;
107  return ret;
108 }
109 
110 static void close_slaves(AVFormatContext *avf)
111 {
112  TeeContext *tee = avf->priv_data;
113  unsigned i;
114 
115  for (i = 0; i < tee->nb_slaves; i++) {
116  close_slave(&tee->slaves[i]);
117  }
118  av_freep(&tee->slaves);
119 }
120 
121 static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
122 {
123  int i, ret;
125  AVDictionaryEntry *entry;
126  char *filename;
127  char *format = NULL, *select = NULL, *on_fail = NULL;
128  AVFormatContext *avf2 = NULL;
129  AVStream *st, *st2;
130  int stream_count;
131  int fullret;
132  char *subselect = NULL, *next_subselect = NULL, *first_subselect = NULL, *tmp_select = NULL;
133 
134  if ((ret = ff_tee_parse_slave_options(avf, slave, &options, &filename)) < 0)
135  return ret;
136 
137 #define STEAL_OPTION(option, field) do { \
138  if ((entry = av_dict_get(options, option, NULL, 0))) { \
139  field = entry->value; \
140  entry->value = NULL; /* prevent it from being freed */ \
141  av_dict_set(&options, option, NULL, 0); \
142  } \
143  } while (0)
144 
145  STEAL_OPTION("f", format);
146  STEAL_OPTION("select", select);
147  STEAL_OPTION("onfail", on_fail);
148 
149  ret = parse_slave_failure_policy_option(on_fail, tee_slave);
150  if (ret < 0) {
151  av_log(avf, AV_LOG_ERROR,
152  "Invalid onfail option value, valid options are 'abort' and 'ignore'\n");
153  goto end;
154  }
155 
156  ret = avformat_alloc_output_context2(&avf2, NULL, format, filename);
157  if (ret < 0)
158  goto end;
159  tee_slave->avf = avf2;
160  av_dict_copy(&avf2->metadata, avf->metadata, 0);
161  avf2->opaque = avf->opaque;
162  avf2->io_open = avf->io_open;
163  avf2->io_close = avf->io_close;
165  avf2->flags = avf->flags;
166 
167  tee_slave->stream_map = av_calloc(avf->nb_streams, sizeof(*tee_slave->stream_map));
168  if (!tee_slave->stream_map) {
169  ret = AVERROR(ENOMEM);
170  goto end;
171  }
172 
173  stream_count = 0;
174  for (i = 0; i < avf->nb_streams; i++) {
175  st = avf->streams[i];
176  if (select) {
177  tmp_select = av_strdup(select); // av_strtok is destructive so we regenerate it in each loop
178  if (!tmp_select) {
179  ret = AVERROR(ENOMEM);
180  goto end;
181  }
182  fullret = 0;
183  first_subselect = tmp_select;
184  next_subselect = NULL;
185  while (subselect = av_strtok(first_subselect, slave_select_sep, &next_subselect)) {
186  first_subselect = NULL;
187 
188  ret = avformat_match_stream_specifier(avf, avf->streams[i], subselect);
189  if (ret < 0) {
190  av_log(avf, AV_LOG_ERROR,
191  "Invalid stream specifier '%s' for output '%s'\n",
192  subselect, slave);
193  goto end;
194  }
195  if (ret != 0) {
196  fullret = 1; // match
197  break;
198  }
199  }
200  av_freep(&tmp_select);
201 
202  if (fullret == 0) { /* no match */
203  tee_slave->stream_map[i] = -1;
204  continue;
205  }
206  }
207  tee_slave->stream_map[i] = stream_count++;
208 
209  if (!(st2 = avformat_new_stream(avf2, NULL))) {
210  ret = AVERROR(ENOMEM);
211  goto end;
212  }
213 
214  ret = ff_stream_encode_params_copy(st2, st);
215  if (ret < 0)
216  goto end;
217  }
218 
219  ret = ff_format_output_open(avf2, filename, NULL);
220  if (ret < 0) {
221  av_log(avf, AV_LOG_ERROR, "Slave '%s': error opening: %s\n", slave,
222  av_err2str(ret));
223  goto end;
224  }
225 
226  if ((ret = avformat_write_header(avf2, &options)) < 0) {
227  av_log(avf, AV_LOG_ERROR, "Slave '%s': error writing header: %s\n",
228  slave, av_err2str(ret));
229  goto end;
230  }
231  tee_slave->header_written = 1;
232 
233  tee_slave->bsfs = av_calloc(avf2->nb_streams, sizeof(*tee_slave->bsfs));
234  if (!tee_slave->bsfs) {
235  ret = AVERROR(ENOMEM);
236  goto end;
237  }
238 
239  entry = NULL;
240  while (entry = av_dict_get(options, "bsfs", NULL, AV_DICT_IGNORE_SUFFIX)) {
241  const char *spec = entry->key + strlen("bsfs");
242  if (*spec) {
243  if (strspn(spec, slave_bsfs_spec_sep) != 1) {
244  av_log(avf, AV_LOG_ERROR,
245  "Specifier separator in '%s' is '%c', but only characters '%s' "
246  "are allowed\n", entry->key, *spec, slave_bsfs_spec_sep);
247  ret = AVERROR(EINVAL);
248  goto end;
249  }
250  spec++; /* consume separator */
251  }
252 
253  for (i = 0; i < avf2->nb_streams; i++) {
254  ret = avformat_match_stream_specifier(avf2, avf2->streams[i], spec);
255  if (ret < 0) {
256  av_log(avf, AV_LOG_ERROR,
257  "Invalid stream specifier '%s' in bsfs option '%s' for slave "
258  "output '%s'\n", spec, entry->key, filename);
259  goto end;
260  }
261 
262  if (ret > 0) {
263  av_log(avf, AV_LOG_DEBUG, "spec:%s bsfs:%s matches stream %d of slave "
264  "output '%s'\n", spec, entry->value, i, filename);
265  if (tee_slave->bsfs[i]) {
266  av_log(avf, AV_LOG_WARNING,
267  "Duplicate bsfs specification associated to stream %d of slave "
268  "output '%s', filters will be ignored\n", i, filename);
269  continue;
270  }
271  ret = av_bsf_list_parse_str(entry->value, &tee_slave->bsfs[i]);
272  if (ret < 0) {
273  av_log(avf, AV_LOG_ERROR,
274  "Error parsing bitstream filter sequence '%s' associated to "
275  "stream %d of slave output '%s'\n", entry->value, i, filename);
276  goto end;
277  }
278  }
279  }
280 
281  av_dict_set(&options, entry->key, NULL, 0);
282  }
283 
284  for (i = 0; i < avf->nb_streams; i++){
285  int target_stream = tee_slave->stream_map[i];
286  if (target_stream < 0)
287  continue;
288 
289  if (!tee_slave->bsfs[target_stream]) {
290  /* Add pass-through bitstream filter */
291  ret = av_bsf_get_null_filter(&tee_slave->bsfs[target_stream]);
292  if (ret < 0) {
293  av_log(avf, AV_LOG_ERROR,
294  "Failed to create pass-through bitstream filter: %s\n",
295  av_err2str(ret));
296  goto end;
297  }
298  }
299 
300  tee_slave->bsfs[target_stream]->time_base_in = avf->streams[i]->time_base;
301  ret = avcodec_parameters_copy(tee_slave->bsfs[target_stream]->par_in,
302  avf->streams[i]->codecpar);
303  if (ret < 0)
304  goto end;
305 
306  ret = av_bsf_init(tee_slave->bsfs[target_stream]);
307  if (ret < 0) {
308  av_log(avf, AV_LOG_ERROR,
309  "Failed to initialize bitstream filter(s): %s\n",
310  av_err2str(ret));
311  goto end;
312  }
313  }
314 
315  if (options) {
316  entry = NULL;
317  while ((entry = av_dict_get(options, "", entry, AV_DICT_IGNORE_SUFFIX)))
318  av_log(avf2, AV_LOG_ERROR, "Unknown option '%s'\n", entry->key);
320  goto end;
321  }
322 
323 end:
324  av_free(format);
325  av_free(select);
326  av_free(on_fail);
327  av_dict_free(&options);
328  av_freep(&tmp_select);
329  return ret;
330 }
331 
332 static void log_slave(TeeSlave *slave, void *log_ctx, int log_level)
333 {
334  int i;
335  av_log(log_ctx, log_level, "filename:'%s' format:%s\n",
336  slave->avf->filename, slave->avf->oformat->name);
337  for (i = 0; i < slave->avf->nb_streams; i++) {
338  AVStream *st = slave->avf->streams[i];
339  AVBSFContext *bsf = slave->bsfs[i];
340  const char *bsf_name;
341 
342  av_log(log_ctx, log_level, " stream:%d codec:%s type:%s",
345 
346  bsf_name = bsf->filter->priv_class ?
347  bsf->filter->priv_class->item_name(bsf) : bsf->filter->name;
348  av_log(log_ctx, log_level, " bsfs: %s\n", bsf_name);
349  }
350 }
351 
352 static int tee_process_slave_failure(AVFormatContext *avf, unsigned slave_idx, int err_n)
353 {
354  TeeContext *tee = avf->priv_data;
355  TeeSlave *tee_slave = &tee->slaves[slave_idx];
356 
357  tee->nb_alive--;
358 
359  close_slave(tee_slave);
360 
361  if (!tee->nb_alive) {
362  av_log(avf, AV_LOG_ERROR, "All tee outputs failed.\n");
363  return err_n;
364  } else if (tee_slave->on_fail == ON_SLAVE_FAILURE_ABORT) {
365  av_log(avf, AV_LOG_ERROR, "Slave muxer #%u failed, aborting.\n", slave_idx);
366  return err_n;
367  } else {
368  av_log(avf, AV_LOG_ERROR, "Slave muxer #%u failed: %s, continuing with %u/%u slaves.\n",
369  slave_idx, av_err2str(err_n), tee->nb_alive, tee->nb_slaves);
370  return 0;
371  }
372 }
373 
375 {
376  TeeContext *tee = avf->priv_data;
377  unsigned nb_slaves = 0, i;
378  const char *filename = avf->filename;
379  char **slaves = NULL;
380  int ret;
381 
382  while (*filename) {
383  char *slave = av_get_token(&filename, slave_delim);
384  if (!slave) {
385  ret = AVERROR(ENOMEM);
386  goto fail;
387  }
388  ret = av_dynarray_add_nofree(&slaves, &nb_slaves, slave);
389  if (ret < 0) {
390  av_free(slave);
391  goto fail;
392  }
393  if (strspn(filename, slave_delim))
394  filename++;
395  }
396 
397  if (!(tee->slaves = av_mallocz_array(nb_slaves, sizeof(*tee->slaves)))) {
398  ret = AVERROR(ENOMEM);
399  goto fail;
400  }
401  tee->nb_slaves = tee->nb_alive = nb_slaves;
402 
403  for (i = 0; i < nb_slaves; i++) {
404  if ((ret = open_slave(avf, slaves[i], &tee->slaves[i])) < 0) {
405  ret = tee_process_slave_failure(avf, i, ret);
406  if (ret < 0)
407  goto fail;
408  } else {
409  log_slave(&tee->slaves[i], avf, AV_LOG_VERBOSE);
410  }
411  av_freep(&slaves[i]);
412  }
413 
414  for (i = 0; i < avf->nb_streams; i++) {
415  int j, mapped = 0;
416  for (j = 0; j < tee->nb_slaves; j++)
417  if (tee->slaves[j].avf)
418  mapped += tee->slaves[j].stream_map[i] >= 0;
419  if (!mapped)
420  av_log(avf, AV_LOG_WARNING, "Input stream #%d is not mapped "
421  "to any slave.\n", i);
422  }
423  av_free(slaves);
424  return 0;
425 
426 fail:
427  for (i = 0; i < nb_slaves; i++)
428  av_freep(&slaves[i]);
429  close_slaves(avf);
430  av_free(slaves);
431  return ret;
432 }
433 
435 {
436  TeeContext *tee = avf->priv_data;
437  int ret_all = 0, ret;
438  unsigned i;
439 
440  for (i = 0; i < tee->nb_slaves; i++) {
441  if ((ret = close_slave(&tee->slaves[i])) < 0) {
442  ret = tee_process_slave_failure(avf, i, ret);
443  if (!ret_all && ret < 0)
444  ret_all = ret;
445  }
446  }
447  av_freep(&tee->slaves);
448  return ret_all;
449 }
450 
452 {
453  TeeContext *tee = avf->priv_data;
454  AVFormatContext *avf2;
455  AVBSFContext *bsfs;
456  AVPacket pkt2;
457  int ret_all = 0, ret;
458  unsigned i, s;
459  int s2;
460 
461  for (i = 0; i < tee->nb_slaves; i++) {
462  if (!(avf2 = tee->slaves[i].avf))
463  continue;
464 
465  /* Flush slave if pkt is NULL*/
466  if (!pkt) {
467  ret = av_interleaved_write_frame(avf2, NULL);
468  if (ret < 0) {
469  ret = tee_process_slave_failure(avf, i, ret);
470  if (!ret_all && ret < 0)
471  ret_all = ret;
472  }
473  continue;
474  }
475 
476  s = pkt->stream_index;
477  s2 = tee->slaves[i].stream_map[s];
478  if (s2 < 0)
479  continue;
480 
481  memset(&pkt2, 0, sizeof(AVPacket));
482  if ((ret = av_packet_ref(&pkt2, pkt)) < 0)
483  if (!ret_all) {
484  ret_all = ret;
485  continue;
486  }
487  bsfs = tee->slaves[i].bsfs[s2];
488  pkt2.stream_index = s2;
489 
490  ret = av_bsf_send_packet(bsfs, &pkt2);
491  if (ret < 0) {
492  av_log(avf, AV_LOG_ERROR, "Error while sending packet to bitstream filter: %s\n",
493  av_err2str(ret));
494  ret = tee_process_slave_failure(avf, i, ret);
495  if (!ret_all && ret < 0)
496  ret_all = ret;
497  }
498 
499  while(1) {
500  ret = av_bsf_receive_packet(bsfs, &pkt2);
501  if (ret == AVERROR(EAGAIN)) {
502  ret = 0;
503  break;
504  } else if (ret < 0) {
505  break;
506  }
507 
508  av_packet_rescale_ts(&pkt2, bsfs->time_base_out,
509  avf2->streams[s2]->time_base);
510  ret = av_interleaved_write_frame(avf2, &pkt2);
511  if (ret < 0)
512  break;
513  };
514 
515  if (ret < 0) {
516  ret = tee_process_slave_failure(avf, i, ret);
517  if (!ret_all && ret < 0)
518  ret_all = ret;
519  }
520  }
521  return ret_all;
522 }
523 
525  .name = "tee",
526  .long_name = NULL_IF_CONFIG_SMALL("Multiple muxer tee"),
527  .priv_data_size = sizeof(TeeContext),
531  .priv_class = &tee_muxer_class,
533 };
void av_bsf_free(AVBSFContext **ctx)
Free a bitstream filter context and everything associated with it; write NULL into the supplied point...
Definition: bsf.c:36
#define NULL
Definition: coverity.c:32
static int tee_write_packet(AVFormatContext *avf, AVPacket *pkt)
Definition: tee.c:451
const char * s
Definition: avisynth_c.h:768
const AVClass * priv_class
A class for the private data, used to declare bitstream filter private AVOptions. ...
Definition: avcodec.h:5796
SlaveFailurePolicy
Definition: tee.c:31
int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
Write a packet to an output media file ensuring correct interleaving.
Definition: mux.c:1225
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
Definition: avformat.h:1592
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
TeeSlave * slaves
Definition: tee.c:54
static int tee_write_trailer(AVFormatContext *avf)
Definition: tee.c:434
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:3980
const struct AVBitStreamFilter * filter
The bitstream filter this context is an instance of.
Definition: avcodec.h:5740
The bitstream filter state.
Definition: avcodec.h:5731
static const char *const slave_bsfs_spec_sep
Definition: tee.c:58
Convenience header that includes libavutil's core.
static void log_slave(TeeSlave *slave, void *log_ctx, int log_level)
Definition: tee.c:332
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition: dict.c:217
static AVPacket pkt
int header_written
Definition: tee.c:47
SlaveFailurePolicy on_fail
Definition: tee.c:42
int av_bsf_get_null_filter(AVBSFContext **bsf)
Get null/pass-through bitstream filter.
Definition: bsf.c:540
#define AVFMT_ALLOW_FLUSH
Format allows flushing.
Definition: avformat.h:495
static int tee_process_slave_failure(AVFormatContext *avf, unsigned slave_idx, int err_n)
Definition: tee.c:352
static const char *const slave_delim
Definition: tee.c:57
int av_bsf_init(AVBSFContext *ctx)
Prepare the filter for use, after all the parameters and options have been set.
Definition: bsf.c:135
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:260
Format I/O context.
Definition: avformat.h:1338
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
int av_bsf_receive_packet(AVBSFContext *ctx, AVPacket *pkt)
Retrieve a filtered packet.
Definition: bsf.c:199
AVOutputFormat ff_tee_muxer
Definition: tee.c:524
static int close_slave(TeeSlave *tee_slave)
Definition: tee.c:84
AVOptions.
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
void ff_format_io_close(AVFormatContext *s, AVIOContext **pb)
Definition: utils.c:5255
static void close_slaves(AVFormatContext *avf)
Definition: tee.c:110
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:4780
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:4193
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1406
const char * name
Definition: avcodec.h:5778
unsigned nb_alive
Definition: tee.c:53
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:40
int flags
Flags modifying the (de)muxer behaviour.
Definition: avformat.h:1449
int ff_format_output_open(AVFormatContext *s, const char *url, AVDictionary **options)
Utility function to open IO stream of output format.
Definition: utils.c:5245
int ff_stream_encode_params_copy(AVStream *dst, const AVStream *src)
Copy encoding parameters from source to destination stream.
Definition: utils.c:4016
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem)
Add an element to a dynamic array.
Definition: mem.c:310
const OptionDef options[]
Definition: ffserver.c:3969
static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
Definition: tee.c:121
#define av_log(a,...)
static const char *const slave_select_sep
Definition: tee.c:59
struct AVOutputFormat * oformat
The output container format.
Definition: avformat.h:1357
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
Definition: avpacket.c:576
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
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Copy the contents of src to dst.
Definition: utils.c:4148
#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:1554
void av_packet_rescale_ts(AVPacket *pkt, AVRational tb_src, AVRational tb_dst)
Convert valid timing fields (timestamps / durations) in a packet from one timebase to another...
Definition: avpacket.c:630
#define s2
Definition: regdef.h:39
av_default_item_name
#define DEFAULT_SLAVE_FAILURE_POLICY
Definition: tee.c:36
#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
AVBSFContext ** bsfs
bitstream filters per stream
Definition: tee.c:40
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
unsigned nb_slaves
Definition: tee.c:52
int * stream_map
map from input to output streams indexes, disabled output streams are set to -1
Definition: tee.c:46
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
Definition: dict.c:203
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:3976
AVRational time_base_in
The timebase used for the timestamps of the input packets.
Definition: avcodec.h:5768
static void * av_mallocz_array(size_t nmemb, size_t size)
Definition: mem.h:226
#define fail()
Definition: checkasm.h:83
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:1820
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1394
Definition: tee.c:38
char filename[1024]
input or output filename
Definition: avformat.h:1414
int ff_tee_parse_slave_options(void *log, char *slave, AVDictionary **options, char **filename)
Definition: tee_common.c:32
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:527
static const AVClass tee_muxer_class
Definition: tee.c:61
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
Definition: avstring.c:213
AVRational time_base_out
The timebase used for the timestamps of the output packets.
Definition: avcodec.h:5774
static int write_trailer(AVFormatContext *s1)
Definition: v4l2enc.c:94
int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt)
Submit a packet for filtering.
Definition: bsf.c:176
const char * name
Definition: avformat.h:524
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:119
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:78
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
Definition: utils.c:3146
Stream structure.
Definition: avformat.h:889
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:267
Definition: tee.c:50
AVIOContext * pb
I/O context.
Definition: avformat.h:1380
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:70
static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)
Definition: ffmpeg.c:645
static const char * format
Definition: movenc.c:47
Describe the class of an AVClass context structure.
Definition: log.h:67
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
Definition: utils.c:4129
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
Main libavformat public API header.
int av_bsf_list_parse_str(const char *str, AVBSFContext **bsf)
Parse string describing list of bitstream filters and create single AVBSFContext describing the whole...
Definition: bsf.c:504
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:478
char * key
Definition: dict.h:86
#define av_free(p)
#define AVERROR_OPTION_NOT_FOUND
Option not found.
Definition: error.h:61
char * value
Definition: dict.h:87
void * priv_data
Format private data.
Definition: avformat.h:1366
static void write_header(FFV1Context *f)
Definition: ffv1enc.c:344
int av_write_trailer(AVFormatContext *s)
Write the stream trailer to an output media file and free the file private data.
Definition: mux.c:1287
#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:1241
int stream_index
Definition: avcodec.h:1603
static int parse_slave_failure_policy_option(const char *opt, TeeSlave *tee_slave)
Definition: tee.c:67
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avformat.h:926
int(* io_open)(struct AVFormatContext *s, AVIOContext **pb, const char *url, int flags, AVDictionary **options)
Definition: avformat.h:1898
This structure stores compressed data.
Definition: avcodec.h:1578
AVCodecParameters * par_in
Parameters of the input stream.
Definition: avcodec.h:5757
AVFormatContext * avf
Definition: tee.c:39
void(* io_close)(struct AVFormatContext *s, AVIOContext *pb)
A callback for closing the streams opened with AVFormatContext.io_open().
Definition: avformat.h:1904
static int tee_write_header(AVFormatContext *avf)
Definition: tee.c:374
#define STEAL_OPTION(option, field)