21#include <VideoToolbox/VideoToolbox.h>
55 ret = VTPixelTransferSessionCreate(kCFAllocatorDefault, &
s->transfer);
61#define STRING_OPTION(var_name, func_name, default_value) \
63 if (s->var_name##_string) { \
64 int var = av_##func_name##_from_name(s->var_name##_string); \
66 av_log(avctx, AV_LOG_ERROR, "Invalid %s.\n", #var_name); \
67 return AVERROR(EINVAL); \
71 s->var_name = default_value; \
83 "Doesn't support converting to colour primaries %s\n",
84 s->colour_primaries_string);
87 VTSessionSetProperty(
s->transfer, kVTPixelTransferPropertyKey_DestinationColorPrimaries,
value);
94 "Doesn't support converting to trc %s\n",
95 s->colour_transfer_string);
98 VTSessionSetProperty(
s->transfer, kVTPixelTransferPropertyKey_DestinationTransferFunction,
value);
105 "Doesn't support converting to colorspace %s\n",
106 s->colour_matrix_string);
109 VTSessionSetProperty(
s->transfer, kVTPixelTransferPropertyKey_DestinationYCbCrMatrix,
value);
112 VTSessionSetProperty(
s->transfer, kVTPixelTransferPropertyKey_ScalingMode, kVTScalingMode_CropSourceToCleanAperture);
122 VTPixelTransferSessionInvalidate(
s->transfer);
123 CFRelease(
s->transfer);
134 CVPixelBufferRef
src;
135 CVPixelBufferRef
dst;
141 CFNumberRef crop_width_num;
142 CFNumberRef crop_height_num;
143 CFNumberRef crop_offset_left_num;
144 CFNumberRef crop_offset_top_num;
145 const void *clean_aperture_keys[4];
146 const void *source_clean_aperture_values[4];
147 CFDictionaryRef source_clean_aperture;
162 out->crop_bottom = 0;
168 av_reduce(&
out->sample_aspect_ratio.num, &
out->sample_aspect_ratio.den,
173 out->color_primaries =
s->colour_primaries;
175 out->color_trc =
s->colour_transfer;
177 out->colorspace =
s->colour_matrix;
185 crop_width_num = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &
width);
186 crop_height_num = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &
height);
187 crop_offset_left_num = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &
left);
188 crop_offset_top_num = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &top);
190 clean_aperture_keys[0] = kCVImageBufferCleanApertureWidthKey;
191 clean_aperture_keys[1] = kCVImageBufferCleanApertureHeightKey;
192 clean_aperture_keys[2] = kCVImageBufferCleanApertureHorizontalOffsetKey;
193 clean_aperture_keys[3] = kCVImageBufferCleanApertureVerticalOffsetKey;
195 source_clean_aperture_values[0] = crop_width_num;
196 source_clean_aperture_values[1] = crop_height_num;
197 source_clean_aperture_values[2] = crop_offset_left_num;
198 source_clean_aperture_values[3] = crop_offset_top_num;
200 source_clean_aperture = CFDictionaryCreate(kCFAllocatorDefault,
202 source_clean_aperture_values,
204 &kCFTypeDictionaryKeyCallBacks,
205 &kCFTypeDictionaryValueCallBacks);
207 CFRelease(crop_width_num);
208 CFRelease(crop_height_num);
209 CFRelease(crop_offset_left_num);
210 CFRelease(crop_offset_top_num);
212 src = (CVPixelBufferRef)in->
data[3];
213 dst = (CVPixelBufferRef)
out->data[3];
214 CVBufferSetAttachment(
src, kCVImageBufferCleanApertureKey,
215 source_clean_aperture, kCVAttachmentMode_ShouldPropagate);
216 ret = VTPixelTransferSessionTransferImage(
s->transfer,
src,
dst);
217 CFRelease(source_clean_aperture);
256 outlink->
w =
s->output_width;
257 outlink->
h =
s->output_height;
273 hw_frame_ctx_out->
width = outlink->
w;
274 hw_frame_ctx_out->
height = outlink->
h;
284 "Failed to init videotoolbox frame context, %s\n",
292#define OFFSET(x) offsetof(ScaleVtContext, x)
293#define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
295 {
"w",
"Output video width",
297 {
"h",
"Output video height",
299 {
"color_matrix",
"Output colour matrix coefficient set",
301 {
"color_primaries",
"Output colour primaries",
303 {
"color_transfer",
"Output colour transfer characteristics",
327 .p.name =
"scale_vt",
329 .p.priv_class = &scale_vt_class,
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
const FFFilter ff_vf_scale_vt
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int ff_filter_init_hw_frames(AVFilterContext *avctx, AVFilterLink *link, int default_pool_size)
Perform any additional setup required for hardware frames.
static int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
static const AVColorPrimariesDesc color_primaries[AVCOL_PRI_NB]
int(* init)(AVBSFContext *ctx)
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
#define AVFILTER_FLAG_HWDEVICE
The filter can create hardware frames using AVFilterContext.hw_device_ctx.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
#define AVERROR_EXTERNAL
Generic error in an external library.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
void av_frame_side_data_remove_by_props(AVFrameSideData ***sd, int *nb_sd, int props)
Remove and free all side data instances that match any of the given side data properties.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
@ AV_SIDE_DATA_PROP_SIZE_DEPENDENT
Side data depends on the video dimensions.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
CFStringRef av_map_videotoolbox_color_matrix_from_av(enum AVColorSpace space)
Convert an AVColorSpace to a VideoToolbox/CoreVideo color matrix string.
CFStringRef av_map_videotoolbox_color_primaries_from_av(enum AVColorPrimaries pri)
Convert an AVColorPrimaries to a VideoToolbox/CoreVideo color primaries string.
CFStringRef av_map_videotoolbox_color_trc_from_av(enum AVColorTransferCharacteristic trc)
Convert an AVColorTransferCharacteristic to a VideoToolbox/CoreVideo color transfer function string.
An API-specific header for AV_HWDEVICE_TYPE_VIDEOTOOLBOX.
static av_cold void uninit(AVBitStreamFilterContext *ctx)
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
static FilterLink * ff_filter_link(AVFilterLink *link)
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
#define AVFILTER_DEFINE_CLASS(fname)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
@ AV_PIX_FMT_VIDEOTOOLBOX
hardware decoding through Videotoolbox
AVColorPrimaries
Chromaticity coordinates of the source primaries.
AVColorTransferCharacteristic
Color Transfer Characteristic.
AVColorSpace
YUV colorspace type.
int ff_scale_adjust_dimensions(AVFilterLink *inlink, int *ret_w, int *ret_h, int force_original_aspect_ratio, int force_divisible_by, double w_adj)
Transform evaluated width and height obtained from ff_scale_eval_dimensions into actual target width ...
int ff_scale_eval_dimensions(void *log_ctx, const char *w_expr, const char *h_expr, AVFilterLink *inlink, AVFilterLink *outlink, int *ret_w, int *ret_h)
Parse and evaluate string expressions for width and height.
@ SCALE_FORCE_OAR_DISABLE
uint8_t * data
The data buffer.
Describe the class of an AVClass context structure.
AVFilterLink ** inputs
array of pointers to input links
void * priv
private data for use by the filter
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
AVFilterContext * src
source filter
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
AVFilterContext * dst
dest filter
A filter pad used for either input or output.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
This struct describes a set or pool of "hardware" frames (i.e.
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
int width
The allocated dimensions of the frames in this pool.
Rational number (pair of numerator and denominator).
Link properties exposed to filter code, but not external callers.
AVBufferRef * hw_frames_ctx
For hwaccel pixel formats, this should be a reference to the AVHWFramesContext describing the frames.
VTPixelTransferSessionRef transfer
enum AVColorPrimaries colour_primaries
enum AVColorTransferCharacteristic colour_transfer
char * colour_primaries_string
char * colour_transfer_string
char * colour_matrix_string
enum AVColorSpace colour_matrix
static AVFormatContext * ctx
static av_cold void scale_vt_uninit(AVFilterContext *avctx)
static const AVFilterPad scale_vt_outputs[]
static const AVOption scale_vt_options[]
static const AVFilterPad scale_vt_inputs[]
static int scale_vt_filter_frame(AVFilterLink *link, AVFrame *in)
static av_cold int scale_vt_init(AVFilterContext *avctx)
static int scale_vt_config_output(AVFilterLink *outlink)
#define STRING_OPTION(var_name, func_name, default_value)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.