From: 1035567130@qq.com
To: ffmpeg-devel@ffmpeg.org
Cc: Wang Yaqiang <wangyaqiang03@kuaishou.com>
Subject: [FFmpeg-devel] [PATCH] libavcodec/libwebpenc_animencoder.c: support ICCP when the source material contains the icc profile
Date: Thu, 9 Mar 2023 17:31:47 +0800
Message-ID: <tencent_C9683B594685E951E7E9D008C13585EF7705@qq.com> (raw)
From: Wang Yaqiang <wangyaqiang03@kuaishou.com>
when the source material contains the icc profile,
the AVFrame have side_data with type AV_FRAME_DATA_ICC_PROFILE,
write the ICCP chunk make sure the colors are displayed correctly.
Signed-off-by: Wang Yaqiang <wangyaqiang03@kuaishou.com>
---
libavcodec/libwebpenc_animencoder.c | 39 ++++++++++++++++++++++++++++-
1 file changed, 38 insertions(+), 1 deletion(-)
diff --git a/libavcodec/libwebpenc_animencoder.c b/libavcodec/libwebpenc_animencoder.c
index 8756231f23..acdefc75a4 100644
--- a/libavcodec/libwebpenc_animencoder.c
+++ b/libavcodec/libwebpenc_animencoder.c
@@ -45,6 +45,8 @@ typedef struct LibWebPAnimContext {
void *first_frame_opaque;
AVBufferRef *first_frame_opaque_ref;
+ WebPData icc_data;
+
int done; // If true, we have assembled the bitstream already
} LibWebPAnimContext;
@@ -62,6 +64,7 @@ static av_cold int libwebp_anim_encode_init(AVCodecContext *avctx)
return AVERROR(EINVAL);
s->first_frame_pts = AV_NOPTS_VALUE;
s->done = 0;
+ WebPDataInit(&s->icc_data);
}
return ret;
}
@@ -79,6 +82,27 @@ static int libwebp_anim_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
WebPData assembled_data = { 0 };
ret = WebPAnimEncoderAssemble(s->enc, &assembled_data);
if (ret) {
+ if (s->icc_data.bytes) {
+ WebPMux *muxer = WebPMuxCreate(&assembled_data,1);
+ WebPDataClear(&assembled_data);
+ if (!muxer) {
+ ret = AVERROR(ENOMEM);
+ return ret;
+ }
+ ret = WebPMuxSetChunk(muxer,"ICCP",&s->icc_data,0);
+ if (!ret) {
+ ret = AVERROR_INVALIDDATA;
+ WebPMuxDelete(muxer);
+ return ret;
+ }
+ ret = WebPMuxAssemble(muxer,&assembled_data);
+ WebPMuxDelete(muxer);
+ if (!ret) {
+ ret = AVERROR_INVALIDDATA;
+ WebPDataClear(&assembled_data);
+ return ret;
+ }
+ }
ret = ff_get_encode_buffer(avctx, pkt, assembled_data.size, 0);
if (ret < 0) {
WebPDataClear(&assembled_data);
@@ -117,6 +141,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
int timestamp_ms;
WebPPicture *pic = NULL;
AVFrame *alt_frame = NULL;
+ AVFrameSideData *frame_side_data = NULL;
ret = ff_libwebp_get_frame(avctx, &s->cc, frame, &alt_frame, &pic);
if (ret < 0)
goto end;
@@ -131,7 +156,18 @@ FF_ENABLE_DEPRECATION_WARNINGS
ret = ff_libwebp_error_to_averror(pic->error_code);
goto end;
}
-
+ if (!s->icc_data.bytes) {
+ frame_side_data = av_frame_get_side_data(frame,AV_FRAME_DATA_ICC_PROFILE);
+ if (frame_side_data) {
+ s->icc_data.bytes = WebPMalloc(frame_side_data->size);
+ if (!s->icc_data.bytes) {
+ ret = AVERROR(ENOMEM);
+ goto end;
+ }
+ s->icc_data.size = frame_side_data->size;
+ memcpy(s->icc_data.bytes,frame_side_data->data,frame_side_data->size);
+ }
+ }
if (!avctx->frame_num) {
s->first_frame_pts = frame->pts;
#if FF_API_REORDERED_OPAQUE
@@ -170,6 +206,7 @@ static int libwebp_anim_encode_close(AVCodecContext *avctx)
av_buffer_unref(&s->first_frame_opaque_ref);
+ WebPDataClear(&s->icc_data);
return 0;
}
--
2.39.2
_______________________________________________
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".
next reply other threads:[~2023-03-09 9:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-09 9:31 1035567130 [this message]
2023-03-09 11:57 ` Steven Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tencent_C9683B594685E951E7E9D008C13585EF7705@qq.com \
--to=1035567130@qq.com \
--cc=ffmpeg-devel@ffmpeg.org \
--cc=wangyaqiang03@kuaishou.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
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