[FFmpeg-devel] [PATCH v2 1/1] avcodec/vpp_qsv: Copy side data from input to output frame
Soft Works
softworkz at hotmail.com
Tue Nov 30 16:22:38 EET 2021
Signed-off-by: softworkz <softworkz at hotmail.com>
---
V2: Add public method av_frame_copy_side_data() instead to copying the implementation.
libavfilter/qsvvpp.c | 5 ++++
libavfilter/vf_overlay_qsv.c | 19 +++++++++---
libavutil/frame.c | 57 ++++++++++++++++++++----------------
libavutil/frame.h | 12 ++++++++
4 files changed, 64 insertions(+), 29 deletions(-)
diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
index d1218355c7..b291216292 100644
--- a/libavfilter/qsvvpp.c
+++ b/libavfilter/qsvvpp.c
@@ -849,6 +849,11 @@ int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame *picr
return AVERROR(EAGAIN);
break;
}
+
+ ret = av_frame_copy_side_data(out_frame->frame, in_frame->frame, 0);
+ if (ret < 0)
+ return ret;
+
out_frame->frame->pts = av_rescale_q(out_frame->surface.Data.TimeStamp,
default_tb, outlink->time_base);
diff --git a/libavfilter/vf_overlay_qsv.c b/libavfilter/vf_overlay_qsv.c
index 7e76b39aa9..02518e020c 100644
--- a/libavfilter/vf_overlay_qsv.c
+++ b/libavfilter/vf_overlay_qsv.c
@@ -231,13 +231,24 @@ static int process_frame(FFFrameSync *fs)
{
AVFilterContext *ctx = fs->parent;
QSVOverlayContext *s = fs->opaque;
+ AVFrame *frame0 = NULL;
AVFrame *frame = NULL;
- int ret = 0, i;
+ int ret = 0;
- for (i = 0; i < ctx->nb_inputs; i++) {
+ for (unsigned i = 0; i < ctx->nb_inputs; i++) {
ret = ff_framesync_get_frame(fs, i, &frame, 0);
- if (ret == 0)
- ret = ff_qsvvpp_filter_frame(s->qsv, ctx->inputs[i], frame);
+
+ if (ret == 0) {
+ AVFrame *temp;
+
+ if (i == 0)
+ frame0 = frame;
+ else
+ ret = av_frame_copy_side_data(frame, frame0, 0);
+
+ ret = ret < 0 ? ret : ff_qsvvpp_filter_frame(s->qsv, ctx->inputs[i], frame);
+ }
+
if (ret < 0 && ret != AVERROR(EAGAIN))
break;
}
diff --git a/libavutil/frame.c b/libavutil/frame.c
index 1f1f573407..7a19245ea4 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -296,6 +296,36 @@ int av_frame_get_buffer2(AVFrame *frame, int align)
}
}
+int av_frame_copy_side_data(AVFrame* dst, const AVFrame* src, int force_copy)
+{
+ for (unsigned i = 0; i < src->nb_side_data; i++) {
+ const AVFrameSideData *sd_src = src->side_data[i];
+ AVFrameSideData *sd_dst;
+ if ( sd_src->type == AV_FRAME_DATA_PANSCAN
+ && (src->width != dst->width || src->height != dst->height))
+ continue;
+ if (force_copy) {
+ sd_dst = av_frame_new_side_data(dst, sd_src->type,
+ sd_src->size);
+ if (!sd_dst) {
+ wipe_side_data(dst);
+ return AVERROR(ENOMEM);
+ }
+ memcpy(sd_dst->data, sd_src->data, sd_src->size);
+ } else {
+ AVBufferRef *ref = av_buffer_ref(sd_src->buf);
+ sd_dst = av_frame_new_side_data_from_buf(dst, sd_src->type, ref);
+ if (!sd_dst) {
+ av_buffer_unref(&ref);
+ wipe_side_data(dst);
+ return AVERROR(ENOMEM);
+ }
+ }
+ av_dict_copy(&sd_dst->metadata, sd_src->metadata, 0);
+ }
+ return 0;
+}
+
static int frame_copy_props(AVFrame *dst, const AVFrame *src, int force_copy)
{
int ret, i;
@@ -340,31 +370,8 @@ static int frame_copy_props(AVFrame *dst, const AVFrame *src, int force_copy)
av_dict_copy(&dst->metadata, src->metadata, 0);
- for (i = 0; i < src->nb_side_data; i++) {
- const AVFrameSideData *sd_src = src->side_data[i];
- AVFrameSideData *sd_dst;
- if ( sd_src->type == AV_FRAME_DATA_PANSCAN
- && (src->width != dst->width || src->height != dst->height))
- continue;
- if (force_copy) {
- sd_dst = av_frame_new_side_data(dst, sd_src->type,
- sd_src->size);
- if (!sd_dst) {
- wipe_side_data(dst);
- return AVERROR(ENOMEM);
- }
- memcpy(sd_dst->data, sd_src->data, sd_src->size);
- } else {
- AVBufferRef *ref = av_buffer_ref(sd_src->buf);
- sd_dst = av_frame_new_side_data_from_buf(dst, sd_src->type, ref);
- if (!sd_dst) {
- av_buffer_unref(&ref);
- wipe_side_data(dst);
- return AVERROR(ENOMEM);
- }
- }
- av_dict_copy(&sd_dst->metadata, sd_src->metadata, 0);
- }
+ if (ret = av_frame_copy_side_data(dst, src, force_copy) < 0)
+ return ret;
ret = av_buffer_replace(&dst->opaque_ref, src->opaque_ref);
ret |= av_buffer_replace(&dst->private_ref, src->private_ref);
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 9dfd5a886a..6dec040ce8 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -885,6 +885,18 @@ int av_frame_copy(AVFrame *dst, const AVFrame *src);
*/
int av_frame_copy_props(AVFrame *dst, const AVFrame *src);
+/**
+ * Copy only side-data from src to dst.
+ *
+ * @param dst a frame to which the side data should be copied.
+ * @param src a frame from which to copy the side data.
+ * @param force_copy determines whether to copy the actual data or only just
+ * create references to the buffers.
+ *
+ * @return >= 0 on success, a negative AVERROR on error.
+ */
+int av_frame_copy_side_data(AVFrame* dst, const AVFrame* src, int force_copy);
+
/**
* Get the buffer reference a given data plane is stored in.
*
--
2.30.2.windows.1
More information about the ffmpeg-devel
mailing list