Skip to content

Instantly share code, notes, and snippets.

@whatvn
Created October 9, 2014 07:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whatvn/3868df79e2a0f68f3229 to your computer and use it in GitHub Desktop.
Save whatvn/3868df79e2a0f68f3229 to your computer and use it in GitHub Desktop.
scale
// scale video
static AVFrame* scale_encode_write_frame(AVFrame *frame, int src_w, int src_h,
int dst_w, int dst_h) {
int ret = 0;
AVFrame *scale_frame;
scale_frame = av_frame_alloc();
if (!scale_frame) {
av_log(NULL, AV_LOG_DEBUG, "Cannot get allocate scale frame\n");
return frame;
}
struct SwsContext *scale_context = NULL;
scale_context = sws_getContext(src_w, src_h,
AV_PIX_FMT_YUV420P,
dst_w, dst_h,
AV_PIX_FMT_YUV420P, SWS_BILINEAR, NULL, NULL, NULL);
if (!scale_context) {
av_log(NULL, AV_LOG_DEBUG, "Cannot get scaling context\n");
av_frame_free(&scale_frame);
return frame;
}
if ((ret = av_image_alloc(scale_frame->data, scale_frame->linesize,
dst_w, dst_h, AV_PIX_FMT_YUV420P, 1)) < 0) {
fprintf(stderr, "Could not allocate destination image\n");
av_frame_free(&scale_frame);
return frame;
}
ret = sws_scale(scale_context, (const uint8_t* const*) frame->data,
//ret = sws_scale(scale_context, frame->data,
frame->linesize, 0, src_h,
scale_frame->data, scale_frame->linesize);
sws_freeContext(scale_context);
if (ret < 0) {
av_frame_free(&scale_frame);
return frame;
} else {
printf("Using scale frame\n");
scale_frame->pts = av_frame_get_best_effort_timestamp(scale_frame);
scale_frame->pict_type = AV_PICTURE_TYPE_NONE;
av_frame_free(&frame);
return scale_frame;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment