Go to the documentation of this file.
40 for (y = 0; y <
height; y++)
41 for (x = 0; x <
width; x++)
42 data[0][y * linesize[0] + x] = x + y + frame_index * 3;
45 for (y = 0; y <
height / 2; y++) {
46 for (x = 0; x <
width / 2; x++) {
47 data[1][y * linesize[1] + x] = 128 + y + frame_index * 2;
48 data[2][y * linesize[2] + x] = 64 + x + frame_index * 5;
53 int main(
int argc,
char **argv)
55 uint8_t *src_data[4], *dst_data[4];
56 int src_linesize[4], dst_linesize[4];
57 int src_w = 320, src_h = 240, dst_w, dst_h;
59 const char *dst_size =
NULL;
60 const char *dst_filename =
NULL;
67 fprintf(stderr,
"Usage: %s output_file output_size\n"
68 "API example program to show how to scale an image with libswscale.\n"
69 "This program generates a series of pictures, rescales them to the given "
70 "output_size and saves them to an output file named output_file\n."
74 dst_filename = argv[1];
79 "Invalid size '%s', must be in the form WxH or a valid size abbreviation\n",
84 dst_file = fopen(dst_filename,
"wb");
86 fprintf(stderr,
"Could not open destination file %s\n", dst_filename);
96 "Impossible to create scale context for the conversion "
97 "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
107 fprintf(stderr,
"Could not allocate source image\n");
114 fprintf(stderr,
"Could not allocate destination image\n");
119 for (
i = 0;
i < 100;
i++) {
124 sws_scale(sws_ctx, (
const uint8_t *
const*)src_data,
125 src_linesize, 0,
src_h, dst_data, dst_linesize);
128 fwrite(dst_data[0], 1, dst_bufsize, dst_file);
131 fprintf(stderr,
"Scaling succeeded. Play the output file with the command:\n"
132 "ffplay -f rawvideo -pix_fmt %s -video_size %dx%d %s\n",
AVPixelFormat
Pixel format.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
int src_w
Deprecated frame property overrides, for the legacy API only.
void sws_freeContext(SwsContext *swsContext)
Free the swscaler context swsContext.
@ SWS_BILINEAR
bilinear filtering
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
int av_image_alloc(uint8_t *pointers[4], int linesizes[4], int w, int h, enum AVPixelFormat pix_fmt, int align)
Allocate an image with size w and h and pixel format pix_fmt, and fill pointers and linesizes accordi...
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
int src_h
Width and height of the source frame.
int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str)
Parse str and put in width_ptr and height_ptr the detected values.
#define i(width, name, range_min, range_max)
int dst_h
Width and height of the destination frame.
SwsContext * sws_getContext(int srcW, int srcH, enum AVPixelFormat srcFormat, int dstW, int dstH, enum AVPixelFormat dstFormat, int flags, SwsFilter *srcFilter, SwsFilter *dstFilter, const double *param)
Allocate and return an SwsContext.
int attribute_align_arg sws_scale(SwsContext *sws, const uint8_t *const srcSlice[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
swscale wrapper, so we don't need to export the SwsContext.
static void fill_yuv_image(uint8_t *data[4], int linesize[4], int width, int height, int frame_index)
int main(int argc, char **argv)
Main external API structure.
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.