[FFmpeg-cvslog] ivfenc: write duration for frame_cnt=1.
Ronald S. Bultje
git at videolan.org
Wed Mar 3 14:30:32 EET 2021
ffmpeg | branch: master | Ronald S. Bultje <rsbultje at gmail.com> | Tue Mar 2 13:52:44 2021 -0500| [d29ec02d48a7fae1e3ed5a7bd79ab3fd73b42a96] | committer: Ronald S. Bultje
ivfenc: write duration for frame_cnt=1.
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d29ec02d48a7fae1e3ed5a7bd79ab3fd73b42a96
---
libavformat/ivfenc.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/libavformat/ivfenc.c b/libavformat/ivfenc.c
index 0951f56c92..889c00438c 100644
--- a/libavformat/ivfenc.c
+++ b/libavformat/ivfenc.c
@@ -23,7 +23,7 @@
typedef struct IVFEncContext {
unsigned frame_cnt;
- uint64_t last_pts, sum_delta_pts;
+ uint64_t last_pts, sum_delta_pts, last_pkt_duration;
} IVFEncContext;
static int ivf_init(AVFormatContext *s)
@@ -86,6 +86,7 @@ static int ivf_write_packet(AVFormatContext *s, AVPacket *pkt)
avio_write(pb, pkt->data, pkt->size);
if (ctx->frame_cnt)
ctx->sum_delta_pts += pkt->pts - ctx->last_pts;
+ ctx->last_pkt_duration = pkt->duration;
ctx->frame_cnt++;
ctx->last_pts = pkt->pts;
@@ -97,12 +98,15 @@ static int ivf_write_trailer(AVFormatContext *s)
AVIOContext *pb = s->pb;
IVFEncContext *ctx = s->priv_data;
- if ((pb->seekable & AVIO_SEEKABLE_NORMAL) && ctx->frame_cnt > 1) {
+ if ((pb->seekable & AVIO_SEEKABLE_NORMAL) &&
+ (ctx->frame_cnt > 1 || (ctx->frame_cnt == 1 && ctx->last_pkt_duration))) {
int64_t end = avio_tell(pb);
avio_seek(pb, 24, SEEK_SET);
// overwrite the "length" field (duration)
- avio_wl32(pb, ctx->frame_cnt * ctx->sum_delta_pts / (ctx->frame_cnt - 1));
+ avio_wl32(pb, ctx->last_pkt_duration ?
+ ctx->sum_delta_pts + ctx->last_pkt_duration :
+ ctx->frame_cnt * ctx->sum_delta_pts / (ctx->frame_cnt - 1));
avio_wl32(pb, 0); // zero out unused bytes
avio_seek(pb, end, SEEK_SET);
}
More information about the ffmpeg-cvslog
mailing list