Skip to content

Instantly share code, notes, and snippets.

@whatvn
Created October 9, 2014 03:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whatvn/b20234a20703416b79d5 to your computer and use it in GitHub Desktop.
Save whatvn/b20234a20703416b79d5 to your computer and use it in GitHub Desktop.
scale
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;
frame = av_frame_alloc();
if (!frame) {
av_log(NULL, AV_LOG_DEBUG, "Cannot get allocate scale frame\n");
return frame;
}
SwsContext *scale_context = NULL;
scale_context = sws_getContext(src_w, src_h,
ifmt_ctx->video_codec->pix_fmts,
dst_w, dst_h,
ifmt_ctx->video_codec->pix_fmts, 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;
}
ret = sws_scale(scale_context, (const uint8_t * const*) frame->data,
(const int) frame->linesize, 0, src_h,
scale_frame->data, frame->linesize);
sws_freeContext(scale_context);
if (ret < 0) {
av_frame_free(&scale_frame);
return frame;
} else {
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