@ -1232,8 +1232,8 @@ void PushFlow::encodePushFlow()
codecContext - > height = m_iHeight ;
codecContext - > time_base = { 1 , m_iFramerateVideo } ;
codecContext - > pix_fmt = AV_PIX_FMT_YUV420P ; // 设置为YUV420P格式
codecContext - > gop_size = 1 ; //多少帧产生一组关键帧
codecContext - > max_b_frames = 1 ; //b帧, 参考帧
codecContext - > gop_size = 50 ; //多少帧产生一组关键帧
codecContext - > max_b_frames = 0 ; //b帧, 参考帧: 设置为1会导致视频回退的现象
// codecContext->bit_rate = 1000000; // 设置比特率为 1000000
// 打开视频编码器
@ -1246,17 +1246,17 @@ void PushFlow::encodePushFlow()
}
// 打开输出文件
if ( avio_open( & formatContext- > pb , outputVideoPath, AVIO_FLAG_WRITE) < 0 )
{
qDebug( ) < < " Error: Failed to open output file" ;
avcodec_close( codecContext) ;
avcodec_free_context( & codecContext) ;
avformat_free_context( formatContext) ;
return;
}
// if ( avio_open(& formatContext->pb, outputVideoPath, AVIO_FLAG_WRITE) < 0)
// {
// qDebug() << " Error: Failed to open output file";
// avcodec_close( codecContext);
// avcodec_free_context(& codecContext);
// avformat_free_context( formatContext);
// return;
// }
// 写入文件头
avformat_write_header( formatContext, nullptr) ;
// avformat_write_header( formatContext, nullptr);
// 使用sws_scale进行颜色空间转换
SwsContext * swsContext = sws_getContext ( m_iWidth , m_iHeight , AV_PIX_FMT_BGR24 ,
@ -1345,7 +1345,7 @@ void PushFlow::encodePushFlow()
fclose ( fp ) ;
// 写入文件尾
av_write_trailer( formatContext) ;
// av_write_trailer( formatContext);
// 释放AVFrame和相关资源
av_freep ( & frame - > data [ 0 ] ) ;