这是什么呀 2019-02-25 13:40 采纳率: 0%
浏览 2102
已结题

ffmepg sws_scale函数在处理4K视频时,速度较慢

第一次提问,格式可能不对,请见谅

    numBytes = av_image_get_buffer_size(AV_PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height,4);

    out_buffer_rgb = (uint8_t *)av_malloc(numBytes * sizeof(uint8_t));

    av_image_fill_arrays(pFrameRGB->data, pFrameRGB->linesize, out_buffer_rgb, AV_PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height, 4);




    /*
    img_convert_ctx = sws_getContext(pCodecCtx->width, pCodecCtx->height,
                                     pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height,
                                     AV_PIX_FMT_RGB24, SWS_BICUBIC, NULL, NULL, NULL);
    */
    img_convert_ctx = sws_getContext(pCodecCtx->width, pCodecCtx->height,
                                     AV_PIX_FMT_NV12, pCodecCtx->width, pCodecCtx->height,
                                     AV_PIX_FMT_RGB24, SWS_POINT, NULL, NULL, NULL);




    int got_picture = 0;

    while (1)
    {

        ret = packet_queue_get(&ps->video_packet_queue, packet, 0);
        if (ret <= 0)
        {
            cout << " video_packet_queue empty" << endl;
            continue;
        }

        int ret = avcodec_send_packet(ps->pvideo_codec_ctx, packet);
        if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF)
            continue;

        ret = avcodec_receive_frame(ps->pvideo_codec_ctx, pDecodedFrame);
        if (ret < 0 && ret != AVERROR_EOF)
            continue;

        ret = av_hwframe_transfer_data(pFrame,pDecodedFrame, 0);
        if (ret < 0)
            continue;


        //if (got_picture)
        {

            Uint32 pretimer = SDL_GetTicks();

            int ret = sws_scale(img_convert_ctx,
                      (uint8_t const *const *)pFrame->data,
                      pFrame->linesize, 0, pCodecCtx->height, pFrameRGB->data,
                      pFrameRGB->linesize);


            cout << "sws_scale" << SDL_GetTicks() - pretimer  << endl;


            //glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, data->codec_ctx->width, data->codec_ctx->height, GL_RGB, GL_UNSIGNED_BYTE, ...);

        }
        av_packet_unref(packet);
    }

使用上述代码,在处理4K视频时 sws_scale 使用的时间较长,请问如何解决。

类似问题

https://stackoverflow.com/questions/50644157/extremely-slow-ffmpeg-sws-scale-only-on-heavy-duty

https://ffmpeg.org/pipermail/libav-user/2015-August/008348.html

  • 写回答

1条回答 默认 最新

  • devmiao 2019-02-25 23:49
    关注
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向