【发布时间】:2016-12-21 10:09:17
【问题描述】:
我正在寻找一种将我自己的 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;
}
【问题讨论】:
标签: c ffmpeg video-streaming