1

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)

1
  • 1240 rep and no formatting skills :/ Commented Jul 20, 2017 at 19:42

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

3 Comments

Okay, this is sad, but I think you're right. I will do some benchmarks with swscale.
If scaling is not possible while decoding then what does this value do int AVCodecContext::lowres ? The definition found from ffmpeg.org/doxygen/4.1/avcodec_8h_source.html says #if FF_API_LOWRES /** * low resolution decoding, 1-> 1/2 size, 2->1/4 size * - encoding: unused * - decoding: Set by user. */ int lowres; #endif The line "low resolution decoding, 1-> 1/2 size, 2->1/4 size" suggests its possible to decode while scaling. But setting this is not working properly. I'm trying to figure this out too.
That is supported only by a VERY limited number of codecs. You need to call av_codec_get_max_lowres (or check the source code for .max_lowres) to see if the codec supports it. Most do not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.