1. <pre name="code" class="cpp"><pre name="code" class="cpp">/*
  2. 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
  3. */
  4. #include "stdio.h"
  5. #include "stdlib.h"
  6. #include "libavformat/avformat.h"
  7. #include "libavdevice/avdevice.h"
  8. #include "libswresample/swresample.h"
  9. #include "libavutil/opt.h"
  10. #include "libavutil/channel_layout.h"
  11. #include "libavutil/parseutils.h"
  12. #include "libavutil/samplefmt.h"
  13. #include "libavutil/fifo.h"
  14. #include "libavutil/intreadwrite.h"
  15. #include "libavutil/dict.h"
  16. #include "libavutil/mathematics.h"
  17. #include "libavutil/pixdesc.h"
  18. #include "libavutil/avstring.h"
  19. #include "libavutil/imgutils.h"
  20. #include "libavutil/timestamp.h"
  21. #include "libavutil/bprint.h"
  22. #include "libavutil/time.h"
  23. #include "libavutil/threadmessage.h"
  24. #include "libavfilter/avcodec.h"
  25. #include "libavcodec/avcodec.h"
  26. #if HAVE_SYS_RESOURCE_H
  27. #include <sys/time.h>
  28. #include <sys/types.h>
  29. #include <sys/resource.h>
  30. #elif HAVE_GETPROCESSTIMES
  31. #include <windows.h>
  32. #endif
  33. #if HAVE_GETPROCESSMEMORYINFO
  34. #include <windows.h>
  35. #include <psapi.h>
  36. #endif
  37. #if HAVE_SYS_SELECT_H
  38. #include <sys/select.h>
  39. #endif
  40. #if HAVE_TERMIOS_H
  41. #include <fcntl.h>
  42. #include <sys/ioctl.h>
  43. #include <sys/time.h>
  44. #include <termios.h>
  45. #elif HAVE_KBHIT
  46. #include <conio.h>
  47. #endif
  48. #if HAVE_PTHREADS
  49. #include <pthread.h>
  50. #endif
  51. #include <time.h>
  52. #include "libavutil/avassert.h"
  53. #define MAX_LEN  1024 * 50
  54. int main()
  55. {
  56. //下面初始化h264解码库
  57. //avcodec_init();
  58. av_register_all();
  59. avcodec_register_all();
  60. /* find the video encoder */
  61. AVCodec *videoCodec = avcodec_find_encoder(CODEC_ID_H264);//得到264的编码器类
  62. if(!videoCodec)
  63. {
  64. printf("avcodec_find_decoder error\n");
  65. return -1;
  66. }
  67. /*AVCodecParserContext *avParserContext = av_parser_init(CODEC_ID_H264);//得到解析帧类,主要用于后面的帧头查找
  68. if(!avParserContext)
  69. {
  70. printf("av_parser_init  error\n");
  71. return -1;
  72. }*/
  73. AVCodecContext *codec_ = avcodec_alloc_context3(videoCodec);//编码会话层
  74. if(!codec_)
  75. {
  76. printf("avcodec_alloc_context3  error\n");
  77. return -1;
  78. }
  79. //初始化参数,下面的参数应该由具体的业务决定
  80. codec_->time_base.num = 1;
  81. codec_->time_base.den = 25;//帧率
  82. codec_->gop_size = 1;
  83. codec_->max_b_frames = 1;
  84. codec_->thread_count = 1;
  85. codec_->pix_fmt = PIX_FMT_YUV420P;
  86. //codec_->frame_number = 1; //每包一个视频帧
  87. //codec_->codec_type = AVMEDIA_TYPE_VIDEO;
  88. codec_->bit_rate = 1000000;
  89. codec_->width = 720;//视频宽
  90. codec_->height = 576;//视频高
  91. if(avcodec_open2(codec_, videoCodec, NULL) < 0)//打开编码器
  92. {
  93. printf("avcodec_open2 error\n");
  94. return -1;
  95. }
  96. FILE *myH264 = fopen("t.264", "wb");
  97. if(myH264 == NULL)
  98. {
  99. perror("cant open 264 file\n");
  100. return -1;
  101. }
  102. FILE *yuvfile = fopen("my264.yuv", "rb");
  103. if(yuvfile == NULL)
  104. {
  105. perror("cant open YUV file\n");
  106. return -1;
  107. }
  108. int readFileLen = 1;
  109. char readBuf[MAX_LEN];
  110. printf("readBuf address  is %x\n", readBuf);
  111. //
  112. int outbuf_size=100000;
  113. unsigned char * outbuf= malloc(outbuf_size);
  114. int u_size=0;
  115. AVPacket avpkt;
  116. unsigned char * yuv_buf= malloc(720*576*3/2);
  117. AVFrame *m_pYUVFrame=malloc(sizeof(AVFrame));
  118. int flag=0;
  119. while(1)
  120. {
  121. int len = fread(yuv_buf,720*576*3/2,1,yuvfile);
  122. if(len<=0)
  123. {
  124. printf("read over\n");
  125. break;
  126. }
  127. else
  128. {
  129. avpicture_fill((AVPicture*)m_pYUVFrame,(unsigned char *)yuv_buf,PIX_FMT_YUV420P,720,576);
  130. int got_packet_ptr =0;
  131. av_init_packet(&avpkt);
  132. avpkt.data=outbuf;
  133. avpkt.size=outbuf_size;
  134. while(1)
  135. {
  136. u_size = avcodec_encode_video(codec_,outbuf,outbuf_size,m_pYUVFrame);
  137. if(u_size>0 && u_size<100000)
  138. {
  139. m_pYUVFrame->pts++;
  140. fwrite(avpkt.data,1,u_size,myH264);
  141. flag++;
  142. break;
  143. }
  144. }
  145. }
  146. // if(flag>20)break;
  147. }
  148. avcodec_close(codec_);
  149. av_free(codec_);
  150. fclose(yuvfile);
  151. fclose(myH264);
  152. }
  153. </pre><br><br></pre>

嵌入式linux------ffmpeg移植 编码H264(am335x编码H264)的更多相关文章

  1. 【课程分享】深入浅出嵌入式linux系统移植开发 (环境搭建、uboot的移植、嵌入式内核的配置与编译)

    深入浅出嵌入式linux系统移植开发 (环境搭建.uboot的移植.嵌入式内核的配置与编译) 亲爱的网友,我这里有套课程想和大家分享,假设对这个课程有兴趣的,能够加我的QQ2059055336和我联系 ...

  2. 嵌入式linux系统移植(一)

    内容:   交叉编译环境   bootloader功能子系统   内核核心子系统   文件系统子系统要点:  搭建交叉编译环境  bootloader的选择和移植  kernel的配置.编译.移植和调 ...

  3. 嵌入式Linux系统移植——uboot常用命令

    flash的一般分区: 其它数据 环境变量 可执行程序.如bootloader print(可缩写为:pri):打印查看uboot这个软件中集成的环境变量setenv.saveenv:设置.保存环境变 ...

  4. 嵌入式Linux系统移植(二)——交叉编译工具集

    常用工具:readelf.size.nm.strip.strings.objdump.objcopy.addr2line readelf:读可执行文件的elf头 ELF Header: Magic: ...

  5. 手把手带你基于嵌入式Linux移植samba服务

    摘要:Samba是在Linux和UNIX系统上实现SMB协议的一个免费软件,由服务器及客户端程序构成. 本文分享自华为云社区<嵌入式Linux下移植samba服务--<基于北斗和4G ca ...

  6. 嵌入式linux和嵌入式android系统有什么区别和联系?

    转自:http://bbs.eeworld.com.cn/thread-430437-1-1.html 这个问题很多人问,尤其是初入嵌入式的菜鸟.其实大家都认为android是java,已经不是lin ...

  7. FFMPEG H264/H265 编码延迟问题

    最新使用FFmpeg进行H264的编码时,发现视频编码有延迟,不是实时编码.进过一番研究发现,仅仅要在调用avcodec_open2函数 打开编码器时,设置AVDictionary參数就可以.关键代码 ...

  8. H264视频编码成MP4文件

    firehood的专栏 Wince嵌入式开发       目录视图 摘要视图 订阅 赠书 | AI专栏(AI圣经!<深度学习>中文版)      每周荐书:Kotlin.分布式.Keras ...

  9. 开发RTSP 直播软件 H264 AAC 编码

    上一篇对摄像头预览,拍照做了大概的介绍,现在已经可以拿到视频帧了,在加上 RTSP 实现,就是直播的雏形,当然还要加上一些 WEB 管理和手机平台的支援,就是一整套直播软件. 介绍一些基础概念:RTP ...

  10. 采集音频和摄像头视频并实时H264编码及AAC编码[转]

    0. 前言 我在前两篇文章中写了DirectShow捕获音视频然后生成avi,再进行264编码的方法.那种方法有一些局限性,不适合实时性质的应用,如:视频会议.视频聊天.视频监控等.本文所使用的技术, ...

随机推荐

  1. vsftpd安装和使用 Linux系统和window系统

    vsftpd 安装(Linux)一.安装系统环境 centos 6.9 64位二.vsftpd版本 vsftpd-2.2.2-24.el6.x86_64三.安装步骤1.安装 执行 yum -y ins ...

  2. bzoj 4830: [Hnoi2017]抛硬币 [范德蒙德卷积 扩展lucas]

    4830: [Hnoi2017]抛硬币 题意:A投a次硬币,B投b次硬币,a比b正面朝上次数多的方案数,模\(10^k\). \(b \le a \le b+10000 \le 10^{15}, k ...

  3. BZOJ 1770: [Usaco2009 Nov]lights 燈 [高斯消元XOR 搜索]

    题意: 经典灯问题,求最少次数 本题数据不水,必须要暴搜自由元的取值啦 想了好久 然而我看到网上的程序都没有用记录now的做法,那样做遇到自由元应该可能会丢解吧...? 我的做法是把自由元保存下来,枚 ...

  4. element ui 1.4 升级到 2.0.11

    公司的框架 选取的是 花裤衩大神开源的 基于 element ui + Vue 的后台管理项目, 项目源码就不公开了,记录 分享下 步骤 1. 卸载 element ui 1.4的依赖包 2. 卸载完 ...

  5. MIT-线性代数笔记(7-11)

    第 07 讲 求解 Ax=0 :主变量,特解 矩阵的秩Rank(A):矩阵主元的个数. 找出“主变量”pivotvariables,主列,即主元所在的列,其他列,称为自由列.(自由列表示可以自由或任意 ...

  6. 使用Spring Boot搭建应用开发框架(一) —— 基础架构

    Spring的简史 第一阶段:XML配置,在Spring1.x时代,使用Spring开发满眼都是xml配置的Bean,随着项目的扩大,我们需要把xml配置文件分放到不同的配置文件里,那时候需要频繁的在 ...

  7. JSON工具类

    import java.sql.Timestamp; import java.util.Collection; import java.util.Date; import org.soul.util. ...

  8. CocosCreator游戏开发---菜鸟学习之路(一)

    PS(废话): 辞职后在家好久好久了,久到经济不允许了,接着就准备再次出去找工作了,然而工作哪有那么好找,特别是像我这种菜鸟.而且我还准备转行,准备去做游戏,技能等级接近于0,那工作就更难找了.既然如 ...

  9. Apache设置二级域名和虚拟主机

    apache  httpd.conf 最后: ------------------------------NameVirtualHost *:80<VirtualHost *:80>    ...

  10. 一个备份mysql 数据库的脚本

    # 获取当前系统日期,格式为: 2009-2-21DATE=`date "+%F"` # 定义mysql 服务的主目录 DB_DIR=/usr # 定义备份后的路径BAK_DIR= ...