1.下载并编译FFMPEG。
https://github.com/kewlbear/FFmpeg-iOS-build-script
下载后有个build-ffmpeg.sh
文件。终端执行即可自动下载并编译完成。
我在运行的时候并没有提示权限的相关问题,如果你在安装的时候出现问题,自己搜索下怎么解决哈~
2.导入编译好的静态库
编译完成后,当前目录有个FFmpeg-iOS文件夹,拖进项目中。
3.添加引用库
AVFoundation.framework
libz.dylib
libbz2.dylib
libiconv.dylib
IOS9以后文件的后缀为tbd,不影响。
4.添加头文件搜索路径
Header Search Paths
-> $(PROJECT_DIR)/FFmpeg-iOS/include
错误情况:'libavcodec/avcodec.h' file not found
解决办法:检查include文件路径,并重新修改$(PROJECT_DIR)/....../FFmpeg-iOS/include
Library Search Paths
- >$(PROJECT_DIR)/FFmpeg-iOS/lib
同样可能因为你的路径不正确引起 file not found
的问题
5.修改一个.m文件为.mm,开启C/C++ 混编模式。
修改后,我的项目仍然报错 avcodec_configuration()
不可用。当我在复现这个问题的时候,把.mm修改回.m,这时候不会再报编译错误。应该是Xcode已经开启了混编模式,所以不会再出问题。并且编译通过,avcodec_configuration()
可以打印。
一、什么是ffmpeg
一套可以用来记录、转换数字音频、视频,并能将其转化为流的开源计算机程序。官网
二、ffmpeg下载、安装
1、终端执行下载命令:
brew install ffmpeg
#或者(区别是下面安装的为最新版本)
brew install ffmpeg --HEAD123
=brew install 安装依赖出现以下提示=
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see man brew
).
解决办法:
2、选择第三方仓库,安装options,并和ffmepg关联起来
有两个仓库,分别是homebrew-ffmpeg和varenc-homebrew-ffmpeg
brew tap homebrew-ffmpeg/ffmpeg
#从第三方下载
brew install homebrew-ffmpeg/ffmpeg/ffmpeg
#查看仓库支持哪些options
brew options homebrew-ffmpeg/ffmpeg/ffmpeg
#替换option
brew install homebrew-ffmpeg/ffmpeg/ffmpeg --with-<option1> --with-<option2> ...12345678
执行如上几个步骤后,就成功的安装好ffmepg及其依赖包,同时将ffmepg和许多编解码库关联起来了。
三、ffmpeg使用
1、ffmpeg ts与mp4互相转换
mp4转ts
ffmpeg -i 文件名.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 文件名.ts1
ts转mp4
ffmpeg -i 文件名.ts -acodec copy -vcodec copy -absf aac_adtstoasc 文件名.mp1
ts转mp3
ffmpeg -i 文件名.ts -f mp3 文件名.mp3
版本
ffmpeg version N-89803-g856b7cae9f Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 7.2.0 (GCC)
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-amf --enable-cuda --enable-cuvid --enable-d3d11va --enable-nvenc --enable-dxva2 --enable-avisynth --enable-libmfx
libavutil 56. 7.100 / 56. 7.100
libavcodec 58. 9.100 / 58. 9.100
libavformat 58. 3.100 / 58. 3.100
libavdevice 58. 0.100 / 58. 0.100
libavfilter 7. 11.101 / 7. 11.101
libswscale 5. 0.101 / 5. 0.101
libswresample 3. 0.101 / 3. 0.101
libpostproc 55. 0.100 / 55. 0.1001234567891011
用法
ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...1
获取帮助
-h -- 输出基本选项-h long -- 输出更多的选择-h full -- 输出所有选项(包括所有格式和编码特定的选项,很长)-h type=name -- 输出所有选项指定的decoder/encoder/demuxer/muxer/filter1234
获取 帮助/信息/功能
-L show license-h topic show help-? topic show help-help topic show help--help topic show help-version show version-buildconf show 构建配置-formats show available 格式-muxers show available 复用器-demuxers show available 解复用器-devices show available 设备-codecs show available 编解码器-decoders show available 解码器-encoders show available 编码器-bsfs show available 位流过滤-protocols show available 协议-filters show available 过滤器-pix_fmts show available 像素格式
-layouts show 标准的渠道布局-sample_fmts show available 音频样本格式-colors show available 色彩名称
-sources device list sources of the input device-sinks device list sinks of the output device-hwaccels show available HW加速度方法123456789101112131415161718192021222324
全局选项 (影响整个程序,而不是一个文件)
-loglevel loglevel 设置日志级别-v loglevel 设置日志级别-report 生成一个报告-max_alloc bytes 设置一个单独分配的块的最大大小-y 覆盖输出文件-n 不覆盖输出文件-ignore_unknown 忽略未知的流类型-filter_threads 过滤线程数(非复数)-filter_complex_threads 过滤线程数(复数)-stats 在编码过程中打印进度报告-max_error_rate ratio of errors 最大错误率(0.0:没有错误,1.0:100%错误)-bits_per_raw_sample number 设置每个原始样本的比特数-vol volume 改变音频音量(256=normal)12345678910111213
每个文件的主要选项:
-f fmt 强制格式-c codec 编解码器名称
-codec codec 编解码器名称-pre preset 预设的名称-map_metadata outfile[,metadata]:infile[,metadata]
从infile中设置outfile的元数据信息
-t duration 记录或转码 "duration" seconds of audio/video-to time_stop 录或转码停止时间-fs limit_size 设置文件大小的上限(字节)-ss time_off 设置开始时间偏移量-sseof time_off 设置起始时间偏移量相对于EOF-seek_timestamp 启用/禁用 seeking by timestamp with -ss-timestamp time 设置记录时间戳('now'来设置当前时间)-metadata string=string 添加元数据-program title=string:st=number...
添加指定流的程序
-target type 指定目标文件类型 ("vcd", "svcd", "dvd", "dv" or "dv50" with 可选的前缀 "pal-", "ntsc-" or "film-")-apad 音频垫-frames number 将帧数设置为输出-filter filter_graph 设置流的过滤图-filter_script filename 从文件中读取流过滤图描述-reinit_filter 对输入参数的改变进行重新初始化-discard discard-disposition disposition123456789101112131415161718192021222324
视频选项
-vframes number 将视频帧的数量设置为输出-r rate 设置帧速率 (Hz值,分数或abbreviation)-s size 设置帧大小 (WxH or abbreviation)-aspect aspect 设置长宽比 (4:3, 16:9 or 1.3333, 1.7777)-bits_per_raw_sample number 设置每个原始样本的比特数-vn 禁用视频-vcodec codec 强加视频编解码器 ('copy' to copy stream)-timecode hh:mm:ss[:;.]ff 设置初始时间码值.-pass n 选择通过数量 (1 to 3)-vf filter_graph 设置视频过滤器-ab bitrate 声频码率 (please use -b:a)-b bitrate 视频码率 (please use -b:v)-dn 禁用数据12345678910111213
音频选项
-aframes number 将音频帧的数量设置为输出-aq quality 设置音频质量 (codec-specific)-ar rate 设置音频采样率 (in Hz)-ac channels 设置音频信道数-an 禁用音频-acodec codec 强加音频编解码器 ('copy' to copy stream)-vol volume 改变音频音量(256=normal)-af filter_graph 设置音频过滤器12345678
字幕选项
-s size 设置帧大小 (WxH or abbreviation)-sn 用副标题-scodec codec force 副标题编解码器 ('copy' to copy stream)-stag fourcc/tag force 副标题 tag/fourcc-fix_sub_duration 修正字幕时间-canvas_size size 设置画布大小 (WxH or abbreviation)-spre preset 将字幕选项设置为指定的预设值
推荐本站淘宝优惠价购买喜欢的宝贝:
本文链接:https://zblog.hqyman.cn/post/11815.html 非本站原创文章欢迎转载,原创文章需保留本站地址!
打赏

微信支付宝扫一扫,打赏作者吧~
休息一下~~