FFmpeg
utils.c
Go to the documentation of this file.
1 /*
2  * various utility functions for use within FFmpeg
3  * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
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
9  * License 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 GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include <stdint.h>
23 #include <time.h>
24 
25 #include "config.h"
26 
27 #include "libavutil/avassert.h"
28 #include "libavutil/avstring.h"
29 #include "libavutil/bprint.h"
30 #include "libavutil/dict.h"
31 #include "libavutil/internal.h"
32 #include "libavutil/mem.h"
33 #include "libavutil/opt.h"
34 #include "libavutil/parseutils.h"
35 #include "libavutil/time.h"
37 
38 #include "libavcodec/internal.h"
39 
40 #include "avformat.h"
41 #include "avio_internal.h"
42 #include "internal.h"
43 #if CONFIG_NETWORK
44 #include "network.h"
45 #endif
46 #include "os_support.h"
47 #include "urldecode.h"
48 
49 /**
50  * @file
51  * various utility functions for use within FFmpeg
52  */
53 
54 /* an arbitrarily chosen "sane" max packet size -- 50M */
55 #define SANE_CHUNK_SIZE (50000000)
56 
57 /* Read the data in sane-sized chunks and append to pkt.
58  * Return the number of bytes read or an error. */
60 {
61  int orig_size = pkt->size;
62  int ret;
63 
64  do {
65  int prev_size = pkt->size;
66  int read_size;
67 
68  /* When the caller requests a lot of data, limit it to the amount
69  * left in file or SANE_CHUNK_SIZE when it is not known. */
70  read_size = size;
71  if (read_size > SANE_CHUNK_SIZE/10) {
72  read_size = ffio_limit(s, read_size);
73  // If filesize/maxsize is unknown, limit to SANE_CHUNK_SIZE
74  if (ffiocontext(s)->maxsize < 0)
75  read_size = FFMIN(read_size, SANE_CHUNK_SIZE);
76  }
77 
78  ret = av_grow_packet(pkt, read_size);
79  if (ret < 0)
80  break;
81 
82  ret = avio_read(s, pkt->data + prev_size, read_size);
83  if (ret != read_size) {
84  av_shrink_packet(pkt, prev_size + FFMAX(ret, 0));
85  break;
86  }
87 
88  size -= read_size;
89  } while (size > 0);
90  if (size > 0)
92 
93  if (!pkt->size)
95  return pkt->size > orig_size ? pkt->size - orig_size : ret;
96 }
97 
99 {
100 #if FF_API_INIT_PACKET
102  av_init_packet(pkt);
103  pkt->data = NULL;
104  pkt->size = 0;
106 #else
108 #endif
109  pkt->pos = avio_tell(s);
110 
111  return append_packet_chunked(s, pkt, size);
112 }
113 
115 {
116  if (!pkt->size)
117  return av_get_packet(s, pkt, size);
118  return append_packet_chunked(s, pkt, size);
119 }
120 
121 int av_filename_number_test(const char *filename)
122 {
123  AVBPrint bp;
124 
125  if (!filename)
126  return 0;
129 }
130 
131 /**********************************************************/
132 
133 unsigned int ff_codec_get_tag(const AVCodecTag *tags, enum AVCodecID id)
134 {
135  while (tags->id != AV_CODEC_ID_NONE) {
136  if (tags->id == id)
137  return tags->tag;
138  tags++;
139  }
140  return 0;
141 }
142 
143 enum AVCodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag)
144 {
145  for (int i = 0; tags[i].id != AV_CODEC_ID_NONE; i++)
146  if (tag == tags[i].tag)
147  return tags[i].id;
148  for (int i = 0; tags[i].id != AV_CODEC_ID_NONE; i++)
149  if (ff_toupper4(tag) == ff_toupper4(tags[i].tag))
150  return tags[i].id;
151  return AV_CODEC_ID_NONE;
152 }
153 
154 enum AVCodecID ff_get_pcm_codec_id(int bps, int flt, int be, int sflags)
155 {
156  if (bps <= 0 || bps > 64)
157  return AV_CODEC_ID_NONE;
158 
159  if (flt) {
160  switch (bps) {
161  case 32:
163  case 64:
165  default:
166  return AV_CODEC_ID_NONE;
167  }
168  } else {
169  bps += 7;
170  bps >>= 3;
171  if (sflags & (1 << (bps - 1))) {
172  switch (bps) {
173  case 1:
174  return AV_CODEC_ID_PCM_S8;
175  case 2:
177  case 3:
179  case 4:
181  case 8:
183  default:
184  return AV_CODEC_ID_NONE;
185  }
186  } else {
187  switch (bps) {
188  case 1:
189  return AV_CODEC_ID_PCM_U8;
190  case 2:
192  case 3:
194  case 4:
196  default:
197  return AV_CODEC_ID_NONE;
198  }
199  }
200  }
201 }
202 
203 unsigned int av_codec_get_tag(const AVCodecTag *const *tags, enum AVCodecID id)
204 {
205  unsigned int tag;
206  if (!av_codec_get_tag2(tags, id, &tag))
207  return 0;
208  return tag;
209 }
210 
211 int av_codec_get_tag2(const AVCodecTag * const *tags, enum AVCodecID id,
212  unsigned int *tag)
213 {
214  for (int i = 0; tags && tags[i]; i++) {
215  const AVCodecTag *codec_tags = tags[i];
216  while (codec_tags->id != AV_CODEC_ID_NONE) {
217  if (codec_tags->id == id) {
218  *tag = codec_tags->tag;
219  return 1;
220  }
221  codec_tags++;
222  }
223  }
224  return 0;
225 }
226 
227 enum AVCodecID av_codec_get_id(const AVCodecTag *const *tags, unsigned int tag)
228 {
229  for (int i = 0; tags && tags[i]; i++) {
230  enum AVCodecID id = ff_codec_get_id(tags[i], tag);
231  if (id != AV_CODEC_ID_NONE)
232  return id;
233  }
234  return AV_CODEC_ID_NONE;
235 }
236 
238 {
239  av_freep(&par->extradata);
240  par->extradata_size = 0;
241 
242  if (size < 0 || size >= INT32_MAX - AV_INPUT_BUFFER_PADDING_SIZE)
243  return AVERROR(EINVAL);
244 
246  if (!par->extradata)
247  return AVERROR(ENOMEM);
248 
249  memset(par->extradata + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
250  par->extradata_size = size;
251 
252  return 0;
253 }
254 
255 /*******************************************************/
256 
257 uint64_t ff_ntp_time(void)
258 {
259  return (av_gettime() / 1000) * 1000 + NTP_OFFSET_US;
260 }
261 
262 uint64_t ff_get_formatted_ntp_time(uint64_t ntp_time_us)
263 {
264  uint64_t ntp_ts, frac_part, sec;
265  uint32_t usec;
266 
267  //current ntp time in seconds and microseconds
268  sec = ntp_time_us / 1000000;
269  usec = ntp_time_us % 1000000;
270 
271  //encoding in ntp timestamp format
272  frac_part = usec * 0xFFFFFFFFULL;
273  frac_part /= 1000000;
274 
275  if (sec > 0xFFFFFFFFULL)
276  av_log(NULL, AV_LOG_WARNING, "NTP time format roll over detected\n");
277 
278  ntp_ts = sec << 32;
279  ntp_ts |= frac_part;
280 
281  return ntp_ts;
282 }
283 
284 uint64_t ff_parse_ntp_time(uint64_t ntp_ts)
285 {
286  uint64_t sec = ntp_ts >> 32;
287  uint64_t frac_part = ntp_ts & 0xFFFFFFFFULL;
288  uint64_t usec = (frac_part * 1000000) / 0xFFFFFFFFULL;
289 
290  return (sec * 1000000) + usec;
291 }
292 
293 int ff_bprint_get_frame_filename(struct AVBPrint *buf, const char *path, int64_t number, int flags)
294 {
295  const char *p;
296  char c;
297  int nd, percentd_found;
298 
299  p = path;
300  percentd_found = 0;
301  for (;;) {
302  c = *p++;
303  if (c == '\0')
304  break;
305  if (c == '%') {
306  do {
307  nd = 0;
308  while (av_isdigit(*p)) {
309  if (nd >= INT_MAX / 10 - 255)
310  goto fail;
311  nd = nd * 10 + *p++ - '0';
312  }
313  c = *p++;
314  } while (av_isdigit(c));
315 
316  switch (c) {
317  case '%':
318  goto addchar;
319  case 'd':
320  if (!(flags & AV_FRAME_FILENAME_FLAGS_MULTIPLE) && percentd_found)
321  goto fail;
322  percentd_found = 1;
323  if (number < 0)
324  nd += 1;
325  av_bprintf(buf, "%0*" PRId64, nd, number);
326  break;
327  default:
328  goto fail;
329  }
330  } else {
331 addchar:
332  av_bprint_chars(buf, c, 1);
333  }
334  }
335  if (!percentd_found)
336  goto fail;
338  return AVERROR(ENOMEM);
339  return 0;
340 fail:
341  return AVERROR(EINVAL);
342 }
343 
344 static int get_frame_filename(char *buf, int buf_size, const char *path, int64_t number, int flags)
345 {
346  AVBPrint bp;
347  av_bprint_init_for_buffer(&bp, buf, buf_size);
348  return ff_bprint_get_frame_filename(&bp, path, number, flags) < 0 ? -1 : 0;
349 }
350 
351 int av_get_frame_filename2(char *buf, int buf_size, const char *path, int number, int flags)
352 {
353  return get_frame_filename(buf, buf_size, path, number, flags);
354 }
355 
356 int av_get_frame_filename(char *buf, int buf_size, const char *path, int number)
357 {
358  return get_frame_filename(buf, buf_size, path, number, 0);
359 }
360 
361 void av_url_split(char *proto, int proto_size,
362  char *authorization, int authorization_size,
363  char *hostname, int hostname_size,
364  int *port_ptr, char *path, int path_size, const char *url)
365 {
366  const char *p, *ls, *at, *at2, *col, *brk;
367 
368  if (port_ptr)
369  *port_ptr = -1;
370  if (proto_size > 0)
371  proto[0] = 0;
372  if (authorization_size > 0)
373  authorization[0] = 0;
374  if (hostname_size > 0)
375  hostname[0] = 0;
376  if (path_size > 0)
377  path[0] = 0;
378 
379  /* parse protocol */
380  if ((p = strchr(url, ':'))) {
381  av_strlcpy(proto, url, FFMIN(proto_size, p + 1 - url));
382  p++; /* skip ':' */
383  if (*p == '/')
384  p++;
385  if (*p == '/')
386  p++;
387  } else {
388  /* no protocol means plain filename */
389  av_strlcpy(path, url, path_size);
390  return;
391  }
392 
393  /* separate path from hostname */
394  ls = p + strcspn(p, "/?#");
395  av_strlcpy(path, ls, path_size);
396 
397  /* the rest is hostname, use that to parse auth/port */
398  if (ls != p) {
399  /* authorization (user[:pass]@hostname) */
400  at2 = p;
401  while ((at = strchr(p, '@')) && at < ls) {
402  av_strlcpy(authorization, at2,
403  FFMIN(authorization_size, at + 1 - at2));
404  p = at + 1; /* skip '@' */
405  }
406 
407  if (*p == '[' && (brk = strchr(p, ']')) && brk < ls) {
408  /* [host]:port */
409  av_strlcpy(hostname, p + 1,
410  FFMIN(hostname_size, brk - p));
411  if (brk[1] == ':' && port_ptr)
412  *port_ptr = atoi(brk + 2);
413  } else if ((col = strchr(p, ':')) && col < ls) {
414  av_strlcpy(hostname, p,
415  FFMIN(col + 1 - p, hostname_size));
416  if (port_ptr)
417  *port_ptr = atoi(col + 1);
418  } else
419  av_strlcpy(hostname, p,
420  FFMIN(ls + 1 - p, hostname_size));
421  }
422 }
423 
424 int ff_mkdir_p(const char *path)
425 {
426  int ret = 0;
427  char *temp = av_strdup(path);
428  char *pos = temp;
429  char tmp_ch = '\0';
430 
431  if (!path || !temp) {
432  return -1;
433  }
434 
435  if (!av_strncasecmp(temp, "/", 1) || !av_strncasecmp(temp, "\\", 1)) {
436  pos++;
437  } else if (!av_strncasecmp(temp, "./", 2) || !av_strncasecmp(temp, ".\\", 2)) {
438  pos += 2;
439  }
440 
441  for ( ; *pos != '\0'; ++pos) {
442  if (*pos == '/' || *pos == '\\') {
443  tmp_ch = *pos;
444  *pos = '\0';
445  ret = mkdir(temp, 0755);
446  if (ret < 0 && errno != EEXIST) {
447  int err = errno;
448  av_free(temp);
449  errno = err;
450  return ret;
451  }
452  *pos = tmp_ch;
453  }
454  }
455 
456  if ((*(pos - 1) != '/') && (*(pos - 1) != '\\')) {
457  ret = mkdir(temp, 0755);
458  }
459 
460  av_free(temp);
461  return ret;
462 }
463 
464 char *ff_data_to_hex(char *buff, const uint8_t *src, int s, int lowercase)
465 {
466  static const char hex_table_uc[16] = { '0', '1', '2', '3',
467  '4', '5', '6', '7',
468  '8', '9', 'A', 'B',
469  'C', 'D', 'E', 'F' };
470  static const char hex_table_lc[16] = { '0', '1', '2', '3',
471  '4', '5', '6', '7',
472  '8', '9', 'a', 'b',
473  'c', 'd', 'e', 'f' };
474  const char *hex_table = lowercase ? hex_table_lc : hex_table_uc;
475 
476  for (int i = 0; i < s; i++) {
477  buff[i * 2] = hex_table[src[i] >> 4];
478  buff[i * 2 + 1] = hex_table[src[i] & 0xF];
479  }
480  buff[2 * s] = '\0';
481 
482  return buff;
483 }
484 
485 int ff_hex_to_data(uint8_t *data, const char *p)
486 {
487  int c, len, v;
488 
489  len = 0;
490  v = 1;
491  for (;;) {
492  p += strspn(p, SPACE_CHARS);
493  if (*p == '\0')
494  break;
495  c = av_toupper((unsigned char) *p++);
496  if (c >= '0' && c <= '9')
497  c = c - '0';
498  else if (c >= 'A' && c <= 'F')
499  c = c - 'A' + 10;
500  else
501  break;
502  v = (v << 4) | c;
503  if (v & 0x100) {
504  if (data)
505  data[len] = v;
506  len++;
507  v = 1;
508  }
509  }
510  return len;
511 }
512 
513 void ff_parse_key_value(const char *str, ff_parse_key_val_cb callback_get_buf,
514  void *context)
515 {
516  const char *ptr = str;
517 
518  /* Parse key=value pairs. */
519  for (;;) {
520  const char *key;
521  char *dest = NULL, *dest_end;
522  int key_len, dest_len = 0;
523 
524  /* Skip whitespace and potential commas. */
525  while (*ptr && (av_isspace(*ptr) || *ptr == ','))
526  ptr++;
527  if (!*ptr)
528  break;
529 
530  key = ptr;
531 
532  if (!(ptr = strchr(key, '=')))
533  break;
534  ptr++;
535  key_len = ptr - key;
536 
537  callback_get_buf(context, key, key_len, &dest, &dest_len);
538  dest_end = dest ? dest + dest_len - 1 : NULL;
539 
540  if (*ptr == '\"') {
541  ptr++;
542  while (*ptr && *ptr != '\"') {
543  if (*ptr == '\\') {
544  if (!ptr[1])
545  break;
546  if (dest && dest < dest_end)
547  *dest++ = ptr[1];
548  ptr += 2;
549  } else {
550  if (dest && dest < dest_end)
551  *dest++ = *ptr;
552  ptr++;
553  }
554  }
555  if (*ptr == '\"')
556  ptr++;
557  } else {
558  for (; *ptr && !(av_isspace(*ptr) || *ptr == ','); ptr++)
559  if (dest && dest < dest_end)
560  *dest++ = *ptr;
561  }
562  if (dest)
563  *dest = 0;
564  }
565 }
566 
568 {
569 #if CONFIG_NETWORK
570  int ret;
571  if ((ret = ff_network_init()) < 0)
572  return ret;
573  if ((ret = ff_tls_init()) < 0)
574  return ret;
575 #endif
576  return 0;
577 }
578 
580 {
581 #if CONFIG_NETWORK
583  ff_tls_deinit();
584 #endif
585  return 0;
586 }
587 
588 int ff_is_http_proto(const char *filename) {
589  const char *proto = avio_find_protocol_name(filename);
590  return proto ? (!av_strcasecmp(proto, "http") || !av_strcasecmp(proto, "https")) : 0;
591 }
592 
593 int ff_bprint_to_codecpar_extradata(AVCodecParameters *par, struct AVBPrint *buf)
594 {
595  int ret;
596  char *str;
597 
598  ret = av_bprint_finalize(buf, &str);
599  if (ret < 0)
600  return ret;
601  if (!av_bprint_is_complete(buf)) {
602  av_free(str);
603  return AVERROR(ENOMEM);
604  }
605 
606  par->extradata = str;
607  /* Note: the string is NUL terminated (so extradata can be read as a
608  * string), but the ending character is not accounted in the size (in
609  * binary formats you are likely not supposed to mux that character). When
610  * extradata is copied, it is also padded with AV_INPUT_BUFFER_PADDING_SIZE
611  * zeros. */
612  par->extradata_size = buf->len;
613  return 0;
614 }
615 
616 int ff_dict_set_timestamp(AVDictionary **dict, const char *key, int64_t timestamp)
617 {
618  int microsecs = timestamp % 1000000;
619  time_t seconds = timestamp / 1000000 - (microsecs < 0);
620  struct tm *ptm, tmbuf;
621  ptm = gmtime_r(&seconds, &tmbuf);
622  if (ptm) {
623  char buf[32];
624  if (!strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S", ptm))
625  return AVERROR_EXTERNAL;
626  av_strlcatf(buf, sizeof(buf), ".%06dZ", microsecs + (microsecs < 0) * 1000000);
627  return av_dict_set(dict, key, buf, 0);
628  } else {
629  return AVERROR_EXTERNAL;
630  }
631 }
632 
633 static const AVOption* find_opt(void *obj, const char *name, size_t len)
634 {
635  char decoded_name[128];
636 
637  if (ff_urldecode_len(decoded_name, sizeof(decoded_name), name, len, 1) < 0)
638  return NULL;
639 
640  return av_opt_find(obj, decoded_name, NULL, 0, 0);
641 }
642 
643 int ff_parse_opts_from_query_string(void *obj, const char *str, int allow_unknown)
644 {
645  const AVOption *opt;
646  char optval[512];
647  int ret;
648 
649  if (*str == '?')
650  str++;
651  while (*str) {
652  size_t len = strcspn(str, "=&");
653  opt = find_opt(obj, str, len);
654  if (!opt) {
655  if (!allow_unknown) {
656  av_log(obj, AV_LOG_ERROR, "Query string option '%.*s' does not exist\n", (int)len, str);
658  }
659  av_log(obj, AV_LOG_VERBOSE, "Ignoring unknown query string option '%.*s'\n", (int)len, str);
660  }
661  str += len;
662  if (!opt) {
663  len = strcspn(str, "&");
664  str += len;
665  } else if (*str == '&' || *str == '\0') {
666  /* Check for bool options without value, e.g. "?verify".
667  * Unfortunately "listen" is a tri-state INT for some protocols so
668  * we also have to allow that for backward compatibility. */
669  if (opt->type != AV_OPT_TYPE_BOOL && strcmp(opt->name, "listen")) {
670  av_log(obj, AV_LOG_ERROR, "Non-bool query string option '%s' has no value\n", opt->name);
671  return AVERROR(EINVAL);
672  }
673  ret = av_opt_set_int(obj, opt->name, 1, 0);
674  if (ret < 0)
675  return ret;
676  } else {
677  av_assert2(*str == '=');
678  str++;
679  len = strcspn(str, "&");
680  if (ff_urldecode_len(optval, sizeof(optval), str, len, 1) < 0) {
681  av_log(obj, AV_LOG_ERROR, "Query string option '%s' value is too long\n", opt->name);
682  return AVERROR(EINVAL);
683  }
684  ret = av_opt_set(obj, opt->name, optval, 0);
685  if (ret < 0)
686  return ret;
687  str += len;
688  }
689  if (*str)
690  str++;
691  }
692  return 0;
693 }
694 
695 void *ff_bprint_finalize_as_fam(struct AVBPrint *bp, const void *struct_ptr, size_t fam_offset)
696 {
697  if (!av_bprint_is_complete(bp)) {
699  return NULL;
700  }
701 
702  uint8_t *p = av_malloc(fam_offset + bp->len);
703  if (!p) {
705  return NULL;
706  }
707  memcpy(p, struct_ptr, fam_offset);
708  memcpy(p + fam_offset, bp->str, bp->len);
710 
711  return p;
712 }
AV_CODEC_ID_PCM_S16LE
@ AV_CODEC_ID_PCM_S16LE
Definition: codec_id.h:330
ff_dict_set_timestamp
int ff_dict_set_timestamp(AVDictionary **dict, const char *key, int64_t timestamp)
Set a dictionary value to an ISO-8601 compliant timestamp string.
Definition: utils.c:616
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: packet.c:434
be
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it be(in the first position) for now. Options ------- Then comes the options array. This is what will define the user accessible options. For example
FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:67
ff_codec_get_id
enum AVCodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag)
Definition: utils.c:143
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:216
AV_CODEC_ID_PCM_F32BE
@ AV_CODEC_ID_PCM_F32BE
Definition: codec_id.h:350
get_frame_filename
static int get_frame_filename(char *buf, int buf_size, const char *path, int64_t number, int flags)
Definition: utils.c:344
ff_data_to_hex
char * ff_data_to_hex(char *buff, const uint8_t *src, int s, int lowercase)
Write hexadecimal string corresponding to given binary data.
Definition: utils.c:464
AVCodecParameters::extradata
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: codec_par.h:71
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
ff_bprint_get_frame_filename
int ff_bprint_get_frame_filename(struct AVBPrint *buf, const char *path, int64_t number, int flags)
Return in 'buf' the path with 'd' replaced by a number.
Definition: utils.c:293
av_bprint_is_complete
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
Definition: bprint.h:218
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
av_codec_get_tag2
int av_codec_get_tag2(const AVCodecTag *const *tags, enum AVCodecID id, unsigned int *tag)
Definition: utils.c:211
ff_mkdir_p
int ff_mkdir_p(const char *path)
Automatically create sub-directories.
Definition: utils.c:424
av_bprint_init
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition: bprint.c:69
ff_ntp_time
uint64_t ff_ntp_time(void)
Get the current time since NTP epoch in microseconds.
Definition: utils.c:257
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:49
ffiocontext
static av_always_inline FFIOContext * ffiocontext(AVIOContext *ctx)
Definition: avio_internal.h:81
AVCodecTag::id
enum AVCodecID id
Definition: internal.h:43
int64_t
long long int64_t
Definition: coverity.c:34
find_opt
static const AVOption * find_opt(void *obj, const char *name, size_t len)
Definition: utils.c:633
av_grow_packet
int av_grow_packet(AVPacket *pkt, int grow_by)
Increase packet size, correctly zeroing padding.
Definition: packet.c:121
av_strcasecmp
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
Definition: avstring.c:208
av_isspace
static av_const int av_isspace(int c)
Locale-independent conversion of ASCII isspace.
Definition: avstring.h:218
AV_FRAME_FILENAME_FLAGS_IGNORE_TRUNCATION
#define AV_FRAME_FILENAME_FLAGS_IGNORE_TRUNCATION
Ignore truncated output instead of returning an error.
Definition: avformat.h:3020
internal.h
AVPacket::data
uint8_t * data
Definition: packet.h:603
av_get_frame_filename2
int av_get_frame_filename2(char *buf, int buf_size, const char *path, int number, int flags)
Return in 'buf' the path with 'd' replaced by a number.
Definition: utils.c:351
AVOption
AVOption.
Definition: opt.h:428
data
const char data[16]
Definition: mxf.c:149
AV_CODEC_ID_PCM_U24LE
@ AV_CODEC_ID_PCM_U24LE
Definition: codec_id.h:344
ff_toupper4
unsigned int ff_toupper4(unsigned int x)
Definition: to_upper4.h:29
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:226
AVDictionary
Definition: dict.c:32
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
ff_network_close
void ff_network_close(void)
Definition: network.c:121
key
const char * key
Definition: ffmpeg_mux_init.c:2971
av_get_frame_filename
int av_get_frame_filename(char *buf, int buf_size, const char *path, int number)
Definition: utils.c:356
av_strlcatf
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
Definition: avstring.c:103
os_support.h
ff_network_init
int ff_network_init(void)
Initialize the network subsystem.
Definition: network.c:63
ff_tls_init
int ff_tls_init(void)
Definition: network.c:39
av_filename_number_test
int av_filename_number_test(const char *filename)
Check whether filename actually is a numbered sequence generator.
Definition: utils.c:121
AV_CODEC_ID_PCM_S64LE
@ AV_CODEC_ID_PCM_S64LE
Definition: codec_id.h:361
av_bprint_init_for_buffer
void av_bprint_init_for_buffer(AVBPrint *buf, char *buffer, unsigned size)
Init a print buffer using a pre-existing buffer.
Definition: bprint.c:85
AV_CODEC_ID_PCM_S16BE
@ AV_CODEC_ID_PCM_S16BE
Definition: codec_id.h:331
AV_BPRINT_SIZE_COUNT_ONLY
#define AV_BPRINT_SIZE_COUNT_ONLY
av_shrink_packet
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
Definition: packet.c:113
gmtime_r
#define gmtime_r
Definition: time_internal.h:34
avio_tell
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:494
AVERROR_OPTION_NOT_FOUND
#define AVERROR_OPTION_NOT_FOUND
Option not found.
Definition: error.h:63
av_opt_set
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
Definition: opt.c:824
avformat_network_init
int avformat_network_init(void)
Do global initialization of network libraries.
Definition: utils.c:567
SPACE_CHARS
#define SPACE_CHARS
Definition: dnn_backend_tf.c:356
AV_CODEC_ID_PCM_S8
@ AV_CODEC_ID_PCM_S8
Definition: codec_id.h:334
avassert.h
av_codec_get_tag
unsigned int av_codec_get_tag(const AVCodecTag *const *tags, enum AVCodecID id)
Definition: utils.c:203
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
AV_PKT_FLAG_CORRUPT
#define AV_PKT_FLAG_CORRUPT
The packet content is corrupted.
Definition: packet.h:651
AVCodecTag
Definition: internal.h:42
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:504
av_append_packet
int av_append_packet(AVIOContext *s, AVPacket *pkt, int size)
Read data and append it to the current content of the AVPacket.
Definition: utils.c:114
AV_CODEC_ID_PCM_U16BE
@ AV_CODEC_ID_PCM_U16BE
Definition: codec_id.h:333
ff_bprint_finalize_as_fam
void * ff_bprint_finalize_as_fam(struct AVBPrint *bp, const void *struct_ptr, size_t fam_offset)
Allocate copy of a structure and copy contents of an AVBPrint buffer to the flexible array member of ...
Definition: utils.c:695
ff_hex_to_data
int ff_hex_to_data(uint8_t *data, const char *p)
Parse a string of hexadecimal strings.
Definition: utils.c:485
time_internal.h
context
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option keep it simple and lowercase description are in without and describe what they for example set the foo of the bar offset is the offset of the field in your context
Definition: writing_filters.txt:91
fail
#define fail
Definition: test.h:478
NULL
#define NULL
Definition: coverity.c:32
AV_CODEC_ID_PCM_U24BE
@ AV_CODEC_ID_PCM_U24BE
Definition: codec_id.h:345
AV_CODEC_ID_PCM_U32BE
@ AV_CODEC_ID_PCM_U32BE
Definition: codec_id.h:341
AV_CODEC_ID_PCM_S64BE
@ AV_CODEC_ID_PCM_S64BE
Definition: codec_id.h:362
parseutils.h
ff_parse_key_value
void ff_parse_key_value(const char *str, ff_parse_key_val_cb callback_get_buf, void *context)
Parse a string with comma-separated key=value pairs.
Definition: utils.c:513
time.h
ff_get_formatted_ntp_time
uint64_t ff_get_formatted_ntp_time(uint64_t ntp_time_us)
Get the NTP time stamp formatted as per the RFC-5905.
Definition: utils.c:262
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
av_opt_set_int
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
Definition: opt.c:869
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:47
AVCodecParameters::extradata_size
int extradata_size
Size of the extradata content in bytes.
Definition: codec_par.h:75
av_strncasecmp
int av_strncasecmp(const char *a, const char *b, size_t n)
Locale-independent case-insensitive compare.
Definition: avstring.c:218
av_opt_find
const AVOption * av_opt_find(void *obj, const char *name, const char *unit, int opt_flags, int search_flags)
Look for an option in an object.
Definition: opt.c:1984
AVIOContext
Bytestream IO Context.
Definition: avio.h:160
AV_CODEC_ID_PCM_S24LE
@ AV_CODEC_ID_PCM_S24LE
Definition: codec_id.h:342
AVPacket::size
int size
Definition: packet.h:604
av_bprint_finalize
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:235
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
bps
unsigned bps
Definition: movenc.c:2074
ff_get_pcm_codec_id
enum AVCodecID ff_get_pcm_codec_id(int bps, int flt, int be, int sflags)
Select a PCM codec based on the given parameters.
Definition: utils.c:154
size
int size
Definition: twinvq_data.h:10344
NTP_OFFSET_US
#define NTP_OFFSET_US
Definition: internal.h:415
AVOption::name
const char * name
Definition: opt.h:429
ff_urldecode_len
int ff_urldecode_len(char *dest, size_t dest_len, const char *url, size_t url_max_len, int decode_plus_sign)
Decodes an URL from its percent-encoded form back into normal representation.
Definition: urldecode.c:99
av_isdigit
static av_const int av_isdigit(int c)
Locale-independent conversion of ASCII isdigit.
Definition: avstring.h:202
AVERROR_EXTERNAL
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:59
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:609
AV_FRAME_FILENAME_FLAGS_MULTIPLE
#define AV_FRAME_FILENAME_FLAGS_MULTIPLE
Allow multiple d.
Definition: avformat.h:3019
SANE_CHUNK_SIZE
#define SANE_CHUNK_SIZE
Definition: utils.c:55
ffio_limit
int ffio_limit(AVIOContext *s, int size)
Definition: aviobuf.c:1064
av_assert2
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:68
bprint.h
av_malloc
#define av_malloc(s)
Definition: ops_asmgen.c:44
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:48
avio_internal.h
internal.h
ff_parse_opts_from_query_string
int ff_parse_opts_from_query_string(void *obj, const char *str, int allow_unknown)
Set a list of query string options on an object.
Definition: utils.c:643
s
uint8_t s
Definition: llvidencdsp.c:39
AV_CODEC_ID_PCM_F64BE
@ AV_CODEC_ID_PCM_F64BE
Definition: codec_id.h:352
av_toupper
static av_const int av_toupper(int c)
Locale-independent conversion of ASCII characters to uppercase.
Definition: avstring.h:227
av_url_split
void av_url_split(char *proto, int proto_size, char *authorization, int authorization_size, char *hostname, int hostname_size, int *port_ptr, char *path, int path_size, const char *url)
Split a URL string into components.
Definition: utils.c:361
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
AV_CODEC_ID_PCM_S32BE
@ AV_CODEC_ID_PCM_S32BE
Definition: codec_id.h:339
len
int len
Definition: vorbis_enc_data.h:426
av_get_packet
int av_get_packet(AVIOContext *s, AVPacket *pkt, int size)
Allocate and read the payload of a packet and initialize its fields with default values.
Definition: utils.c:98
ff_tls_deinit
void ff_tls_deinit(void)
Definition: network.c:49
tag
uint32_t tag
Definition: movenc.c:2073
ret
ret
Definition: filter_design.txt:187
ff_is_http_proto
int ff_is_http_proto(const char *filename)
Utility function to check if the file uses http or https protocol.
Definition: utils.c:588
ff_bprint_to_codecpar_extradata
int ff_bprint_to_codecpar_extradata(AVCodecParameters *par, struct AVBPrint *buf)
Finalize buf into extradata and set its size appropriately.
Definition: utils.c:593
lowercase
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option keep it simple and lowercase description are in lowercase
Definition: writing_filters.txt:89
pos
unsigned int pos
Definition: spdifenc.c:414
avformat.h
av_bprintf
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition: bprint.c:122
dict.h
AVOption::type
enum AVOptionType type
Definition: opt.h:444
network.h
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
id
enum AVCodecID id
Definition: dts2pts.c:607
avformat_network_deinit
int avformat_network_deinit(void)
Undo the initialization done by avformat_network_init.
Definition: utils.c:579
urldecode.h
avio_read
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:615
ff_parse_key_val_cb
void(* ff_parse_key_val_cb)(void *context, const char *key, int key_len, char **dest, int *dest_len)
Callback function type for ff_parse_key_value.
Definition: internal.h:494
AV_CODEC_ID_PCM_U32LE
@ AV_CODEC_ID_PCM_U32LE
Definition: codec_id.h:340
temp
else temp
Definition: vf_mcdeint.c:275
Windows::Graphics::DirectX::Direct3D11::p
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
Definition: vsrc_gfxcapture_winrt.hpp:53
av_gettime
int64_t av_gettime(void)
Get the current time in microseconds.
Definition: time.c:40
FF_DISABLE_DEPRECATION_WARNINGS
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:66
AV_CODEC_ID_PCM_S32LE
@ AV_CODEC_ID_PCM_S32LE
Definition: codec_id.h:338
mem.h
ff_codec_get_tag
unsigned int ff_codec_get_tag(const AVCodecTag *tags, enum AVCodecID id)
Definition: utils.c:133
AV_CODEC_ID_PCM_U8
@ AV_CODEC_ID_PCM_U8
Definition: codec_id.h:335
av_strdup
#define av_strdup(s)
Definition: ops_asmgen.c:47
AV_CODEC_ID_PCM_F64LE
@ AV_CODEC_ID_PCM_F64LE
Definition: codec_id.h:353
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
AVPacket
This structure stores compressed data.
Definition: packet.h:580
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition: opt.h:326
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
av_dict_set
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:86
AVPacket::pos
int64_t pos
byte position in stream, -1 if unknown
Definition: packet.h:623
avio_find_protocol_name
const char * avio_find_protocol_name(const char *url)
Return the name of the protocol that will handle the passed URL.
Definition: avio.c:663
ff_parse_ntp_time
uint64_t ff_parse_ntp_time(uint64_t ntp_ts)
Parse the NTP time in microseconds (since NTP epoch).
Definition: utils.c:284
AV_CODEC_ID_PCM_U16LE
@ AV_CODEC_ID_PCM_U16LE
Definition: codec_id.h:332
av_strlcpy
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
Definition: avstring.c:85
AV_CODEC_ID_PCM_F32LE
@ AV_CODEC_ID_PCM_F32LE
Definition: codec_id.h:351
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
av_bprint_chars
void av_bprint_chars(AVBPrint *buf, char c, unsigned n)
Append char c n times to a print buffer.
Definition: bprint.c:130
pkt
static AVPacket * pkt
Definition: demux_decode.c:55
avstring.h
av_codec_get_id
enum AVCodecID av_codec_get_id(const AVCodecTag *const *tags, unsigned int tag)
Definition: utils.c:227
AVCodecTag::tag
unsigned int tag
Definition: internal.h:44
ff_alloc_extradata
int ff_alloc_extradata(AVCodecParameters *par, int size)
Allocate extradata with additional AV_INPUT_BUFFER_PADDING_SIZE at end which is always set to 0.
Definition: utils.c:237
AV_CODEC_ID_PCM_S24BE
@ AV_CODEC_ID_PCM_S24BE
Definition: codec_id.h:343
src
#define src
Definition: vp8dsp.c:248
append_packet_chunked
static int append_packet_chunked(AVIOContext *s, AVPacket *pkt, int size)
Definition: utils.c:59