FFmpeg  2.1.1
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 "avformat.h"
27 
28 #define MAX_SLAVES 16
29 
30 typedef struct {
32  AVBitStreamFilterContext **bsfs; ///< bitstream filters per stream
33 
34  /** map from input to output streams indexes,
35  * disabled output streams are set to -1 */
36  int *stream_map;
37 } TeeSlave;
38 
39 typedef struct TeeContext {
40  const AVClass *class;
41  unsigned nb_slaves;
43 } TeeContext;
44 
45 static const char *const slave_delim = "|";
46 static const char *const slave_opt_open = "[";
47 static const char *const slave_opt_close = "]";
48 static const char *const slave_opt_delim = ":]"; /* must have the close too */
49 static const char *const slave_bsfs_spec_sep = "/";
50 
51 static const AVClass tee_muxer_class = {
52  .class_name = "Tee muxer",
53  .item_name = av_default_item_name,
54  .version = LIBAVUTIL_VERSION_INT,
55 };
56 
57 static int parse_slave_options(void *log, char *slave,
58  AVDictionary **options, char **filename)
59 {
60  const char *p;
61  char *key, *val;
62  int ret;
63 
64  if (!strspn(slave, slave_opt_open)) {
65  *filename = slave;
66  return 0;
67  }
68  p = slave + 1;
69  if (strspn(p, slave_opt_close)) {
70  *filename = (char *)p + 1;
71  return 0;
72  }
73  while (1) {
74  ret = av_opt_get_key_value(&p, "=", slave_opt_delim, 0, &key, &val);
75  if (ret < 0) {
76  av_log(log, AV_LOG_ERROR, "No option found near \"%s\"\n", p);
77  goto fail;
78  }
79  ret = av_dict_set(options, key, val,
81  if (ret < 0)
82  goto fail;
83  if (strspn(p, slave_opt_close))
84  break;
85  p++;
86  }
87  *filename = (char *)p + 1;
88  return 0;
89 
90 fail:
91  av_dict_free(options);
92  return ret;
93 }
94 
95 /**
96  * Parse list of bitstream filters and add them to the list of filters
97  * pointed to by bsfs.
98  *
99  * The list must be specified in the form:
100  * BSFS ::= BSF[,BSFS]
101  */
102 static int parse_bsfs(void *log_ctx, const char *bsfs_spec,
104 {
105  char *bsf_name, *buf, *dup, *saveptr;
106  int ret = 0;
107 
108  if (!(dup = buf = av_strdup(bsfs_spec)))
109  return AVERROR(ENOMEM);
110 
111  while (bsf_name = av_strtok(buf, ",", &saveptr)) {
113 
114  if (!bsf) {
115  av_log(log_ctx, AV_LOG_ERROR,
116  "Cannot initialize bitstream filter with name '%s', "
117  "unknown filter or internal error happened\n",
118  bsf_name);
119  ret = AVERROR_UNKNOWN;
120  goto end;
121  }
122 
123  /* append bsf context to the list of bsf contexts */
124  *bsfs = bsf;
125  bsfs = &bsf->next;
126 
127  buf = NULL;
128  }
129 
130 end:
131  av_free(dup);
132  return ret;
133 }
134 
135 static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
136 {
137  int i, ret;
138  AVDictionary *options = NULL;
139  AVDictionaryEntry *entry;
140  char *filename;
141  char *format = NULL, *select = NULL;
142  AVFormatContext *avf2 = NULL;
143  AVStream *st, *st2;
144  int stream_count;
145 
146  if ((ret = parse_slave_options(avf, slave, &options, &filename)) < 0)
147  return ret;
148 
149 #define STEAL_OPTION(option, field) do { \
150  if ((entry = av_dict_get(options, option, NULL, 0))) { \
151  field = entry->value; \
152  entry->value = NULL; /* prevent it from being freed */ \
153  av_dict_set(&options, option, NULL, 0); \
154  } \
155  } while (0)
156 
157  STEAL_OPTION("f", format);
158  STEAL_OPTION("select", select);
159 
160  ret = avformat_alloc_output_context2(&avf2, NULL, format, filename);
161  if (ret < 0)
162  goto end;
163  av_dict_copy(&avf2->metadata, avf->metadata, 0);
164 
165  tee_slave->stream_map = av_calloc(avf->nb_streams, sizeof(*tee_slave->stream_map));
166  if (!tee_slave->stream_map) {
167  ret = AVERROR(ENOMEM);
168  goto end;
169  }
170 
171  stream_count = 0;
172  for (i = 0; i < avf->nb_streams; i++) {
173  st = avf->streams[i];
174  if (select) {
175  ret = avformat_match_stream_specifier(avf, avf->streams[i], select);
176  if (ret < 0) {
177  av_log(avf, AV_LOG_ERROR,
178  "Invalid stream specifier '%s' for output '%s'\n",
179  select, slave);
180  goto end;
181  }
182 
183  if (ret == 0) { /* no match */
184  tee_slave->stream_map[i] = -1;
185  continue;
186  }
187  }
188  tee_slave->stream_map[i] = stream_count++;
189 
190  if (!(st2 = avformat_new_stream(avf2, NULL))) {
191  ret = AVERROR(ENOMEM);
192  goto end;
193  }
194  st2->id = st->id;
195  st2->r_frame_rate = st->r_frame_rate;
196  st2->time_base = st->time_base;
197  st2->start_time = st->start_time;
198  st2->duration = st->duration;
199  st2->nb_frames = st->nb_frames;
200  st2->disposition = st->disposition;
202  st2->avg_frame_rate = st->avg_frame_rate;
203  av_dict_copy(&st2->metadata, st->metadata, 0);
204  if ((ret = avcodec_copy_context(st2->codec, st->codec)) < 0)
205  goto end;
206  }
207 
208  if (!(avf2->oformat->flags & AVFMT_NOFILE)) {
209  if ((ret = avio_open(&avf2->pb, filename, AVIO_FLAG_WRITE)) < 0) {
210  av_log(avf, AV_LOG_ERROR, "Slave '%s': error opening: %s\n",
211  slave, av_err2str(ret));
212  goto end;
213  }
214  }
215 
216  if ((ret = avformat_write_header(avf2, &options)) < 0) {
217  av_log(avf, AV_LOG_ERROR, "Slave '%s': error writing header: %s\n",
218  slave, av_err2str(ret));
219  goto end;
220  }
221 
222  tee_slave->avf = avf2;
223  tee_slave->bsfs = av_calloc(avf2->nb_streams, sizeof(TeeSlave));
224  if (!tee_slave->bsfs) {
225  ret = AVERROR(ENOMEM);
226  goto end;
227  }
228 
229  entry = NULL;
230  while (entry = av_dict_get(options, "bsfs", NULL, AV_DICT_IGNORE_SUFFIX)) {
231  const char *spec = entry->key + strlen("bsfs");
232  if (*spec) {
233  if (strspn(spec, slave_bsfs_spec_sep) != 1) {
234  av_log(avf, AV_LOG_ERROR,
235  "Specifier separator in '%s' is '%c', but only characters '%s' "
236  "are allowed\n", entry->key, *spec, slave_bsfs_spec_sep);
237  return AVERROR(EINVAL);
238  }
239  spec++; /* consume separator */
240  }
241 
242  for (i = 0; i < avf2->nb_streams; i++) {
243  ret = avformat_match_stream_specifier(avf2, avf2->streams[i], spec);
244  if (ret < 0) {
245  av_log(avf, AV_LOG_ERROR,
246  "Invalid stream specifier '%s' in bsfs option '%s' for slave "
247  "output '%s'\n", spec, entry->key, filename);
248  goto end;
249  }
250 
251  if (ret > 0) {
252  av_log(avf, AV_LOG_DEBUG, "spec:%s bsfs:%s matches stream %d of slave "
253  "output '%s'\n", spec, entry->value, i, filename);
254  if (tee_slave->bsfs[i]) {
255  av_log(avf, AV_LOG_WARNING,
256  "Duplicate bsfs specification associated to stream %d of slave "
257  "output '%s', filters will be ignored\n", i, filename);
258  continue;
259  }
260  ret = parse_bsfs(avf, entry->value, &tee_slave->bsfs[i]);
261  if (ret < 0) {
262  av_log(avf, AV_LOG_ERROR,
263  "Error parsing bitstream filter sequence '%s' associated to "
264  "stream %d of slave output '%s'\n", entry->value, i, filename);
265  goto end;
266  }
267  }
268  }
269 
270  av_dict_set(&options, entry->key, NULL, 0);
271  }
272 
273  if (options) {
274  entry = NULL;
275  while ((entry = av_dict_get(options, "", entry, AV_DICT_IGNORE_SUFFIX)))
276  av_log(avf2, AV_LOG_ERROR, "Unknown option '%s'\n", entry->key);
278  goto end;
279  }
280 
281 end:
282  av_free(format);
283  av_free(select);
284  av_dict_free(&options);
285  return ret;
286 }
287 
288 static void close_slaves(AVFormatContext *avf)
289 {
290  TeeContext *tee = avf->priv_data;
291  AVFormatContext *avf2;
292  unsigned i, j;
293 
294  for (i = 0; i < tee->nb_slaves; i++) {
295  avf2 = tee->slaves[i].avf;
296 
297  for (j = 0; j < avf2->nb_streams; j++) {
298  AVBitStreamFilterContext *bsf_next, *bsf = tee->slaves[i].bsfs[j];
299  while (bsf) {
300  bsf_next = bsf->next;
302  bsf = bsf_next;
303  }
304  }
305  av_freep(&tee->slaves[i].stream_map);
306  av_freep(&tee->slaves[i].bsfs);
307 
308  avio_close(avf2->pb);
309  avf2->pb = NULL;
310  avformat_free_context(avf2);
311  tee->slaves[i].avf = NULL;
312  }
313 }
314 
315 static void log_slave(TeeSlave *slave, void *log_ctx, int log_level)
316 {
317  int i;
318  av_log(log_ctx, log_level, "filename:'%s' format:%s\n",
319  slave->avf->filename, slave->avf->oformat->name);
320  for (i = 0; i < slave->avf->nb_streams; i++) {
321  AVStream *st = slave->avf->streams[i];
322  AVBitStreamFilterContext *bsf = slave->bsfs[i];
323 
324  av_log(log_ctx, log_level, " stream:%d codec:%s type:%s",
327  if (bsf) {
328  av_log(log_ctx, log_level, " bsfs:");
329  while (bsf) {
330  av_log(log_ctx, log_level, "%s%s",
331  bsf->filter->name, bsf->next ? "," : "");
332  bsf = bsf->next;
333  }
334  }
335  av_log(log_ctx, log_level, "\n");
336  }
337 }
338 
340 {
341  TeeContext *tee = avf->priv_data;
342  unsigned nb_slaves = 0, i;
343  const char *filename = avf->filename;
344  char *slaves[MAX_SLAVES];
345  int ret;
346 
347  while (*filename) {
348  if (nb_slaves == MAX_SLAVES) {
349  av_log(avf, AV_LOG_ERROR, "Maximum %d slave muxers reached.\n",
350  MAX_SLAVES);
351  ret = AVERROR_PATCHWELCOME;
352  goto fail;
353  }
354  if (!(slaves[nb_slaves++] = av_get_token(&filename, slave_delim))) {
355  ret = AVERROR(ENOMEM);
356  goto fail;
357  }
358  if (strspn(filename, slave_delim))
359  filename++;
360  }
361 
362  for (i = 0; i < nb_slaves; i++) {
363  if ((ret = open_slave(avf, slaves[i], &tee->slaves[i])) < 0)
364  goto fail;
365  log_slave(&tee->slaves[i], avf, AV_LOG_VERBOSE);
366  av_freep(&slaves[i]);
367  }
368 
369  tee->nb_slaves = nb_slaves;
370 
371  for (i = 0; i < avf->nb_streams; i++) {
372  int j, mapped = 0;
373  for (j = 0; j < tee->nb_slaves; j++)
374  mapped += tee->slaves[j].stream_map[i] >= 0;
375  if (!mapped)
376  av_log(avf, AV_LOG_WARNING, "Input stream #%d is not mapped "
377  "to any slave.\n", i);
378  }
379  return 0;
380 
381 fail:
382  for (i = 0; i < nb_slaves; i++)
383  av_freep(&slaves[i]);
384  close_slaves(avf);
385  return ret;
386 }
387 
388 static int filter_packet(void *log_ctx, AVPacket *pkt,
390 {
391  AVCodecContext *enc_ctx = fmt_ctx->streams[pkt->stream_index]->codec;
392  int ret = 0;
393 
394  while (bsf_ctx) {
395  AVPacket new_pkt = *pkt;
396  ret = av_bitstream_filter_filter(bsf_ctx, enc_ctx, NULL,
397  &new_pkt.data, &new_pkt.size,
398  pkt->data, pkt->size,
399  pkt->flags & AV_PKT_FLAG_KEY);
400  if (ret == 0 && new_pkt.data != pkt->data && new_pkt.destruct) {
401  if ((ret = av_copy_packet(&new_pkt, pkt)) < 0)
402  break;
403  ret = 1;
404  }
405 
406  if (ret > 0) {
407  av_free_packet(pkt);
408  new_pkt.buf = av_buffer_create(new_pkt.data, new_pkt.size,
409  av_buffer_default_free, NULL, 0);
410  if (!new_pkt.buf)
411  break;
412  }
413  *pkt = new_pkt;
414 
415  bsf_ctx = bsf_ctx->next;
416  }
417 
418  if (ret < 0) {
419  av_log(log_ctx, AV_LOG_ERROR,
420  "Failed to filter bitstream with filter %s for stream %d in file '%s' with codec %s\n",
421  bsf_ctx->filter->name, pkt->stream_index, fmt_ctx->filename,
422  avcodec_get_name(enc_ctx->codec_id));
423  }
424 
425  return ret;
426 }
427 
429 {
430  TeeContext *tee = avf->priv_data;
431  AVFormatContext *avf2;
432  int ret_all = 0, ret;
433  unsigned i;
434 
435  for (i = 0; i < tee->nb_slaves; i++) {
436  avf2 = tee->slaves[i].avf;
437  if ((ret = av_write_trailer(avf2)) < 0)
438  if (!ret_all)
439  ret_all = ret;
440  if (!(avf2->oformat->flags & AVFMT_NOFILE)) {
441  if ((ret = avio_close(avf2->pb)) < 0)
442  if (!ret_all)
443  ret_all = ret;
444  avf2->pb = NULL;
445  }
446  }
447  close_slaves(avf);
448  return ret_all;
449 }
450 
452 {
453  TeeContext *tee = avf->priv_data;
454  AVFormatContext *avf2;
455  AVPacket pkt2;
456  int ret_all = 0, ret;
457  unsigned i, s;
458  int s2;
459  AVRational tb, tb2;
460 
461  for (i = 0; i < tee->nb_slaves; i++) {
462  avf2 = tee->slaves[i].avf;
463  s = pkt->stream_index;
464  s2 = tee->slaves[i].stream_map[s];
465  if (s2 < 0)
466  continue;
467 
468  if ((ret = av_copy_packet(&pkt2, pkt)) < 0 ||
469  (ret = av_dup_packet(&pkt2))< 0)
470  if (!ret_all) {
471  ret = ret_all;
472  continue;
473  }
474  tb = avf ->streams[s ]->time_base;
475  tb2 = avf2->streams[s2]->time_base;
476  pkt2.pts = av_rescale_q(pkt->pts, tb, tb2);
477  pkt2.dts = av_rescale_q(pkt->dts, tb, tb2);
478  pkt2.duration = av_rescale_q(pkt->duration, tb, tb2);
479  pkt2.stream_index = s2;
480 
481  filter_packet(avf2, &pkt2, avf2, tee->slaves[i].bsfs[s2]);
482  if ((ret = av_interleaved_write_frame(avf2, &pkt2)) < 0)
483  if (!ret_all)
484  ret_all = ret;
485  }
486  return ret_all;
487 }
488 
490  .name = "tee",
491  .long_name = NULL_IF_CONFIG_SMALL("Multiple muxer tee"),
492  .priv_data_size = sizeof(TeeContext),
496  .priv_class = &tee_muxer_class,
497  .flags = AVFMT_NOFILE,
498 };
const char const char void * val
Definition: avisynth_c.h:671
static int tee_write_packet(AVFormatContext *avf, AVPacket *pkt)
Definition: tee.c:451
const char * s
Definition: avisynth_c.h:668
void * av_calloc(size_t nmemb, size_t size) av_malloc_attrib
Allocate a block of nmemb * size bytes with alignment suitable for all memory accesses (including vec...
Definition: mem.c:249
#define AVERROR_PATCHWELCOME
char * key
Definition: dict.h:81
void av_free_packet(AVPacket *pkt)
Free a packet.
Definition: avpacket.c:279
int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
Write a packet to an output media file ensuring correct interleaving.
Definition: mux.c:757
AVBitStreamFilterContext ** bsfs
bitstream filters per stream
Definition: tee.c:32
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:387
static const char *const slave_opt_delim
Definition: tee.c:48
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: avcodec.h:4153
#define LIBAVUTIL_VERSION_INT
Definition: avcodec.h:820
char * av_strdup(const char *s) av_malloc_attrib
Duplicate the string s.
Definition: mem.c:256
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
Definition: aviobuf.c:860
static int filter_packet(void *log_ctx, AVPacket *pkt, AVFormatContext *fmt_ctx, AVBitStreamFilterContext *bsf_ctx)
Definition: tee.c:388
AVDictionaryEntry * av_dict_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:39
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:686
static int tee_write_trailer(AVFormatContext *avf)
Definition: tee.c:428
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:733
int size
Definition: avcodec.h:1064
int av_copy_packet(AVPacket *dst, AVPacket *src)
Copy packet, including contents.
Definition: avpacket.c:264
static const char *const slave_bsfs_spec_sep
Definition: tee.c:49
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
static void log_slave(TeeSlave *slave, void *log_ctx, int log_level)
Definition: tee.c:315
int av_dup_packet(AVPacket *pkt)
Definition: avpacket.c:247
struct AVBitStreamFilterContext * next
Definition: avcodec.h:4774
int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src)
Copy the settings of the source AVCodecContext into the destination AVCodecContext.
Definition: options.c:185
static const char *const slave_delim
Definition: tee.c:45
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition: avcodec.h:1046
#define AV_DICT_DONT_STRDUP_KEY
Take ownership of a key that&#39;s been allocated with av_malloc() and children.
Definition: dict.h:69
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:234
if((e=av_dict_get(options,"", NULL, AV_DICT_IGNORE_SUFFIX)))
Definition: avfilter.c:965
static const char *const slave_opt_close
Definition: tee.c:47
AVDictionary * metadata
Definition: avformat.h:735
Format I/O context.
Definition: avformat.h:968
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:148
AVOutputFormat ff_tee_muxer
Definition: tee.c:489
const char * av_default_item_name(void *ctx)
Return the context name.
Definition: log.c:145
int flags
can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_RAWPICTURE, AVFMT_GLOBALHEADER, AVFMT_NOTIMESTAMPS, AVFMT_VARIABLE_FPS, AVFMT_NODIMENSIONS, AVFMT_NOSTREAMS, AVFMT_ALLOW_FLUSH, AVFMT_TS_NONSTRICT
Definition: avformat.h:414
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:55
attribute_deprecated void(* destruct)(struct AVPacket *)
Definition: avcodec.h:1088
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:67
int id
Format-specific stream ID.
Definition: avformat.h:674
static void close_slaves(AVFormatContext *avf)
Definition: tee.c:288
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:4133
AVBufferRef * av_buffer_create(uint8_t *data, int size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
Definition: buffer.c:27
#define AV_LOG_VERBOSE
Detailed information.
Definition: avcodec.h:4163
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:347
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:3348
int duration
Duration of this packet in AVStream-&gt;time_base units, 0 if unknown.
Definition: avcodec.h:1085
const OptionDef options[]
Definition: ffserver.c:4682
static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
Definition: tee.c:135
static int parse_slave_options(void *log, char *slave, AVDictionary **options, char **filename)
Definition: tee.c:57
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1113
void av_buffer_default_free(void *opaque, uint8_t *data)
Default free callback, which calls av_free() on the buffer data.
Definition: buffer.c:60
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:130
void av_dict_copy(AVDictionary **dst, AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition: dict.c:176
#define av_err2str(errnum)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: avcodec.h:4147
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:219
#define AVERROR_UNKNOWN
#define s2
Definition: regdef.h:39
void * priv_data
Format private data.
Definition: avformat.h:988
char filename[1024]
input or output filename
Definition: avformat.h:1018
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:151
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: avcodec.h:4168
unsigned nb_slaves
Definition: tee.c:41
void av_bitstream_filter_close(AVBitStreamFilterContext *bsf)
Release bitstream filter context.
int * stream_map
map from input to output streams indexes, disabled output streams are set to -1
Definition: tee.c:36
void av_dict_free(AVDictionary **m)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
Definition: dict.c:162
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
Definition: utils.c:2626
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:740
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1069
struct AVBitStreamFilter * filter
Definition: avcodec.h:4772
goto fail
Definition: avfilter.c:963
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:70
unsigned int nb_streams
A list of all streams in the file.
Definition: avformat.h:1015
Definition: tee.c:30
static const AVClass tee_muxer_class
Definition: tee.c:51
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that&#39;s been allocated with av_malloc() and chilren.
Definition: dict.h:72
ret
Definition: avfilter.c:961
AVStream ** streams
Definition: avformat.h:1016
static int write_trailer(AVFormatContext *s1)
Definition: v4l2enc.c:93
char * value
Definition: dict.h:82
const char * name
Definition: avformat.h:395
TeeSlave slaves[MAX_SLAVES]
Definition: tee.c:42
Stream structure.
Definition: avformat.h:667
int av_bitstream_filter_filter(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size, int keyframe)
Filter bitstream.
Definition: tee.c:39
enum AVMediaType codec_type
Definition: avcodec.h:1154
enum AVCodecID codec_id
Definition: avcodec.h:1157
#define AVIO_FLAG_WRITE
write-only
Definition: avio.h:333
static const char *const slave_opt_open
Definition: tee.c:46
main external API structure.
Definition: avcodec.h:1146
AVIOContext * pb
I/O context.
Definition: avformat.h:1001
void * buf
Definition: avisynth_c.h:594
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:62
int avio_open(AVIOContext **s, const char *url, int flags)
Create and initialize a AVIOContext for accessing the resource indicated by url.
Definition: aviobuf.c:838
#define AVERROR_OPTION_NOT_FOUND
Describe the class of an AVClass context structure.
Definition: log.h:50
static AVFormatContext * fmt_ctx
Definition: demuxing.c:37
rational number numerator/denominator
Definition: rational.h:43
uint8_t * data
Definition: avcodec.h:1063
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:102
AVDictionary * metadata
Definition: avformat.h:1128
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
Definition: utils.c:3271
static int flags
Definition: cpu.c:45
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition: avformat.h:720
#define MAX_SLAVES
Definition: tee.c:28
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base...
Definition: avformat.h:713
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:183
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:124
Main libavformat public API header.
int disposition
AV_DISPOSITION_* bit field.
Definition: avformat.h:724
int64_t nb_frames
number of frames in this stream if known or 0
Definition: avformat.h:722
struct AVOutputFormat * oformat
Definition: avformat.h:982
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:1244
static void write_header(FFV1Context *f)
Definition: ffv1enc.c:492
#define AVERROR(e)
int64_t dts
Decompression timestamp in AVStream-&gt;time_base units; the time at which the packet is decompressed...
Definition: avcodec.h:1062
int av_write_trailer(AVFormatContext *s)
Write the stream trailer to an output media file and free the file private data.
Definition: mux.c:800
#define AV_DICT_IGNORE_SUFFIX
Definition: dict.h:68
static AVPacket pkt
Definition: demuxing.c:52
int stream_index
Definition: avcodec.h:1065
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avformat.h:703
AVRational r_frame_rate
Real base framerate of the stream.
Definition: avformat.h:839
This structure stores compressed data.
Definition: avcodec.h:1040
const char * name
Definition: avcodec.h:4779
static int write_packet(AVFormatContext *s1, AVPacket *pkt)
Definition: v4l2enc.c:85
AVFormatContext * avf
Definition: tee.c:31
int64_t pts
Presentation timestamp in AVStream-&gt;time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1056
static int tee_write_header(AVFormatContext *avf)
Definition: tee.c:339
#define STEAL_OPTION(option, field)
AVBitStreamFilterContext * av_bitstream_filter_init(const char *name)
Create and initialize a bitstream filter context given a bitstream filter name.
#define tb
Definition: regdef.h:68