71 #define LICENSE_PREFIX "libavformat license: "
76 #define SANE_CHUNK_SIZE (50000000)
82 int64_t chunk_size =
size;
83 int64_t orig_pos = pkt->
pos;
84 int orig_size = pkt->
size;
88 int prev_size = pkt->
size;
97 read_size =
FFMIN(size, chunk_size);
104 if (ret != read_size) {
115 return pkt->
size > orig_size ? pkt->
size - orig_size : ret;
169 if (score > *score_max) {
172 }
else if (score == *score_max)
179 if (fmt->extensions &&
188 if (fmt->extensions &&
av_match_ext(
"mp3", fmt->extensions)) {
206 static const struct {
226 "Probe with size=%d, packets=%d detected %s with score=%d\n",
229 for (i = 0; fmt_id_type[i].name; i++) {
230 if (!strcmp(fmt->
name, fmt_id_type[i].name)) {
244 #define PROBE_BUF_MIN 2048
245 #define PROBE_BUF_MAX (1 << 20)
248 const char *filename,
void *logctx,
249 unsigned int offset,
unsigned int max_probe_size)
253 int ret = 0, probe_size;
262 if (offset >= max_probe_size)
265 max_probe_size -= offset;
267 for (probe_size =
PROBE_BUF_MIN; probe_size <= max_probe_size && !*fmt;
268 probe_size =
FFMIN(probe_size << 1,
269 FFMAX(max_probe_size, probe_size + 1))) {
296 "Format detected only with low score of %d, "
297 "misdetection possible!\n", score);
300 "Probed with size=%d and score=%d\n", probe_size, score);
354 (*plast_pktl)->next = pktl;
356 *packet_buffer = pktl;
400 if ((ret =
init_input(s, filename, &tmp)) < 0)
436 if (id3v2_extra_meta &&
487 "nothing to probe for stream %d\n", st->
index);
539 if (!pktl || ret ==
AVERROR(EAGAIN))
553 "Dropped corrupted packet (stream = %d)\n",
647 if (frame_size <= 0 || st->codec->sample_rate <= 0)
668 int64_t dts, int64_t pts)
681 for (; pktl; pktl = pktl->
next) {
706 for (; pktl; pktl = pktl->
next) {
720 for (; pktl; pktl = pktl->
next) {
742 int num, den, presentation_delayed, delay, i;
753 presentation_delayed = 0;
759 presentation_delayed = 1;
771 if (delay == 1 && pkt->
dts == pkt->
pts &&
805 presentation_delayed = 1;
808 "IN delayed:%d pts:%"PRId64
", dts:%"PRId64
" "
809 "cur_dts:%"PRId64
" st:%d pc:%p\n",
814 if ((delay == 0 || (delay == 1 && pc)) &&
816 if (presentation_delayed) {
884 "OUTdelayed:%d/%d pts:%"PRId64
", dts:%"PRId64
" cur_dts:%"PRId64
"\n",
885 presentation_delayed, delay, pkt->
pts, pkt->
dts, st->
cur_dts);
898 *pkt_buf = pktl->
next;
916 int ret = 0, got_output = 0;
924 while (size > 0 || (pkt == &
flush_pkt && got_output)) {
929 &out_pkt.
data, &out_pkt.
size, data, size,
937 got_output = !!out_pkt.
size;
989 #if FF_API_DESTRUCT_PACKET
1025 *pkt_buffer = pktl->
next;
1027 *pkt_buffer_end =
NULL;
1034 int ret = 0, i, got_packet = 0;
1062 cur_pkt.
pts < cur_pkt.
dts) {
1064 "Invalid timestamps stream=%d, pts=%"PRId64
", "
1065 "dts=%"PRId64
", size=%d\n",
1071 "ff_read_packet stream=%d, pts=%"PRId64
", dts=%"PRId64
", "
1072 "size=%d, duration=%d, flags=%d\n",
1112 "read_frame_internal stream=%d, pts=%"PRId64
", dts=%"PRId64
", "
1113 "size=%d, duration=%d, flags=%d\n",
1161 if (pktl && ret !=
AVERROR(EAGAIN)) {
1189 int first_audio_index = -1;
1201 if (first_audio_index < 0 &&
1203 first_audio_index = i;
1205 return first_audio_index >= 0 ? first_audio_index : 0;
1263 int *nb_index_entries,
1264 unsigned int *index_entries_allocated_size,
1265 int64_t pos, int64_t timestamp,
1271 if ((
unsigned) *nb_index_entries + 1 >= UINT_MAX /
sizeof(
AVIndexEntry))
1275 index_entries_allocated_size,
1276 (*nb_index_entries + 1) *
1281 *index_entries = entries;
1287 index = (*nb_index_entries)++;
1288 ie = &entries[
index];
1289 assert(index == 0 || ie[-1].timestamp < timestamp);
1291 ie = &entries[
index];
1295 memmove(entries + index + 1, entries + index,
1297 (*nb_index_entries)++;
1298 }
else if (ie->
pos == pos && distance < ie->min_distance)
1317 timestamp, size, distance, flags);
1321 int64_t wanted_timestamp,
int flags)
1330 if (b && entries[b - 1].timestamp < wanted_timestamp)
1336 if (timestamp >= wanted_timestamp)
1338 if (timestamp <= wanted_timestamp)
1344 while (m >= 0 && m < nb_entries &&
1348 if (m == nb_entries)
1356 wanted_timestamp, flags);
1360 int64_t target_ts,
int flags)
1364 int64_t ts_min, ts_max, ts;
1369 if (stream_index < 0)
1372 av_dlog(s,
"read_seek: %d %"PRId64
"\n", stream_index, target_ts);
1378 st = s->
streams[stream_index];
1386 index =
FFMAX(index, 0);
1392 av_dlog(s,
"using cached pos_min=0x%"PRIx64
" dts_min=%"PRId64
"\n",
1400 assert(index < st->nb_index_entries);
1407 av_dlog(s,
"using cached pos_max=0x%"PRIx64
" pos_limit=0x%"PRIx64
1408 " dts_max=%"PRId64
"\n", pos_max, pos_limit, ts_max);
1412 pos =
ff_gen_search(s, stream_index, target_ts, pos_min, pos_max, pos_limit,
1427 int64_t pos_min, int64_t pos_max, int64_t pos_limit,
1428 int64_t ts_min, int64_t ts_max,
1429 int flags, int64_t *ts_ret,
1431 int64_t *, int64_t))
1434 int64_t start_pos, filesize;
1437 av_dlog(s,
"gen_seek: %d %"PRId64
"\n", stream_index, target_ts);
1441 ts_min = read_timestamp(s, stream_index, &pos_min, INT64_MAX);
1449 pos_max = filesize - 1;
1452 ts_max = read_timestamp(s, stream_index, &pos_max,
1460 int64_t tmp_pos = pos_max + 1;
1461 int64_t tmp_ts = read_timestamp(s, stream_index,
1462 &tmp_pos, INT64_MAX);
1467 if (tmp_pos >= filesize)
1470 pos_limit = pos_max;
1473 if (ts_min > ts_max)
1475 else if (ts_min == ts_max)
1476 pos_limit = pos_min;
1479 while (pos_min < pos_limit) {
1480 av_dlog(s,
"pos_min=0x%"PRIx64
" pos_max=0x%"PRIx64
" dts_min=%"PRId64
1481 " dts_max=%"PRId64
"\n", pos_min, pos_max, ts_min, ts_max);
1482 assert(pos_limit <= pos_max);
1484 if (no_change == 0) {
1485 int64_t approximate_keyframe_distance = pos_max - pos_limit;
1487 pos =
av_rescale(target_ts - ts_min, pos_max - pos_min,
1489 pos_min - approximate_keyframe_distance;
1490 }
else if (no_change == 1) {
1492 pos = (pos_min + pos_limit) >> 1;
1500 else if (pos > pos_limit)
1505 ts = read_timestamp(s, stream_index, &pos, INT64_MAX);
1510 av_dlog(s,
"%"PRId64
" %"PRId64
" %"PRId64
" / %"PRId64
" %"PRId64
" %"PRId64
1511 " target:%"PRId64
" limit:%"PRId64
" start:%"PRId64
" noc:%d\n",
1512 pos_min, pos, pos_max, ts_min, ts, ts_max, target_ts,
1513 pos_limit, start_pos, no_change);
1519 if (target_ts <= ts) {
1520 pos_limit = start_pos - 1;
1524 if (target_ts >= ts) {
1533 ts_min = read_timestamp(s, stream_index, &pos_min, INT64_MAX);
1535 ts_max = read_timestamp(s, stream_index, &pos_min, INT64_MAX);
1536 av_dlog(s,
"pos=0x%"PRIx64
" %"PRId64
"<=%"PRId64
"<=%"PRId64
"\n",
1537 pos, ts_min, target_ts, ts_max);
1543 int64_t pos,
int flags)
1545 int64_t pos_min, pos_max;
1552 else if (pos > pos_max)
1561 int64_t timestamp,
int flags)
1568 st = s->
streams[stream_index];
1572 if (index < 0 && st->nb_index_entries &&
1573 timestamp < st->index_entries[0].timestamp)
1576 if (index < 0 || index == st->nb_index_entries - 1) {
1593 }
while (read_status ==
AVERROR(EAGAIN));
1594 if (read_status < 0)
1619 int64_t timestamp,
int flags)
1631 if (stream_index < 0) {
1633 if (stream_index < 0)
1636 st = s->
streams[stream_index];
1663 int64_t timestamp,
int flags)
1674 int64_t ts, int64_t max_ts,
int flags)
1676 if (min_ts > ts || max_ts < ts)
1698 flags | ((uint64_t) ts - min_ts >
1699 (uint64_t) max_ts - ts
1734 int64_t
start_time, start_time1, end_time, end_time1;
1735 int64_t
duration, duration1, filesize;
1739 start_time = INT64_MAX;
1740 end_time = INT64_MIN;
1741 duration = INT64_MIN;
1747 start_time =
FFMIN(start_time, start_time1);
1749 end_time1 = start_time1 +
1752 end_time =
FFMAX(end_time, end_time1);
1758 duration =
FFMAX(duration, duration1);
1761 if (start_time != INT64_MAX) {
1763 if (end_time != INT64_MIN)
1764 duration =
FFMAX(duration, end_time - start_time);
1766 if (duration != INT64_MIN) {
1833 #define DURATION_MAX_READ_SIZE 250000
1834 #define DURATION_MAX_RETRY 3
1841 int read_size, i, ret;
1843 int64_t filesize, offset,
duration;
1853 "start time is not set in estimate_timings_from_pts\n");
1878 }
while (ret ==
AVERROR(EAGAIN));
1881 read_size += pkt->
size;
1886 duration = end_time = pkt->
pts;
1923 file_size =
FFMAX(0, file_size);
1937 "Estimating duration from bitrate, this may be inaccurate\n");
1948 av_dlog(ic,
"%d: start_time: %0.3f duration: %0.3f\n", i,
1953 "stream: start_time: %0.3f duration: %0.3f bitrate=%d kb/s\n",
1995 int got_picture = 1, ret = 0;
2016 av_dict_set(options ? options : &thread_opt,
"threads",
"1", 0);
2033 while ((pkt.
size > 0 || (!pkt.
data && got_picture)) &&
2042 &got_picture, &pkt);
2078 if (tag == tags[i].tag)
2099 if (sflags & (1 << (bps - 1))) {
2132 for (i = 0; tags && tags[i]; i++) {
2143 for (i = 0; tags && tags[i]; i++) {
2168 if (j != i && next_start > ch->
start && next_start < end)
2171 ch->
end = (end == INT64_MAX) ? ch->
start : end;
2178 return (i + 1) * 1001;
2180 return ((
const int[]) { 24, 30, 60, 12, 15 })[i - 60 * 12] * 1000 * 12;
2203 int i, count, ret, read_size, j;
2226 av_dict_set(options ? &options[i] : &thread_opt,
"threads",
"1", 0);
2232 options ? &options[i] : &thread_opt);
2238 options ? &options[i] : &thread_opt);
2260 int fps_analyze_framecount = 20;
2269 fps_analyze_framecount *= 2;
2299 "Probe buffer size limit %d reached\n", ic->
probesize);
2324 (options && i < orig_nb_streams)
2325 ? &options[i] :
NULL);
2331 "decoding for stream %d failed\n", st->
index);
2336 "Could not find codec parameters (%s)\n", buf);
2350 goto find_stream_info_err;
2353 read_size += pkt->
size;
2361 "Non-increasing DTS in stream %d: packet %d with DTS "
2362 "%"PRId64
", packet %d with DTS %"PRId64
"\n",
2378 "DTS discontinuity in stream %d: packet %d with DTS "
2379 "%"PRId64
", packet %d with DTS %"PRId64
"\n",
2427 (options && i < orig_nb_streams) ? &options[i] :
NULL);
2449 double best_error = 0.01;
2466 if (error < best_error) {
2468 best_fps = std_fps.
num;
2473 best_fps, 12 * 1001, INT_MAX);
2504 find_stream_info_err:
2524 int wanted_stream_nb,
int related_stream,
2525 AVCodec **decoder_ret,
int flags)
2529 unsigned *program =
NULL;
2532 if (related_stream >= 0 && wanted_stream_nb < 0) {
2539 for (i = 0; i < nb_streams; i++) {
2540 int real_stream_index = program ? program[i] : i;
2545 if (wanted_stream_nb >= 0 && real_stream_index != wanted_stream_nb)
2561 ret = real_stream_index;
2563 if (program && i == nb_streams - 1 && ret < 0) {
2571 *decoder_ret = best_decoder;
2716 av_dlog(ac,
"new_program: id=0x%04x\n",
id);
2735 int64_t start, int64_t end,
const char *title)
2753 chapter->
start = start;
2790 uint64_t v =
lrintf(d * 100);
2793 else if (v % (100 * 1000))
2806 if (strcmp(
"language", tag->
key))
2808 "%s %-16s: %s\n", indent, tag->
key, tag->
value);
2814 int index,
int is_output)
2841 display_aspect_ratio.
num, display_aspect_ratio.
den);
2876 const char *url,
int is_output)
2884 is_output ?
"Output" :
"Input",
2887 is_output ?
"to" :
"from", url);
2892 int hours, mins, secs, us;
2930 int j, k, total = 0;
2935 name ? name->
value :
"");
2944 if (total < ic->nb_streams)
2962 char *q, buf1[20], c;
2963 int nd,
len, percentd_found;
2976 nd = nd * 10 + *p++ -
'0';
2987 snprintf(buf1,
sizeof(buf1),
"%0*d", nd, number);
2989 if ((q - buf + len) > buf_size - 1)
2991 memcpy(q, buf1, len);
2999 if ((q - buf) < buf_size - 1)
3003 if (!percentd_found)
3012 #define HEXDUMP_PRINT(...) \
3015 av_log(avcl, level, __VA_ARGS__); \
3017 fprintf(f, __VA_ARGS__); \
3025 for (i = 0; i <
size; i += 16) {
3030 for (j = 0; j < 16; j++) {
3037 for (j = 0; j <
len; j++) {
3039 if (c < ' ' || c >
'~')
3093 char *authorization,
int authorization_size,
3094 char *hostname,
int hostname_size,
3095 int *port_ptr,
char *path,
int path_size,
const char *url)
3097 const char *p, *ls, *at, *col, *brk;
3103 if (authorization_size > 0)
3104 authorization[0] = 0;
3105 if (hostname_size > 0)
3111 if ((p = strchr(url,
':'))) {
3125 ls = strchr(p,
'/');
3127 ls = strchr(p,
'?');
3136 if ((at = strchr(p,
'@')) && at < ls) {
3138 FFMIN(authorization_size, at + 1 - p));
3142 if (*p ==
'[' && (brk = strchr(p,
']')) && brk < ls) {
3145 FFMIN(hostname_size, brk - p));
3146 if (brk[1] ==
':' && port_ptr)
3147 *port_ptr = atoi(brk + 2);
3148 }
else if ((col = strchr(p,
':')) && col < ls) {
3150 FFMIN(col + 1 - p, hostname_size));
3152 *port_ptr = atoi(col + 1);
3155 FFMIN(ls + 1 - p, hostname_size));
3162 static const char hex_table_uc[16] = {
'0',
'1',
'2',
'3',
3165 'C',
'D',
'E',
'F' };
3166 static const char hex_table_lc[16] = {
'0',
'1',
'2',
'3',
3169 'c',
'd',
'e',
'f' };
3170 const char *hex_table = lowercase ? hex_table_lc : hex_table_uc;
3172 for (i = 0; i < s; i++) {
3173 buff[i * 2] = hex_table[src[i] >> 4];
3174 buff[i * 2 + 1] = hex_table[src[i] & 0xF];
3191 if (c >=
'0' && c <=
'9')
3193 else if (c >=
'A' && c <=
'F')
3209 unsigned int pts_num,
unsigned int pts_den)
3213 if (new_tb.
num != pts_num)
3215 "st:%d removing common factor %d from timebase\n",
3219 "st:%d has too large timebase, reducing\n", s->
index);
3221 if (new_tb.
num <= 0 || new_tb.
den <= 0) {
3223 "Ignoring attempt to set invalid timebase for st:%d\n",
3234 const char *ptr = str;
3239 char *dest =
NULL, *dest_end;
3240 int key_len, dest_len = 0;
3243 while (*ptr && (
av_isspace(*ptr) || *ptr ==
','))
3250 if (!(ptr = strchr(key,
'=')))
3253 key_len = ptr - key;
3255 callback_get_buf(context, key, key_len, &dest, &dest_len);
3256 dest_end = dest + dest_len - 1;
3260 while (*ptr && *ptr !=
'\"') {
3264 if (dest && dest < dest_end)
3268 if (dest && dest < dest_end)
3276 for (; *ptr && !(
av_isspace(*ptr) || *ptr ==
','); ptr++)
3277 if (dest && dest < dest_end)
3297 struct tm time1 = { 0 }, time2 = { 0 };
3299 ret1 = strptime(datestr,
"%Y - %m - %d %T", &time1);
3300 ret2 = strptime(datestr,
"%Y - %m - %dT%T", &time2);
3307 "strptime() unavailable on this system, cannot convert "
3308 "the date string.\n");
3318 return ofmt->
query_codec(codec_id, std_compliance);
3351 uint64_t channel_layout,
int32_t sample_rate,
3363 if (channel_layout) {
3371 if (width || height) {
3378 bytestream_put_le32(&data, flags);
3380 bytestream_put_le32(&data, channels);
3382 bytestream_put_le64(&data, channel_layout);
3384 bytestream_put_le32(&data, sample_rate);
3385 if (width || height) {
3386 bytestream_put_le32(&data, width);
3387 bytestream_put_le32(&data, height);
3394 static const uint8_t avci100_1080p_extradata[] = {
3396 0x00, 0x00, 0x00, 0x01, 0x67, 0x7a, 0x10, 0x29,
3397 0xb6, 0xd4, 0x20, 0x22, 0x33, 0x19, 0xc6, 0x63,
3398 0x23, 0x21, 0x01, 0x11, 0x98, 0xce, 0x33, 0x19,
3399 0x18, 0x21, 0x02, 0x56, 0xb9, 0x3d, 0x7d, 0x7e,
3400 0x4f, 0xe3, 0x3f, 0x11, 0xf1, 0x9e, 0x08, 0xb8,
3401 0x8c, 0x54, 0x43, 0xc0, 0x78, 0x02, 0x27, 0xe2,
3402 0x70, 0x1e, 0x30, 0x10, 0x10, 0x14, 0x00, 0x00,
3403 0x03, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0xca,
3404 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3406 0x00, 0x00, 0x00, 0x01, 0x68, 0xce, 0x33, 0x48,
3409 static const uint8_t avci100_1080i_extradata[] = {
3411 0x00, 0x00, 0x00, 0x01, 0x67, 0x7a, 0x10, 0x29,
3412 0xb6, 0xd4, 0x20, 0x22, 0x33, 0x19, 0xc6, 0x63,
3413 0x23, 0x21, 0x01, 0x11, 0x98, 0xce, 0x33, 0x19,
3414 0x18, 0x21, 0x03, 0x3a, 0x46, 0x65, 0x6a, 0x65,
3415 0x24, 0xad, 0xe9, 0x12, 0x32, 0x14, 0x1a, 0x26,
3416 0x34, 0xad, 0xa4, 0x41, 0x82, 0x23, 0x01, 0x50,
3417 0x2b, 0x1a, 0x24, 0x69, 0x48, 0x30, 0x40, 0x2e,
3418 0x11, 0x12, 0x08, 0xc6, 0x8c, 0x04, 0x41, 0x28,
3419 0x4c, 0x34, 0xf0, 0x1e, 0x01, 0x13, 0xf2, 0xe0,
3420 0x3c, 0x60, 0x20, 0x20, 0x28, 0x00, 0x00, 0x03,
3421 0x00, 0x08, 0x00, 0x00, 0x03, 0x01, 0x94, 0x00,
3423 0x00, 0x00, 0x00, 0x01, 0x68, 0xce, 0x33, 0x48,
3426 static const uint8_t avci50_1080i_extradata[] = {
3428 0x00, 0x00, 0x00, 0x01, 0x67, 0x6e, 0x10, 0x28,
3429 0xa6, 0xd4, 0x20, 0x32, 0x33, 0x0c, 0x71, 0x18,
3430 0x88, 0x62, 0x10, 0x19, 0x19, 0x86, 0x38, 0x8c,
3431 0x44, 0x30, 0x21, 0x02, 0x56, 0x4e, 0x6e, 0x61,
3432 0x87, 0x3e, 0x73, 0x4d, 0x98, 0x0c, 0x03, 0x06,
3433 0x9c, 0x0b, 0x73, 0xe6, 0xc0, 0xb5, 0x18, 0x63,
3434 0x0d, 0x39, 0xe0, 0x5b, 0x02, 0xd4, 0xc6, 0x19,
3435 0x1a, 0x79, 0x8c, 0x32, 0x34, 0x24, 0xf0, 0x16,
3436 0x81, 0x13, 0xf7, 0xff, 0x80, 0x01, 0x80, 0x02,
3437 0x71, 0x80, 0x80, 0x80, 0xa0, 0x00, 0x00, 0x03,
3438 0x00, 0x20, 0x00, 0x00, 0x06, 0x50, 0x80, 0x00,
3440 0x00, 0x00, 0x00, 0x01, 0x68, 0xee, 0x31, 0x12,
3443 static const uint8_t avci100_720p_extradata[] = {
3445 0x00, 0x00, 0x00, 0x01, 0x67, 0x7a, 0x10, 0x29,
3446 0xb6, 0xd4, 0x20, 0x2a, 0x33, 0x1d, 0xc7, 0x62,
3447 0xa1, 0x08, 0x40, 0x54, 0x66, 0x3b, 0x8e, 0xc5,
3448 0x42, 0x02, 0x10, 0x25, 0x64, 0x2c, 0x89, 0xe8,
3449 0x85, 0xe4, 0x21, 0x4b, 0x90, 0x83, 0x06, 0x95,
3450 0xd1, 0x06, 0x46, 0x97, 0x20, 0xc8, 0xd7, 0x43,
3451 0x08, 0x11, 0xc2, 0x1e, 0x4c, 0x91, 0x0f, 0x01,
3452 0x40, 0x16, 0xec, 0x07, 0x8c, 0x04, 0x04, 0x05,
3453 0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x03,
3454 0x00, 0x64, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00,
3456 0x00, 0x00, 0x00, 0x01, 0x68, 0xce, 0x31, 0x12,
3465 data = avci100_1080p_extradata;
3466 size =
sizeof(avci100_1080p_extradata);
3468 data = avci100_1080i_extradata;
3469 size =
sizeof(avci100_1080i_extradata);
3472 data = avci50_1080i_extradata;
3473 size =
sizeof(avci50_1080i_extradata);
3475 data = avci100_720p_extradata;
3476 size =
sizeof(avci100_720p_extradata);