63 return LIBAV_CONFIGURATION;
68 #define LICENSE_PREFIX "libavformat license: "
115 }
else if (num >= den) {
129 if(f)
return f->
next;
135 if(f)
return f->
next;
165 ext = strrchr(filename,
'.');
171 while (*p !=
'\0' && *p !=
',' && q-ext1<
sizeof(ext1)-1)
192 namelen = strlen(name);
193 while ((p = strchr(names,
','))) {
194 len =
FFMAX(p - names, namelen);
203 const char *mime_type)
206 int score_max, score;
209 #if CONFIG_IMAGE2_MUXER
210 if (!short_name && filename &&
221 if (fmt->
name && short_name && !strcmp(fmt->
name, short_name))
229 if (score > score_max) {
238 const char *filename,
const char *mime_type,
enum AVMediaType type){
242 #if CONFIG_IMAGE2_MUXER
243 if(!strcmp(fmt->
name,
"image2") || !strcmp(fmt->
name,
"image2pipe")){
293 old_size = pkt->
size;
336 if (score > *score_max) {
339 }
else if (score == *score_max)
354 if (fmt->extensions &&
av_match_ext(
"mp3", fmt->extensions)) {
370 static const struct {
389 for (i = 0; fmt_id_type[i].name; i++) {
390 if (!strcmp(fmt->
name, fmt_id_type[i].name)) {
403 #if FF_API_FORMAT_PARAMETERS
412 if (ap->time_base.num) {
413 snprintf(buf,
sizeof(buf),
"%d/%d", ap->time_base.den, ap->time_base.num);
416 if (ap->sample_rate) {
417 snprintf(buf,
sizeof(buf),
"%d", ap->sample_rate);
421 snprintf(buf,
sizeof(buf),
"%d", ap->channels);
424 if (ap->width || ap->height) {
425 snprintf(buf,
sizeof(buf),
"%dx%d", ap->width, ap->height);
432 snprintf(buf,
sizeof(buf),
"%d", ap->channel);
438 if (ap->mpeg2ts_compute_pcr) {
441 if (ap->initial_pause) {
461 memset(ap, 0,
sizeof(default_ap));
463 opts = convert_format_parameters(ap);
465 if(!ap->prealloced_context)
475 "will be ignored with AVFMT_NOFILE format.\n");
481 ic->
pb = ic->
pb ? ic->
pb : pb;
491 #define PROBE_BUF_MIN 2048
492 #define PROBE_BUF_MAX (1<<20)
495 const char *filename,
void *logctx,
496 unsigned int offset,
unsigned int max_probe_size)
499 unsigned char *buf =
NULL;
500 int ret = 0, probe_size;
502 if (!max_probe_size) {
510 if (offset >= max_probe_size) {
514 for(probe_size=
PROBE_BUF_MIN; probe_size<=max_probe_size && !*fmt;
515 probe_size =
FFMIN(probe_size<<1,
FFMAX(max_probe_size, probe_size+1))) {
517 int buf_offset = (probe_size ==
PROBE_BUF_MIN) ? 0 : probe_size>>1;
519 if (probe_size < offset) {
525 if ((ret =
avio_read(pb, buf + buf_offset, probe_size - buf_offset)) < 0) {
535 pd.
buf = &buf[offset];
543 av_log(logctx,
AV_LOG_WARNING,
"Format detected only with low score of %d, misdetection possible!\n", score);
545 av_log(logctx,
AV_LOG_DEBUG,
"Probed with size=%d and score=%d\n", probe_size, score);
561 #if FF_API_FORMAT_PARAMETERS
570 if (!ap || !ap->prealloced_context)
625 if ((ret =
init_input(s, filename, &tmp)) < 0)
691 (*plast_pktl)->next = pktl;
693 *packet_buffer = pktl;
727 if (!pktl || ret ==
AVERROR(EAGAIN))
737 "Dropped corrupted packet (stream = %d)\n",
802 if (bits_per_sample) {
805 frame_size = (size << 3) / (bits_per_sample * enc->
channels);
852 if (frame_size <= 0 || st->codec->sample_rate <= 0)
888 int64_t dts, int64_t pts)
899 for(; pktl; pktl= pktl->
next){
923 for(; pktl; pktl= pktl->
next){
935 for(; pktl; pktl= pktl->
next){
955 int num, den, presentation_delayed, delay, i;
970 presentation_delayed = 0;
976 presentation_delayed = 1;
1033 presentation_delayed = 1;
1039 if (presentation_delayed) {
1062 if(old_diff < new_diff && old_diff < (pkt->
duration>>3)){
1206 av_log(s,
AV_LOG_WARNING,
"Invalid timestamps stream=%d, pts=%"PRId64
", dts=%"PRId64
", size=%d\n",
1216 av_log(s,
AV_LOG_DEBUG,
"av_read_packet stream=%d, pts=%"PRId64
", dts=%"PRId64
", size=%d, duration=%d, flags=%d\n",
1241 av_log(s,
AV_LOG_DEBUG,
"read_frame_internal stream=%d, pts=%"PRId64
", dts=%"PRId64
", size=%d, duration=%d, flags=%d\n",
1299 if (pktl && ret !=
AVERROR(EAGAIN)) {
1341 int first_audio_index = -1;
1353 first_audio_index = i;
1355 return first_audio_index >= 0 ? first_audio_index : 0;
1393 #if FF_API_SEEK_PUBLIC
1427 int *nb_index_entries,
1428 unsigned int *index_entries_allocated_size,
1434 if((
unsigned)*nb_index_entries + 1 >= UINT_MAX /
sizeof(
AVIndexEntry))
1438 index_entries_allocated_size,
1439 (*nb_index_entries + 1) *
1444 *index_entries= entries;
1449 index= (*nb_index_entries)++;
1450 ie= &entries[
index];
1451 assert(index==0 || ie[-1].timestamp < timestamp);
1453 ie= &entries[
index];
1457 memmove(entries + index + 1, entries + index,
sizeof(
AVIndexEntry)*(*nb_index_entries - index));
1458 (*nb_index_entries)++;
1459 }
else if(ie->
pos == pos && distance < ie->min_distance)
1477 timestamp, size, distance, flags);
1481 int64_t wanted_timestamp,
int flags)
1490 if(b && entries[b-1].timestamp < wanted_timestamp)
1496 if(timestamp >= wanted_timestamp)
1498 if(timestamp <= wanted_timestamp)
1518 wanted_timestamp, flags);
1521 #if FF_API_SEEK_PUBLIC
1531 int64_t ts_min, ts_max, ts;
1536 if (stream_index < 0)
1539 av_dlog(s,
"read_seek: %d %"PRId64
"\n", stream_index, target_ts);
1550 index=
FFMAX(index, 0);
1556 av_dlog(s,
"using cached pos_min=0x%"PRIx64
" dts_min=%"PRId64
"\n",
1563 assert(index < st->nb_index_entries);
1570 av_dlog(s,
"using cached pos_max=0x%"PRIx64
" pos_limit=0x%"PRIx64
" dts_max=%"PRId64
"\n",
1571 pos_max,pos_limit, ts_max);
1575 pos=
ff_gen_search(s, stream_index, target_ts, pos_min, pos_max, pos_limit, ts_min, ts_max, flags, &ts, avif->
read_timestamp);
1588 #if FF_API_SEEK_PUBLIC
1589 int64_t av_gen_search(
AVFormatContext *s,
int stream_index, int64_t target_ts,
1590 int64_t pos_min, int64_t pos_max, int64_t pos_limit,
1591 int64_t ts_min, int64_t ts_max,
int flags, int64_t *ts_ret,
1592 int64_t (*read_timestamp)(
struct AVFormatContext *,
int , int64_t *, int64_t ))
1594 return ff_gen_search(s, stream_index, target_ts, pos_min, pos_max,
1595 pos_limit, ts_min, ts_max, flags, ts_ret,
1601 int64_t pos_min, int64_t pos_max, int64_t pos_limit,
1602 int64_t ts_min, int64_t ts_max,
int flags, int64_t *ts_ret,
1603 int64_t (*read_timestamp)(
struct AVFormatContext *,
int , int64_t *, int64_t ))
1606 int64_t start_pos, filesize;
1609 av_dlog(s,
"gen_seek: %d %"PRId64
"\n", stream_index, target_ts);
1613 ts_min = read_timestamp(s, stream_index, &pos_min,
INT64_MAX);
1621 pos_max = filesize - 1;
1624 ts_max = read_timestamp(s, stream_index, &pos_max, pos_max + step);
1631 int64_t tmp_pos= pos_max + 1;
1632 int64_t tmp_ts= read_timestamp(s, stream_index, &tmp_pos,
INT64_MAX);
1637 if(tmp_pos >= filesize)
1643 if(ts_min > ts_max){
1645 }
else if(ts_min == ts_max){
1650 while (pos_min < pos_limit) {
1651 av_dlog(s,
"pos_min=0x%"PRIx64
" pos_max=0x%"PRIx64
" dts_min=%"PRId64
" dts_max=%"PRId64
"\n",
1652 pos_min, pos_max, ts_min, ts_max);
1653 assert(pos_limit <= pos_max);
1656 int64_t approximate_keyframe_distance= pos_max - pos_limit;
1658 pos =
av_rescale(target_ts - ts_min, pos_max - pos_min, ts_max - ts_min)
1659 + pos_min - approximate_keyframe_distance;
1660 }
else if(no_change==1){
1662 pos = (pos_min + pos_limit)>>1;
1670 else if(pos > pos_limit)
1674 ts = read_timestamp(s, stream_index, &pos,
INT64_MAX);
1679 av_dlog(s,
"%"PRId64
" %"PRId64
" %"PRId64
" / %"PRId64
" %"PRId64
" %"PRId64
" target:%"PRId64
" limit:%"PRId64
" start:%"PRId64
" noc:%d\n",
1680 pos_min, pos, pos_max, ts_min, ts, ts_max, target_ts,
1681 pos_limit, start_pos, no_change);
1687 if (target_ts <= ts) {
1688 pos_limit = start_pos - 1;
1692 if (target_ts >= ts) {
1701 ts_min = read_timestamp(s, stream_index, &pos_min,
INT64_MAX);
1703 ts_max = read_timestamp(s, stream_index, &pos_min,
INT64_MAX);
1704 av_dlog(s,
"pos=0x%"PRIx64
" %"PRId64
"<=%"PRId64
"<=%"PRId64
"\n",
1705 pos, ts_min, target_ts, ts_max);
1711 int64_t pos_min, pos_max;
1715 if (stream_index < 0)
1724 if (pos < pos_min) pos= pos_min;
1725 else if(pos > pos_max) pos= pos_max;
1730 av_update_cur_dts(s, st, ts);
1736 int stream_index, int64_t timestamp,
int flags)
1743 st = s->
streams[stream_index];
1747 if(index < 0 && st->nb_index_entries && timestamp < st->index_entries[0].timestamp)
1750 if(index < 0 || index==st->nb_index_entries-1){
1767 }
while (read_status ==
AVERROR(EAGAIN));
1768 if (read_status < 0)
1806 if(stream_index < 0){
1808 if(stream_index < 0)
1839 if(min_ts > ts || max_ts < ts)
1886 int64_t
start_time, start_time1, end_time, end_time1;
1887 int64_t
duration, duration1, filesize;
1898 start_time =
FFMIN(start_time, start_time1);
1900 end_time1 = start_time1
1902 end_time =
FFMAX(end_time, end_time1);
1907 duration =
FFMAX(duration, duration1);
1913 duration =
FFMAX(duration, end_time - start_time);
1974 #define DURATION_MAX_READ_SIZE 250000
1975 #define DURATION_MAX_RETRY 3
1982 int read_size, i, ret;
1984 int64_t filesize, offset,
duration;
2021 }
while(ret ==
AVERROR(EAGAIN));
2024 read_size += pkt->
size;
2029 duration = end_time = pkt->
pts;
2067 file_size =
FFMAX(0, file_size);
2091 av_dlog(ic,
"%d: start_time: %0.3f duration: %0.3f\n", i,
2095 av_dlog(ic,
"stream: start_time: %0.3f duration: %0.3f bitrate=%d kb/s\n",
2137 int got_picture = 1, ret = 0;
2152 av_dict_set(options ? options : &thread_opt,
"threads",
"1", 0);
2160 while ((pkt.
size > 0 || (!pkt.
data && got_picture)) &&
2170 &got_picture, &pkt);
2203 if(tag == tags[i].tag)
2216 for(i=0; tags && tags[i]; i++){
2226 for(i=0; tags && tags[i]; i++){
2247 if (j != i && next_start > ch->
start && next_start < end)
2255 if(i<60*12)
return i*1001;
2256 else return ((
const int[]){24,30,60,12,15})[i-60*12]*1000*12;
2279 #if FF_API_FORMAT_PARAMETERS
2288 int i, count, ret, read_size, j;
2318 av_dict_set(options ? &options[i] : &thread_opt,
"threads",
"1", 0);
2351 int fps_analyze_framecount = 20;
2360 fps_analyze_framecount *= 2;
2410 (options && i < orig_nb_streams) ?
2411 &options[i] :
NULL);
2416 "decoding for stream %d failed\n", st->
index);
2421 "Could not find codec parameters (%s)\n", buf);
2431 goto find_stream_info_err;
2433 read_size += pkt->
size;
2456 int ticks=
lrintf(dur*framerate/(1001*12));
2457 double error = dur - (double)ticks*1001*12 / framerate;
2524 if(error < best_error){
2575 if(ppkt1->stream_index != i)
2577 if(ppkt1->pkt->dts < 0)
2592 find_stream_info_err:
2614 int wanted_stream_nb,
2621 unsigned *program =
NULL;
2624 if (related_stream >= 0 && wanted_stream_nb < 0) {
2631 for (i = 0; i < nb_streams; i++) {
2632 int real_stream_index = program ? program[i] : i;
2637 if (wanted_stream_nb >= 0 && real_stream_index != wanted_stream_nb)
2652 ret = real_stream_index;
2654 if (program && i == nb_streams - 1 && ret < 0) {
2661 *decoder_ret = best_decoder;
2685 #if FF_API_FORMAT_PARAMETERS
2737 #if FF_API_CLOSE_INPUT_FILE
2758 #if FF_API_NEW_STREAM
2774 if (s->
nb_streams >= INT_MAX/
sizeof(*streams))
2823 av_dlog(ac,
"new_program: id=0x%04x\n",
id);
2859 chapter->
start = start;
2868 #if FF_API_FORMAT_PARAMETERS
2898 unsigned int tag = 0;
2926 #if FF_API_FORMAT_PARAMETERS
2994 "Tag %s/0x%08x incompatible with output codec id '%d'\n",
3005 av_log(s,
AV_LOG_WARNING,
"Codec for stream %d does not use global headers but container format requires global headers\n", i);
3070 int num, den, frame_size, i;
3072 av_dlog(s,
"compute_pkt_fields2: pts:%"PRId64
" dts:%"PRId64
" cur_dts:%"PRId64
" b:%d size:%d st:%d\n",
3109 "Application provided invalid, non monotonically increasing dts to muxer in stream %d: %"PRId64
" >= %"PRId64
"\n",
3163 this_pktl->
pkt= *pkt;
3174 while(!compare(s, &(*next_point)->pkt, pkt)){
3175 next_point= &(*next_point)->
next;
3182 assert(!*next_point);
3187 this_pktl->
next= *next_point;
3190 *next_point= this_pktl;
3217 if(stream_count && (s->
nb_streams == stream_count || flush)){
3262 av_dlog(s,
"av_interleaved_write_frame size:%d dts:%"PRId64
" pts:%"PRId64
"\n",
3365 if(strcmp(
"language", tag->
key))
3398 display_aspect_ratio.
num, display_aspect_ratio.
den);
3434 #if FF_API_DUMP_FORMAT
3455 is_output ?
"Output" :
"Input",
3458 is_output ?
"to" :
"from", url);
3463 int hours, mins, secs, us;
3500 int j, k, total = 0;
3505 name ? name->
value :
"");
3513 if (total < ic->nb_streams)
3526 gettimeofday(&tv,
NULL);
3527 return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
3535 #if FF_API_PARSE_DATE
3538 int64_t parse_date(
const char *timestr,
int duration)
3546 #if FF_API_FIND_INFO_TAG
3549 int find_info_tag(
char *arg,
int arg_size,
const char *tag1,
const char *info)
3556 const char *path,
int number)
3559 char *q, buf1[20], c;
3560 int nd,
len, percentd_found;
3572 while (isdigit(*p)) {
3573 nd = nd * 10 + *p++ -
'0';
3576 }
while (isdigit(c));
3585 snprintf(buf1,
sizeof(buf1),
"%0*d", nd, number);
3587 if ((q - buf + len) > buf_size - 1)
3589 memcpy(q, buf1, len);
3597 if ((q - buf) < buf_size - 1)
3601 if (!percentd_found)
3614 #define PRINT(...) do { if (!f) av_log(avcl, level, __VA_ARGS__); else fprintf(f, __VA_ARGS__); } while(0)
3616 for(i=0;i<
size;i+=16) {
3623 PRINT(
" %02x", buf[i+j]);
3628 for(j=0;j<
len;j++) {
3630 if (c < ' ' || c >
'~')
3652 #define PRINT(...) do { if (!f) av_log(avcl, level, __VA_ARGS__); else fprintf(f, __VA_ARGS__); } while(0)
3676 void av_pkt_dump(FILE *
f,
AVPacket *pkt,
int dump_payload)
3689 void av_pkt_dump_log(
void *avcl,
int level,
AVPacket *pkt,
int dump_payload)
3703 char *authorization,
int authorization_size,
3704 char *hostname,
int hostname_size,
3706 char *path,
int path_size,
3709 const char *p, *ls, *at, *col, *brk;
3711 if (port_ptr) *port_ptr = -1;
3712 if (proto_size > 0) proto[0] = 0;
3713 if (authorization_size > 0) authorization[0] = 0;
3714 if (hostname_size > 0) hostname[0] = 0;
3715 if (path_size > 0) path[0] = 0;
3718 if ((p = strchr(url,
':'))) {
3730 ls = strchr(p,
'/');
3732 ls = strchr(p,
'?');
3741 if ((at = strchr(p,
'@')) && at < ls) {
3743 FFMIN(authorization_size, at + 1 - p));
3747 if (*p ==
'[' && (brk = strchr(p,
']')) && brk < ls) {
3750 FFMIN(hostname_size, brk - p));
3751 if (brk[1] ==
':' && port_ptr)
3752 *port_ptr = atoi(brk + 2);
3753 }
else if ((col = strchr(p,
':')) && col < ls) {
3755 FFMIN(col + 1 - p, hostname_size));
3756 if (port_ptr) *port_ptr = atoi(col + 1);
3759 FFMIN(ls + 1 - p, hostname_size));
3766 static const char hex_table_uc[16] = {
'0',
'1',
'2',
'3',
3769 'C',
'D',
'E',
'F' };
3770 static const char hex_table_lc[16] = {
'0',
'1',
'2',
'3',
3773 'c',
'd',
'e',
'f' };
3774 const char *hex_table = lowercase ? hex_table_lc : hex_table_uc;
3776 for(i = 0; i < s; i++) {
3777 buff[i * 2] = hex_table[src[i] >> 4];
3778 buff[i * 2 + 1] = hex_table[src[i] & 0xF];
3794 c = toupper((
unsigned char) *p++);
3795 if (c >=
'0' && c <=
'9')
3797 else if (c >=
'A' && c <=
'F')
3812 #if FF_API_SET_PTS_INFO
3813 void av_set_pts_info(
AVStream *s,
int pts_wrap_bits,
3814 unsigned int pts_num,
unsigned int pts_den)
3821 unsigned int pts_num,
unsigned int pts_den)
3825 if(new_tb.
num != pts_num)
3830 if(new_tb.
num <= 0 || new_tb.
den <= 0) {
3839 const char *authorization,
const char *hostname,
3840 int port,
const char *fmt, ...)
3849 if (authorization && authorization[0])
3851 #if CONFIG_NETWORK && defined(AF_INET6)
3854 memset(&hints, 0,
sizeof(hints));
3874 int len = strlen(str);
3877 vsnprintf(str + len, size > len ? size - len : 0, fmt, vl);
3904 const char *ptr = str;
3909 char *dest =
NULL, *dest_end;
3910 int key_len, dest_len = 0;
3913 while (*ptr && (isspace(*ptr) || *ptr ==
','))
3920 if (!(ptr = strchr(key,
'=')))
3923 key_len = ptr - key;
3925 callback_get_buf(context, key, key_len, &dest, &dest_len);
3926 dest_end = dest + dest_len - 1;
3930 while (*ptr && *ptr !=
'\"') {
3934 if (dest && dest < dest_end)
3938 if (dest && dest < dest_end)
3946 for (; *ptr && !(isspace(*ptr) || *ptr ==
','); ptr++)
3947 if (dest && dest < dest_end)
3970 if (base && strstr(base,
"://") && rel[0] ==
'/') {
3973 sep = strstr(buf,
"://");
3976 sep = strchr(sep,
'/');
3984 if (!base || strstr(rel,
"://") || rel[0] ==
'/') {
3991 sep = strrchr(buf,
'/');
3999 sep = strrchr(buf,
'/');
4001 if (!strcmp(sep ? &sep[1] : buf,
"..")) {
4019 struct tm time1 = {0}, time2 = {0};
4021 ret1 = strptime(datestr,
"%Y - %m - %d %T", &time1);
4022 ret2 = strptime(datestr,
"%Y - %m - %dT%T", &time2);
4029 "the date string.\n");
4038 return ofmt->
query_codec(codec_id, std_compliance);
4070 uint64_t channel_layout, int32_t sample_rate,
4082 if (channel_layout) {
4090 if (width || height) {
4097 bytestream_put_le32(&data, flags);
4099 bytestream_put_le32(&data, channels);
4101 bytestream_put_le64(&data, channel_layout);
4103 bytestream_put_le32(&data, sample_rate);
4104 if (width || height) {
4105 bytestream_put_le32(&data, width);
4106 bytestream_put_le32(&data, height);