打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
使用ffmpeg进行h.264编码

m_fmt->video_codec = CODEC_ID_H264;

/* 添加视频流 */
m_video_st = av_new_stream(m_oc, 0);
if (!m_video_st) {
return 0;
}
m_videoc=avcodec_alloc_context();
m_videoc = m_video_st->codec;

/* 视频相关参数 */
m_videoc->codec_id = m_fmt->video_codec;
m_videoc->codec_type = CODEC_TYPE_VIDEO;
m_videoc->bit_rate = video_bitrate*1000;
m_videoc->width = video_width;
m_videoc->height = video_height;
m_videoc->time_base.den = 25;
m_videoc->time_base.num = 1;
m_videoc->dct_algo = 0;
m_videoc->gop_size = 12;
m_videoc->me_pre_cmp=2;
m_videoc->cqp = 26;
m_videoc->me_method =7;
m_videoc->qmin = 3;
m_videoc->qmax = 31;
m_videoc->max_qdiff = 3;
m_videoc->qcompress = 0.5;
m_videoc->qblur = 0.5;
m_videoc->nsse_weight = 8;
m_videoc->i_quant_factor = (float)0.8;
m_videoc->b_quant_factor = 1.25;
m_videoc->b_quant_offset = 1.25;

m_videoc->pix_fmt = PIX_FMT_YUV420P;//当前YUV420

if (m_videoc->codec_id == CODEC_ID_MPEG2VIDEO) {
m_videoc->max_b_frames = 2;
}
if (m_videoc->codec_id == CODEC_ID_MPEG1VIDEO){
m_videoc->mb_decision=2;
}


if(!strcmp(m_oc->oformat->name, "mp4")
|| !strcmp(m_oc->oformat->name, "mov")
|| !strcmp(m_oc->oformat->name, "3gp"))
//m_videoc->flags |= CODEC_FLAG_GLOBAL_HEADER;
m_videoc->flags |=CODEC_FLAG_QSCALE;

    /* 检查参数是否设置完毕*/
    if (av_set_parameters(m_oc, NULL) < 0) {
return 0;
    }
    dump_format(m_oc, 0, filename, 1);

/* 所有视频设置完毕,打开视频解码器,并打开必要的编码缓冲器            */
    if (m_video_st){

AVCodec *video_codec;

/* 查找视频解码器 */
video_codec = avcodec_find_encoder(m_videoc->codec_id);
if (!video_codec) {
return 0;
}

/* 打开视频解码器 */
if (avcodec_open(m_videoc, video_codec) < 0) {
return 0;
}

video_outbuf = NULL;
if (!(m_oc->oformat->flags & AVFMT_RAWPICTURE)) {
/* allocate output buffer */
/* XXX: API change will be done */
/* buffers passed into lav* can be allocated any way you prefer,
as long as they're aligned enough for the architecture, and
they're freed appropriately (such as using av_free for buffers
allocated with av_malloc) */
video_outbuf_size = 200000;
video_outbuf = (uint8_t *)av_malloc(video_outbuf_size);

}

/* allocate the encoded raw picture */
picture = alloc_picture(m_videoc->pix_fmt, m_videoc->width,m_videoc->height);
if (!picture) {
return 0;
}

/* if the output format is not YUV420P, then a temporary YUV420P
picture is needed too. It is then converted to the required
output format */
tmp_picture = NULL;
if (m_videoc->pix_fmt != PIX_FMT_YUV420P) {
tmp_picture = alloc_picture(PIX_FMT_YUV420P, m_videoc->width,m_videoc->height);
if (!tmp_picture) {
return 0;
}
}

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
FFmpeg浅尝辄止(二)
FFMpeg 中比较重要的函数以及数据结构
将摄像头原始RGB数据流编码成H.264文件
ffmpeg AVFilter介绍
using ffmpeg image2pipe with phantomjs to render video from webpage screenshots
(转)利用ffmpeg来进行视频解码的完整示例代码(H.264)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服