70 #define LICENSE_PREFIX "libavformat license: " 75 #define SANE_CHUNK_SIZE (50000000) 81 int64_t chunk_size =
size;
82 int64_t orig_pos = pkt->
pos;
83 int orig_size = pkt->
size;
87 int prev_size = pkt->
size;
96 read_size =
FFMIN(size, chunk_size);
103 if (ret != read_size) {
114 return pkt->
size > orig_size ? pkt->
size - orig_size : ret;
144 static const struct {
165 "Probe with size=%d, packets=%d detected %s with score=%d\n",
168 for (i = 0; fmt_id_type[i].name; i++) {
169 if (!strcmp(fmt->
name, fmt_id_type[i].name)) {
172 #if FF_API_LAVF_AVCTX 237 (*plast_pktl)->next = pktl;
239 *packet_buffer = pktl;
262 #if FF_API_LAVF_AVCTX 270 if (!st->
internal->need_codec_update)
277 st->
internal->need_codec_update = 0;
303 if ((ret =
init_input(s, filename, &tmp)) < 0)
339 if (id3v2_extra_meta &&
352 #if FF_API_LAVF_AVCTX 353 update_stream_avctx(s);
397 "nothing to probe for stream %d\n", st->
index);
449 if (!pktl || ret ==
AVERROR(EAGAIN))
471 "Dropped corrupted packet (stream = %d)\n",
531 }
else if (codec_framerate.
den * 1000LL > codec_framerate.
num) {
532 *pnum = codec_framerate.
den;
533 *pden = codec_framerate.
num;
549 if (frame_size <= 0 || st->codecpar->sample_rate <= 0)
570 int64_t dts, int64_t
pts)
583 for (; pktl; pktl = pktl->
next) {
608 for (; pktl; pktl = pktl->
next) {
622 for (; pktl; pktl = pktl->
next) {
644 int num, den, presentation_delayed, delay, i;
655 presentation_delayed = 0;
661 presentation_delayed = 1;
673 if (delay == 1 && pkt->
dts == pkt->
pts &&
707 presentation_delayed = 1;
710 "IN delayed:%d pts:%"PRId64
", dts:%"PRId64
" " 711 "cur_dts:%"PRId64
" st:%d pc:%p\n",
716 if ((delay == 0 || (delay == 1 && pc)) &&
718 if (presentation_delayed) {
786 "OUTdelayed:%d/%d pts:%"PRId64
", dts:%"PRId64
" cur_dts:%"PRId64
"\n",
787 presentation_delayed, delay, pkt->
pts, pkt->
dts, st->
cur_dts);
792 #if FF_API_CONVERGENCE_DURATION 804 *pkt_buf = pktl->
next;
822 int ret = 0, got_output = 0;
830 while (size > 0 || (pkt == &
flush_pkt && got_output)) {
835 &out_pkt.
data, &out_pkt.
size, data, size,
843 got_output = !!out_pkt.
size;
861 (
AVRational) { 1, st->internal->avctx->sample_rate },
913 *pkt_buffer = pktl->
next;
915 *pkt_buffer_end =
NULL;
922 int ret = 0, i, got_packet = 0;
951 cur_pkt.
pts < cur_pkt.
dts) {
953 "Invalid timestamps stream=%d, pts=%"PRId64
", " 954 "dts=%"PRId64
", size=%d\n",
960 "ff_read_packet stream=%d, pts=%"PRId64
", dts=%"PRId64
", " 961 "size=%d, duration=%"PRId64
", flags=%d\n",
1007 #if FF_API_LAVF_AVCTX 1008 update_stream_avctx(s);
1013 "read_frame_internal stream=%d, pts=%"PRId64
", dts=%"PRId64
", " 1014 "size=%d, duration=%"PRId64
", flags=%d\n",
1062 if (pktl && ret !=
AVERROR(EAGAIN)) {
1091 int first_audio_index = -1;
1103 if (first_audio_index < 0 &&
1105 first_audio_index = i;
1107 return first_audio_index >= 0 ? first_audio_index : 0;
1165 int *nb_index_entries,
1166 unsigned int *index_entries_allocated_size,
1167 int64_t pos, int64_t timestamp,
1173 if ((
unsigned) *nb_index_entries + 1 >= UINT_MAX /
sizeof(
AVIndexEntry))
1177 index_entries_allocated_size,
1178 (*nb_index_entries + 1) *
1183 *index_entries = entries;
1189 index = (*nb_index_entries)++;
1190 ie = &entries[
index];
1191 assert(index == 0 || ie[-1].timestamp < timestamp);
1193 ie = &entries[
index];
1197 memmove(entries + index + 1, entries + index,
1199 (*nb_index_entries)++;
1200 }
else if (ie->
pos == pos && distance < ie->min_distance)
1219 timestamp, size, distance, flags);
1223 int64_t wanted_timestamp,
int flags)
1232 if (b && entries[b - 1].timestamp < wanted_timestamp)
1238 if (timestamp >= wanted_timestamp)
1240 if (timestamp <= wanted_timestamp)
1246 while (m >= 0 && m < nb_entries &&
1250 if (m == nb_entries)
1258 wanted_timestamp, flags);
1262 int64_t target_ts,
int flags)
1266 int64_t ts_min, ts_max, ts;
1271 if (stream_index < 0)
1280 st = s->
streams[stream_index];
1288 index =
FFMAX(index, 0);
1302 assert(index < st->nb_index_entries);
1310 " dts_max=%"PRId64
"\n", pos_max, pos_limit, ts_max);
1314 pos =
ff_gen_search(s, stream_index, target_ts, pos_min, pos_max, pos_limit,
1329 int64_t pos_min, int64_t pos_max, int64_t pos_limit,
1330 int64_t ts_min, int64_t ts_max,
1331 int flags, int64_t *ts_ret,
1333 int64_t *, int64_t))
1336 int64_t start_pos, filesize;
1343 ts_min = read_timestamp(s, stream_index, &pos_min, INT64_MAX);
1351 pos_max = filesize - 1;
1354 ts_max = read_timestamp(s, stream_index, &pos_max,
1362 int64_t tmp_pos = pos_max + 1;
1363 int64_t tmp_ts = read_timestamp(s, stream_index,
1364 &tmp_pos, INT64_MAX);
1369 if (tmp_pos >= filesize)
1372 pos_limit = pos_max;
1375 if (ts_min > ts_max)
1377 else if (ts_min == ts_max)
1378 pos_limit = pos_min;
1381 while (pos_min < pos_limit) {
1383 " dts_max=%"PRId64
"\n", pos_min, pos_max, ts_min, ts_max);
1384 assert(pos_limit <= pos_max);
1386 if (no_change == 0) {
1387 int64_t approximate_keyframe_distance = pos_max - pos_limit;
1389 pos =
av_rescale(target_ts - ts_min, pos_max - pos_min,
1391 pos_min - approximate_keyframe_distance;
1392 }
else if (no_change == 1) {
1394 pos = (pos_min + pos_limit) >> 1;
1402 else if (pos > pos_limit)
1407 ts = read_timestamp(s, stream_index, &pos, INT64_MAX);
1412 av_log(s,
AV_LOG_TRACE,
"%"PRId64
" %"PRId64
" %"PRId64
" / %"PRId64
" %"PRId64
" %"PRId64
1413 " target:%"PRId64
" limit:%"PRId64
" start:%"PRId64
" noc:%d\n",
1414 pos_min, pos, pos_max, ts_min, ts, ts_max, target_ts,
1415 pos_limit, start_pos, no_change);
1421 if (target_ts <= ts) {
1422 pos_limit = start_pos - 1;
1426 if (target_ts >= ts) {
1435 ts_min = read_timestamp(s, stream_index, &pos_min, INT64_MAX);
1437 ts_max = read_timestamp(s, stream_index, &pos_min, INT64_MAX);
1439 pos, ts_min, target_ts, ts_max);
1445 int64_t pos,
int flags)
1447 int64_t pos_min, pos_max;
1454 else if (pos > pos_max)
1463 int64_t timestamp,
int flags)
1470 st = s->
streams[stream_index];
1474 if (index < 0 && st->nb_index_entries &&
1475 timestamp < st->index_entries[0].timestamp)
1478 if (index < 0 || index == st->nb_index_entries - 1) {
1495 }
while (read_status ==
AVERROR(EAGAIN));
1496 if (read_status < 0)
1521 int64_t timestamp,
int flags)
1533 if (stream_index < 0) {
1535 if (stream_index < 0)
1538 st = s->
streams[stream_index];
1565 int64_t timestamp,
int flags)
1576 int64_t ts, int64_t max_ts,
int flags)
1578 if (min_ts > ts || max_ts < ts)
1600 flags | ((uint64_t) ts - min_ts >
1601 (uint64_t) max_ts - ts
1636 int64_t
start_time, start_time1, end_time, end_time1;
1637 int64_t
duration, duration1, filesize;
1641 start_time = INT64_MAX;
1642 end_time = INT64_MIN;
1643 duration = INT64_MIN;
1649 start_time =
FFMIN(start_time, start_time1);
1651 end_time1 = start_time1 +
1654 end_time =
FFMAX(end_time, end_time1);
1660 duration =
FFMAX(duration, duration1);
1663 if (start_time != INT64_MAX) {
1665 if (end_time != INT64_MIN)
1666 duration =
FFMAX(duration, end_time - start_time);
1668 if (duration != INT64_MIN) {
1735 #define DURATION_MAX_READ_SIZE 250000 1736 #define DURATION_MAX_RETRY 3 1743 int read_size, i, ret;
1745 int64_t filesize, offset,
duration;
1755 "start time is not set in estimate_timings_from_pts\n");
1780 }
while (ret ==
AVERROR(EAGAIN));
1783 read_size += pkt->
size;
1788 duration = end_time = pkt->
pts;
1825 file_size =
FFMAX(0, file_size);
1839 "Estimating duration from bitrate, this may be inaccurate\n");
1855 "stream: start_time: %0.3f duration: %0.3f bitrate=%d kb/s\n",
1898 int got_picture = 1, ret = 0;
1908 #if FF_API_LAVF_AVCTX 1910 codec = st->codec->codec ? st->codec->codec
1925 av_dict_set(options ? options : &thread_opt,
"threads",
"1", 0);
1926 ret =
avcodec_open2(avctx, codec, options ? options : &thread_opt);
1942 while ((pkt.
size > 0 || (!pkt.
data && got_picture)) &&
1987 if (tag == tags[i].tag)
2008 if (sflags & (1 << (bps - 1))) {
2041 for (i = 0; tags && tags[i]; i++) {
2052 for (i = 0; tags && tags[i]; i++) {
2077 if (j != i && next_start > ch->
start && next_start < end)
2080 ch->
end = (end == INT64_MAX) ? ch->
start : end;
2087 return (i + 1) * 1001;
2089 return ((
const int[]) { 24, 30, 60, 12, 15 })[i - 60 * 12] * 1000 * 12;
2094 int i, count, ret, read_size, j;
2116 #if FF_API_LAVF_AVCTX 2130 goto find_stream_info_err;
2135 #if FF_API_LAVF_AVCTX 2137 codec = st->codec->codec ? st->codec->codec
2146 av_dict_set(options ? &options[i] : &thread_opt,
"threads",
"1", 0);
2150 && codec && !avctx->
codec)
2152 options ? &options[i] : &thread_opt);
2156 if (codec && !avctx->
codec)
2158 options ? &options[i] : &thread_opt);
2180 int fps_analyze_framecount = 20;
2189 fps_analyze_framecount *= 2;
2220 "Probe buffer size limit %d reached\n", ic->
probesize);
2245 (options && i < orig_nb_streams)
2246 ? &options[i] :
NULL);
2252 "decoding for stream %d failed\n", st->
index);
2257 "Could not find codec parameters (%s)\n", buf);
2271 goto find_stream_info_err;
2274 read_size += pkt->
size;
2281 goto find_stream_info_err;
2290 "Non-increasing DTS in stream %d: packet %d with DTS " 2291 "%"PRId64
", packet %d with DTS %"PRId64
"\n",
2307 "DTS discontinuity in stream %d: packet %d with DTS " 2308 "%"PRId64
", packet %d with DTS %"PRId64
"\n",
2357 (options && i < orig_nb_streams) ? &options[i] :
NULL);
2378 double best_error = 0.01;
2395 if (error < best_error) {
2397 best_fps = std_fps.
num;
2402 best_fps, 12 * 1001, INT_MAX);
2439 goto find_stream_info_err;
2441 #if FF_API_LAVF_AVCTX 2445 goto find_stream_info_err;
2449 if (!st->codec->subtitle_header)
2450 goto find_stream_info_err;
2453 st->codec->subtitle_header_size);
2463 find_stream_info_err:
2483 int wanted_stream_nb,
int related_stream,
2484 AVCodec **decoder_ret,
int flags)
2488 unsigned *program =
NULL;
2491 if (related_stream >= 0 && wanted_stream_nb < 0) {
2498 for (i = 0; i < nb_streams; i++) {
2499 int real_stream_index = program ? program[i] : i;
2504 if (wanted_stream_nb >= 0 && real_stream_index != wanted_stream_nb)
2520 ret = real_stream_index;
2522 if (program && i == nb_streams - 1 && ret < 0) {
2530 *decoder_ret = best_decoder;
2581 #if FF_API_LAVF_AVCTX 2583 av_free(st->codec->extradata);
2584 av_free(st->codec->subtitle_header);
2667 #if FF_API_LAVF_AVCTX 2683 #if FF_API_LAVF_AVCTX 2686 st->codec->bit_rate = 0;
2724 #if FF_API_LAVF_AVCTX 2725 st->
internal->need_codec_update = 1;
2759 int64_t start, int64_t end,
const char *title)
2777 chapter->
start = start;
2820 char *q, buf1[20], c;
2821 int nd,
len, percentd_found;
2834 nd = nd * 10 + *p++ -
'0';
2845 snprintf(buf1,
sizeof(buf1),
"%0*d", nd, number);
2847 if ((q - buf + len) > buf_size - 1)
2849 memcpy(q, buf1, len);
2857 if ((q - buf) < buf_size - 1)
2861 if (!percentd_found)
2871 char *authorization,
int authorization_size,
2872 char *hostname,
int hostname_size,
2873 int *port_ptr,
char *path,
int path_size,
const char *url)
2875 const char *p, *ls, *at, *col, *brk;
2881 if (authorization_size > 0)
2882 authorization[0] = 0;
2883 if (hostname_size > 0)
2889 if ((p = strchr(url,
':'))) {
2903 ls = strchr(p,
'/');
2905 ls = strchr(p,
'?');
2914 if ((at = strchr(p,
'@')) && at < ls) {
2916 FFMIN(authorization_size, at + 1 - p));
2920 if (*p ==
'[' && (brk = strchr(p,
']')) && brk < ls) {
2923 FFMIN(hostname_size, brk - p));
2924 if (brk[1] ==
':' && port_ptr)
2925 *port_ptr = atoi(brk + 2);
2926 }
else if ((col = strchr(p,
':')) && col < ls) {
2928 FFMIN(col + 1 - p, hostname_size));
2930 *port_ptr = atoi(col + 1);
2933 FFMIN(ls + 1 - p, hostname_size));
2940 static const char hex_table_uc[16] = {
'0',
'1',
'2',
'3',
2943 'C',
'D',
'E',
'F' };
2944 static const char hex_table_lc[16] = {
'0',
'1',
'2',
'3',
2947 'c',
'd',
'e',
'f' };
2948 const char *hex_table = lowercase ? hex_table_lc : hex_table_uc;
2950 for (i = 0; i < s; i++) {
2951 buff[i * 2] = hex_table[src[i] >> 4];
2952 buff[i * 2 + 1] = hex_table[src[i] & 0xF];
2969 if (c >=
'0' && c <=
'9')
2971 else if (c >=
'A' && c <=
'F')
2987 unsigned int pts_num,
unsigned int pts_den)
2991 if (new_tb.
num != pts_num)
2993 "st:%d removing common factor %d from timebase\n",
2997 "st:%d has too large timebase, reducing\n", s->
index);
2999 if (new_tb.
num <= 0 || new_tb.
den <= 0) {
3001 "Ignoring attempt to set invalid timebase for st:%d\n",
3012 const char *ptr = str;
3017 char *dest =
NULL, *dest_end;
3018 int key_len, dest_len = 0;
3021 while (*ptr && (
av_isspace(*ptr) || *ptr ==
','))
3028 if (!(ptr = strchr(key,
'=')))
3031 key_len = ptr - key;
3033 callback_get_buf(context, key, key_len, &dest, &dest_len);
3034 dest_end = dest + dest_len - 1;
3038 while (*ptr && *ptr !=
'\"') {
3042 if (dest && dest < dest_end)
3046 if (dest && dest < dest_end)
3054 for (; *ptr && !(
av_isspace(*ptr) || *ptr ==
','); ptr++)
3055 if (dest && dest < dest_end)
3074 struct tm time1 = { 0 }, time2 = { 0 };
3075 const char *ret1, *ret2;
3089 return ofmt->
query_codec(codec_id, std_compliance);
3122 uint64_t channel_layout,
int32_t sample_rate,
3134 if (channel_layout) {
3142 if (width || height) {
3149 bytestream_put_le32(&data, flags);
3151 bytestream_put_le32(&data, channels);
3153 bytestream_put_le64(&data, channel_layout);
3155 bytestream_put_le32(&data, sample_rate);
3156 if (width || height) {
3157 bytestream_put_le32(&data, width);
3158 bytestream_put_le32(&data, height);
3165 static const uint8_t avci100_1080p_extradata[] = {
3167 0x00, 0x00, 0x00, 0x01, 0x67, 0x7a, 0x10, 0x29,
3168 0xb6, 0xd4, 0x20, 0x22, 0x33, 0x19, 0xc6, 0x63,
3169 0x23, 0x21, 0x01, 0x11, 0x98, 0xce, 0x33, 0x19,
3170 0x18, 0x21, 0x02, 0x56, 0xb9, 0x3d, 0x7d, 0x7e,
3171 0x4f, 0xe3, 0x3f, 0x11, 0xf1, 0x9e, 0x08, 0xb8,
3172 0x8c, 0x54, 0x43, 0xc0, 0x78, 0x02, 0x27, 0xe2,
3173 0x70, 0x1e, 0x30, 0x10, 0x10, 0x14, 0x00, 0x00,
3174 0x03, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0xca,
3175 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3177 0x00, 0x00, 0x00, 0x01, 0x68, 0xce, 0x33, 0x48,
3180 static const uint8_t avci100_1080i_extradata[] = {
3182 0x00, 0x00, 0x00, 0x01, 0x67, 0x7a, 0x10, 0x29,
3183 0xb6, 0xd4, 0x20, 0x22, 0x33, 0x19, 0xc6, 0x63,
3184 0x23, 0x21, 0x01, 0x11, 0x98, 0xce, 0x33, 0x19,
3185 0x18, 0x21, 0x03, 0x3a, 0x46, 0x65, 0x6a, 0x65,
3186 0x24, 0xad, 0xe9, 0x12, 0x32, 0x14, 0x1a, 0x26,
3187 0x34, 0xad, 0xa4, 0x41, 0x82, 0x23, 0x01, 0x50,
3188 0x2b, 0x1a, 0x24, 0x69, 0x48, 0x30, 0x40, 0x2e,
3189 0x11, 0x12, 0x08, 0xc6, 0x8c, 0x04, 0x41, 0x28,
3190 0x4c, 0x34, 0xf0, 0x1e, 0x01, 0x13, 0xf2, 0xe0,
3191 0x3c, 0x60, 0x20, 0x20, 0x28, 0x00, 0x00, 0x03,
3192 0x00, 0x08, 0x00, 0x00, 0x03, 0x01, 0x94, 0x00,
3194 0x00, 0x00, 0x00, 0x01, 0x68, 0xce, 0x33, 0x48,
3197 static const uint8_t avci50_1080i_extradata[] = {
3199 0x00, 0x00, 0x00, 0x01, 0x67, 0x6e, 0x10, 0x28,
3200 0xa6, 0xd4, 0x20, 0x32, 0x33, 0x0c, 0x71, 0x18,
3201 0x88, 0x62, 0x10, 0x19, 0x19, 0x86, 0x38, 0x8c,
3202 0x44, 0x30, 0x21, 0x02, 0x56, 0x4e, 0x6e, 0x61,
3203 0x87, 0x3e, 0x73, 0x4d, 0x98, 0x0c, 0x03, 0x06,
3204 0x9c, 0x0b, 0x73, 0xe6, 0xc0, 0xb5, 0x18, 0x63,
3205 0x0d, 0x39, 0xe0, 0x5b, 0x02, 0xd4, 0xc6, 0x19,
3206 0x1a, 0x79, 0x8c, 0x32, 0x34, 0x24, 0xf0, 0x16,
3207 0x81, 0x13, 0xf7, 0xff, 0x80, 0x01, 0x80, 0x02,
3208 0x71, 0x80, 0x80, 0x80, 0xa0, 0x00, 0x00, 0x03,
3209 0x00, 0x20, 0x00, 0x00, 0x06, 0x50, 0x80, 0x00,
3211 0x00, 0x00, 0x00, 0x01, 0x68, 0xee, 0x31, 0x12,
3214 static const uint8_t avci100_720p_extradata[] = {
3216 0x00, 0x00, 0x00, 0x01, 0x67, 0x7a, 0x10, 0x29,
3217 0xb6, 0xd4, 0x20, 0x2a, 0x33, 0x1d, 0xc7, 0x62,
3218 0xa1, 0x08, 0x40, 0x54, 0x66, 0x3b, 0x8e, 0xc5,
3219 0x42, 0x02, 0x10, 0x25, 0x64, 0x2c, 0x89, 0xe8,
3220 0x85, 0xe4, 0x21, 0x4b, 0x90, 0x83, 0x06, 0x95,
3221 0xd1, 0x06, 0x46, 0x97, 0x20, 0xc8, 0xd7, 0x43,
3222 0x08, 0x11, 0xc2, 0x1e, 0x4c, 0x91, 0x0f, 0x01,
3223 0x40, 0x16, 0xec, 0x07, 0x8c, 0x04, 0x04, 0x05,
3224 0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x03,
3225 0x00, 0x64, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00,
3227 0x00, 0x00, 0x00, 0x01, 0x68, 0xce, 0x31, 0x12,
3236 data = avci100_1080p_extradata;
3237 size =
sizeof(avci100_1080p_extradata);
3239 data = avci100_1080i_extradata;
3240 size =
sizeof(avci100_1080i_extradata);
3243 data = avci50_1080i_extradata;
3244 size =
sizeof(avci50_1080i_extradata);
3246 data = avci100_720p_extradata;
3247 size =
sizeof(avci100_720p_extradata);
3293 if (sd->
type == type) {
unsigned int nb_chapters
Number of chapters in AVChapter array.
time_t av_timegm(struct tm *tm)
Convert the decomposed UTC time in tm to a time_t value.
unsigned int max_index_size
Maximum amount of memory in bytes to use for the index of each stream.
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.
codec_id is not known (like AV_CODEC_ID_NONE) but lavf should attempt to identify it ...
int(* io_open)(struct AVFormatContext *s, AVIOContext **pb, const char *url, int flags, AVDictionary **options)
A callback for opening new IO streams.
int av_opt_get_dict_val(void *obj, const char *name, int search_flags, AVDictionary **out_val)
const struct AVCodec * codec
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
#define AV_CODEC_PROP_INTRA_ONLY
Codec uses only intra compression.
enum AVFieldOrder field_order
Video only.
int64_t avio_size(AVIOContext *s)
Get the filesize.
static av_const int av_isdigit(int c)
Locale-independent conversion of ASCII isdigit.
This structure describes decoded (raw) audio or video data.
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
#define LIBAV_CONFIGURATION
int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, int size, int distance, int flags)
Add an index entry into a sorted list.
int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd)
Rescale a 64-bit integer with specified rounding.
#define AV_LOG_WARNING
Something somehow does not look correct.
int64_t pos
byte position in stream, -1 if unknown
int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
int64_t pts_buffer[MAX_REORDER_DELAY+1]
static const uint8_t frame_size[4]
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
int index
stream index in AVFormatContext
#define ID3v2_DEFAULT_MAGIC
Default magic bytes for ID3v2 header: "ID3".
av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (%s)\, len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic ? ac->func_descr_generic :ac->func_descr)
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
#define AVIO_FLAG_READ
read-only
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
static av_const int av_isspace(int c)
Locale-independent conversion of ASCII isspace.
AVFormatInternal * internal
An opaque field for libavformat internal usage.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
uint8_t * av_stream_get_side_data(AVStream *st, enum AVPacketSideDataType type, int *size)
Get side information from stream.
void ff_network_close(void)
int event_flags
Flags for the user to detect events happening on the file.
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
int(* split)(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
struct AVStream::@125 * info
int duration
Duration of the current frame.
AVPacketSideData * side_data
An array of side data that applies to the whole stream (i.e.
int ctx_flags
Flags signalling stream properties.
int av_opt_set_dict_val(void *obj, const char *name, const AVDictionary *val, int search_flags)
int ff_id3v2_parse_apic(AVFormatContext *s, ID3v2ExtraMeta **extra_meta)
Create a stream for each APIC (attached picture) extracted from the ID3v2 header. ...
enum AVCodecID subtitle_codec_id
Forced subtitle codec_id.
This struct describes the properties of an encoded stream.
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
enum AVAudioServiceType audio_service_type
Type of service that the audio stream conveys.
unsigned int nb_stream_indexes
int ff_network_inited_globally
#define av_assert0(cond)
assert() equivalent, that is always enabled.
enum AVSampleFormat sample_fmt
audio sample format
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
int ff_network_init(void)
AVCodecParameters * avcodec_parameters_alloc(void)
Allocate a new AVCodecParameters and set its fields to default values (unknown/invalid/0).
unsigned avformat_version(void)
Return the LIBAVFORMAT_VERSION_INT constant.
const char * avformat_license(void)
Return the libavformat license.
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
int id
unique ID to identify the chapter
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
int id
Format-specific stream ID.
enum AVStreamParseType need_parsing
int nb_side_data
The number of elements in the AVStream.side_data array.
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
AVStream ** streams
A list of all streams in the file.
int avcodec_parameters_to_context(AVCodecContext *codec, const AVCodecParameters *par)
Fill the codec context based on the values from the supplied codec parameters.
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
const char * avformat_configuration(void)
Return the libavformat build-time configuration.
static double av_q2d(AVRational a)
Convert rational to double.
int flags
Flags modifying the (de)muxer behaviour.
int av_reallocp(void *ptr, size_t size)
Allocate or reallocate a block of memory.
AVProgram * av_new_program(AVFormatContext *ac, int id)
int avformat_network_init(void)
Do global initialization of network components.
int fps_probe_size
The number of frames used for determining the framerate in avformat_find_stream_info().
#define AVERROR_EOF
End of file.
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
enum AVDiscard discard
selects which program to discard and which to feed to the caller
static AVPacket flush_pkt
unsigned int * stream_index
enum AVCodecID video_codec_id
Forced video codec_id.
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
const OptionDef options[]
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
int av_find_best_stream(AVFormatContext *ic, enum AVMediaType type, int wanted_stream_nb, int related_stream, AVCodec **decoder_ret, int flags)
Find the "best" stream in the file.
av_cold int avcodec_close(AVCodecContext *avctx)
Close a given AVCodecContext and free all the data associated with it (but not the AVCodecContext its...
int avctx_inited
1 if avctx has been initialized with the values from the codec parameters
int max_ts_probe
Maximum number of packets to read while waiting for the first timestamp.
static int64_t start_time
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
AVCodecID
Identify the syntax and semantics of the bitstream.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
AVDictionary * metadata
Metadata that applies to the whole file.
int has_b_frames
Size of the frame reordering buffer in the decoder.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
int64_t pos
Byte position of currently parsed frame in stream.
int av_index_search_timestamp(AVStream *st, int64_t wanted_timestamp, int flags)
Get the index for a specific timestamp.
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
Reallocate the given block if it is not large enough, otherwise do nothing.
struct AVCodecParser * parser
An AV_PKT_DATA_PARAM_CHANGE side data packet is laid out as follows:
unsigned int avpriv_toupper4(unsigned int x)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
int avcodec_is_open(AVCodecContext *s)
int attribute_align_arg avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame)
Return decoded output data from a decoder.
int capabilities
Codec capabilities.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int av_read_play(AVFormatContext *s)
Start playing a network-based stream (e.g.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
preferred ID for decoding MPEG audio layer 1, 2 or 3
enum AVMediaType codec_type
General type of the encoded data.
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
void ff_id3v2_free_extra_meta(ID3v2ExtraMeta **extra_meta)
Free memory allocated parsing special (non-text) metadata.
simple assert() macros that are a bit more flexible than ISO C assert().
enum AVPacketSideDataType type
AVRational avg_frame_rate
Average framerate.
New fields can be added to the end with minor version bumps.
void avcodec_parameters_free(AVCodecParameters **ppar)
Free an AVCodecParameters instance and everything associated with it and write NULL to the supplied p...
int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
This function is the same as av_get_audio_frame_duration(), except it works with AVCodecParameters in...
AVInputFormat * av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max)
Guess the file format.
int min_distance
Minimum distance between this and the previous keyframe, used to avoid unneeded searching.
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.
int flags
A combination of AV_PKT_FLAG values.
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
int extradata_size
Size of the extradata content in bytes.
int avformat_query_codec(const AVOutputFormat *ofmt, enum AVCodecID codec_id, int std_compliance)
Test if the given container can store a codec.
static float distance(float x, float y, int band)
int props
Codec properties, a combination of AV_CODEC_PROP_* flags.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
int bit_rate
The average bitrate of the encoded data (in bits per second).
int buf_size
Size of buf except extra allocated bytes.
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
common internal API header
#define FF_MAX_EXTRADATA_SIZE
Maximum size in bytes of extradata.
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
int64_t fps_first_dts
Those are used for average framerate estimation.
int av_read_pause(AVFormatContext *s)
Pause a network-based stream (e.g.
int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq, enum AVRounding rnd)
Rescale a 64-bit integer by 2 rational numbers with specified rounding.
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
char filename[1024]
input or output filename
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
#define AV_TIME_BASE
Internal time base represented as integer.
enum AVCodecID audio_codec_id
Forced audio codec_id.
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
int av_parser_parse2(AVCodecParserContext *s, AVCodecContext *avctx, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size, int64_t pts, int64_t dts, int64_t pos)
Parse a packet.
static const chunk_decoder decoder[8]
int width
picture width / height.
int64_t offset
byte offset from starting packet start
int av_find_default_stream_index(AVFormatContext *s)
int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt, const char *filename, void *logctx, unsigned int offset, unsigned int max_probe_size)
Probe a bytestream to determine the input format.
internal header for RIFF based (de)muxers do NOT include this in end user applications ...
void av_parser_close(AVCodecParserContext *s)
uint8_t * av_stream_new_side_data(AVStream *st, enum AVPacketSideDataType type, int size)
Allocate new information from stream.
const char * av_small_strptime(const char *p, const char *fmt, struct tm *dt)
Simplified version of strptime.
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
unsigned int probesize
Maximum size of the data read from input for determining the input container format.
preferred ID for MPEG-1/2 video decoding
int av_get_frame_filename(char *buf, int buf_size, const char *path, int number)
Return in 'buf' the path with 'd' replaced by a number.
void ff_id3v2_read(AVFormatContext *s, const char *magic, ID3v2ExtraMeta **extra_meta)
Read an ID3v2 tag, including supported extra metadata.
if(ac->has_optimized_func)
int64_t av_gettime(void)
Get the current time in microseconds.
#define AVERROR_PATCHWELCOME
Not yet implemented in Libav, patches welcome.
int64_t end
chapter start/end time in time_base units
int attribute_align_arg avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
Supply raw packet data as input to a decoder.
int avformat_network_deinit(void)
Undo the initialization done by avformat_network_init.
AVCodecParserContext * av_parser_init(int codec_id)
AVStreamInternal * internal
An opaque field for libavformat internal usage.
enum AVMediaType codec_type
int ff_check_interrupt(AVIOInterruptCB *cb)
Check if the user has requested to interrupt a blocking function associated with cb.
int debug
Flags to enable debugging.
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer...
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
int av_opt_set_dict(void *obj, AVDictionary **options)
int sample_rate
samples per second
AVIOContext * pb
I/O context.
main external API structure.
AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
int av_filename_number_test(const char *filename)
Check whether filename actually is a numbered sequence generator.
void(* io_close)(struct AVFormatContext *s, AVIOContext *pb)
A callback for closing the streams opened with AVFormatContext.io_open().
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Describe the class of an AVClass context structure.
static av_const int av_toupper(int c)
Locale-independent conversion of ASCII characters to uppercase.
rational number numerator/denominator
int avcodec_parameters_from_context(AVCodecParameters *par, const AVCodecContext *codec)
Fill the parameters struct based on the values from the supplied codec context.
int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
This structure contains the data a format has to probe a file.
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
int avio_pause(AVIOContext *h, int pause)
Pause and resume playing - only meaningful if using a network streaming protocol (e.g.
int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
Seek to timestamp ts.
attribute_deprecated int64_t convergence_duration
This struct describes the properties of a single codec described by an AVCodecID. ...
static int64_t pts
Global timestamp for the audio frames.
int64_t start_time
Position of the first frame of the component, in AV_TIME_BASE fractional seconds. ...
int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Seek to the keyframe at timestamp.
int64_t duration
Decoding: duration of the stream, in stream time base.
int sample_rate
Audio only.
AVPacketSideData * side_data
Additional packet data that can be provided by the container.
attribute_deprecated int64_t convergence_duration
void av_opt_free(void *obj)
Free all allocated objects in obj.
#define FF_DISABLE_DEPRECATION_WARNINGS
common internal api header.
struct AVPacketList * next
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
int64_t start_time
Decoding: pts of the first frame of the stream, in stream time base.
int disposition
AV_DISPOSITION_* bit field.
enum AVCodecID orig_codec_id
int pts_wrap_bits
number of bits in pts (used for wrapping control)
AVRational time_base
time base in which the start/end timestamps are specified
#define PARSER_FLAG_COMPLETE_FRAMES
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
int av_grow_packet(AVPacket *pkt, int grow_by)
Increase packet size, correctly zeroing padding.
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
#define AV_PKT_FLAG_CORRUPT
The packet content is corrupted.
int max_analyze_duration
Maximum duration (in AV_TIME_BASE units) of the data read from input in avformat_find_stream_info().
struct AVInputFormat * iformat
The input container format.
void avformat_close_input(AVFormatContext **ps)
Close an opened input AVFormatContext.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
int av_packet_ref(AVPacket *dst, AVPacket *src)
Setup a new reference to the data described by a given packet.
unsigned int index_entries_allocated_size
#define AVERROR_DECODER_NOT_FOUND
Decoder not found.
#define FF_ENABLE_DEPRECATION_WARNINGS
int channels
number of audio channels
struct AVCodecParserContext * parser
void * priv_data
Format private data.
int codec_info_nb_frames
Number of frames that have been demuxed during av_find_stream_info()
#define AVERROR_STREAM_NOT_FOUND
Stream not found.
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
AVCodecContext * avctx
The codec context used by avformat_find_stream_info, the parser, etc.
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
int bit_rate
Total stream bitrate in bit/s, 0 if not available.
int repeat_pict
This field is used for proper frame duration computation in lavf.
int64_t duration
Duration of the stream, in AV_TIME_BASE fractional seconds.
unbuffered private I/O API
AVCodecParameters * codecpar
#define FFSWAP(type, a, b)
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int size)
Allocate new information of a packet.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
AVInputFormat * av_probe_input_format(AVProbeData *pd, int is_opened)
Guess the file format.
This structure stores compressed data.
int key_frame
Set by parser to 1 for key frames and 0 for non-key frames.
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
AVPacket attached_pic
For streams with AV_DISPOSITION_ATTACHED_PIC disposition, this packet will contain the attached pictu...
#define AV_NOPTS_VALUE
Undefined timestamp value.
int64_t av_compare_mod(uint64_t a, uint64_t b, uint64_t mod)
Compare 2 integers modulo mod.
uint8_t * subtitle_header
Header containing style information for text subtitles.