aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBaptiste Coudurier <baptiste.coudurier@gmail.com>2008-11-16 02:56:34 +0000
committerBaptiste Coudurier <baptiste.coudurier@gmail.com>2008-11-16 02:56:34 +0000
commitebd610557e26d9c41e86bf357e8395e019d7db9b (patch)
tree8dc579819bc686c543a10d9482a2b337a8bd2202
parent51c1520114909ef7159cc7d66247e098a572a061 (diff)
downloadffmpeg-ebd610557e26d9c41e86bf357e8395e019d7db9b.tar.gz
set pts in flv demuxer
Originally committed as revision 15841 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r--libavformat/flvdec.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c
index 0b25a25e96..29925c342c 100644
--- a/libavformat/flvdec.c
+++ b/libavformat/flvdec.c
@@ -26,6 +26,10 @@
#include "avformat.h"
#include "flv.h"
+typedef struct {
+ int wrong_dts; ///< wrong dts due to negative cts
+} FLVContext;
+
static int flv_probe(AVProbeData *p)
{
const uint8_t *d;
@@ -299,9 +303,10 @@ static int flv_get_extradata(AVFormatContext *s, AVStream *st, int size)
static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
{
+ FLVContext *flv = s->priv_data;
int ret, i, type, size, flags, is_audio;
int64_t next, pos;
- unsigned dts;
+ int64_t dts, pts = AV_NOPTS_VALUE;
AVStream *st = NULL;
retry:
@@ -401,9 +406,14 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
int type = get_byte(s->pb);
size--;
if (st->codec->codec_id == CODEC_ID_H264) {
- // cts offset ignored because it might to be signed
- // and would cause pts < dts
- get_be24(s->pb);
+ int32_t cts = (get_be24(s->pb)+0xff800000)^0xff800000; // sign extension
+ pts = dts + cts;
+ if (cts < 0) { // dts are wrong
+ flv->wrong_dts = 1;
+ av_log(s, AV_LOG_WARNING, "negative cts, previous timestamps might be wrong\n");
+ }
+ if (flv->wrong_dts)
+ dts = AV_NOPTS_VALUE;
}
if (type == 0) {
if ((ret = flv_get_extradata(s, st, size)) < 0)
@@ -420,6 +430,7 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
packet */
pkt->size = ret;
pkt->dts = dts;
+ pkt->pts = pts == AV_NOPTS_VALUE ? dts : pts;
pkt->stream_index = st->index;
if (is_audio || ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY))
@@ -431,7 +442,7 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
AVInputFormat flv_demuxer = {
"flv",
NULL_IF_CONFIG_SMALL("FLV format"),
- 0,
+ sizeof(FLVContext),
flv_probe,
flv_read_header,
flv_read_packet,