嵌入式linux------ffmpeg移植 编码H264(am335x编码H264)
- <pre name="code" class="cpp"><pre name="code" class="cpp">/*
- arm-linux-gcc -o yuv2264 yuv2264.c -I/usr/local/ffmpeg_arm/include/ -L/usr/local/ffmpeg_arm/lib/ -lswresample -lavformat -lavutil -lavcodec -lswscale -lx264 libSDL.a
- */
- #include "stdio.h"
- #include "stdlib.h"
- #include "libavformat/avformat.h"
- #include "libavdevice/avdevice.h"
- #include "libswresample/swresample.h"
- #include "libavutil/opt.h"
- #include "libavutil/channel_layout.h"
- #include "libavutil/parseutils.h"
- #include "libavutil/samplefmt.h"
- #include "libavutil/fifo.h"
- #include "libavutil/intreadwrite.h"
- #include "libavutil/dict.h"
- #include "libavutil/mathematics.h"
- #include "libavutil/pixdesc.h"
- #include "libavutil/avstring.h"
- #include "libavutil/imgutils.h"
- #include "libavutil/timestamp.h"
- #include "libavutil/bprint.h"
- #include "libavutil/time.h"
- #include "libavutil/threadmessage.h"
- #include "libavfilter/avcodec.h"
- #include "libavcodec/avcodec.h"
- #if HAVE_SYS_RESOURCE_H
- #include <sys/time.h>
- #include <sys/types.h>
- #include <sys/resource.h>
- #elif HAVE_GETPROCESSTIMES
- #include <windows.h>
- #endif
- #if HAVE_GETPROCESSMEMORYINFO
- #include <windows.h>
- #include <psapi.h>
- #endif
- #if HAVE_SYS_SELECT_H
- #include <sys/select.h>
- #endif
- #if HAVE_TERMIOS_H
- #include <fcntl.h>
- #include <sys/ioctl.h>
- #include <sys/time.h>
- #include <termios.h>
- #elif HAVE_KBHIT
- #include <conio.h>
- #endif
- #if HAVE_PTHREADS
- #include <pthread.h>
- #endif
- #include <time.h>
- #include "libavutil/avassert.h"
- #define MAX_LEN 1024 * 50
- int main()
- {
- //下面初始化h264解码库
- //avcodec_init();
- av_register_all();
- avcodec_register_all();
- /* find the video encoder */
- AVCodec *videoCodec = avcodec_find_encoder(CODEC_ID_H264);//得到264的编码器类
- if(!videoCodec)
- {
- printf("avcodec_find_decoder error\n");
- return -1;
- }
- /*AVCodecParserContext *avParserContext = av_parser_init(CODEC_ID_H264);//得到解析帧类,主要用于后面的帧头查找
- if(!avParserContext)
- {
- printf("av_parser_init error\n");
- return -1;
- }*/
- AVCodecContext *codec_ = avcodec_alloc_context3(videoCodec);//编码会话层
- if(!codec_)
- {
- printf("avcodec_alloc_context3 error\n");
- return -1;
- }
- //初始化参数,下面的参数应该由具体的业务决定
- codec_->time_base.num = 1;
- codec_->time_base.den = 25;//帧率
- codec_->gop_size = 1;
- codec_->max_b_frames = 1;
- codec_->thread_count = 1;
- codec_->pix_fmt = PIX_FMT_YUV420P;
- //codec_->frame_number = 1; //每包一个视频帧
- //codec_->codec_type = AVMEDIA_TYPE_VIDEO;
- codec_->bit_rate = 1000000;
- codec_->width = 720;//视频宽
- codec_->height = 576;//视频高
- if(avcodec_open2(codec_, videoCodec, NULL) < 0)//打开编码器
- {
- printf("avcodec_open2 error\n");
- return -1;
- }
- FILE *myH264 = fopen("t.264", "wb");
- if(myH264 == NULL)
- {
- perror("cant open 264 file\n");
- return -1;
- }
- FILE *yuvfile = fopen("my264.yuv", "rb");
- if(yuvfile == NULL)
- {
- perror("cant open YUV file\n");
- return -1;
- }
- int readFileLen = 1;
- char readBuf[MAX_LEN];
- printf("readBuf address is %x\n", readBuf);
- //
- int outbuf_size=100000;
- unsigned char * outbuf= malloc(outbuf_size);
- int u_size=0;
- AVPacket avpkt;
- unsigned char * yuv_buf= malloc(720*576*3/2);
- AVFrame *m_pYUVFrame=malloc(sizeof(AVFrame));
- int flag=0;
- while(1)
- {
- int len = fread(yuv_buf,720*576*3/2,1,yuvfile);
- if(len<=0)
- {
- printf("read over\n");
- break;
- }
- else
- {
- avpicture_fill((AVPicture*)m_pYUVFrame,(unsigned char *)yuv_buf,PIX_FMT_YUV420P,720,576);
- int got_packet_ptr =0;
- av_init_packet(&avpkt);
- avpkt.data=outbuf;
- avpkt.size=outbuf_size;
- while(1)
- {
- u_size = avcodec_encode_video(codec_,outbuf,outbuf_size,m_pYUVFrame);
- if(u_size>0 && u_size<100000)
- {
- m_pYUVFrame->pts++;
- fwrite(avpkt.data,1,u_size,myH264);
- flag++;
- break;
- }
- }
- }
- // if(flag>20)break;
- }
- avcodec_close(codec_);
- av_free(codec_);
- fclose(yuvfile);
- fclose(myH264);
- }
- </pre><br><br></pre>
嵌入式linux------ffmpeg移植 编码H264(am335x编码H264)的更多相关文章
- 【课程分享】深入浅出嵌入式linux系统移植开发 (环境搭建、uboot的移植、嵌入式内核的配置与编译)
深入浅出嵌入式linux系统移植开发 (环境搭建.uboot的移植.嵌入式内核的配置与编译) 亲爱的网友,我这里有套课程想和大家分享,假设对这个课程有兴趣的,能够加我的QQ2059055336和我联系 ...
- 嵌入式linux系统移植(一)
内容: 交叉编译环境 bootloader功能子系统 内核核心子系统 文件系统子系统要点: 搭建交叉编译环境 bootloader的选择和移植 kernel的配置.编译.移植和调 ...
- 嵌入式Linux系统移植——uboot常用命令
flash的一般分区: 其它数据 环境变量 可执行程序.如bootloader print(可缩写为:pri):打印查看uboot这个软件中集成的环境变量setenv.saveenv:设置.保存环境变 ...
- 嵌入式Linux系统移植(二)——交叉编译工具集
常用工具:readelf.size.nm.strip.strings.objdump.objcopy.addr2line readelf:读可执行文件的elf头 ELF Header: Magic: ...
- 手把手带你基于嵌入式Linux移植samba服务
摘要:Samba是在Linux和UNIX系统上实现SMB协议的一个免费软件,由服务器及客户端程序构成. 本文分享自华为云社区<嵌入式Linux下移植samba服务--<基于北斗和4G ca ...
- 嵌入式linux和嵌入式android系统有什么区别和联系?
转自:http://bbs.eeworld.com.cn/thread-430437-1-1.html 这个问题很多人问,尤其是初入嵌入式的菜鸟.其实大家都认为android是java,已经不是lin ...
- FFMPEG H264/H265 编码延迟问题
最新使用FFmpeg进行H264的编码时,发现视频编码有延迟,不是实时编码.进过一番研究发现,仅仅要在调用avcodec_open2函数 打开编码器时,设置AVDictionary參数就可以.关键代码 ...
- H264视频编码成MP4文件
firehood的专栏 Wince嵌入式开发 目录视图 摘要视图 订阅 赠书 | AI专栏(AI圣经!<深度学习>中文版) 每周荐书:Kotlin.分布式.Keras ...
- 开发RTSP 直播软件 H264 AAC 编码
上一篇对摄像头预览,拍照做了大概的介绍,现在已经可以拿到视频帧了,在加上 RTSP 实现,就是直播的雏形,当然还要加上一些 WEB 管理和手机平台的支援,就是一整套直播软件. 介绍一些基础概念:RTP ...
- 采集音频和摄像头视频并实时H264编码及AAC编码[转]
0. 前言 我在前两篇文章中写了DirectShow捕获音视频然后生成avi,再进行264编码的方法.那种方法有一些局限性,不适合实时性质的应用,如:视频会议.视频聊天.视频监控等.本文所使用的技术, ...
随机推荐
- Yii的Relational Active Record三张表连接查询
需求如下: 查询book表信息,同时关联entitystags表,以entitystags的字段eid关联book的主键,再关联查询tags表,以entitystags表的tid字段关联tags表的主 ...
- iOS-隐藏Navigation导航栏线
去除navigationBar上那条线: ///隐藏navigationBar导航栏线(直接写在UINavigationController-viewDidLoad方法里面即可) UIView *ba ...
- SpringMVC源码情操陶冶-DispatcherServlet简析(二)
承接前文SpringMVC源码情操陶冶-DispatcherServlet类简析(一),主要讲述初始化的操作,本文将简单介绍springmvc如何处理请求 DispatcherServlet#doDi ...
- 使用json文件给es中导入数据
使用json文件可以给es中导入数据,10万条左右的数据可以一次导入,数量太大时导入就会报错.大数量的到导入还是需要用bulk方式. accounts.json文件格式如下: {"index ...
- BZOJ 4259: 残缺的字符串 [FFT]
4259: 残缺的字符串 题意:s,t,星号任意字符,匹配方案数 和上题一样 多乘上一个\(a_{j+i}\)就行了 #include <iostream> #include <cs ...
- BZOJ 4408: [Fjoi 2016]神秘数 [主席树]
传送门 题意: 一个可重复数字集合S的神秘数定义为最小的不能被S的子集的和表示的正整数.例如S={1,1,1,4,13},8无法表示为集合S的子集的和,故集合S的神秘数为8.现给定n个正整数a[1]. ...
- BZOJ 1898: [Zjoi2005]Swamp 沼泽鳄鱼 [矩阵乘法]
1898: [Zjoi2005]Swamp 沼泽鳄鱼 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1082 Solved: 602[Submit][S ...
- Python之数据类型转换
平时我们在处理数据的时候,有些数据类型不是我们想要的,怎么办? 一.数据类型转换:要转换的类型(数据) 要把num01转换为整数:int(num01) 要把num01转换为浮点数:float(num0 ...
- 教我徒弟Android开发入门(二)
前言: 上一期实现了简单的QQ登录效果,这一期继续对上一期进行扩展 本期的知识点: Toast弹窗,三种方法实现按钮的点击事件监听 正文: Toast弹窗其实很简单,在Android Studio ...
- MySQL数据库基础(MySQL5.7安装、配置)
写在前面: MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下产品.MySQL 是最流行的关系型数据库管理系统之一,在 WEB 应用方面,MySQ ...