[FFmpeg-devel] [PATCH] swscale: add API to convert AVFrames directly

Clément Bœsch u at pkh.me
Sun Sep 29 23:36:52 CEST 2013


On Sun, Sep 29, 2013 at 04:53:02PM +0200, wm4 wrote:
[...]
> +/**
> + * Scale and convert image data in src to the dimension and image parameters
> + * in dst. You must initialize dst and allocate image data before calling this
> + * function. In particular, you must set the image format and image dimensions
> + * on dst prior to calling this function.
> + *
> + * Warning: libswscale expects that dst is writable (see av_frame_is_writable()).
> + *          The reason this is not done automatically is that this would not
> + *          allow the user to provide a static destination buffer (as the
> + *          AVFrame API expects
> + *
> + * Warning: this will transparently reinitialize the sws context, and overwrite
> + *          some swscale options according to AVFrame. This includes settings
> + *          like source/destination image dimensions, pixel format, color space,
> + *          color range, chroma position, and possibly more. Should AVFrame be
> + *          extended to carry more image parameters in the future, this
> + *          function might be updated to include them as well. This is usually
> + *          convenient and the right thing to do, but if you do not want
> + *          libswscale to overwrite your settings, use the low-level API and
> + *          not sws_scale_frame().
> + *

@warning

> + * Example how to scale a given "src" image to 2x the size and 8 bit 4:2:0 YCbCr:
> + *

@code

> + *      AVFrame *src = ...;
> + *      SwsContext *sws = sws_alloc_context();
> + *      AVFrame *dst = av_frame_alloc();
> + *      if (!dst) goto error;
> + *      dst->format = AV_PIX_FMT_YUV420P;
> + *      dst->width = src->width * 2;
> + *      dst->height = src->height * 2;
> + *      if (av_frame_copy_props(dst, src) < 0) goto error; // don't change anything else
> + *      if (av_frame_get_buffer(dst, 32) < 0) goto error; // allocate image
> + *      if (sws_scale_frame(sws, dst, src) < 0) goto error;
> + *      // dst now contains the scaled image data
> + *

@endcode

[...]

-- 
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130929/f66dab03/attachment.asc>


More information about the ffmpeg-devel mailing list