diff options
author | wm4 <wm4@nowhere> | 2017-10-16 16:36:21 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2017-10-16 16:36:51 +0200 |
commit | 0a7c5a130e73c7c96faafc7da80fa56ee9b7bf00 (patch) | |
tree | 8f08e6ebf7656a15062c1d39d1bba15a8771e6bd /common/av_common.c | |
parent | a7464c4ed84762f81205f52c338b41bd43a973ee (diff) | |
download | mpv-0a7c5a130e73c7c96faafc7da80fa56ee9b7bf00.tar.bz2 mpv-0a7c5a130e73c7c96faafc7da80fa56ee9b7bf00.tar.xz |
video: properly pass through ICC data
The same should happen with any other side data that matters to mpv,
otherwise filters will drop it.
(No, don't try to argue that mpv should use AVFrame. That won't work.)
ffmpeg_garbage() is copy&paste from frame_new_side_data() in FFmpeg
(roughly feed201849b8f91), because it's not public API. The name
reflects my opinion about FFmpeg's API.
In mp_image_to_av_frame(), change the too-fragile
*new_ref = (struct mp_image){0};
into explicitly zeroing out the fields that are "transferred" to the
created AVFrame.
Diffstat (limited to 'common/av_common.c')
-rw-r--r-- | common/av_common.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/common/av_common.c b/common/av_common.c index c91da79634..d3237250ef 100644 --- a/common/av_common.c +++ b/common/av_common.c @@ -352,3 +352,38 @@ int mp_set_avopts(struct mp_log *log, void *avobj, char **kv) } return success; } + +AVFrameSideData *ffmpeg_garbage(AVFrame *frame, + enum AVFrameSideDataType type, + AVBufferRef *buf) +{ + AVFrameSideData *ret, **tmp; + + if (!buf) + return NULL; + + if (frame->nb_side_data > INT_MAX / sizeof(*frame->side_data) - 1) + goto fail; + + tmp = av_realloc(frame->side_data, + (frame->nb_side_data + 1) * sizeof(*frame->side_data)); + if (!tmp) + goto fail; + frame->side_data = tmp; + + ret = av_mallocz(sizeof(*ret)); + if (!ret) + goto fail; + + ret->buf = buf; + ret->data = ret->buf->data; + ret->size = buf->size; + ret->type = type; + + frame->side_data[frame->nb_side_data++] = ret; + + return ret; +fail: + av_buffer_unref(&buf); + return NULL; +} |