mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
avformat/flvenc: fix timestamp of key frame index
Firstly, the timestamps generated from framerate are inaccurate for variable framerate mode. Secondly, the timestamps always start from zero, while pts/dts can start from nonzero. FLV demuxer rejects such index with message: "Found invalid index entries, clearing the index".
This commit is contained in:
parent
30aa0c3f48
commit
693c5be320
@ -104,7 +104,6 @@ typedef struct FLVContext {
|
|||||||
int64_t lastkeyframelocation_offset;
|
int64_t lastkeyframelocation_offset;
|
||||||
int64_t lastkeyframelocation;
|
int64_t lastkeyframelocation;
|
||||||
|
|
||||||
int acurframeindex;
|
|
||||||
int64_t keyframes_info_offset;
|
int64_t keyframes_info_offset;
|
||||||
|
|
||||||
int64_t filepositions_count;
|
int64_t filepositions_count;
|
||||||
@ -391,7 +390,6 @@ static void write_metadata(AVFormatContext *s, unsigned int ts)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (flv->flags & FLV_ADD_KEYFRAME_INDEX) {
|
if (flv->flags & FLV_ADD_KEYFRAME_INDEX) {
|
||||||
flv->acurframeindex = 0;
|
|
||||||
flv->keyframe_index_size = 0;
|
flv->keyframe_index_size = 0;
|
||||||
|
|
||||||
put_amf_string(pb, "hasVideo");
|
put_amf_string(pb, "hasVideo");
|
||||||
@ -993,8 +991,7 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt)
|
|||||||
switch (par->codec_type) {
|
switch (par->codec_type) {
|
||||||
case AVMEDIA_TYPE_VIDEO:
|
case AVMEDIA_TYPE_VIDEO:
|
||||||
flv->videosize += (avio_tell(pb) - cur_offset);
|
flv->videosize += (avio_tell(pb) - cur_offset);
|
||||||
flv->lasttimestamp = flv->acurframeindex / flv->framerate;
|
flv->lasttimestamp = pkt->dts / 1000.0;
|
||||||
flv->acurframeindex++;
|
|
||||||
if (pkt->flags & AV_PKT_FLAG_KEY) {
|
if (pkt->flags & AV_PKT_FLAG_KEY) {
|
||||||
double ts = flv->lasttimestamp;
|
double ts = flv->lasttimestamp;
|
||||||
int64_t pos = cur_offset;
|
int64_t pos = cur_offset;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
5f38d76da3ed4a5be06ca604c53666f2 *tests/data/fate/flv-add_keyframe_index.flv
|
9f3d6de74f3329651a4c515c20cea00f *tests/data/fate/flv-add_keyframe_index.flv
|
||||||
630192 tests/data/fate/flv-add_keyframe_index.flv
|
630192 tests/data/fate/flv-add_keyframe_index.flv
|
||||||
#tb 0: 1/1000
|
#tb 0: 1/1000
|
||||||
#media_type 0: video
|
#media_type 0: video
|
||||||
|
Loading…
Reference in New Issue
Block a user