ffmpeg学习历程

一. 需求

       将ffmpeg移植到arm-linux环境(我的是海思HI35XX系列平台:HI3531A, HI3521A, HI3520D等),实现将H264裸流(我的是直接从海思编码模块VENC获取)封装成.mp4或.avi格式的视频文件。
      由于嵌入式环境FLASH空间有限,必须将ffmpeg裁剪得足够小。

 实现代码: ffmpeg实现将H264裸流封装成.mp4或.avi文件

二. ffmpeg学习 

● 跟着雷神认识ffmpeg

    [总结]FFMPEG视音频编解码零基础学习方法

● 必须明白的概念:

    编程中什么是「Context(上下文)」?

● 免费分享雷神的ffmpeg相关工程

    雷霄骅(leixiaohua1020)ffmpeg相关工程

● 遇到的问题:

    雷神的ffmpeg工程都是基于VS2010写的,而我用VS2013打开,编译报如下错误:

    error LNK2026: 模块对于 SAFESEH 映像是不安全的

三. ffmpeg移植 

● 源码下载

    http://ffmpeg.org/releases/ 

    我下的是ffmpeg-2.1.3.tar.gz,用这个版本原因:
           版本跟雷神教程的差不多(2014年左右的版本);
           较新版本(3.x,4.x)很多API都变了,不利于同步雷神的教程学习;
           够用就行,没必须追求最新的;
           然后,213,你懂的。。。

● 源码分析

    ffmpeg结构体分析

    ffmpeg源代码分析

● 移植Ubuntu平台

./configure --prefix=./install

make

make install

(如果提示:yasm/nasm not found or too old. Use --disable-yasm for a crippled build. 就按它说的加 --disable-yasm)

编译后,得到相关头文件和库,把雷神源码拷过来编译即可运行

 g++ test_01.cpp -o a.out -I./include/ -L./lib/ -lavformat -lavcodec -lavutil -lpthread -ldl -lm

● 移植arm-linux平台(我的是海思HI3521A) 

./configure --prefix=./install --enable-cross-compile --target-os=linux --cpu=cortex-a7 --arch=arm --cross-prefix=arm-hisiv300-linux- 

make

make install

arm-hisiv300-linux-g++ test_01.cpp -o a.out -I./include/ -L./lib/ -lavformat -lavcodec -lavutil -lpthread -ldl -lm

● 可能遇到的问题

①报错:各种"undefined reference to xxx"

   办法:我们是C++工程,而ffmpeg是C语言实现的,所有包含的ffmpeg头文件,用extern "C"引用
                extern "C"
                {
                #include "libavformat/avformat.h"
                #include "libavcodec/avcodec.h"
                }

 ②报错:error: #error missing -D__STDC_CONSTANT_MACROS / #define __STDC_CONSTANT_MACROS

    办法:添加__STDC_CONSTANT_MACROS宏(雷神也是这么做的)

               #define __STDC_CONSTANT_MACROS

③报错:ffmpeg的time.h和自己工程的time.h冲突,导致时间相关的结构体都出错
                error: field ‘st_atim’ has incomplete type
                error: field ‘st_mtim’ has incomplete type
                error: field ‘st_ctim’ has incomplete type
                error: variable ‘timespec time1’ has initializer but incomplete type
                ................

    办法:ffmpeg源码中的time.c和time.h重命名为avtime.c和time.h,当然,ffmpeg源码所有涉及包含此time.h地方也相应改动

④报错:In function ‘int32_t av_clipl_int32_c(int64_t)’:
                error: ‘UINT64_C’ was not declared in this scope

    办法:在libavutil/common.h添加如下代码:

                #ifndef UINT64_C
                #define UINT64_C(value) __CONCAT(value, ULL)
                #endif

● 源码修改    

基于上述的③④两点修改源码,并将修改后的源码分享给大家

修改过的 ffmpeg-2.1.3.tar.gz

四. ffmpeg裁剪

 ● 编译裁剪

 ● 源码裁剪

 

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值