简体   繁体   English

如何使用ffmpeg和H.265预缩放帧

[英]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: 我想使用H.265编码( AV_CODEC_ID_HEVC )解码视频帧,我使用以下代码:

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). 效果很好,我得到了YUV帧并可以进一步处理它(例如转换为RGB或缩放等)。但是,我想以某种方式告诉ffmpeg库,在解码时缩放AVFrame (功率的缩放因子) 2)就足够了。 I don't want to scale after converting to RGB or use swscale or anything. 我不想在转换为RGB或使用swscale或其他东西后进行缩放。 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? 是否可以给AVCodecContext一些提示以缩放帧? (I tried setting avctx.width and avctx.height , but this did not help) (我尝试设置avctx.widthavctx.height ,但这没有帮助)

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 您可以使用swscale一步缩放并转换为RGB

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM