* [FFmpeg-devel] [PATCH] libavcodec/libwebpenc_animencoder.c: support ICCP when the source material contains the icc profile
@ 2023-03-09 9:31 1035567130
2023-03-09 11:57 ` Steven Liu
0 siblings, 1 reply; 2+ messages in thread
From: 1035567130 @ 2023-03-09 9:31 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Wang Yaqiang
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".
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [FFmpeg-devel] [PATCH] libavcodec/libwebpenc_animencoder.c: support ICCP when the source material contains the icc profile
2023-03-09 9:31 [FFmpeg-devel] [PATCH] libavcodec/libwebpenc_animencoder.c: support ICCP when the source material contains the icc profile 1035567130
@ 2023-03-09 11:57 ` Steven Liu
0 siblings, 0 replies; 2+ messages in thread
From: Steven Liu @ 2023-03-09 11:57 UTC (permalink / raw)
To: FFmpeg development discussions and patches; +Cc: Wang Yaqiang
<1035567130@qq.com> 于2023年3月9日周四 17:32写道:
>
> 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;
you can return AVERROR(ENOMEM); here;
> + }
> + ret = WebPMuxSetChunk(muxer,"ICCP",&s->icc_data,0);
> + if (!ret) {
> + ret = AVERROR_INVALIDDATA;
> + WebPMuxDelete(muxer);
> + return ret;
ditoo,
> + }
> + ret = WebPMuxAssemble(muxer,&assembled_data);
> + WebPMuxDelete(muxer);
> + if (!ret) {
> + ret = AVERROR_INVALIDDATA;
> + WebPDataClear(&assembled_data);
> + return ret;
ditoo,
or maybe you should try use goto for clean operation?
> + }
> + }
> 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".
Thanks
Steven
_______________________________________________
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] 2+ messages in thread
end of thread, other threads:[~2023-03-09 11:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-09 9:31 [FFmpeg-devel] [PATCH] libavcodec/libwebpenc_animencoder.c: support ICCP when the source material contains the icc profile 1035567130
2023-03-09 11:57 ` Steven Liu
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