将alpha通道写入已解码的ffmpeg帧

时间:2016-08-15 07:38:17

标签: c ffmpeg video-streaming

我正在寻找一种快速方法将我自己的alpha通道添加到已解码的ffmpeg帧。

我有一个带有RGB信息的AVI文件,我有一个描述透明度alpha通道(灰度)的同步视频流。在使用ffmpeg解码AVI文件时,我想将输出帧转换为RGBA,同时添加我自己的alpha信息。最后,我将获得一个半透明的视频流。

是否有任何优化的函数,可能在libswscale或libswresample中,做这样的事情比仅仅迭代像素更好?

基本上我希望能够编写这样的函数,只要我有 sws_scale_and_add_alpha 这样的函数:

void* FFmpegLib_nextFrame_withAlpha(void* _handle, uint8_t* my_alpha_channel)
{
    FFmpegLibHandle* handle = (FFmpegLibHandle*)_handle;
    AVPacket        packet;
    int             frameFinished;

    while(av_read_frame(handle->pFormatCtx, &packet) >= 0) {
        // Is this a packet from the video stream?
        if(packet.stream_index==handle->videoStream) {
            // Decode video frame
            avcodec_decode_video2(handle->pCodecCtx, handle->pFrame, &frameFinished, &packet);
            // Did we get a video frame?
            if(frameFinished) {
                sws_scale_and_add_alpha
                (
                    handle->sws_ctx,
                    (uint8_t const * const *)handle->pFrame->data,
                    handle->pFrame->linesize,
                    0,
                    handle->pCodecCtx->height,
                    handle->pFrameARGB->data,
                    handle->pFrameARGB->linesize,
                    my_alpha_channel
                );

                return handle->pFrameARGB->data;
            }
        }
    }

    return NULL;
}

0 个答案:

没有答案
相关问题