【问题标题】:What are the alternative way to sacle video frame in ffmpeg?在ffmpeg中缩放视频帧的替代方法是什么?
【发布时间】:2020-05-06 13:57:31
【问题描述】:

所以,基本上,我在 c++ 中使用 FFmpeg lib 渲染视频。可以使用哪些优化技术来渲染快速帧,以便在视频渲染中获得更好的 o/p?

// app data structure
typedef struct {
    AVFormatContext *fmt_ctx;
    int stream_idx;
    AVRational time_base;
    AVStream *video_stream;
    AVCodecContext *codec_ctx;
    AVCodecContext *pCodecCtxOrig;
    AVCodec *decoder;
    AVPacket *packet;
    AVFrame *av_frame;
    AVFrame *gl_frame;
    AVStream *pStream;
    struct SwsContext *conv_ctx;
} AppData;

 if (!data->conv_ctx) {
            data->conv_ctx = sws_getContext(data->codec_ctx->width,
                                            data->codec_ctx->height, data->codec_ctx->pix_fmt,
                                            data->codec_ctx->width, data->codec_ctx->height,
                                            AV_PIX_FMT_RGB0,
                                            SWS_FAST_BILINEAR, NULL, NULL, NULL);
        }
        if (!data->conv_ctx) {
            printf("Couldn't initialize sw scaler\n");
            return false;
        }

        sws_scale(data->conv_ctx, data->av_frame->data, data->av_frame->linesize, 0,
                  data->codec_ctx->height, data->gl_frame->data, data->gl_frame->linesize);
        glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, data->codec_ctx->width,
                        data->codec_ctx->height, GL_RGBA, GL_UNSIGNED_BYTE,
                        data->gl_frame->data[0]);

这个函数是映射视频帧,这对我来说映射视频帧的效率很低。 如何在 OpenGL 中避免 sws_scale 和映射视频帧?

【问题讨论】:

    标签: c++ opencv opengl video-processing


    【解决方案1】:

    您可以将数据上传到纹理并在将帧绘制到目的地时在片段着色器中进行颜色转换,而不是调用sws_scale。由于您可能会在codec_ctx->pix_fmt 中遇到许多不同的格式,因此您需要手动支持许多不同的转换。对于平面格式,例如 YUV420,您可能需要为每个平面创建单独的纹理。

    为了进一步改进,如果 FFMPEG 在 GPU 上解码,您可以通过在 FFMPEG 后端和 OpenGL 之间使用适当的互操作来避免 GPU->CPU->GPU 数据往返。见How to convert an ffmpeg texture to Open GL texture without copying to CPU memory。不用说,由于各种不同的后端,它很复杂。

    【讨论】:

      猜你喜欢
      • 2011-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-14
      • 2011-08-05
      • 1970-01-01
      • 1970-01-01
      • 2018-06-27
      相关资源
      最近更新 更多