Commit 4d3dd167 authored by Alex Converse's avatar Alex Converse Committed by Alex Converse

flvenc: Factorize timestamp writing

The code is trivial but the semantics in the spec are ambiguous. This
should help keep parts of the muxer interpreting them consistently.
parent d7eb8d84
...@@ -230,12 +230,17 @@ static void put_amf_string(AVIOContext *pb, const char *str) ...@@ -230,12 +230,17 @@ static void put_amf_string(AVIOContext *pb, const char *str)
avio_write(pb, str, len); avio_write(pb, str, len);
} }
// FLV timestamps are 32 bits signed, RTMP timestamps should be 32-bit unsigned
static void put_timestamp(AVIOContext *pb, int64_t ts) {
avio_wb24(pb, ts & 0xFFFFFF);
avio_w8(pb, (ts >> 24) & 0x7F);
}
static void put_avc_eos_tag(AVIOContext *pb, unsigned ts) static void put_avc_eos_tag(AVIOContext *pb, unsigned ts)
{ {
avio_w8(pb, FLV_TAG_TYPE_VIDEO); avio_w8(pb, FLV_TAG_TYPE_VIDEO);
avio_wb24(pb, 5); /* Tag Data Size */ avio_wb24(pb, 5); /* Tag Data Size */
avio_wb24(pb, ts); /* lower 24 bits of timestamp in ms */ put_timestamp(pb, ts);
avio_w8(pb, (ts >> 24) & 0x7F); /* MSB of ts in ms */
avio_wb24(pb, 0); /* StreamId = 0 */ avio_wb24(pb, 0); /* StreamId = 0 */
avio_w8(pb, 23); /* ub[4] FrameType = 1, ub[4] CodecId = 7 */ avio_w8(pb, 23); /* ub[4] FrameType = 1, ub[4] CodecId = 7 */
avio_w8(pb, 2); /* AVC end of sequence */ avio_w8(pb, 2); /* AVC end of sequence */
...@@ -492,8 +497,7 @@ static void flv_write_codec_header(AVFormatContext* s, AVCodecParameters* par) { ...@@ -492,8 +497,7 @@ static void flv_write_codec_header(AVFormatContext* s, AVCodecParameters* par) {
par->codec_type == AVMEDIA_TYPE_VIDEO ? par->codec_type == AVMEDIA_TYPE_VIDEO ?
FLV_TAG_TYPE_VIDEO : FLV_TAG_TYPE_AUDIO); FLV_TAG_TYPE_VIDEO : FLV_TAG_TYPE_AUDIO);
avio_wb24(pb, 0); // size patched later avio_wb24(pb, 0); // size patched later
avio_wb24(pb, 0); // ts put_timestamp(pb, 0);
avio_w8(pb, 0); // ts ext
avio_wb24(pb, 0); // streamid avio_wb24(pb, 0); // streamid
pos = avio_tell(pb); pos = avio_tell(pb);
if (par->codec_id == AV_CODEC_ID_AAC) { if (par->codec_id == AV_CODEC_ID_AAC) {
...@@ -978,8 +982,7 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -978,8 +982,7 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt)
} }
avio_wb24(pb, size + flags_size); avio_wb24(pb, size + flags_size);
avio_wb24(pb, ts & 0xFFFFFF); put_timestamp(pb, ts);
avio_w8(pb, (ts >> 24) & 0x7F); // timestamps are 32 bits _signed_
avio_wb24(pb, flv->reserved); avio_wb24(pb, flv->reserved);
if (par->codec_type == AVMEDIA_TYPE_DATA || if (par->codec_type == AVMEDIA_TYPE_DATA ||
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment