15
15
* You should have received a copy of the GNU Lesser General Public
16
16
* License along with this library; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
19
#include "avformat.h"
510
516
/** Size of probe buffer, for guessing file type from file contents. */
511
#define PROBE_BUF_SIZE 2048
517
#define PROBE_BUF_MIN 2048
518
#define PROBE_BUF_MAX 131072
514
521
* Open a media file as input. The codec are not opened. Only the file
527
534
AVFormatParameters *ap)
529
int err, must_open_file, file_opened;
530
uint8_t buf[PROBE_BUF_SIZE];
536
int err, must_open_file, file_opened, probe_size;
531
537
AVProbeData probe_data, *pd = &probe_data;
532
538
ByteIOContext pb1, *pb = &pb1;
561
567
if (buf_size > 0) {
562
568
url_setbufsize(pb, buf_size);
571
for(probe_size= PROBE_BUF_MIN; probe_size<=PROBE_BUF_MAX && !fmt; probe_size<<=1){
565
572
/* read probe data */
566
pd->buf_size = get_buffer(pb, buf, PROBE_BUF_SIZE);
573
pd->buf= av_realloc(pd->buf, probe_size);
574
pd->buf_size = get_buffer(pb, pd->buf, probe_size);
567
575
if (url_fseek(pb, 0, SEEK_SET) == (offset_t)-EPIPE) {
569
577
if (url_fopen(pb, filename, URL_RDONLY) < 0) {
570
579
err = AVERROR_IO;
583
/* guess file format */
584
fmt = av_probe_input_format(pd, 1);
577
/* guess file format */
579
fmt = av_probe_input_format(pd, 1);
582
589
/* if still no format found, error */
1131
1139
* @param timestamp timestamp in the timebase of the given stream
1133
1141
int av_add_index_entry(AVStream *st,
1134
int64_t pos, int64_t timestamp, int distance, int flags)
1142
int64_t pos, int64_t timestamp, int size, int distance, int flags)
1136
1144
AVIndexEntry *entries, *ie;
1193
1202
if (pkt->stream_index == 0 && st->parser &&
1194
1203
(pkt->flags & PKT_FLAG_KEY)) {
1195
1204
av_add_index_entry(st, st->parser->frame_offset, pkt->dts,
1196
0, AVINDEX_KEYFRAME);
1205
0, 0, AVINDEX_KEYFRAME);
1198
1207
av_free_packet(pkt);
1849
1864
int av_find_stream_info(AVFormatContext *ic)
1851
int i, count, ret, read_size;
1866
int i, count, ret, read_size, j;
1853
1868
AVPacket pkt1, *pkt;
1854
1869
AVPacketList *pktl=NULL, **ppktl;
1888
1903
if (!has_codec_parameters(st->codec))
1890
1905
/* variable fps and no guess at the real fps */
1891
if( st->codec->time_base.den >= 1000LL*st->codec->time_base.num
1906
if( st->codec->time_base.den >= 101LL*st->codec->time_base.num
1892
1907
&& duration_count[i]<20 && st->codec->codec_type == CODEC_TYPE_VIDEO)
1894
1909
if(st->parser && st->parser->parser->split && !st->codec->extradata)
1919
1934
ret = -1; /* we could not have all the codec parameters before EOF */
1920
1935
for(i=0;i<ic->nb_streams;i++) {
1921
1936
st = ic->streams[i];
1922
if (!has_codec_parameters(st->codec))
1937
if (!has_codec_parameters(st->codec)){
1939
avcodec_string(buf, sizeof(buf), st->codec, 0);
1940
av_log(ic, AV_LOG_INFO, "Could not find codec parameters (%s)\n", buf);
1925
1944
if (i == ic->nb_streams)
2018
2037
st = ic->streams[i];
2019
2038
if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
2020
2039
if(st->codec->codec_id == CODEC_ID_RAWVIDEO && !st->codec->codec_tag && !st->codec->bits_per_sample)
2021
// MEANX st->codec->codec_tag= avcodec_pix_fmt_to_codec_tag(st->codec->pix_fmt);
2040
st->codec->codec_tag= avcodec_pix_fmt_to_codec_tag(st->codec->pix_fmt);
2023
if(duration_count[i] && st->codec->time_base.num*1000LL <= st->codec->time_base.den &&
2024
st->time_base.num*duration_sum[i]/duration_count[i]*1000LL > st->time_base.den){
2042
if(duration_count[i] && st->codec->time_base.num*101LL <= st->codec->time_base.den &&
2043
st->time_base.num*duration_sum[i]/duration_count[i]*101LL > st->time_base.den){
2044
int64_t num, den, error, best_error;
2028
2046
num= st->time_base.den*duration_count[i];
2029
2047
den= st->time_base.num*duration_sum[i];
2031
av_reduce(&fps1.num, &fps1.den, num*1001, den*1000, FFMAX(st->time_base.den, st->time_base.num)/4);
2032
av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, num, den, FFMAX(st->time_base.den, st->time_base.num)/4);
2033
if(fps1.num < st->r_frame_rate.num && fps1.den == 1 && (fps1.num==24 || fps1.num==30)){ //FIXME better decission
2034
st->r_frame_rate.num= fps1.num*1000;
2035
st->r_frame_rate.den= fps1.den*1001;
2049
best_error= INT64_MAX;
2050
for(j=1; j<60*12; j++){
2051
error= ABS(1001*12*num - 1001*j*den);
2052
if(error < best_error){
2054
av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, j, 12, INT_MAX);
2057
for(j=24; j<=30; j+=6){
2058
error= ABS(1001*12*num - 1000*12*j*den);
2059
if(error < best_error){
2061
av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, j*1000, 1001, INT_MAX);
2720
2747
/* Finally we give up and parse it as double */
2721
*frame_rate_base = DEFAULT_FRAME_RATE_BASE; //FIXME use av_d2q()
2722
*frame_rate = (int)(strtod(arg, 0) * (*frame_rate_base) + 0.5);
2748
AVRational time_base = av_d2q(strtod(arg, 0), DEFAULT_FRAME_RATE_BASE);
2749
*frame_rate_base = time_base.den;
2750
*frame_rate = time_base.num;
2724
2752
if (!*frame_rate || !*frame_rate_base)
3224
3260
AVImageFormat *fmt,
3225
3261
int (*alloc_cb)(void *, AVImageInfo *info), void *opaque)
3227
char buf[PROBE_BUF_SIZE];
3263
uint8_t buf[PROBE_BUF_MIN];
3228
3264
AVProbeData probe_data, *pd = &probe_data;
3233
3269
pd->filename = filename;
3235
3271
pos = url_ftell(pb);
3236
pd->buf_size = get_buffer(pb, buf, PROBE_BUF_SIZE);
3272
pd->buf_size = get_buffer(pb, buf, PROBE_BUF_MIN);
3237
3273
url_fseek(pb, pos, SEEK_SET);
3238
3274
fmt = av_probe_image_format(pd);