FFMPEG:压缩之H264编码(YUV420P->H264)
来源:互联网 发布:磁力搜索 知乎 编辑:程序博客网 时间:2024/04/28 08:33
720*576@25hz,550帧的yuv420p数据,编码时间13.3秒。
void CTest0Dlg::OnButton5()
{
// TODO: Add your control notification handler code here
int nWidth = 720;
int nHeight= 576;
av_register_all();
avcodec_register_all();
AVFrame *m_pYUVFrame = new AVFrame[1];; //YUV帧数据
AVCodecContext *c= NULL;
AVCodec *pCodecH264; //编码器
uint8_t * yuv_buff;//
//查找h264编码器
pCodecH264 = avcodec_find_encoder(CODEC_ID_H264);
if(!pCodecH264)
{
fprintf(stderr, "h264 codec not found\n");
exit(1);
}
c= avcodec_alloc_context();
c->bit_rate = 1000000;// put sample parameters
c->width =720;//
c->height = 576;//
// frames per second
AVRational rate;
rate.num = 1;
rate.den = 25;
c->time_base= rate;//(AVRational){1,25};
c->gop_size = 10; // emit one intra frame every ten frames
c->max_b_frames=1;
c->thread_count = 1;
c->pix_fmt = PIX_FMT_YUV420P;//PIX_FMT_RGB24;
//av_opt_set(c->priv_data, /*"preset"*/"libvpx-1080p.ffpreset", /*"slow"*/NULL, 0);
//打开编码器
if(avcodec_open(c,pCodecH264)<0)
TRACE("不能打开编码库");
int size = c->width * c->height;
yuv_buff = (uint8_t *) malloc((size * 3) / 2); // size for YUV 420
//图象编码
int outbuf_size=100000;
uint8_t * outbuf= (uint8_t*)malloc(outbuf_size);
int u_size = 0;
FILE *f=NULL;
char * filename = "e:\\pic\\000.264";
f = fopen(filename, "wb");
if (!f)
{
TRACE( "could not open %s\n", filename);
exit(1);
}
AVPacket avpkt;
FILE *fp;
fp = fopen("d:\\temp\\VIDEO720576.yuv","rb+");
//AVFrame *pTFrame=new AVFrame
while (1)
{
int len = fread(yuv_buff,1,nWidth* nHeight*3/2,fp);
if (len==0)
{
break;
}
avpicture_fill((AVPicture*)m_pYUVFrame, (uint8_t*)yuv_buff, PIX_FMT_YUV420P, nWidth, nHeight);
int got_packet_ptr = 0;
av_init_packet(&avpkt);
avpkt.data = outbuf;
avpkt.size = outbuf_size;
while(1)
{
u_size = avcodec_encode_video(c, outbuf, outbuf_size, m_pYUVFrame);
if (u_size > 0 && u_size<100000)
{
fwrite(avpkt.data, 1, u_size, f);
break;
}
}
}
fclose(f);
fclose(fp);
delete []m_pYUVFrame;
free(outbuf);
avcodec_close(c);
av_free(c);
MessageBox("over");
}
http://download.csdn.net/detail/mao0514/8202691
0 0
- FFMPEG:压缩之H264编码(YUV420P->H264)
- iOS FFmpeg实时YUV420P编码H264
- FFMPEG:H264解码-SDL显示(RGB32、RGB24、YUV420P、YUV422)
- ffmpeg把H264数据流解码成YUV420P
- 嵌入式linux------ffmpeg移植 编码H264(am335x编码H264)
- ffmpeg--编码解码h264
- FFMPEG编码h264过程
- ffmpeg h264 编码。。。
- ffmpeg学习八:软件生成yuv420p视频并将其编码为H264格式
- ffmpeg 实现视频h264编码 (一)
- H264之ffmpeg解码
- 使用FFMpeg进行H264编码
- 使用FFMpeg进行H264编码
- 使用FFMpeg进行H264编码
- 使用FFMpeg进行H264编码
- 使用FFMpeg进行H264编码
- 使用FFMpeg进行H264编码 .
- 使用FFMpeg进行H264编码
- 8天玩转并行开发——第八天 用VS性能向导解剖你的程序
- android程序开机启动
- org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read
- 安装oracle之后,服务里面没有OracleOraDb10g_home1TNSListener
- PHP求字符串的长度 部分正则表达式
- FFMPEG:压缩之H264编码(YUV420P->H264)
- dom4j创建带有命名空间的xml
- abstract和interface的区别
- Win2012与SQL2008R2群集
- First Missing Positive
- 谷歌浏览器插件使用
- Windows下删除不需要的服务
- 【网络协议】基于winpcap的以太网络抓包及协议分析
- linux spi子系统