* [FFmpeg-devel] [PATCH v2 1/3] avformat/flvenc: fix timestamp of key frame index
[not found] <20220729044310.125-1-quinkblack@foxmail.com>
@ 2022-07-29 4:43 ` Zhao Zhili
2022-07-29 4:43 ` [FFmpeg-devel] [PATCH v2 2/3] avformat/flvdec: make key frame timestamps more accurate Zhao Zhili
2022-07-29 4:43 ` [FFmpeg-devel] [PATCH v2 3/3] avformat/flvenc: fix shadowed variable ts Zhao Zhili
2 siblings, 0 replies; 3+ messages in thread
From: Zhao Zhili @ 2022-07-29 4:43 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Zhao Zhili
From: Zhao Zhili <zhilizhao@tencent.com>
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".
---
libavformat/flvenc.c | 5 +----
tests/ref/fate/flv-add_keyframe_index | 2 +-
2 files changed, 2 insertions(+), 5 deletions(-)
diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
index 770ca319ed..1c4ffb985a 100644
--- a/libavformat/flvenc.c
+++ b/libavformat/flvenc.c
@@ -104,7 +104,6 @@ typedef struct FLVContext {
int64_t lastkeyframelocation_offset;
int64_t lastkeyframelocation;
- int acurframeindex;
int64_t keyframes_info_offset;
int64_t filepositions_count;
@@ -391,7 +390,6 @@ static void write_metadata(AVFormatContext *s, unsigned int ts)
}
if (flv->flags & FLV_ADD_KEYFRAME_INDEX) {
- flv->acurframeindex = 0;
flv->keyframe_index_size = 0;
put_amf_string(pb, "hasVideo");
@@ -993,8 +991,7 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt)
switch (par->codec_type) {
case AVMEDIA_TYPE_VIDEO:
flv->videosize += (avio_tell(pb) - cur_offset);
- flv->lasttimestamp = flv->acurframeindex / flv->framerate;
- flv->acurframeindex++;
+ flv->lasttimestamp = pkt->dts / 1000.0;
if (pkt->flags & AV_PKT_FLAG_KEY) {
double ts = flv->lasttimestamp;
int64_t pos = cur_offset;
diff --git a/tests/ref/fate/flv-add_keyframe_index b/tests/ref/fate/flv-add_keyframe_index
index 39c4bed85a..6549170a68 100644
--- a/tests/ref/fate/flv-add_keyframe_index
+++ b/tests/ref/fate/flv-add_keyframe_index
@@ -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
#tb 0: 1/1000
#media_type 0: video
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 3+ messages in thread
* [FFmpeg-devel] [PATCH v2 2/3] avformat/flvdec: make key frame timestamps more accurate
[not found] <20220729044310.125-1-quinkblack@foxmail.com>
2022-07-29 4:43 ` [FFmpeg-devel] [PATCH v2 1/3] avformat/flvenc: fix timestamp of key frame index Zhao Zhili
@ 2022-07-29 4:43 ` Zhao Zhili
2022-07-29 4:43 ` [FFmpeg-devel] [PATCH v2 3/3] avformat/flvenc: fix shadowed variable ts Zhao Zhili
2 siblings, 0 replies; 3+ messages in thread
From: Zhao Zhili @ 2022-07-29 4:43 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Zhao Zhili
From: Zhao Zhili <zhilizhao@tencent.com>
There was an implicit cast from double to int64_t in time unit of
second.
---
libavformat/flvdec.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c
index 8dba92661b..10f0ea7736 100644
--- a/libavformat/flvdec.c
+++ b/libavformat/flvdec.c
@@ -146,9 +146,9 @@ static void add_keyframes_index(AVFormatContext *s)
if (ffstream(stream)->nb_index_entries == 0) {
for (i = 0; i < flv->keyframe_count; i++) {
av_log(s, AV_LOG_TRACE, "keyframe filepositions = %"PRId64" times = %"PRId64"\n",
- flv->keyframe_filepositions[i], flv->keyframe_times[i] * 1000);
+ flv->keyframe_filepositions[i], flv->keyframe_times[i]);
av_add_index_entry(stream, flv->keyframe_filepositions[i],
- flv->keyframe_times[i] * 1000, 0, 0, AVINDEX_KEYFRAME);
+ flv->keyframe_times[i], 0, 0, AVINDEX_KEYFRAME);
}
} else
av_log(s, AV_LOG_WARNING, "Skipping duplicate index\n");
@@ -428,6 +428,7 @@ static int parse_keyframes_index(AVFormatContext *s, AVIOContext *ioc, int64_t m
amf_get_string(ioc, str_val, sizeof(str_val)) > 0) {
int64_t **current_array;
unsigned int arraylen;
+ int factor;
// Expect array object in context
if (avio_r8(ioc) != AMF_DATA_TYPE_ARRAY)
@@ -440,10 +441,12 @@ static int parse_keyframes_index(AVFormatContext *s, AVIOContext *ioc, int64_t m
if (!strcmp(KEYFRAMES_TIMESTAMP_TAG , str_val) && !times) {
current_array = ×
timeslen = arraylen;
+ factor = 1000;
} else if (!strcmp(KEYFRAMES_BYTEOFFSET_TAG, str_val) &&
!filepositions) {
current_array = &filepositions;
fileposlen = arraylen;
+ factor = 1;
} else
// unexpected metatag inside keyframes, will not use such
// metadata for indexing
@@ -458,11 +461,9 @@ static int parse_keyframes_index(AVFormatContext *s, AVIOContext *ioc, int64_t m
double d;
if (avio_r8(ioc) != AMF_DATA_TYPE_NUMBER)
goto invalid;
- d = av_int2double(avio_rb64(ioc));
+ d = av_int2double(avio_rb64(ioc)) * factor;
if (isnan(d) || d < INT64_MIN || d > INT64_MAX)
goto invalid;
- if (current_array == × && (d <= INT64_MIN / 1000 || d >= INT64_MAX / 1000))
- goto invalid;
if (avio_feof(ioc))
goto invalid;
current_array[0][i] = d;
@@ -478,7 +479,7 @@ static int parse_keyframes_index(AVFormatContext *s, AVIOContext *ioc, int64_t m
if (timeslen == fileposlen && fileposlen>1 && max_pos <= filepositions[0]) {
for (i = 0; i < FFMIN(2,fileposlen); i++) {
flv->validate_index[i].pos = filepositions[i];
- flv->validate_index[i].dts = times[i] * 1000;
+ flv->validate_index[i].dts = times[i];
flv->validate_count = i + 1;
}
flv->keyframe_times = times;
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 3+ messages in thread
* [FFmpeg-devel] [PATCH v2 3/3] avformat/flvenc: fix shadowed variable ts
[not found] <20220729044310.125-1-quinkblack@foxmail.com>
2022-07-29 4:43 ` [FFmpeg-devel] [PATCH v2 1/3] avformat/flvenc: fix timestamp of key frame index Zhao Zhili
2022-07-29 4:43 ` [FFmpeg-devel] [PATCH v2 2/3] avformat/flvdec: make key frame timestamps more accurate Zhao Zhili
@ 2022-07-29 4:43 ` Zhao Zhili
2 siblings, 0 replies; 3+ messages in thread
From: Zhao Zhili @ 2022-07-29 4:43 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Zhao Zhili
From: Zhao Zhili <zhilizhao@tencent.com>
---
libavformat/flvenc.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
index 1c4ffb985a..5d574fa790 100644
--- a/libavformat/flvenc.c
+++ b/libavformat/flvenc.c
@@ -993,12 +993,9 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt)
flv->videosize += (avio_tell(pb) - cur_offset);
flv->lasttimestamp = pkt->dts / 1000.0;
if (pkt->flags & AV_PKT_FLAG_KEY) {
- double ts = flv->lasttimestamp;
- int64_t pos = cur_offset;
-
- flv->lastkeyframetimestamp = ts;
- flv->lastkeyframelocation = pos;
- ret = flv_append_keyframe_info(s, flv, ts, pos);
+ flv->lastkeyframetimestamp = flv->lasttimestamp;
+ flv->lastkeyframelocation = cur_offset;
+ ret = flv_append_keyframe_info(s, flv, flv->lasttimestamp, cur_offset);
if (ret < 0)
goto fail;
}
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-07-29 4:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20220729044310.125-1-quinkblack@foxmail.com>
2022-07-29 4:43 ` [FFmpeg-devel] [PATCH v2 1/3] avformat/flvenc: fix timestamp of key frame index Zhao Zhili
2022-07-29 4:43 ` [FFmpeg-devel] [PATCH v2 2/3] avformat/flvdec: make key frame timestamps more accurate Zhao Zhili
2022-07-29 4:43 ` [FFmpeg-devel] [PATCH v2 3/3] avformat/flvenc: fix shadowed variable ts Zhao Zhili
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git