For software scaling the example is as follows, might help you.
int main(int argc, char **argv) { const char *src_filename = NULL; const char *src_resolution = NULL; const char *src_pix_fmt_name = NULL; enum AVPixelFormat src_pix_fmt = AV_PIX_FMT_NONE; uint8_t *src_data[4]; int src_linesize[4]; int src_w=0, src_h=0; FILE *src_file; int src_bufsize; const char *dst_filename = NULL; const char *dst_resolution = NULL; const char *dst_pix_fmt_name = NULL; enum AVPixelFormat dst_pix_fmt = AV_PIX_FMT_NONE; uint8_t *dst_data[4]; int dst_linesize[4]; int dst_w=0, dst_h=0; FILE *dst_file; int dst_bufsize; struct SwsContext *sws_ctx; int ret; int frame_count = 0; if (argc != 7) { fprintf(stderr, "*Usage: %s src_file src_resolution src_pix_fmt dst_file dst_resolution dst_pix_fmt*\n" "API example program to show how to scale an video/image with libswscale.\n" "This program generates a series of pictures, rescales them to the given " "resolution and saves them to an output file\n." "\n", argv[0]); exit(1); } src_filename = argv[1]; src_resolution = argv[2]; src_pix_fmt_name = argv[3]; dst_filename = argv[4]; dst_resolution = argv[5]; dst_pix_fmt_name = argv[6]; if(AV_PIX_FMT_NONE == (src_pix_fmt = av_get_pix_fmt(src_pix_fmt_name))) { fprintf(stderr, "Invalid source pixel format '%s'\n", src_pix_fmt_name); exit(1); } if(AV_PIX_FMT_NONE == (dst_pix_fmt = av_get_pix_fmt(dst_pix_fmt_name))) { fprintf(stderr, "Invalid destination pixel format '%s'\n", dst_pix_fmt_name); exit(1); } if (av_parse_video_size(&src_w, &src_h, src_resolution) < 0) { fprintf(stderr, "Invalid source resolution '%s', must be in the form WxH or a valid size abbreviation\n", src_resolution); exit(1); } if (av_parse_video_size(&dst_w, &dst_h, dst_resolution) < 0) { fprintf(stderr, "Invalid destination resolution '%s', must be in the form WxH or a valid size abbreviation\n", dst_resolution); exit(1); } src_file = fopen(src_filename, "rb"); if (!src_file) { fprintf(stderr, "Could not open source file %s\n", src_filename); exit(1); } dst_file = fopen(dst_filename, "wb"); if (!dst_file) { fprintf(stderr, "Could not open destination file %s\n", dst_filename); exit(1); } /* create scaling context */ sws_ctx = *sws_getContext*(src_w, src_h, src_pix_fmt, dst_w, dst_h, dst_pix_fmt, SWS_BILINEAR, NULL, NULL, NULL); if (!sws_ctx) { fprintf(stderr, "Impossible to create scale context for the conversion " "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n", av_get_pix_fmt_name(src_pix_fmt), src_w, src_h, av_get_pix_fmt_name(dst_pix_fmt), dst_w, dst_h); ret = AVERROR(EINVAL); goto end; } /* allocate source and destination image buffers */ if ((ret = *av_image_alloc*(src_data, src_linesize, src_w, src_h, src_pix_fmt, 16)) < 0) { fprintf(stderr, "Could not allocate source image\n"); goto end; } src_bufsize = ret; /* buffer is going to be written to rawvideo file, no alignment */ if ((ret = *av_image_alloc*(dst_data, dst_linesize, dst_w, dst_h, dst_pix_fmt, 1)) < 0) { fprintf(stderr, "Could not allocate destination image\n"); goto end; } dst_bufsize = ret; /* read image from source file */ while(src_bufsize == fread(src_data[0], 1, src_bufsize, src_file)) { /* convert to destination format */ *sws_scale*(sws_ctx, (const uint8_t * const*)src_data,src_linesize, 0, src_h, dst_data, dst_linesize); /* write scaled image to file */ fwrite(dst_data[0], 1, dst_bufsize, dst_file); printf("No of frames converted = %d\r",++frame_count); fflush(stdout); } printf("\n"); fprintf(stderr, "Scaling succeeded. Play the output file with the command:\n" "ffplay -f rawvideo -pix_fmt %s -video_size %dx%d %s\n", av_get_pix_fmt_name(dst_pix_fmt), dst_w, dst_h, dst_filename); end: fclose(src_file); fclose(dst_file); av_freep(&src_data[0]); av_freep(&dst_data[0]); sws_freeContext(sws_ctx); return ret; } -- View this message in context: http://libav-users.943685.n4.nabble.com/Libav-user-imgutils-h-decode-dst-buffer-going-from-avpicture-fill-to-av-image-fill-arrays-tp4662419p4662429.html Sent from the libav-users mailing list archive at Nabble.com. _______________________________________________ Libav-user mailing list Libav-user@ffmpeg.org http://ffmpeg.org/mailman/listinfo/libav-user