我想用 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;
...
}
这很好用,我得到了我的 YUV 帧并且可以进一步处理它(比如转换为 RGB 或缩放等)但是,我想以某种方式告诉 ffmpeg 库,以缩放AVFrame
同时解码(幂的比例因子2就足够了)。我不想在转换为 RGB 或使用swscale
或任何东西后进行缩放。我必须解码很多帧并且需要更小的分辨率。
是否可以提供AVCodecContext
一些提示来缩放框架?(我尝试设置avctx.width
and avctx.height
,但这没有帮助)