[FFmpeg-devel] [PATCH] avcodec/libwebpenc_anim: support setting the duration of the last frame.
From: Wang Yaqiang
Signed-off-by: Wang Yaqiang
---
libavcodec/libwebpenc_animencoder.c | 18 --
libavcodec/libwebpenc_common.c | 2 ++
libavcodec/libwebpenc_common.h | 1 +
3 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/libavcodec/libwebpenc_animencoder.c
b/libavcodec/libwebpenc_animencoder.c
index c5361d7f92..dbf1bd946d 100644
--- a/libavcodec/libwebpenc_animencoder.c
+++ b/libavcodec/libwebpenc_animencoder.c
@@ -38,6 +38,7 @@ typedef struct LibWebPAnimContext {
WebPAnimEncoder *enc; // the main AnimEncoder object
int64_t first_frame_pts; // pts of the first encoded frame.
int64_t end_pts; // pts + duration of the last frame
+int64_t prev_frame_pts; // pts of the previously encoded frame.
void *first_frame_opaque;
AVBufferRef*first_frame_opaque_ref;
@@ -72,7 +73,19 @@ static int libwebp_anim_encode_frame(AVCodecContext *avctx,
AVPacket *pkt,
if (s->done) { // Second flush: return empty package to denote finish.
*got_packet = 0;
return 0;
-} else { // First flush: assemble bitstream and return it.
+} else {
+if (s->cc.last_delay > 0) {
+int timestamp_ms = avctx->time_base.num * (s->cc.last_delay +
s->prev_frame_pts) * 1000 / avctx->time_base.den;
+ret = WebPAnimEncoderAdd(s->enc, NULL, timestamp_ms,
&s->cc.config);
+if (!ret) {
+av_log(avctx, AV_LOG_ERROR,
+ "Encoding WebP frame failed!\n");
+ret = AVERROR_EXTERNAL;
+goto end;
+}
+s->end_pts = s->prev_frame_pts + s->cc.last_delay;
+}
+// First flush: assemble bitstream and return it.
WebPData assembled_data = { 0 };
ret = WebPAnimEncoderAssemble(s->enc, &assembled_data);
if (ret) {
@@ -137,7 +150,8 @@ static int libwebp_anim_encode_frame(AVCodecContext *avctx,
AVPacket *pkt,
if (frame->pts != AV_NOPTS_VALUE)
s->end_pts = frame->pts + frame->duration;
-
+s->prev_frame_pts = frame->pts;
ret = 0;
*got_packet = 0;
diff --git a/libavcodec/libwebpenc_common.c b/libavcodec/libwebpenc_common.c
index 80040ea9e3..13fb6aa690 100644
--- a/libavcodec/libwebpenc_common.c
+++ b/libavcodec/libwebpenc_common.c
@@ -49,6 +49,8 @@ static const AVOption options[] = {
{ "cr_threshold","Conditional replenishment threshold",
OFFSET(cr_threshold), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE
},
{ "cr_size" ,"Conditional replenishment block size",
OFFSET(cr_size) , AV_OPT_TYPE_INT, { .i64 = 16 }, 0, 256, VE
},
{ "quality" ,"Quality",OFFSET(quality),
AV_OPT_TYPE_FLOAT, { .dbl = 75 }, 0, 100, VE
},
+{ "final_delay", "Force delay (in centiseconds) after the last frame",
OFFSET(last_delay),
+ AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE },
{ NULL },
};
diff --git a/libavcodec/libwebpenc_common.h b/libavcodec/libwebpenc_common.h
index 2735ccc88d..8e5f37805a 100644
--- a/libavcodec/libwebpenc_common.h
+++ b/libavcodec/libwebpenc_common.h
@@ -47,6 +47,7 @@ typedef struct LibWebPContextCommon {
AVFrame *ref;
int cr_size;
int cr_threshold;
+int last_delay;
} LibWebPContextCommon;
int ff_libwebp_error_to_averror(int err);
--
2.39.3 (Apple Git-146)
___
ffmpeg-devel mailing list
[email protected]
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
[email protected] with subject "unsubscribe".
[FFmpeg-devel] [PATCH] avcodec/libwebpenc_anim: support setting the duration of the last frame
From: Wang Yaqiang
Signed-off-by: Wang Yaqiang
---
libavcodec/libwebpenc_animencoder.c | 17 +++--
libavcodec/libwebpenc_common.c | 2 ++
libavcodec/libwebpenc_common.h | 1 +
3 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/libavcodec/libwebpenc_animencoder.c
b/libavcodec/libwebpenc_animencoder.c
index c5361d7f92..558fcc246d 100644
--- a/libavcodec/libwebpenc_animencoder.c
+++ b/libavcodec/libwebpenc_animencoder.c
@@ -38,6 +38,7 @@ typedef struct LibWebPAnimContext {
WebPAnimEncoder *enc; // the main AnimEncoder object
int64_t first_frame_pts; // pts of the first encoded frame.
int64_t end_pts; // pts + duration of the last frame
+int64_t prev_frame_pts; // pts of the previously encoded frame.
void *first_frame_opaque;
AVBufferRef*first_frame_opaque_ref;
@@ -72,7 +73,19 @@ static int libwebp_anim_encode_frame(AVCodecContext *avctx,
AVPacket *pkt,
if (s->done) { // Second flush: return empty package to denote finish.
*got_packet = 0;
return 0;
-} else { // First flush: assemble bitstream and return it.
+} else {
+if (s->cc.last_delay > 0) {
+int timestamp_ms = avctx->time_base.num * (s->cc.last_delay +
s->prev_frame_pts) * 1000 / avctx->time_base.den;
+ret = WebPAnimEncoderAdd(s->enc, NULL, timestamp_ms,
&s->cc.config);
+if (!ret) {
+av_log(avctx, AV_LOG_ERROR,
+ "Encoding WebP frame failed!\n");
+ret = AVERROR_EXTERNAL;
+goto end;
+}
+s->end_pts = s->prev_frame_pts + s->cc.last_delay;
+}
+// First flush: assemble bitstream and return it.
WebPData assembled_data = { 0 };
ret = WebPAnimEncoderAssemble(s->enc, &assembled_data);
if (ret) {
@@ -137,7 +150,7 @@ static int libwebp_anim_encode_frame(AVCodecContext *avctx,
AVPacket *pkt,
if (frame->pts != AV_NOPTS_VALUE)
s->end_pts = frame->pts + frame->duration;
-
+s->prev_frame_pts = frame->pts;
ret = 0;
*got_packet = 0;
diff --git a/libavcodec/libwebpenc_common.c b/libavcodec/libwebpenc_common.c
index 80040ea9e3..13fb6aa690 100644
--- a/libavcodec/libwebpenc_common.c
+++ b/libavcodec/libwebpenc_common.c
@@ -49,6 +49,8 @@ static const AVOption options[] = {
{ "cr_threshold","Conditional replenishment threshold",
OFFSET(cr_threshold), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE
},
{ "cr_size" ,"Conditional replenishment block size",
OFFSET(cr_size) , AV_OPT_TYPE_INT, { .i64 = 16 }, 0, 256, VE
},
{ "quality" ,"Quality",OFFSET(quality),
AV_OPT_TYPE_FLOAT, { .dbl = 75 }, 0, 100, VE
},
+{ "final_delay", "Force delay (in centiseconds) after the last frame",
OFFSET(last_delay),
+ AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE },
{ NULL },
};
diff --git a/libavcodec/libwebpenc_common.h b/libavcodec/libwebpenc_common.h
index 2735ccc88d..8e5f37805a 100644
--- a/libavcodec/libwebpenc_common.h
+++ b/libavcodec/libwebpenc_common.h
@@ -47,6 +47,7 @@ typedef struct LibWebPContextCommon {
AVFrame *ref;
int cr_size;
int cr_threshold;
+int last_delay;
} LibWebPContextCommon;
int ff_libwebp_error_to_averror(int err);
--
2.39.3 (Apple Git-146)
___
ffmpeg-devel mailing list
[email protected]
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
[email protected] with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2] avcodec/libwebpenc_anim: support setting the duration of the last frame
From: Wang Yaqiang
Signed-off-by: Wang Yaqiang
---
libavcodec/libwebpenc_animencoder.c | 17 +++--
libavcodec/libwebpenc_common.c | 2 ++
libavcodec/libwebpenc_common.h | 1 +
3 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/libavcodec/libwebpenc_animencoder.c
b/libavcodec/libwebpenc_animencoder.c
index c5361d7f92..558fcc246d 100644
--- a/libavcodec/libwebpenc_animencoder.c
+++ b/libavcodec/libwebpenc_animencoder.c
@@ -38,6 +38,7 @@ typedef struct LibWebPAnimContext {
WebPAnimEncoder *enc; // the main AnimEncoder object
int64_t first_frame_pts; // pts of the first encoded frame.
int64_t end_pts; // pts + duration of the last frame
+int64_t prev_frame_pts; // pts of the previously encoded frame.
void *first_frame_opaque;
AVBufferRef*first_frame_opaque_ref;
@@ -72,7 +73,19 @@ static int libwebp_anim_encode_frame(AVCodecContext *avctx,
AVPacket *pkt,
if (s->done) { // Second flush: return empty package to denote finish.
*got_packet = 0;
return 0;
-} else { // First flush: assemble bitstream and return it.
+} else {
+if (s->cc.last_delay > 0) {
+int timestamp_ms = avctx->time_base.num * (s->cc.last_delay +
s->prev_frame_pts) * 1000 / avctx->time_base.den;
+ret = WebPAnimEncoderAdd(s->enc, NULL, timestamp_ms,
&s->cc.config);
+if (!ret) {
+av_log(avctx, AV_LOG_ERROR,
+ "Encoding WebP frame failed!\n");
+ret = AVERROR_EXTERNAL;
+goto end;
+}
+s->end_pts = s->prev_frame_pts + s->cc.last_delay;
+}
+// First flush: assemble bitstream and return it.
WebPData assembled_data = { 0 };
ret = WebPAnimEncoderAssemble(s->enc, &assembled_data);
if (ret) {
@@ -137,7 +150,7 @@ static int libwebp_anim_encode_frame(AVCodecContext *avctx,
AVPacket *pkt,
if (frame->pts != AV_NOPTS_VALUE)
s->end_pts = frame->pts + frame->duration;
-
+s->prev_frame_pts = frame->pts;
ret = 0;
*got_packet = 0;
diff --git a/libavcodec/libwebpenc_common.c b/libavcodec/libwebpenc_common.c
index 80040ea9e3..13fb6aa690 100644
--- a/libavcodec/libwebpenc_common.c
+++ b/libavcodec/libwebpenc_common.c
@@ -49,6 +49,8 @@ static const AVOption options[] = {
{ "cr_threshold","Conditional replenishment threshold",
OFFSET(cr_threshold), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE
},
{ "cr_size" ,"Conditional replenishment block size",
OFFSET(cr_size) , AV_OPT_TYPE_INT, { .i64 = 16 }, 0, 256, VE
},
{ "quality" ,"Quality",OFFSET(quality),
AV_OPT_TYPE_FLOAT, { .dbl = 75 }, 0, 100, VE
},
+{ "final_delay", "Force delay (in centiseconds) after the last frame",
OFFSET(last_delay),
+ AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE },
{ NULL },
};
diff --git a/libavcodec/libwebpenc_common.h b/libavcodec/libwebpenc_common.h
index 2735ccc88d..8e5f37805a 100644
--- a/libavcodec/libwebpenc_common.h
+++ b/libavcodec/libwebpenc_common.h
@@ -47,6 +47,7 @@ typedef struct LibWebPContextCommon {
AVFrame *ref;
int cr_size;
int cr_threshold;
+int last_delay;
} LibWebPContextCommon;
int ff_libwebp_error_to_averror(int err);
--
2.39.3 (Apple Git-146)
___
ffmpeg-devel mailing list
[email protected]
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
[email protected] with subject "unsubscribe".
[FFmpeg-devel] [PATCH] avformat/demux: Fixed the incorrect id3 tag checking logic,
From: 汪亚强
detect only audio formats where the tag might exist.
For example, if an rgb rawvideo data starts with ID3,
it will cause the packet data to be missing by 10 bytes,
causing a transcoding error.
Signed-off-by: 汪亚强
---
libavformat/demux.c | 8
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/libavformat/demux.c b/libavformat/demux.c
index 0e39346f62..d9c9766d51 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -299,9 +299,10 @@ int avformat_open_input(AVFormatContext **ps, const char
*filename,
goto fail;
}
}
-
+int id3v2_check = (!strcmp(s->iformat->name, "mp3") ||
!strcmp(s->iformat->name, "aac") ||
+ !strcmp(s->iformat->name, "tta") ||
!strcmp(s->iformat->name, "wav"));
/* e.g. AVFMT_NOFILE formats will not have an AVIOContext */
-if (s->pb)
+if (s->pb && id3v2_check)
ff_id3v2_read_dict(s->pb, &si->id3v2_meta, ID3v2_DEFAULT_MAGIC,
&id3v2_extra_meta);
if (ffifmt(s->iformat)->read_header)
@@ -320,8 +321,7 @@ int avformat_open_input(AVFormatContext **ps, const char
*filename,
}
if (id3v2_extra_meta) {
-if (!strcmp(s->iformat->name, "mp3") || !strcmp(s->iformat->name,
"aac") ||
-!strcmp(s->iformat->name, "tta") || !strcmp(s->iformat->name,
"wav")) {
+if (id3v2_check) {
if ((ret = ff_id3v2_parse_apic(s, id3v2_extra_meta)) < 0)
goto close;
if ((ret = ff_id3v2_parse_chapters(s, id3v2_extra_meta)) < 0)
--
2.39.3 (Apple Git-146)
___
ffmpeg-devel mailing list
[email protected]
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
[email protected] with subject "unsubscribe".
