39 for (y = 0; y <
height; y++)
40 for (x = 0; x <
width; x++)
41 data[0][y * linesize[0] + x] = x + y + frame_index * 3;
44 for (y = 0; y <
height / 2; y++) {
45 for (x = 0; x <
width / 2; x++) {
46 data[1][y * linesize[1] + x] = 128 + y + frame_index * 2;
47 data[2][y * linesize[2] + x] = 64 + x + frame_index * 5;
52int main(
int argc,
char **argv)
54 uint8_t *src_data[4], *dst_data[4];
55 int src_linesize[4], dst_linesize[4];
56 int src_w = 320, src_h = 240, dst_w, dst_h;
58 const char *dst_size = NULL;
59 const char *dst_filename = NULL;
62 struct SwsContext *sws_ctx;
66 fprintf(stderr,
"Usage: %s output_file output_size\n"
67 "API example program to show how to scale an image with libswscale.\n"
68 "This program generates a series of pictures, rescales them to the given "
69 "output_size and saves them to an output file named output_file\n."
73 dst_filename = argv[1];
78 "Invalid size '%s', must be in the form WxH or a valid size abbreviation\n",
83 dst_file = fopen(dst_filename,
"wb");
85 fprintf(stderr,
"Could not open destination file %s\n", dst_filename);
91 dst_w, dst_h, dst_pix_fmt,
95 "Impossible to create scale context for the conversion "
96 "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
105 src_w, src_h, src_pix_fmt, 16)) < 0) {
106 fprintf(stderr,
"Could not allocate source image\n");
112 dst_w, dst_h, dst_pix_fmt, 1)) < 0) {
113 fprintf(stderr,
"Could not allocate destination image\n");
118 for (i = 0; i < 100; i++) {
123 sws_scale(sws_ctx, (
const uint8_t *
const*)src_data,
124 src_linesize, 0, src_h, dst_data, dst_linesize);
127 fwrite(dst_data[0], 1, dst_bufsize, dst_file);
130 fprintf(stderr,
"Scaling succeeded. Play the output file with the command:\n"
131 "ffplay -f rawvideo -pix_fmt %s -video_size %dx%d %s\n",
void av_freep(void *ptr)
Free a memory block which has been allocated with a function of av_malloc() or av_realloc() family,...
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...
struct 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.
void sws_freeContext(struct SwsContext *swsContext)
Free the swscaler context swsContext.
int sws_scale(struct SwsContext *c, const uint8_t *const srcSlice[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
Scale the image slice in srcSlice and put the resulting scaled slice in the image in dst.
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.
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.
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
int main(int argc, char **argv)
static void fill_yuv_image(uint8_t *data[4], int linesize[4], int width, int height, int frame_index)