aboutsummaryrefslogtreecommitdiff
path: root/libavformat/flvenc.c
diff options
context:
space:
mode:
authorJustin Ruggles2011-10-26 12:43:18 -0400
committerJustin Ruggles2011-11-02 19:26:44 -0400
commit905de1190796d3e62d6545e6af34f2c413a68a47 (patch)
treef9f09e30e4d60527a36f4657b184d296ae39d151 /libavformat/flvenc.c
parentc2d9a65bc08cdb61f13b4101c5bbec7b86d30f9f (diff)
flvenc: use first packet delay as global delay.
This keeps the streams sychronized. The packets must be interleaved per-DTS.
Diffstat (limited to 'libavformat/flvenc.c')
-rw-r--r--libavformat/flvenc.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
index 0d1fa7312a..80ddcd8989 100644
--- a/libavformat/flvenc.c
+++ b/libavformat/flvenc.c
@@ -57,10 +57,10 @@ typedef struct FLVContext {
int64_t duration_offset;
int64_t filesize_offset;
int64_t duration;
+ int64_t delay; ///< first dts delay (needed for AVC & Speex)
} FLVContext;
typedef struct FLVStreamContext {
- int delay; ///< first dts delay for each stream (needed for AVC & Speex)
int64_t last_ts; ///< last timestamp for each stream
} FLVStreamContext;
@@ -207,6 +207,8 @@ static int flv_write_header(AVFormatContext *s)
s->streams[i]->priv_data = sc;
sc->last_ts = -1;
}
+ flv->delay = AV_NOPTS_VALUE;
+
avio_write(pb, "FLV", 3);
avio_w8(pb,1);
avio_w8(pb, FLV_HEADER_FLAG_HASAUDIO * !!audio_enc
@@ -416,10 +418,15 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt)
return -1;
}
}
- if (!sc->delay && pkt->dts < 0)
- sc->delay = -pkt->dts;
+ if (flv->delay == AV_NOPTS_VALUE)
+ flv->delay = -pkt->dts;
+ if (pkt->dts < -flv->delay) {
+ av_log(s, AV_LOG_WARNING, "Packets are not in the proper order with "
+ "respect to DTS\n");
+ return AVERROR(EINVAL);
+ }
- ts = pkt->dts + sc->delay; // add delay to force positive dts
+ ts = pkt->dts + flv->delay; // add delay to force positive dts
/* check Speex packet duration */
if (enc->codec_id == CODEC_ID_SPEEX && ts - sc->last_ts > 160) {
@@ -450,7 +457,7 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt)
avio_write(pb, data ? data : pkt->data, size);
avio_wb32(pb,size+flags_size+11); // previous tag size
- flv->duration = FFMAX(flv->duration, pkt->pts + sc->delay + pkt->duration);
+ flv->duration = FFMAX(flv->duration, pkt->pts + flv->delay + pkt->duration);
avio_flush(pb);