+static int videotoolbox_postproc_frame(void *avctx, AVFrame *frame)
+{
+ VTHWFrame *ref = (VTHWFrame *)frame->buf[0]->data;
+
+ if (!ref->pixbuf) {
+ av_log(avctx, AV_LOG_ERROR, "No frame decoded?\n");
+ av_frame_unref(frame);
+ return AVERROR_EXTERNAL;
+ }
+
+ frame->data[3] = (uint8_t*)ref->pixbuf;
+
+ if (ref->hw_frames_ctx) {
+ av_buffer_unref(&frame->hw_frames_ctx);
+ frame->hw_frames_ctx = av_buffer_ref(ref->hw_frames_ctx);
+ if (!frame->hw_frames_ctx)
+ return AVERROR(ENOMEM);
+ }
+
+ return 0;
+}
+