akw
akw

Reputation: 2110

How to prescale a frame using ffmpeg and H.265

I want to decode video frames with the H.265 coded (AV_CODEC_ID_HEVC) I use the following code:

AVCodec *hevcCodec = avcodec_find_decoder(AV_CODEC_ID_HEVC);
AVCodecContext *avctx  = avcodec_alloc_context3(hevcCodec);
avcodec_open2(avctx, hevcCodec, 0);
AVFrame *frame = av_frame_alloc();
AVPacket pkt;
av_init_packet(&pkt);
pkt.data = myDataPtr;
pkt.size = myDataSize;
int got_frame = 0;
avcodec_send_packet(avctx, &pkt);
if (avcodec_receive_frame(avctx, frame) >=0 ) {
        got_frame = 1;
        ...
}

This works fine, I got my YUV frame and can process it further (like converting to RGB or scaling, etc.) However, I would like to somehow tell the ffmpeg library, to scale the AVFrame while decoding (a scale factor of a power of 2 would be sufficient). I don't want to scale after converting to RGB or use swscale or anything. I have to decode a lot of frames and need a smaller resolution.

Is it possible to give the AVCodecContext some hints to scale the frames? (I tried setting avctx.width and avctx.height, but this did not help)

Upvotes: 1

Views: 590

Answers (1)

szatmary
szatmary

Reputation: 31120

No, decode and scale can not be combined into a single, faster step. You must fully decode then scale. You can scale and convert to RGB as a single step with swscale

Upvotes: 2

Related Questions