33
35
* various utility functions for use within FFmpeg
36
static void av_frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den);
37
static void av_frac_add(AVFrac *f, int64_t incr);
38
unsigned avformat_version(void)
40
return LIBAVFORMAT_VERSION_INT;
43
/* fraction handling */
46
* f = val + (num / den) + 0.5.
48
* 'num' is normalized so that it is such as 0 <= num < den.
50
* @param f fractional number
51
* @param val integer value
52
* @param num must be >= 0
53
* @param den must be >= 1
55
static void av_frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den)
68
* Fractional addition to f: f = f + (incr / f->den).
70
* @param f fractional number
71
* @param incr increment, can be positive or negative
73
static void av_frac_add(AVFrac *f, int64_t incr)
86
} else if (num >= den) {
39
93
/** head of registered input format linked list */
40
94
AVInputFormat *first_iformat = NULL;
293
348
return av_probe_input_format2(pd, is_opened, &score);
351
static int set_codec_from_probe_data(AVStream *st, AVProbeData *pd, int score)
354
fmt = av_probe_input_format2(pd, 1, &score);
357
if (!strcmp(fmt->name, "mp3")) {
358
st->codec->codec_id = CODEC_ID_MP3;
359
st->codec->codec_type = CODEC_TYPE_AUDIO;
360
} else if (!strcmp(fmt->name, "ac3")) {
361
st->codec->codec_id = CODEC_ID_AC3;
362
st->codec->codec_type = CODEC_TYPE_AUDIO;
363
} else if (!strcmp(fmt->name, "mpegvideo")) {
364
st->codec->codec_id = CODEC_ID_MPEG2VIDEO;
365
st->codec->codec_type = CODEC_TYPE_VIDEO;
366
} else if (!strcmp(fmt->name, "m4v")) {
367
st->codec->codec_id = CODEC_ID_MPEG4;
368
st->codec->codec_type = CODEC_TYPE_VIDEO;
369
} else if (!strcmp(fmt->name, "h264")) {
370
st->codec->codec_id = CODEC_ID_H264;
371
st->codec->codec_type = CODEC_TYPE_VIDEO;
296
377
/************************************************************/
297
378
/* input media file */
326
407
{"cryptokey", "decryption key", OFFSET(key), FF_OPT_TYPE_BINARY, 0, 0, 0, D},
327
408
{"indexmem", "max memory used for timestamp index (per stream)", OFFSET(max_index_size), FF_OPT_TYPE_INT, 1<<20, 0, INT_MAX, D},
328
409
{"rtbufsize", "max memory used for buffering real-time frames", OFFSET(max_picture_buffer), FF_OPT_TYPE_INT, 3041280, 0, INT_MAX, D}, /* defaults to 1s of 15fps 352x288 YUYV422 video */
410
{"fdebug", "print specific debug info", OFFSET(debug), FF_OPT_TYPE_FLAGS, DEFAULT, 0, INT_MAX, E|D, "fdebug"},
411
{"ts", NULL, 0, FF_OPT_TYPE_CONST, FF_FDEBUG_TS, INT_MIN, INT_MAX, E|D, "fdebug"},
392
475
ic->priv_data = NULL;
395
err = ic->iformat->read_header(ic, ap);
478
if (ic->iformat->read_header) {
479
err = ic->iformat->read_header(ic, ap);
399
484
if (pb && !ic->data_offset)
400
485
ic->data_offset = url_ftell(ic->pb);
494
588
/*******************************************************/
590
static AVPacket *add_to_pktbuf(AVPacketList **packet_buffer, AVPacket *pkt,
591
AVPacketList **plast_pktl){
592
AVPacketList *pktl = av_mallocz(sizeof(AVPacketList));
597
(*plast_pktl)->next = pktl;
599
*packet_buffer = pktl;
601
/* add the packet in the buffered packet list */
496
607
int av_read_packet(AVFormatContext *s, AVPacket *pkt)
501
ret= s->iformat->read_packet(s, pkt);
504
st= s->streams[pkt->stream_index];
506
switch(st->codec->codec_type){
507
case CODEC_TYPE_VIDEO:
508
if(s->video_codec_id) st->codec->codec_id= s->video_codec_id;
510
case CODEC_TYPE_AUDIO:
511
if(s->audio_codec_id) st->codec->codec_id= s->audio_codec_id;
513
case CODEC_TYPE_SUBTITLE:
514
if(s->subtitle_codec_id)st->codec->codec_id= s->subtitle_codec_id;
613
AVPacketList *pktl = s->raw_packet_buffer;
617
if(s->streams[pkt->stream_index]->codec->codec_id != CODEC_ID_PROBE){
618
s->raw_packet_buffer = pktl->next;
625
ret= s->iformat->read_packet(s, pkt);
628
st= s->streams[pkt->stream_index];
630
switch(st->codec->codec_type){
631
case CODEC_TYPE_VIDEO:
632
if(s->video_codec_id) st->codec->codec_id= s->video_codec_id;
634
case CODEC_TYPE_AUDIO:
635
if(s->audio_codec_id) st->codec->codec_id= s->audio_codec_id;
637
case CODEC_TYPE_SUBTITLE:
638
if(s->subtitle_codec_id)st->codec->codec_id= s->subtitle_codec_id;
642
if(!pktl && st->codec->codec_id!=CODEC_ID_PROBE)
645
add_to_pktbuf(&s->raw_packet_buffer, pkt, &s->raw_packet_buffer_end);
647
if(st->codec->codec_id == CODEC_ID_PROBE){
648
AVProbeData *pd = &st->probe_data;
650
pd->buf = av_realloc(pd->buf, pd->buf_size+pkt->size+AVPROBE_PADDING_SIZE);
651
memcpy(pd->buf+pd->buf_size, pkt->data, pkt->size);
652
pd->buf_size += pkt->size;
653
memset(pd->buf+pd->buf_size, 0, AVPROBE_PADDING_SIZE);
655
if(av_log2(pd->buf_size) != av_log2(pd->buf_size - pkt->size)){
656
set_codec_from_probe_data(st, pd, 1);
657
if(st->codec->codec_id != CODEC_ID_PROBE){
521
666
/**********************************************************/
637
786
static void update_initial_durations(AVFormatContext *s, AVStream *st, AVPacket *pkt)
639
788
AVPacketList *pktl= s->packet_buffer;
641
assert(pkt->duration && !st->cur_dts);
791
if(st->first_dts != AV_NOPTS_VALUE){
792
cur_dts= st->first_dts;
793
for(; pktl; pktl= pktl->next){
794
if(pktl->pkt.stream_index == pkt->stream_index){
795
if(pktl->pkt.pts != pktl->pkt.dts || pktl->pkt.dts != AV_NOPTS_VALUE || pktl->pkt.duration)
797
cur_dts -= pkt->duration;
800
pktl= s->packet_buffer;
801
st->first_dts = cur_dts;
802
}else if(st->cur_dts)
643
805
for(; pktl; pktl= pktl->next){
644
806
if(pktl->pkt.stream_index != pkt->stream_index)
646
808
if(pktl->pkt.pts == pktl->pkt.dts && pktl->pkt.dts == AV_NOPTS_VALUE
647
809
&& !pktl->pkt.duration){
648
pktl->pkt.pts= pktl->pkt.dts= st->cur_dts;
649
st->cur_dts += pkt->duration;
810
pktl->pkt.dts= cur_dts;
811
if(!st->codec->has_b_frames)
812
pktl->pkt.pts= cur_dts;
813
cur_dts += pkt->duration;
650
814
pktl->pkt.duration= pkt->duration;
818
if(st->first_dts == AV_NOPTS_VALUE)
819
st->cur_dts= cur_dts;
656
822
static void compute_pkt_fields(AVFormatContext *s, AVStream *st,
659
825
int num, den, presentation_delayed, delay, i;
828
/* do we have a video B-frame ? */
829
delay= st->codec->has_b_frames;
830
presentation_delayed = 0;
831
/* XXX: need has_b_frame, but cannot get it if the codec is
834
pc && pc->pict_type != FF_B_TYPE)
835
presentation_delayed = 1;
662
837
if(pkt->pts != AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE && pkt->dts > pkt->pts && st->pts_wrap_bits<63
663
838
/*&& pkt->dts-(1LL<<st->pts_wrap_bits) < pkt->pts*/){
664
839
pkt->dts -= 1LL<<st->pts_wrap_bits;
842
// some mpeg2 in mpeg-ps lack dts (issue171 / input_file.mpg)
843
// we take the conservative approach and discard both
844
// Note, if this is misbehaving for a H.264 file then possibly presentation_delayed is not set correctly.
845
if(delay==1 && pkt->dts == pkt->pts && pkt->dts != AV_NOPTS_VALUE && presentation_delayed){
846
av_log(s, AV_LOG_ERROR, "invalid dts/pts combination\n");
847
pkt->dts= pkt->pts= AV_NOPTS_VALUE;
667
850
if (pkt->duration == 0) {
668
851
compute_frame_duration(&num, &den, st, pc, pkt);
669
852
if (den && num) {
670
853
pkt->duration = av_rescale(1, num * (int64_t)st->time_base.den, den * (int64_t)st->time_base.num);
672
if(st->cur_dts == 0 && pkt->duration != 0)
855
if(pkt->duration != 0 && s->packet_buffer)
673
856
update_initial_durations(s, st, pkt);
685
868
pkt->dts += offset;
688
/* do we have a video B-frame ? */
689
delay= st->codec->has_b_frames;
690
presentation_delayed = 0;
691
/* XXX: need has_b_frame, but cannot get it if the codec is
694
pc && pc->pict_type != FF_B_TYPE)
695
presentation_delayed = 1;
696
871
/* This may be redundant, but it should not hurt. */
697
872
if(pkt->dts != AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE && pkt->pts > pkt->dts)
698
873
presentation_delayed = 1;
700
if(st->cur_dts == AV_NOPTS_VALUE){
701
st->cur_dts = 0; //FIXME maybe set it to 0 during init
704
875
// av_log(NULL, AV_LOG_DEBUG, "IN delayed:%d pts:%"PRId64", dts:%"PRId64" cur_dts:%"PRId64" st:%d pc:%p\n", presentation_delayed, pkt->pts, pkt->dts, st->cur_dts, pkt->stream_index, pc);
705
876
/* interpolate PTS and DTS if they are not present */
877
if(delay==0 || (delay==1 && pc)){
707
878
if (presentation_delayed) {
708
879
/* DTS = decompression timestamp */
709
880
/* PTS = presentation timestamp */
717
888
of the frame we are displaying, i.e. the last I- or P-frame */
718
889
if (st->last_IP_duration == 0)
719
890
st->last_IP_duration = pkt->duration;
720
st->cur_dts = pkt->dts + st->last_IP_duration;
891
if(pkt->dts != AV_NOPTS_VALUE)
892
st->cur_dts = pkt->dts + st->last_IP_duration;
721
893
st->last_IP_duration = pkt->duration;
722
894
st->last_IP_pts= pkt->pts;
723
895
/* cannot compute PTS if not present (we can compute it only
739
911
if(pkt->pts == AV_NOPTS_VALUE)
740
912
pkt->pts = st->cur_dts;
741
913
pkt->dts = pkt->pts;
742
st->cur_dts = pkt->pts + pkt->duration;
914
if(pkt->pts != AV_NOPTS_VALUE)
915
st->cur_dts = pkt->pts + pkt->duration;
746
if(pkt->pts != AV_NOPTS_VALUE){
919
if(pkt->pts != AV_NOPTS_VALUE && delay <= MAX_REORDER_DELAY){
747
920
st->pts_buffer[0]= pkt->pts;
748
for(i=1; i<delay+1 && st->pts_buffer[i] == AV_NOPTS_VALUE; i++)
749
st->pts_buffer[i]= (i-delay-1) * pkt->duration;
750
921
for(i=0; i<delay && st->pts_buffer[i] > st->pts_buffer[i+1]; i++)
751
922
FFSWAP(int64_t, st->pts_buffer[i], st->pts_buffer[i+1]);
752
923
if(pkt->dts == AV_NOPTS_VALUE)
1024
if(s->cur_pkt.pts != AV_NOPTS_VALUE &&
1025
s->cur_pkt.dts != AV_NOPTS_VALUE &&
1026
s->cur_pkt.pts < s->cur_pkt.dts){
1027
av_log(s, AV_LOG_WARNING, "Invalid timestamps stream=%d, pts=%"PRId64", dts=%"PRId64", size=%d\n",
1028
s->cur_pkt.stream_index,
1032
// av_free_packet(&s->cur_pkt);
853
1036
st = s->streams[s->cur_pkt.stream_index];
854
if(st->codec->debug & FF_DEBUG_PTS)
855
av_log(s, AV_LOG_DEBUG, "av_read_packet stream=%d, pts=%"PRId64", dts=%"PRId64", size=%d\n",
1037
if(s->debug & FF_FDEBUG_TS)
1038
av_log(s, AV_LOG_DEBUG, "av_read_packet stream=%d, pts=%"PRId64", dts=%"PRId64", size=%d, flags=%d\n",
856
1039
s->cur_pkt.stream_index,
862
1046
s->cur_ptr = s->cur_pkt.data;
870
1054
st->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES;
872
1056
if(st->parser && (s->iformat->flags & AVFMT_GENERIC_INDEX)){
873
st->parser->last_frame_offset=
1057
st->parser->next_frame_offset=
874
1058
st->parser->cur_offset= s->cur_pkt.pos;
879
if(st->codec->debug & FF_DEBUG_PTS)
880
av_log(s, AV_LOG_DEBUG, "av_read_frame_internal stream=%d, pts=%"PRId64", dts=%"PRId64", size=%d\n",
1063
if(s->debug & FF_FDEBUG_TS)
1064
av_log(s, AV_LOG_DEBUG, "av_read_frame_internal stream=%d, pts=%"PRId64", dts=%"PRId64", size=%d, flags=%d\n",
881
1065
pkt->stream_index,
889
static AVPacket *add_to_pktbuf(AVFormatContext *s, AVPacket *pkt){
890
AVPacketList *pktl= s->packet_buffer;
891
AVPacketList **plast_pktl= &s->packet_buffer;
893
while(*plast_pktl) plast_pktl= &(*plast_pktl)->next; //FIXME maybe maintain pointer to the last?
895
pktl = av_mallocz(sizeof(AVPacketList));
899
/* add the packet in the buffered packet list */
905
1074
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
907
1076
AVPacketList *pktl;
1345
if(st->index_entries && st->nb_index_entries){
1518
if(st->nb_index_entries){
1519
assert(st->index_entries);
1346
1520
ie= &st->index_entries[st->nb_index_entries-1];
1347
url_fseek(s->pb, ie->pos, SEEK_SET);
1521
if ((ret = url_fseek(s->pb, ie->pos, SEEK_SET)) < 0)
1348
1523
av_update_cur_dts(s, st, ie->timestamp);
1350
url_fseek(s->pb, 0, SEEK_SET);
1525
if ((ret = url_fseek(s->pb, 0, SEEK_SET)) < 0)
1352
1528
for(i=0;; i++) {
1353
1529
int ret = av_read_frame(s, &pkt);
1372
1548
ie = &st->index_entries[index];
1373
url_fseek(s->pb, ie->pos, SEEK_SET);
1549
if ((ret = url_fseek(s->pb, ie->pos, SEEK_SET)) < 0)
1375
1551
av_update_cur_dts(s, st, ie->timestamp);
1396
1572
/* timestamp for default must be expressed in AV_TIME_BASE units */
1397
1573
timestamp = av_rescale(timestamp, st->time_base.den, AV_TIME_BASE * (int64_t)st->time_base.num);
1399
st= s->streams[stream_index];
1401
1576
/* first, we try the format specific seek */
1402
1577
if (s->iformat->read_seek)
1536
1711
#define DURATION_MAX_READ_SIZE 250000
1538
1713
/* only usable for MPEG-PS streams */
1539
static void av_estimate_timings_from_pts(AVFormatContext *ic, offset_t old_offset)
1714
static void av_estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset)
1541
1716
AVPacket pkt1, *pkt = &pkt1;
1735
static int set_codec_from_probe_data(AVStream *st, AVProbeData *pd, int score)
1738
fmt = av_probe_input_format2(pd, 1, &score);
1741
if (strncmp(fmt->name, "mp3", 3) == 0)
1742
st->codec->codec_id = CODEC_ID_MP3;
1743
else if (strncmp(fmt->name, "ac3", 3) == 0)
1744
st->codec->codec_id = CODEC_ID_AC3;
1749
1914
unsigned int codec_get_tag(const AVCodecTag *tags, int id)
1751
1916
while (tags->id != CODEC_ID_NONE) {
1793
1958
return CODEC_ID_NONE;
1961
static void compute_chapters_end(AVFormatContext *s)
1965
for (i=0; i+1<s->nb_chapters; i++)
1966
if (s->chapters[i]->end == AV_NOPTS_VALUE) {
1967
assert(s->chapters[i]->start <= s->chapters[i+1]->start);
1968
assert(!av_cmp_q(s->chapters[i]->time_base, s->chapters[i+1]->time_base));
1969
s->chapters[i]->end = s->chapters[i+1]->start;
1972
if (s->nb_chapters && s->chapters[i]->end == AV_NOPTS_VALUE) {
1973
assert(s->start_time != AV_NOPTS_VALUE);
1974
assert(s->duration > 0);
1975
s->chapters[i]->end = av_rescale_q(s->start_time + s->duration,
1977
s->chapters[i]->time_base);
1796
1981
/* absolute maximum size we read until we abort */
1797
1982
#define MAX_READ_SIZE 5000000
1799
1984
#define MAX_STD_TIMEBASES (60*12+5)
1800
1985
static int get_std_framerate(int i){
1801
1986
if(i<60*12) return i*1001;
1802
else return ((int[]){24,30,60,12,15})[i-60*12]*1000*12;
1987
else return ((const int[]){24,30,60,12,15})[i-60*12]*1000*12;
1828
2013
int64_t last_dts[MAX_STREAMS];
1829
2014
int duration_count[MAX_STREAMS]={0};
1830
2015
double (*duration_error)[MAX_STD_TIMEBASES];
1831
offset_t old_offset = url_ftell(ic->pb);
2016
int64_t old_offset = url_ftell(ic->pb);
1832
2017
int64_t codec_info_duration[MAX_STREAMS]={0};
1833
2018
int codec_info_nb_frames[MAX_STREAMS]={0};
1834
AVProbeData probe_data[MAX_STREAMS];
1835
int codec_identified[MAX_STREAMS]={0};
1837
2020
duration_error = av_mallocz(MAX_STREAMS * sizeof(*duration_error));
1838
2021
if (!duration_error) return AVERROR(ENOMEM);
1946
2130
if(last == AV_NOPTS_VALUE || duration_count[index]<=1)
1947
2131
last_dts[pkt->stream_index]= pkt->dts;
1949
if (st->codec->codec_id == CODEC_ID_NONE) {
1950
AVProbeData *pd = &(probe_data[st->index]);
1951
pd->buf = av_realloc(pd->buf, pd->buf_size+pkt->size+AVPROBE_PADDING_SIZE);
1952
memcpy(pd->buf+pd->buf_size, pkt->data, pkt->size);
1953
pd->buf_size += pkt->size;
1954
memset(pd->buf+pd->buf_size, 0, AVPROBE_PADDING_SIZE);
1957
2133
if(st->parser && st->parser->parser->split && !st->codec->extradata){
1958
2134
int i= st->parser->parser->split(st->codec, pkt->data, pkt->size);
2000
2176
for(i=0;i<ic->nb_streams;i++) {
2001
2177
st = ic->streams[i];
2002
2178
if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
2003
if(st->codec->codec_id == CODEC_ID_RAWVIDEO && !st->codec->codec_tag && !st->codec->bits_per_sample)
2179
if(st->codec->codec_id == CODEC_ID_RAWVIDEO && !st->codec->codec_tag && !st->codec->bits_per_coded_sample)
2004
2180
st->codec->codec_tag= avcodec_pix_fmt_to_codec_tag(st->codec->pix_fmt);
2006
2182
if(duration_count[i]
2034
2210
}else if(st->codec->codec_type == CODEC_TYPE_AUDIO) {
2035
if (st->codec->codec_id == CODEC_ID_NONE && probe_data[st->index].buf_size > 0) {
2036
codec_identified[st->index] = set_codec_from_probe_data(st, &(probe_data[st->index]), 1);
2037
if (codec_identified[st->index]) {
2038
st->need_parsing = AVSTREAM_PARSE_FULL;
2041
if(!st->codec->bits_per_sample)
2042
st->codec->bits_per_sample= av_get_bits_per_sample(st->codec->codec_id);
2211
if(!st->codec->bits_per_coded_sample)
2212
st->codec->bits_per_coded_sample= av_get_bits_per_sample(st->codec->codec_id);
2046
2216
av_estimate_timings(ic, old_offset);
2048
for(i=0;i<ic->nb_streams;i++) {
2049
st = ic->streams[i];
2050
if (codec_identified[st->index])
2053
//FIXME this is a mess
2054
if(i!=ic->nb_streams){
2055
av_read_frame_flush(ic);
2056
for(i=0;i<ic->nb_streams;i++) {
2057
st = ic->streams[i];
2058
if (codec_identified[st->index]) {
2059
av_seek_frame(ic, st->index, 0.0, 0);
2061
st->cur_dts= st->first_dts;
2063
url_fseek(ic->pb, ic->data_offset, SEEK_SET);
2218
compute_chapters_end(ic);
2067
2221
/* correct DTS for B-frame streams with no timestamps */
2181
2338
st->start_time = AV_NOPTS_VALUE;
2182
2339
st->duration = AV_NOPTS_VALUE;
2183
st->cur_dts = AV_NOPTS_VALUE;
2340
/* we set the current DTS to 0 so that formats without any timestamps
2341
but durations get some timestamps, formats with some unknown
2342
timestamps have their first few packets buffered and the
2343
timestamps corrected before they are returned to the user */
2184
2345
st->first_dts = AV_NOPTS_VALUE;
2186
2347
/* default pts setting is MPEG-like */
2395
AVChapter *ff_new_chapter(AVFormatContext *s, int id, AVRational time_base, int64_t start, int64_t end, const char *title)
2397
AVChapter *chapter = NULL;
2400
for(i=0; i<s->nb_chapters; i++)
2401
if(s->chapters[i]->id == id)
2402
chapter = s->chapters[i];
2405
chapter= av_mallocz(sizeof(AVChapter));
2408
dynarray_add(&s->chapters, &s->nb_chapters, chapter);
2410
av_free(chapter->title);
2411
chapter->title = av_strdup(title);
2413
chapter->time_base= time_base;
2414
chapter->start = start;
2233
2420
/************************************************************/
2234
2421
/* output media file */
2267
2454
av_log(s, AV_LOG_ERROR, "sample rate not set\n");
2457
if(!st->codec->block_align)
2458
st->codec->block_align = st->codec->channels *
2459
av_get_bits_per_sample(st->codec->codec_id) >> 3;
2271
2461
case CODEC_TYPE_VIDEO:
2272
2462
if(st->codec->time_base.num<=0 || st->codec->time_base.den<=0){ //FIXME audio too?
2277
2467
av_log(s, AV_LOG_ERROR, "dimensions not set\n");
2470
if(av_cmp_q(st->sample_aspect_ratio, st->codec->sample_aspect_ratio)){
2471
av_log(s, AV_LOG_ERROR, "Aspect ratio mismatch between encoder and muxer layer\n");
2356
2553
//calculate dts from pts
2357
if(pkt->pts != AV_NOPTS_VALUE && pkt->dts == AV_NOPTS_VALUE){
2554
if(pkt->pts != AV_NOPTS_VALUE && pkt->dts == AV_NOPTS_VALUE && delay <= MAX_REORDER_DELAY){
2358
2555
st->pts_buffer[0]= pkt->pts;
2359
2556
for(i=1; i<delay+1 && st->pts_buffer[i] == AV_NOPTS_VALUE; i++)
2360
2557
st->pts_buffer[i]= (i-delay-1) * pkt->duration;
2367
2564
if(st->cur_dts && st->cur_dts != AV_NOPTS_VALUE && st->cur_dts >= pkt->dts){
2368
av_log(NULL, AV_LOG_ERROR, "error, non monotone timestamps %"PRId64" >= %"PRId64"\n", st->cur_dts, pkt->dts);
2565
av_log(st->codec, AV_LOG_ERROR, "error, non monotone timestamps %"PRId64" >= %"PRId64"\n", st->cur_dts, pkt->dts);
2371
2568
if(pkt->dts != AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE && pkt->pts < pkt->dts){
2372
av_log(NULL, AV_LOG_ERROR, "error, pts < dts\n");
2569
av_log(st->codec, AV_LOG_ERROR, "error, pts < dts\n");
2401
static void truncate_ts(AVStream *st, AVPacket *pkt){
2402
int64_t pts_mask = (2LL << (st->pts_wrap_bits-1)) - 1;
2405
// pkt->dts= 0; //this happens for low_delay=0 and B-frames, FIXME, needs further investigation about what we should do here
2407
if (pkt->pts != AV_NOPTS_VALUE)
2408
pkt->pts &= pts_mask;
2409
if (pkt->dts != AV_NOPTS_VALUE)
2410
pkt->dts &= pts_mask;
2413
2598
int av_write_frame(AVFormatContext *s, AVPacket *pkt)
2600
int ret = compute_pkt_fields2(s->streams[pkt->stream_index], pkt);
2417
ret=compute_pkt_fields2(s->streams[pkt->stream_index], pkt);
2418
2602
if(ret<0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS))
2421
truncate_ts(s->streams[pkt->stream_index], pkt);
2423
2605
ret= s->oformat->write_packet(s, pkt);
2425
2607
ret= url_ferror(s->pb);
3218
char *ff_data_to_hex(char *buff, const uint8_t *src, int s)
3221
static const char hex_table[16] = { '0', '1', '2', '3',
3224
'C', 'D', 'E', 'F' };
3226
for(i = 0; i < s; i++) {
3227
buff[i * 2] = hex_table[src[i] >> 4];
3228
buff[i * 2 + 1] = hex_table[src[i] & 0xF];
3041
3234
void av_set_pts_info(AVStream *s, int pts_wrap_bits,
3042
3235
int pts_num, int pts_den)
3237
unsigned int gcd= ff_gcd(pts_num, pts_den);
3044
3238
s->pts_wrap_bits = pts_wrap_bits;
3045
s->time_base.num = pts_num;
3046
s->time_base.den = pts_den;
3049
/* fraction handling */
3052
* f = val + (num / den) + 0.5.
3054
* 'num' is normalized so that it is such as 0 <= num < den.
3056
* @param f fractional number
3057
* @param val integer value
3058
* @param num must be >= 0
3059
* @param den must be >= 1
3061
static void av_frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den)
3074
* Fractional addition to f: f = f + (incr / f->den).
3076
* @param f fractional number
3077
* @param incr increment, can be positive or negative
3079
static void av_frac_add(AVFrac *f, int64_t incr)
3083
num = f->num + incr;
3086
f->val += num / den;
3092
} else if (num >= den) {
3093
f->val += num / den;
3239
s->time_base.num = pts_num/gcd;
3240
s->time_base.den = pts_den/gcd;
3243
av_log(NULL, AV_LOG_DEBUG, "st:%d removing common factor %d from timebase\n", s->index, gcd);