qnx环境下编译ffmpeg及解码mp4实践
  MJlmRDrYd0Ow 2023年11月02日 65 0


一 ffmpeg简介

1.ffmpeg是一套可以用来进行音视频处理的工具和编解码库;

2.采用LGPL或GPL许可证(不能修改源码,只能使用so库,如果要修改源码,必须发布工程代码);

3.ffmpeg对与硬件平台、GPU做了很多优化,效率非常高;

4.包含库:

(1)avcodec 编解码(最重要的库)

(2)avformat 封装格式处理

(3)avfilter 滤镜特效处理

(4)avdevice 各种设备的输入输出

(5)avutil 工具库

(6)postproc 后加工

(7)swresample 音频采样数据格式转换

(8)swscale 视频像素数据格式转换

二 在qnx710环境编译ffmpeg源码

1.源码:

​GitHub - FFmpeg/FFmpeg: Mirror of https://git.ffmpeg.org/ffmpeg.git​

2.解压

tar jxvf ffmpeg-snapshot.tar.bz2

3.下载yasm(yasm是汇编编译器,ffmpeg为了提高效率使用了汇编指令,如MMX和SSE等,所以系统中未安装yasm时,就会报“nasm/yasm not found or too old. Use --disable-x86asm for a crippled build.”)

wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
#解压
tar zxvf yasm-1.3.0.tar.gz
cd yasm-1.3.0
./configure
make
cp -f yasm ytasm vsyasm /home/zt/ffmpeg/ #将编译出来的yasm拷贝到ffmpeg目录
export PATH=../:$PATH #修改系统路径


4.编译ffmpeg


#! /bin/bash

g_root_path="$( cd "$( dirname "$0" )" && pwd )" #当前路径

function update_build_folder(){
local build_dir=$1
if [[ -z $1 ]]
then
build_dir="build"
fi

if [[ ! -d $build_dir ]]
then
mkdir ${build_dir}
echo ${build_dir}
return 0
else
build_dir=$build_dir"1"
update_build_folder ${build_dir}
return 0
fi
}

function compile_ffmpeg(){
local build_dir_name=$1
local ffmpeg_source_dir_path=$2
local qnx_sdp_source_dir_path=$3

if [[ -z build_dir_name ]] || [[ -z ffmpeg_source_dir_path ]] || [[ -z qnx_sdp_source_dir_path ]]
then
echo error should input 3 param
fi

path_build_dir=$(update_build_folder "$g_root_path/"${build_dir_name})
local pkgconfig_dir_path=$(update_build_folder ${path_build_dir}/pkg)

echo current establish build dir:$path_build_dir
echo current establish pkg dir:$pkgconfig_dir_path

source ${qnx_sdp_source_dir_path}/qnx710/qnxsdp-env.sh

cd ${ffmpeg_source_dir_path}
./configure \
--cc=${qnx_sdp_source_dir_path}/qnx710/host/linux/x86_64/usr/bin/aarch64-unknown-nto-qnx7.1.0-gcc-8.3.0 \
--prefix=${path_build_dir} \
--pkgconfigdir=${pkgconfig_dir_path} \
--enable-pic \
--enable-cross-compile \
--disable-optimizations \
--disable-stripping \
--target-os=qnx \
--arch=aarch64 \
--enable-shared \
--disable-static \
--enable-gpl \
--enable-nonfree \
--enable-asm \
--disable-avdevice \
--disable-swresample \
--disable-postproc \
--disable-avfilter \
--disable-programs \
--disable-logging \
--disable-everything \
--enable-avformat \
--enable-decoder=hevc \
--enable-decoder=h264 \
--enable-decoder=mpeg4 \
--enable-decoder=aac \
--disable-ffplay \
--disable-ffprobe \
--disable-doc \
--disable-devices \
--disable-network \
--disable-hwaccels \
--disable-parsers \
--disable-bsfs \
--disable-debug \
--enable-protocol=file \
--enable-demuxer=mov \
--enable-demuxer=flv \
--disable-indevs \
--extra-cflags="-std=gnu99 -fPIC" \
--disable-outdevs


make && make install
}

compile_ffmpeg \
ffmpeg_build \
/home/xx/ffmpeg/ffmpeg \
/home/xx/qnx710


注意修改如下:


compile_ffmpeg \
ffmpeg_build \ #编译后相关库输出路径
/home/xx/ffmpeg/ffmpeg \ #ffmpeg源码路径
/home/xx/qnx710 #qnx710环境路径

使用时,需要拷贝inclue和lib到自己的代码工程目录,添加相关库链接即可。

三 ffmpeg解码mp4流程

1.打开视频

avformat_open_input(&format_ctx_, video_path, nullptr, nullptr);

2.寻找视频流

avformat_find_stream_info(format_ctx_, nullptr);

3.定位视频索引通道

for (uint i = 0;i < format_ctx_->nb_streams;i++) {
LOG_I("codec_type:%d", format_ctx_->streams[i]->codecpar->codec_type);
if (AVMEDIA_TYPE_VIDEO == format_ctx_->streams[i]->codecpar->codec_type) {
video_stream_index_ = i;
break;
}
}

4.寻找解码器

codec_ = (AVCodec*)avcodec_find_decoder(format_ctx_->streams[video_stream_index_]->codecpar->codec_id);

5.创建解码上下文

codec_ctx_ = avcodec_alloc_context3(codec_);

6.为解码上下文分配参数

ret = avcodec_parameters_to_context(codec_ctx_, format_ctx_->streams[video_stream_index_]->codecpar);

7.配置解码线程数

codec_ctx_->thread_count = thread_num_;

8.打开解码器

ret = avcodec_open2(codec_ctx_, codec_, nullptr);

四 ffmpeg解码mp4实例

1.功能:对指定mp4(1280✖800)文件进行解码,输出为(1280✖800)uyvy格式文件

2.代码

​https://github.com/wangzhicheng2013/ffmpeg_decode_video​

注意:替换I420转uyvy函数即可

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  4koL3J55wyKx   2023年11月13日   35   0   0 icogitCentOS
  b1UHV4WKBb2S   2023年11月13日   39   0   0 ide抗锯齿
  9E2BTpjt8nym   2023年12月06日   34   0   0 WindowsgitCentOS
  b1UHV4WKBb2S   2023年11月13日   33   0   0 裁剪ideflutter
  zSWNgACtCQuP   2023年11月13日   29   0   0 ide
MJlmRDrYd0Ow