ffmpeg读取内存rgb数据初始化流程
(2012-09-17 17:23:27)
标签:
ffmpeg压缩传输流媒体it |
分类: ffmpeg |
//1.function
void COsgVideo::init()
{
av_register_all();
//注册编辑码器;
if ( NULL ==
m_pOutputFormat)
//初始化输出流;
m_pOutputFormat = av_guess_format("AVI", NULL,
NULL);
m_pFormatCtx =
avformat_alloc_context();
//为AVFormatContext分配空间及初始化;
if (!m_pFormatCtx)
{
wprintf(L"不能使用的输出文件扩展: 使用 MPEG 格式代替;\n");
return;
}
m_pFormatCtx->oformat = m_pOutputFormat;
if (m_pOutputFormat->video_codec !=
CODEC_ID_NONE)
{
m_pVideoStream = addVideoStream(m_pFormatCtx,
m_pOutputFormat->video_codec, m_width,
m_height);
}
if (m_pVideoStream) // 现在所有的参数设置完毕,
我们可以打开视频编解码器,初始化必要的缓冲区;
{
openVideo(m_pFormatCtx, m_pVideoStream);
}
m_yuvFrame->pts = 0;
}
//2.function
AVStream* COsgVideo::addVideoStream(AVFormatContext *pFormatCtx, CodecID codec_id, int width, int height)
{
AVStream*
stream = avformat_new_stream(pFormatCtx, NULL);
if
(!stream)
{
wprintf(L"初始化视频流失败;\n");
return
NULL;
}
AVCodecContext* pCodecCtx = stream->codec;
AVCodec*
pCodec =
avcodec_find_encoder(codec_id);
// 寻找视频编解码器 ;
if
(!pCodec)
{
wprintf(L"未能找到视频编解码器;\n");
return
NULL;
}
avcodec_get_context_defaults3(pCodecCtx, pCodec);
pCodecCtx->codec_id = codec_id;
pCodecCtx->bit_rate =
400000;
void COsgVideo::init()
{
}
//2.function
AVStream* COsgVideo::addVideoStream(AVFormatContext *pFormatCtx, CodecID codec_id, int width, int height)
{