FFMPEG堪称自由软件中最完备的一套多媒体支持库,它几乎实现了所有当下常见的数据封装格式、多媒体传输协议以及音视频编解码器。因此,对于从事多媒体技术开发的工程师来说,深入研究FFMPEG成为一门必不可少的工作,可以这样说,FFMPEG之于多媒体开发工程师的重要性正如kernel之于嵌入式系统工程师一般。
几个小知识:
-
FFMPEG项目是由法国人Fabrice Bellard发起的,此人也是著名的CPU模拟器项目QEMU的发起者,同时还是 圆周率算法纪录的保持者。
-
FF是Fast Forward的意思,翻译成中文是“快进”。
-
FFMPEG的LOGO是一个”Z字扫描”示意图,Z字扫描用于将图像的二维频域数据一维化,同时保证了一维化的数据具备良好的统计特性,从而提高其后要进行的一维熵编码的效率。
关于耻辱厅(Hall of Shame):FFMpeg大部分代码遵循LGPL许可证,如果使用者对FFMpeg进行了修改,要求公布修改的源代码;有少部分代码遵循GPL许可证,要求使用者同时公开使用FFMpeg的软件的源代码。实际上,除去部分具备系统软件开发能力的大型公司(Microsoft、Apple等)以及某些著名的音视频技术提供商(Divx、Real等)提供的自有播放器之外,绝大部分第三方开发的播放器都离不开FFMpeg的支持,像Linux桌面环境中的开源播放器VLC、MPlayer,Windows下的KMPlayer、暴风影音以及Android下几乎全部第三方播放器都是基于FFMpeg的。也有许多看似具备自主技术的播放器,其实也都不声不响地使用了FFMpeg,这种行为被称为“盗窃”,参与“盗窃”的公司则被请入耻辱厅,国产播放器暴风影音、QQ影音于2009年上榜。
FFMPEG从功能上划分为几个模块,分别为核心工具(libutils)、媒体格式(libavformat)、编解码(libavcodec)、设备(libavdevice)和后处理(libavfilter, libswscale, libpostproc),分别负责提供公用的功能函数、实现多媒体文件的读包和写包、完成音视频的编解码、管理音视频设备的操作以及进行音视频后处理。
使用FFMPEG
这里指FFMPEG提供的命令行(CLI)工具ffmpeg,其使用方法如下(方括号表示可选项,花括号表示必选项目):
ffmpeg [global options] [[infile options][‘-i’ infile]]... {[outfile options] outfile}...
除了全局选项,其他选项仅对后面紧跟着的输入或输出文件有效。
基本选项
能力集列表
-
-formats:列出支持的文件格式。
-
-codecs:列出支持的编解码器。
-
-decoders:列出支持的解码器。
-
-encoders:列出支持的编码器。
-
-protocols:列出支持的协议。
-
-bsfs:列出支持的比特流过滤器。
-
-filters:列出支持的滤镜。
-
-pix_fmts:列出支持的图像采样格式。
-
-sample_fmts:列出支持的声音采样格式。
常用输入选项
-
-i filename:指定输入文件名。
-
-f fmt:强制设定文件格式,需使用能力集列表中的名称(缺省是根据扩展名选择的)。
-
-t hh:mm:ss[.xxx]:设定输入文件的终止时间点。
-
-ss hh:mm:ss[.xxx]:设定输入文件的起始时间点。
对于输入,以下选项通常是自动识别的,但也可以强制设定。
-
-c codec:指定解码器,需使用能力集列表中的名称。
-
-acodec codec:指定声音的解码器,需使用能力集列表中的名称。
-
-vcodec codec:指定视频的解码器,需使用能力集列表中的名称。
-
-b bitrate:设定音视频流的比特率,整数,单位bps。
-
-r fps:设定视频流的帧率,整数,单位fps。
-
-s WxH : 设定视频的画面大小。也可以通过挂载画面缩放滤镜实现。
-
-pix_fmt format:设定视频流的图像格式(如RGB还是YUV)。
-
-ar sample rate:设定音频流的采样率,整数,单位Hz。
-
-ab bitrate:设定音频流的比特率,整数,单位bps。
-
-ac channels:设置音频流的声道数目。
常用输出选项
-
-f fmt:强制设定文件格式,需使用能力集列表中的名称(缺省是根据扩展名选择的)。
-
-c codec:指定编码器,需使用能力集列表中的名称(编码器设定为”copy“表示不进行编解码)。
-
-acodec codec:指定声音的编码器,需使用能力集列表中的名称(编码器设定为”copy“表示不进行编解码)。
-
-vcodec codec:指定视频的编码器,需使用能力集列表中的名称(编解码器设定为”copy“表示不进行编解码)。
-
-r fps:设定视频编码器的帧率,整数,单位fps。
-
-pix_fmt format:设置视频编码器使用的图像格式(如RGB还是YUV)。
-
-ar sample rate:设定音频编码器的采样率,整数,单位Hz。
-
-b bitrate:设定音视频编码器输出的比特率,整数,单位bps。
-
-ab bitrate:设定音频编码器输出的比特率,整数,单位bps。
-
-ac channels:设置音频编码器的声道数目。
-
-an 忽略任何音频流。
-
-vn 忽略任何视频流。
流标识
FFMPEG的某些选项可以对一个特定的媒体流起作用,这种情况下需要在选项后面增加一个流标识。流标识允许以下几种格式:
-
流序号。譬如“:1”表示第二个流。
-
流类型。譬如“:a“表示音频流,流类型可以和流序号合并使用,譬如“:a:1”表示第二个音频流。
-
节目。节目和流序号可以合并使用。
-
流标识。流标识是一个内部标识号。
假如要设定第二个音频流为copy,则需要指定-codec:a:1 copy
音频选项
视频选项
滤镜选项
高级选项
-
-re:要求按照既定速率处理输入数据,这个速率即是输入文件的帧率。
用例
1、从一个视频文件中抽取一帧图像:
ffmpeg -y -i test.mp4 -ss 00:03:22.000 -vframes 1 -an test.jpg
编译和裁剪
FFMpeg与大部分GNU软件的编译方式类似,是通过configure脚本来实现编译前定制的。这种途径允许用户在编译前对软件进行裁剪,同时通过对宿主系统和目标系统的自动检测来筛选参与编译的模块并为其设定合适的配置。但是,FFMpeg的configure脚本并非如通常的GNU软件一样通过配置工具自动生成,而是完全由人工编写的。configure脚本生成的config.mak和config.h分别在Makefile和源代码的层次上实现编译的控制。
通过运行“./configure –help”可以了解到脚本支持的参数,这些参数大体分为下面几类:
-
标准选项——GNU软件例行配置项目如安装路径等。例:–prefix=…,……
-
列出当前源代码支持的能力集,如编解码器,解复用器,输入输出设备,文件系统等。例:–list-decoders,–list-encoders,……
-
授权选项:–enable-version3,–enable-gpl,–enable-nofree。代码的缺省授权是LGPL v2,如果要使用以LGPL v3、GPL授权的模块或者某些不遵循自有软件授权协议的模块,必须在运行configure时显式使能相应的选项。
-
编译、链接选项。例:–disable-static,–enable-shared,…… 缺省配置是生成静态库而不生成动态库,如果希望禁止静态库、生成动态库都需要显式指定。
-
可执行程序控制选项,决定是否生成ffmpeg、ffplay、ffprobe和ffserver。
-
模块控制选项,筛选参与编译的模块,包括整个库的筛选,例如:–disable-avdevice;一组模块的筛选,例如:–disable-decoders,单个模块的筛选,如:–disable-decoder=… 等。
-
专家级选项,允许开发者进行深度定制,如交叉编译环境的配置、自定义编译器参数的设定、指令级优化、debug控制等。
对于–disable、–enable类的控制选项,如果以–disable为前缀,则缺省是enable的,反之亦然。
总之,无论从商业角度还是技术角度出发,使用configure脚本对FFMpeg进行裁剪是最安全的方式,只有针对于某些configure无法满足的定制要求,才需要考虑修改configure脚本——甚至修改configure生成的配置文件。
以下是一个配置实例,实现运行与Android系统中的ffmpeg库的编译:
./configure --prefix=. --cross-prefix=$NDK_TOOLCHAIN_PREFIX --enable-cross-compile --arch=arm --target-os=linux --cpu=cortex-a8 \ --disable-static --enable-shared --enable-pic --disable-ffmpeg --disable-ffplay --disable-ffserver --disable-ffprobe \ --extra-cflags="-I$NDK_PLATFORM/usr/include" \ --extra-ldflags="-nostdlib -Wl,-T,$NDK_PREBUILT/arm-linux-androideabi/lib/ldscripts/armelf_linux_eabi.x \ -L$NDK_PLATFORM/usr/lib \ $NDK_PREBUILT/lib/gcc/arm-linux-androideabi/4.4.3/crtbegin.o $NDK_PREBUILT/lib/gcc/arm-linux-androideabi/4.4.3/crtend.o \ -lc -lm -ldl"
深入FFMPEG
示例程序
解码
<span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#include <stdio.h></span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#include <string.h></span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#include <stdlib.h></span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#include <sys/time.h></span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#include "libavutil/avstring.h"</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#include "libavformat/avformat.h"</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#include "libavdevice/avdevice.h"</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#include "libavutil/opt.h"</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#include "libswscale/swscale.h"</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#define DECODED_AUDIO_BUFFER_SIZE 192000</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> options <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> streamId<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> frames<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> nodec<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> bplay<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> thread_count<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> int64_t lstart<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> finput<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>256<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> foutput1<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>256<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> foutput2<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>256<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> parse_options<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> options <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>opts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> argc<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">**</span> argv<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> optidx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>optstr<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>argc <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);"><</span> 2<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">1</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> opts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>streamId <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">1</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> opts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>lstart <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">1</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> opts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>frames <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">1</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> opts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>foutput1<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> opts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>foutput2<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> opts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>nodec <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> opts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>bplay <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> opts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>thread_count <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> strcpy<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>opts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>finput<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> argv<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>1<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> optidx <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">2</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">while</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>optidx <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);"><</span> argc<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> optstr <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> argv<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>optidx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">++</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>optstr<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">++</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">!=</span> <span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">'-'</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">1</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">switch</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>optstr<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">++</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">case</span> <span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">'s'</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">:</span> <span class="co1" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">//< stream id</span> opts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>streamId <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> atoi<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>optstr<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw2" style="padding: 0px; margin: 0px; font-weight: bold;">break</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">case</span> <span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">'f'</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">:</span> <span class="co1" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">//< frames</span> opts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>frames <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> atoi<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>optstr<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw2" style="padding: 0px; margin: 0px; font-weight: bold;">break</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">case</span> <span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">'k'</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">:</span> <span class="co1" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">//< skipped</span> opts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>lstart <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> atoll<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>optstr<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw2" style="padding: 0px; margin: 0px; font-weight: bold;">break</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">case</span> <span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">'o'</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">:</span> <span class="co1" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">//< output</span> strcpy<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>opts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>foutput1<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> optstr<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> strcat<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>opts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>foutput1<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">".mpg"</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> strcpy<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>opts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>foutput2<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> optstr<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> strcat<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>opts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>foutput2<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">".raw"</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw2" style="padding: 0px; margin: 0px; font-weight: bold;">break</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">case</span> <span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">'n'</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">:</span> <span class="co1" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">//decoding and output options</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>strcmp<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"dec"</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> optstr<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> 0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> opts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>nodec <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">1</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw2" style="padding: 0px; margin: 0px; font-weight: bold;">break</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">case</span> <span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">'p'</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">:</span> opts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>bplay <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">1</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw2" style="padding: 0px; margin: 0px; font-weight: bold;">break</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">case</span> <span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">'t'</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">:</span> opts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>thread_count <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> atoi<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>optstr<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw2" style="padding: 0px; margin: 0px; font-weight: bold;">break</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">default</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">:</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">1</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">void</span> show_help<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span> program<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"Simple FFMPEG test program<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"Usage: %s inputfile [-sstreamid [-fframes] [-kskipped] [-ooutput_filename(without extension)] [-ndec] [-p] [-tthread_count]]<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> program<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">static</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">void</span> log_callback<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">void</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span> ptr<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> level<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">const</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span> fmt<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> va_list vl<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> vfprintf<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>stdout<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> fmt<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> vl<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* * audio renderer code (oss) */</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#include <sys/ioctl.h></span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#include <unistd.h></span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#include <fcntl.h></span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#include <sys/soundcard.h></span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#define OSS_DEVICE "/dev/dsp0"</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> audio_dsp <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> audio_fd<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> channels<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> format<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> speed<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> map_formats<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="kw2" style="padding: 0px; margin: 0px; font-weight: bold;">enum</span> AVSampleFormat format<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">switch</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>format<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">case</span> AV_SAMPLE_FMT_U8<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">:</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> AFMT_U8<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">case</span> AV_SAMPLE_FMT_S16<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">:</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> AFMT_S16_LE<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">default</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">:</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> AFMT_U8<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> set_audio<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> audio_dsp<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span> dsp<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>dsp<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>audio_fd <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span>1<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"Invalid audio dsp id!<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">1</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span>1 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> ioctl<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>dsp<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>audio_fd<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> SNDCTL_DSP_SETFMT<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>dsp<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>format<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"Failed to set dsp format!<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">1</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span>1 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> ioctl<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>dsp<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>audio_fd<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> SNDCTL_DSP_CHANNELS<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>dsp<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>channels<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"Failed to set dsp format!<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">1</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span>1 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> ioctl<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>dsp<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>audio_fd<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> SNDCTL_DSP_SPEED<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>dsp<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>speed<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"Failed to set dsp format!<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">1</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> play_pcm<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> audio_dsp<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span> dsp<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">unsigned</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>buf<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> size<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>dsp<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>audio_fd <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span>1<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"Invalid audio dsp id!<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">1</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span>1 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> write<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>dsp<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>audio_fd<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> buf<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> size<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"Failed to write audio dsp!<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">1</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* audio renderer code end */</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* video renderer code*/</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#include <linux/fb.h></span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#include <sys/mman.h></span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#define FB_DEVICE "/dev/fb0"</span> <span class="kw2" style="padding: 0px; margin: 0px; font-weight: bold;">enum</span> pic_format <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> eYUV_420_Planer<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> video_fb <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> video_fd<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> fb_var_screeninfo vinfo<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> fb_fix_screeninfo finfo<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">unsigned</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>fbp<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> AVFrame <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>frameRGB<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> x<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> y<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> video_pos<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> open_video<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> video_fb <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> x<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> y<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> screensize<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>video_fd <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> open<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>FB_DEVICE<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> O_WRONLY<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>video_fd <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span>1<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">1</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>ioctl<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>video_fd<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> FBIOGET_FSCREENINFO<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>finfo<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">2</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>ioctl<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>video_fd<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> FBIOGET_VSCREENINFO<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">2</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"video device: resolution %dx%d, %dbpp<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">xres</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">yres</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">bits_per_pixel</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> screensize <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">xres</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">yres</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">bits_per_pixel</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">/</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">8</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>fbp <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">unsigned</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> mmap<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>0<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> screensize<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> PROT_READ<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">|</span>PROT_WRITE<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> MAP_SHARED<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>video_fd<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> 0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>fbp <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span>1<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">3</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>x <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">>=</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">xres</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">||</span> y <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">>=</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">yres</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">4</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">else</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>video_pos.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">x</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> x<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>video_pos.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">y</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> y<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>frameRGB <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> avcodec_alloc_frame<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">!</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>frameRGB<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">5</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* only 420P supported now */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> show_picture<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> video_fb <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> AVFrame <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>frame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> width<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> height<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="kw2" style="padding: 0px; margin: 0px; font-weight: bold;">enum</span> pic_format format<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> SwsContext <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>sws<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> i<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">unsigned</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>dest<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">unsigned</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>src<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>video_fd <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span>1<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">1</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>video_pos.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">x</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">>=</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">xres</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">||</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>video_pos.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">y</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">>=</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">yres</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">2</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>video_pos.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">x</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">+</span> width <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">></span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">xres</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> width <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">xres</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>video_pos.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">x</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>video_pos.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">y</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">+</span> height <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">></span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">yres</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> height <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">yres</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>video_pos.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">y</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>format <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> PIX_FMT_YUV420P<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> sws <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> sws_getContext<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>width<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> height<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> format<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> width<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> height<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> PIX_FMT_RGB32<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> SWS_FAST_BILINEAR<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> NULL<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> NULL<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> NULL<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>sws <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> 0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">3</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>sws_scale<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>sws<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> frame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>data<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> frame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>linesize<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> 0<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> height<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>frameRGB<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>data<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>frameRGB<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>linesize<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">3</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> dest <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>fbp <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">+</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>video_pos.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">x</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">+</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">xoffset</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">bits_per_pixel</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">/</span>8<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">+</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>video_pos.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">y</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">+</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">yoffset</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>finfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">line_length</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">for</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>i <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> i <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);"><</span> height<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> i<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">++</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> memcpy<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>dest<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> src<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> width<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>4<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> src <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">+=</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>frameRGB<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>linesize<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> dest <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">+=</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>finfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">line_length</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">void</span> close_video<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> video_fb <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>fb<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>video_fd <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">!=</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span>1<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> munmap<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>fbp<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">xres</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">yres</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">bits_per_pixel</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">/</span> 8<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> close<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>video_fd<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>video_fd <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">1</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* video renderer code end */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> main<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> argc<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">**</span>argv<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> AVFormatContext<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span> pCtx <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> AVCodecContext <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>pCodecCtx <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> AVCodec <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>pCodec <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> AVPacket packet<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> AVFrame <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>pFrame <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> FILE <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>fpo1 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> NULL<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> FILE <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>fpo2 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> NULL<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> nframe<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> err<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> got_picture<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> picwidth<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> picheight<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> linesize<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">unsigned</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>pBuf<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> i<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> int64_t timestamp<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> options opt<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> usefo <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> audio_dsp dsp<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> video_fb fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> dusecs<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">float</span> usecs1 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">float</span> usecs2 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> timeval elapsed1<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> elapsed2<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> decoded <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> av_register_all<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> av_log_set_callback<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>log_callback<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> av_log_set_level<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>50<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>parse_options<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>opt<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> argc<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> argv<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);"><</span> 0 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">||</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>strlen<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">finput</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> 0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> show_help<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>argv<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> err <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> avformat_open_input<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>pCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">finput</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> 0<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> 0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>err <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);"><</span> 0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"<span class="es1" style="padding: 0px; margin: 0px;">\n</span>->(avformat_open_input)<span class="es1" style="padding: 0px; margin: 0px;">\t</span>ERROR:<span class="es1" style="padding: 0px; margin: 0px;">\t</span>%d<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> err<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">goto</span> fail<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> err <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> avformat_find_stream_info<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>pCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> 0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>err <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);"><</span> 0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"<span class="es1" style="padding: 0px; margin: 0px;">\n</span>->(avformat_find_stream_info)<span class="es1" style="padding: 0px; margin: 0px;">\t</span>ERROR:<span class="es1" style="padding: 0px; margin: 0px;">\t</span>%d<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> err<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">goto</span> fail<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">streamId</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);"><</span> 0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> av_dump_format<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>pCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> 0<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> pCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>filename<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> 0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">goto</span> fail<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">else</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"<span class="es1" style="padding: 0px; margin: 0px;">\n</span> extra data in Stream %d (%dB):"</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">streamId</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> pCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>streams<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">streamId</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>codec<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>extradata_size<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">for</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>i <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> i <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);"><</span> pCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>streams<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">streamId</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>codec<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>extradata_size<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> i<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">++</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>i<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">%</span>16 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> 0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"%2x "</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> pCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>streams<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">streamId</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>codec<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>extradata<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>i<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* try opening output files */</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>strlen<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">foutput1</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&&</span> strlen<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">foutput2</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> fpo1 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> fopen<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">foutput1</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"wb"</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> fpo2 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> fopen<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">foutput2</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"wb"</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">!</span>fpo1 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">||</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">!</span>fpo2<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"<span class="es1" style="padding: 0px; margin: 0px;">\n</span>->error opening output files<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">goto</span> fail<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> usefo <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">1</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">else</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> usefo <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">streamId</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">>=</span> pCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>nb_streams<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"<span class="es1" style="padding: 0px; margin: 0px;">\n</span>->StreamId<span class="es1" style="padding: 0px; margin: 0px;">\t</span>ERROR<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">goto</span> fail<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">lstart</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">></span> 0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> err <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> av_seek_frame<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>pCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">streamId</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">lstart</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> AVSEEK_FLAG_ANY<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>err <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);"><</span> 0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"<span class="es1" style="padding: 0px; margin: 0px;">\n</span>->(av_seek_frame)<span class="es1" style="padding: 0px; margin: 0px;">\t</span>ERROR:<span class="es1" style="padding: 0px; margin: 0px;">\t</span>%d<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> err<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">goto</span> fail<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* for decoder configuration */</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">!</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">nodec</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* prepare codec */</span> pCodecCtx <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> pCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>streams<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">streamId</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>codec<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">thread_count</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);"><=</span> 16 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&&</span> opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">thread_count</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">></span> 0 <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> pCodecCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>thread_count <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">thread_count</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> pCodecCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>thread_type <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> FF_THREAD_FRAME<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> pCodec <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> avcodec_find_decoder<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>pCodecCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>codec_id<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">!</span>pCodec<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"<span class="es1" style="padding: 0px; margin: 0px;">\n</span>->can not find codec!<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">goto</span> fail<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> err <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> avcodec_open2<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>pCodecCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> pCodec<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> 0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>err <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);"><</span> 0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"<span class="es1" style="padding: 0px; margin: 0px;">\n</span>->(avcodec_open)<span class="es1" style="padding: 0px; margin: 0px;">\t</span>ERROR:<span class="es1" style="padding: 0px; margin: 0px;">\t</span>%d<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> err<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">goto</span> fail<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> pFrame <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> avcodec_alloc_frame<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* prepare device */</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">bplay</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* audio devices */</span> dsp.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">audio_fd</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> open<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>OSS_DEVICE<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> O_WRONLY<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>dsp.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">audio_fd</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span>1<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"<span class="es1" style="padding: 0px; margin: 0px;">\n</span>-> can not open audio device<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">goto</span> fail<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> dsp.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">channels</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> pCodecCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>channels<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> dsp.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">speed</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> pCodecCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>sample_rate<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> dsp.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">format</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> map_formats<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>pCodecCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>sample_fmt<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>set_audio<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>dsp<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);"><</span> 0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"<span class="es1" style="padding: 0px; margin: 0px;">\n</span>-> can not set audio device<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">goto</span> fail<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* video devices */</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>open_video<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> 0<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> 0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">!=</span> 0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"<span class="es1" style="padding: 0px; margin: 0px;">\n</span>-> can not open video device<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">goto</span> fail<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> nframe <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">while</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>nframe <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);"><</span> opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">frames</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">||</span> opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">frames</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span>1<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> gettimeofday<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>elapsed1<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> NULL<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> err <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> av_read_frame<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>pCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>packet<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>err <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);"><</span> 0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"<span class="es1" style="padding: 0px; margin: 0px;">\n</span>->(av_read_frame)<span class="es1" style="padding: 0px; margin: 0px;">\t</span>ERROR:<span class="es1" style="padding: 0px; margin: 0px;">\t</span>%d<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> err<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw2" style="padding: 0px; margin: 0px; font-weight: bold;">break</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> gettimeofday<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>elapsed2<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> NULL<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> dusecs <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>elapsed2.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">tv_sec</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span> elapsed1.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">tv_sec</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>1000000 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">+</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>elapsed2.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">tv_usec</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span> elapsed1.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">tv_usec</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> usecs2 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">+=</span> dusecs<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> timestamp <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> av_rescale_q<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>packet.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">dts</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> pCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>streams<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>packet.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">stream_index</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>time_base<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>AVRational<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span>1<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> AV_TIME_BASE<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"<span class="es1" style="padding: 0px; margin: 0px;">\n</span>Frame No %5d stream#%d<span class="es1" style="padding: 0px; margin: 0px;">\t</span>size %6dB, timestamp:%6lld, dts:%6lld, pts:%6lld, "</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> nframe<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">++,</span> packet.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">stream_index</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> packet.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">size</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> timestamp<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> packet.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">dts</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> packet.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">pts</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>packet.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">stream_index</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">streamId</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#if 0 </span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">for</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>i <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> i <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);"><</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">16</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/*packet.size;*/</span> i<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">++</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>i<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">%</span>16 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> 0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"<span class="es1" style="padding: 0px; margin: 0px;">\n</span> pktdata: "</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"%2x "</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> packet.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">data</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>i<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#endif </span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>usefo<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> fwrite<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>packet.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">data</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> packet.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">size</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> 1<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> fpo1<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> fflush<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fpo1<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>pCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>streams<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">streamId</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>codec<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>codec_type <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> AVMEDIA_TYPE_VIDEO <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&&</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">!</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">nodec</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> picheight <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> pCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>streams<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">streamId</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>codec<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>height<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> picwidth <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> pCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>streams<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">streamId</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>codec<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>width<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> gettimeofday<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>elapsed1<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> NULL<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> avcodec_decode_video2<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>pCodecCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> pFrame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>got_picture<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>packet<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> decoded<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">++;</span> gettimeofday<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>elapsed2<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> NULL<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> dusecs <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>elapsed2.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">tv_sec</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span> elapsed1.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">tv_sec</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>1000000 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">+</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>elapsed2.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">tv_usec</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span> elapsed1.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">tv_usec</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> usecs1 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">+=</span> dusecs<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>got_picture<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"[Video: type %d, ref %d, pts %lld, pkt_pts %lld, pkt_dts %lld]"</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> pFrame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>pict_type<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> pFrame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>reference<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> pFrame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>pts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> pFrame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>pkt_pts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> pFrame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>pkt_dts<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>pCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>streams<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">streamId</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>codec<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>pix_fmt <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> PIX_FMT_YUV420P<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>usefo<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> linesize <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> pFrame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>linesize<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> pBuf <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> pFrame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>data<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">for</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>i <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> i <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);"><</span> picheight<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> i<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">++</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> fwrite<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>pBuf<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> picwidth<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> 1<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> fpo2<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> pBuf <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">+=</span> linesize<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> linesize <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> pFrame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>linesize<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>1<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> pBuf <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> pFrame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>data<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>1<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">for</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>i <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> i <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);"><</span> picheight<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">/</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">2</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> i<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">++</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> fwrite<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>pBuf<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> picwidth<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">/</span>2<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> 1<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> fpo2<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> pBuf <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">+=</span> linesize<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> linesize <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> pFrame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>linesize<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>2<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> pBuf <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> pFrame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>data<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>2<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">for</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>i <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> i <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);"><</span> picheight<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">/</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">2</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> i<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">++</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> fwrite<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>pBuf<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> picwidth<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">/</span>2<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> 1<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> fpo2<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> pBuf <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">+=</span> linesize<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> fflush<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fpo2<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">bplay</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* show picture */</span> show_picture<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> pFrame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> picheight<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> picwidth<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> PIX_FMT_YUV420P<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> av_free_packet<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>packet<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">else</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>pCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>streams<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">streamId</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>codec<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>codec_type <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> AVMEDIA_TYPE_AUDIO <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&&</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">!</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">nodec</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> got<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> gettimeofday<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>elapsed1<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> NULL<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> avcodec_decode_audio4<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>pCodecCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> pFrame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>got<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>packet<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> decoded<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">++;</span> gettimeofday<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>elapsed2<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> NULL<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> dusecs <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>elapsed2.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">tv_sec</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span> elapsed1.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">tv_sec</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>1000000 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">+</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>elapsed2.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">tv_usec</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span> elapsed1.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">tv_usec</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> usecs1 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">+=</span> dusecs<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>got<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"[Audio: %5dB raw data, decoding time: %d]"</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> pFrame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>linesize<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> dusecs<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>usefo<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> fwrite<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>pFrame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>data<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> pFrame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>linesize<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> 1<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> fpo2<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> fflush<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fpo2<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">bplay</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> play_pcm<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>dsp<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> pFrame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>data<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> pFrame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>linesize<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">!</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">nodec</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&&</span> pCodecCtx<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> avcodec_close<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>pCodecCtx<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"<span class="es1" style="padding: 0px; margin: 0px;">\n</span>%d frames parsed, average %.2f us per frame<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> nframe<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> usecs2<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">/</span>nframe<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"%d frames decoded, average %.2f us per frame<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> decoded<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> usecs1<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">/</span>decoded<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> fail<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">:</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>pCtx<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> avformat_close_input<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>pCtx<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fpo1<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> fclose<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fpo1<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fpo2<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> fclose<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fpo2<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">!</span>pFrame<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> av_free<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>pFrame<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">!</span>usefo <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&&</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>dsp.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">audio_fd</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">!=</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span>1<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> close<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>dsp.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">audio_fd</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">!</span>usefo <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&&</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fb.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">video_fd</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">!=</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span>1<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> close_video<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>fb<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span>
这一小段代码可以实现的功能包括:
-
打开一个多媒体文件并获取基本的媒体信息。
-
获取编码器句柄。
-
根据给定的时间标签进行一个跳转。
-
读取数据帧。
-
解码音频帧或者视频帧。
-
关闭多媒体文件。
这些功能足以支持一个功能强大的多媒体播放器,因为最复杂的解复用、解码、数据分析过程已经在FFMpeg内部实现了,需要关注的仅剩同步问题。
用户接口
数据结构
基本概念
编解码器、数据帧、媒体流和容器是数字媒体处理系统的四个基本概念。
首先需要统一术语:
-
容器/文件(Conainer/File):即特定格式的多媒体文件。
-
媒体流(Stream):指时间轴上的一段连续数据,如一段声音数据,一段视频数据或一段字幕数据,可以是压缩的,也可以是非压缩的,压缩的数据需要关联特定的编解码器。
-
数据帧/数据包(Frame/Packet):通常,一个媒体流由大量的数据帧组成,对于压缩数据,帧对应着编解码器的最小处理单元。通常,分属于不同媒体流的数据帧交错复用于容器之中,参见 交错。
-
编解码器:编解码器以帧为单位实现压缩数据和原始数据之间的相互转换。
在FFMPEG中,使用AVFormatContext、AVStream、AVCodecContext、AVCodec及AVPacket等结构来抽象这些基本要素,它们的关系如下图所示:
AVCodecContext
这是一个描述编解码器上下文的数据结构,包含了众多编解码器需要的参数信息,如下列出了部分比较重要的域:
<span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">typedef</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> AVCodecContext <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> ...... <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * some codecs need / can use extradata like Huffman tables. * mjpeg: Huffman tables * rv10: additional flags * mpeg4: global headers (they can be in the bitstream or here) * The allocated memory should be FF_INPUT_BUFFER_PADDING_SIZE bytes larger * than extradata_size to avoid prolems if it is read with the bitstream reader. * The bytewise contents of extradata must not depend on the architecture or CPU endianness. * - encoding: Set/allocated/freed by libavcodec. * - decoding: Set/allocated/freed by user. */</span> uint8_t <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>extradata<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> extradata_size<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * This is the fundamental unit of time (in seconds) in terms * of which frame timestamps are represented. For fixed-fps content, * timebase should be 1/framerate and timestamp increments should be * identically 1. * - encoding: MUST be set by user. * - decoding: Set by libavcodec. */</span> AVRational time_base<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* video only */</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * picture width / height. * - encoding: MUST be set by user. * - decoding: Set by libavcodec. * Note: For compatibility it is possible to set this instead of * coded_width/height before decoding. */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> width<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> height<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> ...... <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* audio only */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> sample_rate<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="co1" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">///< samples per second</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> channels<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="co1" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">///< number of audio channels</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * audio sample format * - encoding: Set by user. * - decoding: Set by libavcodec. */</span> <span class="kw2" style="padding: 0px; margin: 0px; font-weight: bold;">enum</span> SampleFormat sample_fmt<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="co1" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">///< sample format</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* The following data should not be initialized. */</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * Samples per packet, initialized when calling 'init'. */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> frame_size<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> frame_number<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="co1" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">///< audio or video frame number</span> ...... <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> codec_name<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>32<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw2" style="padding: 0px; margin: 0px; font-weight: bold;">enum</span> AVMediaType codec_type<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* see AVMEDIA_TYPE_xxx */</span> <span class="kw2" style="padding: 0px; margin: 0px; font-weight: bold;">enum</span> CodecID codec_id<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* see CODEC_ID_xxx */</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A'). * This is used to work around some encoder bugs. * A demuxer should set this to what is stored in the field used to identify the codec. * If there are multiple such fields in a container then the demuxer should choose the one * which maximizes the information about the used codec. * If the codec tag field in a container is larger then 32 bits then the demuxer should * remap the longer ID to 32 bits with a table or other structure. Alternatively a new * extra_codec_tag + size could be added but for this a clear advantage must be demonstrated * first. * - encoding: Set by user, if not then the default based on codec_id will be used. * - decoding: Set by user, will be converted to uppercase by libavcodec during init. */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">unsigned</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> codec_tag<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> ...... <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * Size of the frame reordering buffer in the decoder. * For MPEG-2 it is 1 IPB or 0 low delay IP. * - encoding: Set by libavcodec. * - decoding: Set by libavcodec. */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> has_b_frames<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * number of bytes per packet if constant and known or 0 * Used by some WAV based audio codecs. */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> block_align<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> ...... <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * bits per sample/pixel from the demuxer (needed for huffyuv). * - encoding: Set by libavcodec. * - decoding: Set by user. */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> bits_per_coded_sample<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> ...... <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> AVCodecContext<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
如果是单纯使用libavcodec,这部分信息需要调用者进行初始化;如果是使用整个FFMPEG库,这部分信息在调用avformat_open_input和avformat_find_stream_info的过程中根据文件的头信息及媒体流内的头部信息完成初始化。其中几个主要域的释义如下:
-
extradata/extradata_size:这个buffer中存放了解码器可能会用到的额外信息,在av_read_frame中填充。一般来说,首先,某种具体格式的demuxer在读取格式头信息的时候会填充extradata,其次,如果demuxer没有做这个事情,比如可能在头部压根儿就没有相关的编解码信息,则相应的parser会继续从已经解复用出来的媒体流中继续寻找。在没有找到任何额外信息的情况下,这个buffer指针为空。
-
time_base:编解码器的时间基准,实际上就是视频的帧率(或场率)。
-
width/height:视频的宽和高。
-
sample_rate/channels:音频的采样率和信道数目。
-
sample_fmt: 音频的原始采样格式。
-
codec_name/codec_type/codec_id/codec_tag:编解码器的信息。
AVStream
该结构体描述一个媒体流,定义如下:
<span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">typedef</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> AVStream <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> index<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/**< stream index in AVFormatContext */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> id<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/**< format-specific stream ID */</span> AVCodecContext <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>codec<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/**< codec context */</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * Real base framerate of the stream. * This is the lowest framerate with which all timestamps can be * represented accurately (it is the least common multiple of all * framerates in the stream). Note, this value is just a guess! * For example, if the time base is 1/90000 and all frames have either * approximately 3600 or 1800 timer ticks, then r_frame_rate will be 50/1. */</span> AVRational r_frame_rate<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> ...... <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * This is the fundamental unit of time (in seconds) in terms * of which frame timestamps are represented. For fixed-fps content, * time base should be 1/framerate and timestamp increments should be 1. */</span> AVRational time_base<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> ...... <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * Decoding: pts of the first frame of the stream, in stream time base. * Only set this if you are absolutely 100% sure that the value you set * it to really is the pts of the first frame. * This may be undefined (AV_NOPTS_VALUE). * @note The ASF header does NOT contain a correct start_time the ASF * demuxer must NOT set this. */</span> int64_t start_time<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * Decoding: duration of the stream, in stream time base. * If a source file does not specify a duration, but does specify * a bitrate, this value will be estimated from bitrate and file size. */</span> int64_t duration<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#if LIBAVFORMAT_VERSION_INT < (53<<16)</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> language<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>4<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** ISO 639-2/B 3-letter language code (empty string if undefined) */</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#endif</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* av_read_frame() support */</span> <span class="kw2" style="padding: 0px; margin: 0px; font-weight: bold;">enum</span> AVStreamParseType need_parsing<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> AVCodecParserContext <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>parser<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> ...... <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* av_seek_frame() support */</span> AVIndexEntry <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>index_entries<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/**< Only used if the format does not support seeking natively. */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> nb_index_entries<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">unsigned</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> index_entries_allocated_size<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> int64_t nb_frames<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="co1" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">///< number of frames in this stream if known or 0</span> ...... <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * Average framerate */</span> AVRational avg_frame_rate<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> ...... <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> AVStream<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
主要域的释义如下,其中大部分域的值可以由avformat_open_input根据文件头的信息确定,缺少的信息需要通过调用avformat_find_stream_info读帧及软解码进一步获取:
-
index/id:index对应流的索引,这个数字是自动生成的,根据index可以从AVFormatContext::streams表中索引到该流;而id则是流的标识,依赖于具体的容器格式。比如对于MPEG TS格式,id就是pid。
-
time_base:流的时间基准,是一个实数,该流中媒体数据的pts和dts都将以这个时间基准为粒度。通常,使用av_rescale/av_rescale_q可以实现不同时间基准的转换。
-
start_time:流的起始时间,以流的时间基准为单位,通常是该流中第一个帧的pts。
-
duration:流的总时间,以流的时间基准为单位。
-
need_parsing:对该流parsing过程的控制域。
-
nb_frames:流内的帧数目。
-
r_frame_rate/framerate/avg_frame_rate:帧率相关。
-
codec:指向该流对应的AVCodecContext结构,调用avformat_open_input时生成。
-
parser:指向该流对应的AVCodecParserContext结构,调用avformat_find_stream_info时生成。。
AVFormatContext
这个结构体描述了一个媒体文件或媒体流的构成和基本信息,定义如下:
<span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">typedef</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> AVFormatContext <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">const</span> AVClass <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>av_class<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/**< Set by avformat_alloc_context. */</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* Can only be iformat or oformat, not both at the same time. */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> AVInputFormat <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>iformat<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> AVOutputFormat <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>oformat<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">void</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>priv_data<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> ByteIOContext <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>pb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">unsigned</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> nb_streams<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> AVStream <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>streams<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>MAX_STREAMS<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> filename<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>1024<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/**< input or output filename */</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* stream info */</span> int64_t timestamp<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#if LIBAVFORMAT_VERSION_INT < (53<<16)</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> title<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>512<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> author<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>512<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> copyright<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>512<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> comment<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>512<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> album<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>512<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> year<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/**< ID3 year, 0 if none */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> track<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/**< track number, 0 if none */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> genre<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>32<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/**< ID3 genre */</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#endif</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> ctx_flags<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/**< Format-specific flags, see AVFMTCTX_xx */</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* private data for pts handling (do not modify directly). */</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** This buffer is only needed when packets were already buffered but not decoded, for example to get the codec parameters in MPEG streams. */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> AVPacketList <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>packet_buffer<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** Decoding: position of the first frame of the component, in AV_TIME_BASE fractional seconds. NEVER set this value directly: It is deduced from the AVStream values. */</span> int64_t start_time<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** Decoding: duration of the stream, in AV_TIME_BASE fractional seconds. Only set this value if you know none of the individual stream durations and also dont set any of them. This is deduced from the AVStream values if not set. */</span> int64_t duration<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** decoding: total file size, 0 if unknown */</span> int64_t file_size<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** Decoding: total stream bitrate in bit/s, 0 if not available. Never set it directly if the file_size and the duration are known as FFmpeg can compute it automatically. */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> bit_rate<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* av_read_frame() support */</span> AVStream <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>cur_st<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#if LIBAVFORMAT_VERSION_INT < (53<<16)</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">const</span> uint8_t <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>cur_ptr_deprecated<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> cur_len_deprecated<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> AVPacket cur_pkt_deprecated<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#endif</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* av_seek_frame() support */</span> int64_t data_offset<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** offset of the first packet */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> index_built<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> mux_rate<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">unsigned</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> packet_size<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> preload<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> max_delay<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#define AVFMT_NOOUTPUTLOOP -1</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#define AVFMT_INFINITEOUTPUTLOOP 0</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** number of times to loop output in formats that support it */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> loop_output<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> flags<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#define AVFMT_FLAG_GENPTS 0x0001 ///< Generate missing pts even if it requires parsing future frames.</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#define AVFMT_FLAG_IGNIDX 0x0002 ///< Ignore index.</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#define AVFMT_FLAG_NONBLOCK 0x0004 ///< Do not block when reading packets from input.</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#define AVFMT_FLAG_IGNDTS 0x0008 ///< Ignore DTS on frames that contain both DTS & PTS</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#define AVFMT_FLAG_NOFILLIN 0x0010 ///< Do not infer any values from other values, just return what is stored in the container</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#define AVFMT_FLAG_NOPARSE 0x0020 ///< Do not use AVParsers, you also must set AVFMT_FLAG_NOFILLIN as the fillin code works on frames and no parsing -> no frames. Also seeking to frames can not work if parsing to find frame boundaries has been disabled</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#define AVFMT_FLAG_RTP_HINT 0x0040 ///< Add RTP hinting to the output file</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> loop_input<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** decoding: size of data to probe; encoding: unused. */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">unsigned</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> probesize<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * Maximum time (in AV_TIME_BASE units) during which the input should * be analyzed in avformat_find_stream_info(). */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> max_analyze_duration<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">const</span> uint8_t <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>key<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> keylen<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">unsigned</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> nb_programs<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> AVProgram <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">**</span>programs<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * Forced video codec_id. * Demuxing: Set by user. */</span> <span class="kw2" style="padding: 0px; margin: 0px; font-weight: bold;">enum</span> CodecID video_codec_id<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * Forced audio codec_id. * Demuxing: Set by user. */</span> <span class="kw2" style="padding: 0px; margin: 0px; font-weight: bold;">enum</span> CodecID audio_codec_id<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * Forced subtitle codec_id. * Demuxing: Set by user. */</span> <span class="kw2" style="padding: 0px; margin: 0px; font-weight: bold;">enum</span> CodecID subtitle_codec_id<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * Maximum amount of memory in bytes to use for the index of each stream. * If the index exceeds this size, entries will be discarded as * needed to maintain a smaller size. This can lead to slower or less * accurate seeking (depends on demuxer). * Demuxers for which a full in-memory index is mandatory will ignore * this. * muxing : unused * demuxing: set by user */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">unsigned</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> max_index_size<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * Maximum amount of memory in bytes to use for buffering frames * obtained from realtime capture devices. */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">unsigned</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> max_picture_buffer<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">unsigned</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> nb_chapters<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> AVChapter <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">**</span>chapters<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * Flags to enable debugging. */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> debug<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#define FF_FDEBUG_TS 0x0001</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * Raw packets from the demuxer, prior to parsing and decoding. * This buffer is used for buffering packets until the codec can * be identified, as parsing cannot be done without knowing the * codec. */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> AVPacketList <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>raw_packet_buffer<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> AVPacketList <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>raw_packet_buffer_end<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> AVPacketList <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>packet_buffer_end<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> AVMetadata <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>metadata<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * Remaining size available for raw_packet_buffer, in bytes. * NOT PART OF PUBLIC API */</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#define RAW_PACKET_BUFFER_SIZE 2500000</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> raw_packet_buffer_remaining_size<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * Start time of the stream in real world time, in microseconds * since the unix epoch (00:00 1st January 1970). That is, pts=0 * in the stream was captured at this real world time. * - encoding: Set by user. * - decoding: Unused. */</span> int64_t start_time_realtime<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> AVFormatContext<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
这是FFMpeg中最为基本的一个结构,是其他所有结构的根,是一个多媒体文件或流的根本抽象。其中:
-
nb_streams和streams所表示的AVStream结构指针数组包含了所有内嵌媒体流的描述;
-
iformat和oformat指向对应的demuxer和muxer指针;
-
pb则指向一个控制底层数据读写的ByteIOContext结构。
-
start_time和duration是从streams数组的各个AVStream中推断出的多媒体文件的起始时间和长度,以微妙为单位。
通常,这个结构由avformat_open_input在内部创建并以缺省值初始化部分成员。但是,如果调用者希望自己创建该结构,则需要显式为该结构的一些成员置缺省值——如果没有缺省值的话,会导致之后的动作产生异常。以下成员需要被关注:
-
probesize
-
mux_rate
-
packet_size
-
flags
-
max_analyze_duration
-
key
-
max_index_size
-
max_picture_buffer
-
max_delay
AVPacket
AVPacket定义在avcodec.h中,如下:
<span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">typedef</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> AVPacket <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * Presentation timestamp in AVStream->time_base units; the time at which * the decompressed packet will be presented to the user. * Can be AV_NOPTS_VALUE if it is not stored in the file. * pts MUST be larger or equal to dts as presentation cannot happen before * decompression, unless one wants to view hex dumps. Some formats misuse * the terms dts and pts/cts to mean something different. Such timestamps * must be converted to true pts/dts before they are stored in AVPacket. */</span> int64_t pts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * Decompression timestamp in AVStream->time_base units; the time at which * the packet is decompressed. * Can be AV_NOPTS_VALUE if it is not stored in the file. */</span> int64_t dts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> uint8_t <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>data<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> size<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> stream_index<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> flags<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * Duration of this packet in AVStream->time_base units, 0 if unknown. * Equals next_pts - this_pts in presentation order. */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> duration<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">void</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>destruct<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> AVPacket <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">void</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>priv<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> int64_t pos<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="co1" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">///< byte position in stream, -1 if unknown</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * Time difference in AVStream->time_base units from the pts of this * packet to the point at which the output from the decoder has converged * independent from the availability of previous frames. That is, the * frames are virtually identical no matter if decoding started from * the very first frame or from this keyframe. * Is AV_NOPTS_VALUE if unknown. * This field is not the display duration of the current packet. * * The purpose of this field is to allow seeking in streams that have no * keyframes in the conventional sense. It corresponds to the * recovery point SEI in H.264 and match_time_delta in NUT. It is also * essential for some types of subtitle streams to ensure that all * subtitles are correctly displayed after seeking. */</span> int64_t convergence_duration<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> AVPacket<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
FFMPEG使用AVPacket来暂存媒体数据包及附加信息(解码时间戳、显示时间戳、时长等),这样的媒体数据包所承载的往往不是原始格式的音视频数据,而是以某种方式编码后的数据,编码信息由对应的媒体流结构AVStream给出。AVPacket包含以下数据域:
-
dts表示解码时间戳,pts表示显示时间戳,它们的单位是所属媒体流的时间基准。
-
stream_index给出所属媒体流的索引;
-
data为数据缓冲区指针,size为长度;
-
duration为数据的时长,也是以所属媒体流的时间基准为单位;
-
pos表示该数据在媒体流中的字节偏移量;
-
destruct为用于释放数据缓冲区的函数指针;
-
flags为标志域,其中,最低为置1表示该数据是一个关键帧。
AVPacket结构本身只是个容器,它使用data成员引用实际的数据缓冲区。这个缓冲区的管理方式有两种,其一是通过调用av_new_packet直接创建缓冲区,其二是引用已经存在的缓冲区。缓冲区的释放通过调用av_free_packet实现,其内部实现也采用了两种不同的释放方式,第一种方式是调用AVPacket的destruct函数,这个destruct函数可能是缺省的av_destruct_packet,对应av_new_packet或av_dup_packet创建的缓冲区,也可能是某个自定义的释放函数,表示缓冲区的提供者希望使用者在结束缓冲区的时候按照提供者期望的方式将其释放,第二种方式是仅仅将data和size的值清0,这种情况下往往是引用了一个已经存在的缓冲区,AVPacket的destruct指针为空。
在使用AVPacket时,对于缓冲区的提供者,必须注意通过设置destruct函数指针指定正确的释放方式,如果缓冲区提供者打算自己释放缓冲区,则切记将destruct置空;而对于缓冲区的使用者,务必在使用结束时调用av_free_packet释放缓冲区(虽然释放操作可能只是一个假动作)。如果某个使用者打算较长时间内占用一个AVPacket——比如不打算在函数返回之前释放它——最好调用av_dup_packet进行缓冲区的克隆,将其转化为自有分配的缓冲区,以免对缓冲区的不当占用造成异常错误。av_dup_packet会为destruct指针为空的AVPacket新建一个缓冲区,然后将原缓冲区的数据拷贝至新缓冲区,置data的值为新缓冲区的地址,同时设destruct指针为av_destruct_packet。
时间信息
时间信息用于实现多媒体同步。
同步的目的在于展示多媒体信息时,能够保持媒体对象之间固有的时间关系。同步有两类,一类是流内同步,其主要任务是保证单个媒体流内的时间关系,以满足感知要求,如按照规定的帧率播放一段视频;另一类是流间同步,主要任务是保证不同媒体流之间的时间关系,如音频和视频之间的关系(lipsync)。
对于固定速率的媒体,如固定帧率的视频或固定比特率的音频,可以将时间信息(帧率或比特率)置于文件首部(header),如AVI的hdrl List、MP4的moov box,还有一种相对复杂的方案是将时间信息嵌入媒体流的内部,如MPEG TS和Real video,这种方案可以处理变速率的媒体,亦可有效避免同步过程中的时间漂移。
FFMPEG会为每一个数据包打上时间标签,以更有效地支持上层应用的同步机制。时间标签有两种,一种是DTS,称为解码时间标签,另一种是PTS,称为显示时间标签。对于声音来说 ,这两个时间标签是相同的,但对于某些视频编码格式,由于采用了双向预测技术,会造成DTS和PTS的不一致。
无双向预测帧的情况:
图像类型: I P P P P P P ... I P P DTS: 0 1 2 3 4 5 6... 100 101 102 PTS: 0 1 2 3 4 5 6... 100 101 102
有双向预测帧的情况:
图像类型: I P B B P B B ... I P B DTS: 0 1 2 3 4 5 6 ... 100 101 102 PTS: 0 3 1 2 6 4 5 ... 100 104 102
对于存在双向预测帧的情况,通常要求解码器对图像重排序,以保证输出的图像顺序为显示顺序:
解码器输入:I P B B P B B (DTS) 0 1 2 3 4 5 6 (PTS) 0 3 1 2 6 4 5 解码器输出:X I B B P B B P (PTS) X 0 1 2 3 4 5 6
时间信息的获取:
通过调用avformat_find_stream_info,多媒体应用可以从AVFormatContext对象中拿到媒体文件的时间信息:主要是总时间长度和开始时间,此外还有与时间信息相关的比特率和文件大小。其中时间信息的单位是AV_TIME_BASE:微秒。
<span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">typedef</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> AVFormatContext <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> ...... <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** Decoding: position of the first frame of the component, in AV_TIME_BASE fractional seconds. NEVER set this value directly: It is deduced from the AVStream values. */</span> int64_t start_time<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** Decoding: duration of the stream, in AV_TIME_BASE fractional seconds. Only set this value if you know none of the individual stream durations and also dont set any of them. This is deduced from the AVStream values if not set. */</span> int64_t duration<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** decoding: total file size, 0 if unknown */</span> int64_t file_size<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** Decoding: total stream bitrate in bit/s, 0 if not available. Never set it directly if the file_size and the duration are known as FFmpeg can compute it automatically. */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> bit_rate<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> ...... <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> AVFormatContext<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
以上4个成员变量都是只读的,基于FFMpeg的中间件需要将其封装到某个接口中,如:
LONG GetDuratioin<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>IntfX<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> LONG GetStartTime<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>IntfX<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> LONG GetFileSize<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>IntfX<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> LONG GetBitRate<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>IntfX<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
APIs
FFMpeg的API大部分以0作为成功返回值而一个负数作为错误码。
读系列
读系列API的主要功能是根据某个指定的源获取媒体数据包,这个源可以是一个本地文件、一个RTSP或HTTP源、一个摄像头驱动或者其它。
avformat_open_input
<span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> avformat_open_input<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>AVFormatContext <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">**</span>ic_ptr<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">const</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>filename<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> AVInputFormat <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>fmt<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> AVDictionary <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">**</span>options<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
avformat_open_input完成两个任务:
-
打开一个文件或URL,基于字节流的底层输入模块得到初始化。
-
解析多媒体文件或多媒体流的头信息,创建AVFormatContext结构并填充其中的关键字段,依次为各个原始流建立AVStream结构。
一个多媒体文件或多媒体流与其包含的原始流的关系如下:
多媒体文件/多媒体流 (movie.mkv) 原始流 1 (h.264 video) 原始流 2 (aac audio for Chinese) 原始流 3 (aac audio for english) 原始流 4 (Chinese Subtitle) 原始流 5 (English Subtitle) ...
关于输入参数:
-
ic_ptr,这是一个指向指针的指针,用于返回avformat_open_input内部构造的一个AVFormatContext结构体。
-
filename,指定文件名。
-
fmt,用于显式指定输入文件的格式,如果设为空则自动判断其输入格式。
-
options
这个函数通过解析多媒体文件或流的头信息及其他辅助数据,能够获取足够多的关于文件、流和编解码器的信息,但由于任何一种多媒体格式提供的信息都是有限的,而且不同的多媒体内容制作软件对头信息的设置不尽相同,此外这些软件在产生多媒体内容时难免会引入一些错误,因此这个函数并不保证能够获取所有需要的信息,在这种情况下,则需要考虑另一个函数:avformat_find_stream_info。
avformat_find_stream_info
<span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> avformat_find_stream_info<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>AVFormatContext <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>ic<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> AVDictionary <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">**</span>options<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
这个函数主要用于获取必要的编解码器参数,设置到ic→streams[i]→codec中。
首先必须得到各媒体流对应编解码器的类型和id,这是两个定义在avutils.h和avcodec.h中的枚举:
enum AVMediaType { AVMEDIA_TYPE_UNKNOWN = -1, AVMEDIA_TYPE_VIDEO, AVMEDIA_TYPE_AUDIO, AVMEDIA_TYPE_DATA, AVMEDIA_TYPE_SUBTITLE, AVMEDIA_TYPE_ATTACHMENT, AVMEDIA_TYPE_NB }; enum CodecID { CODEC_ID_NONE, /* video codecs */ CODEC_ID_MPEG1VIDEO, CODEC_ID_MPEG2VIDEO, ///< preferred ID for MPEG-1/2 video decoding CODEC_ID_MPEG2VIDEO_XVMC, CODEC_ID_H261, CODEC_ID_H263, ... };
通常,如果某种媒体格式具备完备而正确的头信息,调用avformat_open_input即可以得到这两个参数,但若是因某种原因avformat_open_input无法获取它们,这一任务将由avformat_find_stream_info完成。
其次还要获取各媒体流对应编解码器的时间基准。
此外,对于音频编解码器,还需要得到:
-
采样率,
-
声道数,
-
位宽,
-
帧长度(对于某些编解码器是必要的),
对于视频编解码器,则是:
-
图像大小,
-
色彩空间及格式,
av_read_frame
<span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> av_read_frame<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>AVFormatContext <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>s<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> AVPacket <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>pkt<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
这个函数用于从多媒体文件或多媒体流中读取媒体数据,获取的数据由AVPacket结构pkt来存放。对于音频数据,如果是固定比特率,则pkt中装载着一个或多个音频帧;如果是可变比特率,则pkt中装载有一个音频帧。对于视频数据,pkt中装载有一个视频帧。需要注意的是:再次调用本函数之前,必须使用av_free_packet释放pkt所占用的资源。
通过pkt→stream_index可以查到获取的媒体数据的类型,从而将数据送交相应的解码器进行后续处理。
av_seek_frame
<span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> av_seek_frame<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>AVFormatContext <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>s<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> stream_index<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> int64_t timestamp<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> flags<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
这个函数通过改变媒体文件的读写指针来实现对媒体文件的随机访问,支持以下三种方式:
-
基于时间的随机访问:具体而言就是将媒体文件读写指针定位到某个给定的时间点上,则之后调用av_read_frame时能够读到时间标签等于给定时间点的媒体数据,通常用于实现媒体播放器的快进、快退等功能。
-
基于文件偏移的随机访问:相当于普通文件的seek函数,timestamp也成为文件的偏移量。
-
基于帧号的随机访问:timestamp为要访问的媒体数据的帧号。
关于参数:
-
s:是个AVFormatContext指针,就是avformat_open_input返回的那个结构。
-
stream_index:指定媒体流,如果是基于时间的随机访问,则第三个参数timestamp将以此媒体流的时间基准为单位;如果设为负数,则相当于不指定具体的媒体流,FFMPEG会按照特定的算法寻找缺省的媒体流,此时,timestamp的单位为AV_TIME_BASE(微秒)。
-
timestamp:时间标签,单位取决于其他参数。
-
flags:定位方式,AVSEEK_FLAG_BYTE表示基于字节偏移,AVSEEK_FLAG_FRAME表示基于帧号,其它表示基于时间。
av_close_input_file
<span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">void</span> av_close_input_file<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>AVFormatContext <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>s<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
关闭一个媒体文件:释放资源,关闭物理IO。
编解码系列
编解码API负责实现媒体原始数据的编码和媒体压缩数据的解码。
avcodec_find_decoder
AVCodec <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>avcodec_find_decoder<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="kw2" style="padding: 0px; margin: 0px; font-weight: bold;">enum</span> CodecID id<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> AVCodec <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>avcodec_find_decoder_by_name<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">const</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>name<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
根据给定的codec id或解码器名称从系统中搜寻并返回一个AVCodec结构的指针。
avcodec_open2
<span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> avcodec_open2<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>AVCodecContext <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>avctx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">const</span> AVCodec <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>codec<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> AVDictionary <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">**</span>options<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
此函数根据输入的AVCodec指针具体化AVCodecContext结构。在调用该函数之前,需要首先调用avcodec_alloc_context分配一个AVCodecContext结构,或调用avformat_open_input获取媒体文件中对应媒体流的AVCodecContext结构;此外还需要通过avcodec_find_decoder获取AVCodec结构。
这一函数还将初始化对应的解码器。
avcodec_decode_video2
<span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> avcodec_decode_video2<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>AVCodecContext <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>avctx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> AVFrame <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>picture<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>got_picture_ptr<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> AVPacket <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>avpkt<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
解码一个视频帧。got_picture_ptr指示是否有解码数据输出。
输入数据在AVPacket结构中,输出数据在AVFrame结构中。AVFrame是定义在avcodec.h中的一个数据结构:
<span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">typedef</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> AVFrame <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> FF_COMMON_FRAME <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> AVFrame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
FF_COMMON_FRAME定义了诸多数据域,大部分由FFMpeg内部使用,对于用户来说,比较重要的主要包括:
<span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#define FF_COMMON_FRAME \ ......</span> uint8_t <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>data<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>4<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>\ <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> linesize<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>4<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>\ <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> key_frame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>\ <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> pict_type<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>\ int64_t pts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>\ <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> reference<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>\ ......
FFMpeg内部以planar的方式存储原始图像数据,即将图像像素分为多个平面(R/G/B或Y/U/V),data数组内的指针分别指向四个像素平面的起始位置,linesize数组则存放各个存贮各个平面的缓冲区的行宽:
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++data[0]->#################################++++++++++++ ++++++++++++###########picture data##########++++++++++++ ++++++++++++#################################++++++++++++ ++++++++++++#################################++++++++++++ ........................ ++++++++++++#################################++++++++++++ |<-------------------line_size[0]---------------------->|
此外,key_frame标识该图像是否是关键帧;pict_type表示该图像的编码类型:I(1)/P(2)/B(3)……;pts是以time_base为单位的时间标签,对于部分解码器如H.261、H.263和MPEG4,可以从头信息中获取;reference表示该图像是否被用作参考。
avcodec_decode_audio4
<span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> avcodec_decode_audio4<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>AVCodecContext <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>avctx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> AVFrame <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>frame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>got_frame_ptr<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> AVPacket <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>avpkt<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
解码一个音频帧。输入数据在AVPacket结构中,输出数据在frame中,got_frame_ptr表示是否有数据输出。
-
avcodec_close
<span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> avcodec_close<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>AVCodecContext <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>avctx<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
关闭解码器,释放avcodec_open中分配的资源。
写系列
写系列API负责将媒体数据以包的形式分发到指定的目标,这个目标可以是一个本地文件、一个RTSP或HTTP流或者其他。
avformat_alloc_output_context2
<span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> avformat_alloc_output_context2<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>AVFormatContext <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">**</span>ctx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> AVOutputFormat <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>oformat<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">const</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>format_name<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">const</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>filename<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
这个函数负责分配一个用于输出目的的AVFormatContext,输出格式由oformat、format_name和filename决定,oformat优先级最高,如果oformat为空则依据format_name,如果format_name为空则依据filename。
avformat_write_header
<span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> avformat_write_header<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>AVFormatContext <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>s<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> AVDictionary <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">**</span>options<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
此函数负责产生一个文件头并写入到输出目标中,调用之前,AVFormatContext结构中的oformat、pb必须正确设置,并且streams列表不能为空,列表中各stream的codec参数需要配置正确。
av_write_frame
<span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> av_write_frame<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>AVFormatContext <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>s<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> AVPacket <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>pkt<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
此函数负责输出一个媒体包。AVFormatContext参数给出输出目标及媒体流的格式设置,pkt是一个包含媒体数据的结构,其内部成员如dts/pts、stream_index等必须被正确设置。
av_interleaved_write_frame
<span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> av_interleaved_write_frame<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>AVFormatContext <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>s<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> AVPacket <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>pkt<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
此函数负责交错地输出一个媒体包。如果调用者无法保证来自各个媒体流的包正确交错,则最好调用此函数输出媒体包,反之,可以调用av_write_frame以提高性能。
av_write_trailer
<span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> av_write_trailer<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>AVFormatContext <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>s<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
其他
avformat_new_stream
AVStream <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>avformat_new_stream<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>AVFormatContext <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>s<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> AVCodec <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>c<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
这个函数负责创建一个AVStream结构,并将其添加到指定的AVFormatContext中,此时,AVStream的大部分域处于非法状态。如果输入参数c不为空,AVStream的codec域根据c实现初始化。
核心架构和机制
过滤链
FFMPEG支持由多个过滤器结构组成的过滤链,以实现对视频帧和音频采样数据的后续处理,如图像缩放、图像增强、声音的重采样等。
数据结构
FFMPEG使用了的四个主要的数据结构来构造过滤链,如上图所示。其中,AVFilter是一个过滤器的抽象,它拥有若干AVFilterPad,分别实现过滤器数据的输入和输出。而AVFilterLink表示各个过滤器之间的连接,这种连接的实现是基于AVFilterPad的,每个连接都有一个实现输入的AVFilterPad和一个实现输出的AVFilterPad以及对应的源过滤器和目的过滤器。
此外,还有两个数据结构AVFilterBuffer和AVFilterBufferRef来表示过滤器的输入输出数据,其中AVFilterBufferRef是AVFilterBuffer的引用,这种设计的目的是避免不必要的数据拷贝。通过avfilter_get_buffer_ref_from_frame可以获得一个AVFrame结构的引用,从而实现过滤器对来自AVFrame的图像原数据或声音采样序列的处理。
APIs
avfilter_open
avfilter_free
avfilter_init_filter
avfilter_link
avfilter_link_free
avfilter_ref_buffer
运作原理
FFMPEG堪称自由软件中最完备的一套多媒体支持库,它几乎实现了所有当下常见的数据封装格式、多媒体传输协议以及音视频编解码器。因此,对于从事多媒体技术开发的工程师来说,深入研究FFMPEG成为一门必不可少的工作,可以这样说,FFMPEG之于多媒体开发工程师的重要性正如kernel之于嵌入式系统工程师一般。
几个小知识:
-
FFMPEG项目是由法国人Fabrice Bellard发起的,此人也是著名的CPU模拟器项目QEMU的发起者,同时还是 圆周率算法纪录的保持者。
-
FF是Fast Forward的意思,翻译成中文是“快进”。
-
FFMPEG的LOGO是一个”Z字扫描”示意图,Z字扫描用于将图像的二维频域数据一维化,同时保证了一维化的数据具备良好的统计特性,从而提高其后要进行的一维熵编码的效率。
关于耻辱厅(Hall of Shame):FFMpeg大部分代码遵循LGPL许可证,如果使用者对FFMpeg进行了修改,要求公布修改的源代码;有少部分代码遵循GPL许可证,要求使用者同时公开使用FFMpeg的软件的源代码。实际上,除去部分具备系统软件开发能力的大型公司(Microsoft、Apple等)以及某些著名的音视频技术提供商(Divx、Real等)提供的自有播放器之外,绝大部分第三方开发的播放器都离不开FFMpeg的支持,像Linux桌面环境中的开源播放器VLC、MPlayer,Windows下的KMPlayer、暴风影音以及Android下几乎全部第三方播放器都是基于FFMpeg的。也有许多看似具备自主技术的播放器,其实也都不声不响地使用了FFMpeg,这种行为被称为“盗窃”,参与“盗窃”的公司则被请入耻辱厅,国产播放器暴风影音、QQ影音于2009年上榜。
FFMPEG从功能上划分为几个模块,分别为核心工具(libutils)、媒体格式(libavformat)、编解码(libavcodec)、设备(libavdevice)和后处理(libavfilter, libswscale, libpostproc),分别负责提供公用的功能函数、实现多媒体文件的读包和写包、完成音视频的编解码、管理音视频设备的操作以及进行音视频后处理。
使用FFMPEG
这里指FFMPEG提供的命令行(CLI)工具ffmpeg,其使用方法如下(方括号表示可选项,花括号表示必选项目):
ffmpeg [global options] [[infile options][‘-i’ infile]]... {[outfile options] outfile}...
除了全局选项,其他选项仅对后面紧跟着的输入或输出文件有效。
基本选项
能力集列表
-
-formats:列出支持的文件格式。
-
-codecs:列出支持的编解码器。
-
-decoders:列出支持的解码器。
-
-encoders:列出支持的编码器。
-
-protocols:列出支持的协议。
-
-bsfs:列出支持的比特流过滤器。
-
-filters:列出支持的滤镜。
-
-pix_fmts:列出支持的图像采样格式。
-
-sample_fmts:列出支持的声音采样格式。
常用输入选项
-
-i filename:指定输入文件名。
-
-f fmt:强制设定文件格式,需使用能力集列表中的名称(缺省是根据扩展名选择的)。
-
-t hh:mm:ss[.xxx]:设定输入文件的终止时间点。
-
-ss hh:mm:ss[.xxx]:设定输入文件的起始时间点。
对于输入,以下选项通常是自动识别的,但也可以强制设定。
-
-c codec:指定解码器,需使用能力集列表中的名称。
-
-acodec codec:指定声音的解码器,需使用能力集列表中的名称。
-
-vcodec codec:指定视频的解码器,需使用能力集列表中的名称。
-
-b bitrate:设定音视频流的比特率,整数,单位bps。
-
-r fps:设定视频流的帧率,整数,单位fps。
-
-s WxH : 设定视频的画面大小。也可以通过挂载画面缩放滤镜实现。
-
-pix_fmt format:设定视频流的图像格式(如RGB还是YUV)。
-
-ar sample rate:设定音频流的采样率,整数,单位Hz。
-
-ab bitrate:设定音频流的比特率,整数,单位bps。
-
-ac channels:设置音频流的声道数目。
常用输出选项
-
-f fmt:强制设定文件格式,需使用能力集列表中的名称(缺省是根据扩展名选择的)。
-
-c codec:指定编码器,需使用能力集列表中的名称(编码器设定为”copy“表示不进行编解码)。
-
-acodec codec:指定声音的编码器,需使用能力集列表中的名称(编码器设定为”copy“表示不进行编解码)。
-
-vcodec codec:指定视频的编码器,需使用能力集列表中的名称(编解码器设定为”copy“表示不进行编解码)。
-
-r fps:设定视频编码器的帧率,整数,单位fps。
-
-pix_fmt format:设置视频编码器使用的图像格式(如RGB还是YUV)。
-
-ar sample rate:设定音频编码器的采样率,整数,单位Hz。
-
-b bitrate:设定音视频编码器输出的比特率,整数,单位bps。
-
-ab bitrate:设定音频编码器输出的比特率,整数,单位bps。
-
-ac channels:设置音频编码器的声道数目。
-
-an 忽略任何音频流。
-
-vn 忽略任何视频流。
流标识
FFMPEG的某些选项可以对一个特定的媒体流起作用,这种情况下需要在选项后面增加一个流标识。流标识允许以下几种格式:
-
流序号。譬如“:1”表示第二个流。
-
流类型。譬如“:a“表示音频流,流类型可以和流序号合并使用,譬如“:a:1”表示第二个音频流。
-
节目。节目和流序号可以合并使用。
-
流标识。流标识是一个内部标识号。
假如要设定第二个音频流为copy,则需要指定-codec:a:1 copy
音频选项
视频选项
滤镜选项
高级选项
-
-re:要求按照既定速率处理输入数据,这个速率即是输入文件的帧率。
用例
1、从一个视频文件中抽取一帧图像:
ffmpeg -y -i test.mp4 -ss 00:03:22.000 -vframes 1 -an test.jpg
编译和裁剪
FFMpeg与大部分GNU软件的编译方式类似,是通过configure脚本来实现编译前定制的。这种途径允许用户在编译前对软件进行裁剪,同时通过对宿主系统和目标系统的自动检测来筛选参与编译的模块并为其设定合适的配置。但是,FFMpeg的configure脚本并非如通常的GNU软件一样通过配置工具自动生成,而是完全由人工编写的。configure脚本生成的config.mak和config.h分别在Makefile和源代码的层次上实现编译的控制。
通过运行“./configure –help”可以了解到脚本支持的参数,这些参数大体分为下面几类:
-
标准选项——GNU软件例行配置项目如安装路径等。例:–prefix=…,……
-
列出当前源代码支持的能力集,如编解码器,解复用器,输入输出设备,文件系统等。例:–list-decoders,–list-encoders,……
-
授权选项:–enable-version3,–enable-gpl,–enable-nofree。代码的缺省授权是LGPL v2,如果要使用以LGPL v3、GPL授权的模块或者某些不遵循自有软件授权协议的模块,必须在运行configure时显式使能相应的选项。
-
编译、链接选项。例:–disable-static,–enable-shared,…… 缺省配置是生成静态库而不生成动态库,如果希望禁止静态库、生成动态库都需要显式指定。
-
可执行程序控制选项,决定是否生成ffmpeg、ffplay、ffprobe和ffserver。
-
模块控制选项,筛选参与编译的模块,包括整个库的筛选,例如:–disable-avdevice;一组模块的筛选,例如:–disable-decoders,单个模块的筛选,如:–disable-decoder=… 等。
-
专家级选项,允许开发者进行深度定制,如交叉编译环境的配置、自定义编译器参数的设定、指令级优化、debug控制等。
对于–disable、–enable类的控制选项,如果以–disable为前缀,则缺省是enable的,反之亦然。
总之,无论从商业角度还是技术角度出发,使用configure脚本对FFMpeg进行裁剪是最安全的方式,只有针对于某些configure无法满足的定制要求,才需要考虑修改configure脚本——甚至修改configure生成的配置文件。
以下是一个配置实例,实现运行与Android系统中的ffmpeg库的编译:
./configure --prefix=. --cross-prefix=$NDK_TOOLCHAIN_PREFIX --enable-cross-compile --arch=arm --target-os=linux --cpu=cortex-a8 \ --disable-static --enable-shared --enable-pic --disable-ffmpeg --disable-ffplay --disable-ffserver --disable-ffprobe \ --extra-cflags="-I$NDK_PLATFORM/usr/include" \ --extra-ldflags="-nostdlib -Wl,-T,$NDK_PREBUILT/arm-linux-androideabi/lib/ldscripts/armelf_linux_eabi.x \ -L$NDK_PLATFORM/usr/lib \ $NDK_PREBUILT/lib/gcc/arm-linux-androideabi/4.4.3/crtbegin.o $NDK_PREBUILT/lib/gcc/arm-linux-androideabi/4.4.3/crtend.o \ -lc -lm -ldl"
深入FFMPEG
示例程序
解码
<span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#include <stdio.h></span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#include <string.h></span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#include <stdlib.h></span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#include <sys/time.h></span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#include "libavutil/avstring.h"</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#include "libavformat/avformat.h"</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#include "libavdevice/avdevice.h"</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#include "libavutil/opt.h"</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#include "libswscale/swscale.h"</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#define DECODED_AUDIO_BUFFER_SIZE 192000</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> options <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> streamId<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> frames<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> nodec<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> bplay<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> thread_count<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> int64_t lstart<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> finput<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>256<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> foutput1<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>256<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> foutput2<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>256<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> parse_options<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> options <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>opts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> argc<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">**</span> argv<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> optidx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>optstr<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>argc <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);"><</span> 2<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">1</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> opts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>streamId <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">1</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> opts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>lstart <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">1</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> opts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>frames <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">1</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> opts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>foutput1<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> opts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>foutput2<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> opts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>nodec <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> opts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>bplay <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> opts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>thread_count <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> strcpy<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>opts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>finput<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> argv<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>1<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> optidx <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">2</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">while</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>optidx <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);"><</span> argc<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> optstr <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> argv<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>optidx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">++</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>optstr<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">++</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">!=</span> <span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">'-'</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">1</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">switch</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>optstr<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">++</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">case</span> <span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">'s'</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">:</span> <span class="co1" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">//< stream id</span> opts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>streamId <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> atoi<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>optstr<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw2" style="padding: 0px; margin: 0px; font-weight: bold;">break</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">case</span> <span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">'f'</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">:</span> <span class="co1" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">//< frames</span> opts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>frames <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> atoi<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>optstr<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw2" style="padding: 0px; margin: 0px; font-weight: bold;">break</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">case</span> <span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">'k'</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">:</span> <span class="co1" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">//< skipped</span> opts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>lstart <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> atoll<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>optstr<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw2" style="padding: 0px; margin: 0px; font-weight: bold;">break</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">case</span> <span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">'o'</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">:</span> <span class="co1" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">//< output</span> strcpy<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>opts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>foutput1<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> optstr<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> strcat<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>opts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>foutput1<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">".mpg"</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> strcpy<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>opts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>foutput2<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> optstr<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> strcat<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>opts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>foutput2<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">".raw"</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw2" style="padding: 0px; margin: 0px; font-weight: bold;">break</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">case</span> <span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">'n'</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">:</span> <span class="co1" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">//decoding and output options</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>strcmp<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"dec"</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> optstr<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> 0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> opts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>nodec <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">1</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw2" style="padding: 0px; margin: 0px; font-weight: bold;">break</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">case</span> <span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">'p'</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">:</span> opts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>bplay <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">1</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw2" style="padding: 0px; margin: 0px; font-weight: bold;">break</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">case</span> <span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">'t'</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">:</span> opts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>thread_count <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> atoi<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>optstr<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw2" style="padding: 0px; margin: 0px; font-weight: bold;">break</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">default</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">:</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">1</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">void</span> show_help<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span> program<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"Simple FFMPEG test program<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"Usage: %s inputfile [-sstreamid [-fframes] [-kskipped] [-ooutput_filename(without extension)] [-ndec] [-p] [-tthread_count]]<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> program<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">static</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">void</span> log_callback<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">void</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span> ptr<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> level<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">const</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span> fmt<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> va_list vl<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> vfprintf<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>stdout<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> fmt<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> vl<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* * audio renderer code (oss) */</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#include <sys/ioctl.h></span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#include <unistd.h></span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#include <fcntl.h></span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#include <sys/soundcard.h></span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#define OSS_DEVICE "/dev/dsp0"</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> audio_dsp <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> audio_fd<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> channels<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> format<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> speed<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> map_formats<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="kw2" style="padding: 0px; margin: 0px; font-weight: bold;">enum</span> AVSampleFormat format<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">switch</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>format<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">case</span> AV_SAMPLE_FMT_U8<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">:</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> AFMT_U8<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">case</span> AV_SAMPLE_FMT_S16<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">:</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> AFMT_S16_LE<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">default</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">:</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> AFMT_U8<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> set_audio<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> audio_dsp<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span> dsp<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>dsp<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>audio_fd <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span>1<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"Invalid audio dsp id!<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">1</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span>1 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> ioctl<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>dsp<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>audio_fd<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> SNDCTL_DSP_SETFMT<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>dsp<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>format<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"Failed to set dsp format!<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">1</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span>1 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> ioctl<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>dsp<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>audio_fd<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> SNDCTL_DSP_CHANNELS<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>dsp<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>channels<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"Failed to set dsp format!<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">1</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span>1 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> ioctl<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>dsp<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>audio_fd<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> SNDCTL_DSP_SPEED<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>dsp<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>speed<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"Failed to set dsp format!<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">1</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> play_pcm<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> audio_dsp<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span> dsp<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">unsigned</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>buf<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> size<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>dsp<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>audio_fd <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span>1<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"Invalid audio dsp id!<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">1</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span>1 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> write<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>dsp<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>audio_fd<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> buf<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> size<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"Failed to write audio dsp!<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">1</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* audio renderer code end */</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* video renderer code*/</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#include <linux/fb.h></span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#include <sys/mman.h></span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#define FB_DEVICE "/dev/fb0"</span> <span class="kw2" style="padding: 0px; margin: 0px; font-weight: bold;">enum</span> pic_format <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> eYUV_420_Planer<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> video_fb <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> video_fd<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> fb_var_screeninfo vinfo<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> fb_fix_screeninfo finfo<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">unsigned</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>fbp<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> AVFrame <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>frameRGB<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> x<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> y<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> video_pos<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> open_video<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> video_fb <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> x<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> y<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> screensize<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>video_fd <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> open<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>FB_DEVICE<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> O_WRONLY<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>video_fd <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span>1<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">1</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>ioctl<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>video_fd<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> FBIOGET_FSCREENINFO<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>finfo<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">2</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>ioctl<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>video_fd<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> FBIOGET_VSCREENINFO<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">2</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"video device: resolution %dx%d, %dbpp<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">xres</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">yres</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">bits_per_pixel</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> screensize <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">xres</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">yres</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">bits_per_pixel</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">/</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">8</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>fbp <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">unsigned</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> mmap<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>0<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> screensize<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> PROT_READ<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">|</span>PROT_WRITE<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> MAP_SHARED<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>video_fd<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> 0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>fbp <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span>1<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">3</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>x <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">>=</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">xres</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">||</span> y <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">>=</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">yres</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">4</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">else</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>video_pos.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">x</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> x<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>video_pos.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">y</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> y<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>frameRGB <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> avcodec_alloc_frame<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">!</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>frameRGB<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">5</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* only 420P supported now */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> show_picture<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> video_fb <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> AVFrame <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>frame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> width<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> height<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="kw2" style="padding: 0px; margin: 0px; font-weight: bold;">enum</span> pic_format format<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> SwsContext <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>sws<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> i<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">unsigned</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>dest<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">unsigned</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>src<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>video_fd <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span>1<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">1</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>video_pos.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">x</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">>=</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">xres</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">||</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>video_pos.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">y</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">>=</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">yres</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">2</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>video_pos.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">x</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">+</span> width <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">></span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">xres</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> width <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">xres</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>video_pos.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">x</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>video_pos.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">y</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">+</span> height <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">></span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">yres</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> height <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">yres</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>video_pos.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">y</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>format <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> PIX_FMT_YUV420P<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> sws <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> sws_getContext<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>width<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> height<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> format<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> width<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> height<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> PIX_FMT_RGB32<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> SWS_FAST_BILINEAR<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> NULL<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> NULL<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> NULL<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>sws <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> 0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">3</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>sws_scale<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>sws<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> frame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>data<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> frame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>linesize<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> 0<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> height<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>frameRGB<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>data<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>frameRGB<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>linesize<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">3</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> dest <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>fbp <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">+</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>video_pos.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">x</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">+</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">xoffset</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">bits_per_pixel</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">/</span>8<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">+</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>video_pos.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">y</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">+</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">yoffset</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>finfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">line_length</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">for</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>i <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> i <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);"><</span> height<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> i<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">++</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> memcpy<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>dest<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> src<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> width<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>4<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> src <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">+=</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>frameRGB<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>linesize<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> dest <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">+=</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>finfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">line_length</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">void</span> close_video<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> video_fb <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>fb<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>video_fd <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">!=</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span>1<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> munmap<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>fbp<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">xres</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">yres</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>vinfo.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">bits_per_pixel</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">/</span> 8<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> close<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>video_fd<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>video_fd <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">1</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* video renderer code end */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> main<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> argc<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">**</span>argv<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> AVFormatContext<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span> pCtx <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> AVCodecContext <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>pCodecCtx <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> AVCodec <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>pCodec <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> AVPacket packet<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> AVFrame <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>pFrame <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> FILE <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>fpo1 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> NULL<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> FILE <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>fpo2 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> NULL<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> nframe<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> err<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> got_picture<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> picwidth<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> picheight<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> linesize<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">unsigned</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>pBuf<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> i<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> int64_t timestamp<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> options opt<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> usefo <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> audio_dsp dsp<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> video_fb fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> dusecs<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">float</span> usecs1 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">float</span> usecs2 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> timeval elapsed1<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> elapsed2<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> decoded <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> av_register_all<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> av_log_set_callback<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>log_callback<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> av_log_set_level<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>50<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>parse_options<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>opt<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> argc<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> argv<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);"><</span> 0 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">||</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>strlen<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">finput</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> 0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> show_help<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>argv<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> err <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> avformat_open_input<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>pCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">finput</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> 0<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> 0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>err <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);"><</span> 0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"<span class="es1" style="padding: 0px; margin: 0px;">\n</span>->(avformat_open_input)<span class="es1" style="padding: 0px; margin: 0px;">\t</span>ERROR:<span class="es1" style="padding: 0px; margin: 0px;">\t</span>%d<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> err<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">goto</span> fail<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> err <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> avformat_find_stream_info<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>pCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> 0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>err <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);"><</span> 0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"<span class="es1" style="padding: 0px; margin: 0px;">\n</span>->(avformat_find_stream_info)<span class="es1" style="padding: 0px; margin: 0px;">\t</span>ERROR:<span class="es1" style="padding: 0px; margin: 0px;">\t</span>%d<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> err<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">goto</span> fail<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">streamId</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);"><</span> 0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> av_dump_format<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>pCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> 0<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> pCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>filename<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> 0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">goto</span> fail<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">else</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"<span class="es1" style="padding: 0px; margin: 0px;">\n</span> extra data in Stream %d (%dB):"</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">streamId</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> pCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>streams<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">streamId</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>codec<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>extradata_size<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">for</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>i <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> i <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);"><</span> pCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>streams<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">streamId</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>codec<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>extradata_size<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> i<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">++</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>i<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">%</span>16 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> 0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"%2x "</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> pCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>streams<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">streamId</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>codec<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>extradata<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>i<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* try opening output files */</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>strlen<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">foutput1</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&&</span> strlen<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">foutput2</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> fpo1 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> fopen<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">foutput1</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"wb"</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> fpo2 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> fopen<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">foutput2</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"wb"</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">!</span>fpo1 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">||</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">!</span>fpo2<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"<span class="es1" style="padding: 0px; margin: 0px;">\n</span>->error opening output files<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">goto</span> fail<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> usefo <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">1</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">else</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> usefo <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">streamId</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">>=</span> pCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>nb_streams<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"<span class="es1" style="padding: 0px; margin: 0px;">\n</span>->StreamId<span class="es1" style="padding: 0px; margin: 0px;">\t</span>ERROR<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">goto</span> fail<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">lstart</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">></span> 0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> err <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> av_seek_frame<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>pCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">streamId</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">lstart</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> AVSEEK_FLAG_ANY<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>err <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);"><</span> 0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"<span class="es1" style="padding: 0px; margin: 0px;">\n</span>->(av_seek_frame)<span class="es1" style="padding: 0px; margin: 0px;">\t</span>ERROR:<span class="es1" style="padding: 0px; margin: 0px;">\t</span>%d<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> err<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">goto</span> fail<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* for decoder configuration */</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">!</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">nodec</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* prepare codec */</span> pCodecCtx <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> pCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>streams<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">streamId</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>codec<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">thread_count</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);"><=</span> 16 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&&</span> opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">thread_count</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">></span> 0 <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> pCodecCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>thread_count <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">thread_count</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> pCodecCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>thread_type <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> FF_THREAD_FRAME<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> pCodec <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> avcodec_find_decoder<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>pCodecCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>codec_id<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">!</span>pCodec<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"<span class="es1" style="padding: 0px; margin: 0px;">\n</span>->can not find codec!<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">goto</span> fail<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> err <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> avcodec_open2<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>pCodecCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> pCodec<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> 0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>err <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);"><</span> 0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"<span class="es1" style="padding: 0px; margin: 0px;">\n</span>->(avcodec_open)<span class="es1" style="padding: 0px; margin: 0px;">\t</span>ERROR:<span class="es1" style="padding: 0px; margin: 0px;">\t</span>%d<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> err<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">goto</span> fail<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> pFrame <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> avcodec_alloc_frame<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* prepare device */</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">bplay</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* audio devices */</span> dsp.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">audio_fd</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> open<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>OSS_DEVICE<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> O_WRONLY<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>dsp.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">audio_fd</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span>1<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"<span class="es1" style="padding: 0px; margin: 0px;">\n</span>-> can not open audio device<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">goto</span> fail<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> dsp.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">channels</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> pCodecCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>channels<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> dsp.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">speed</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> pCodecCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>sample_rate<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> dsp.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">format</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> map_formats<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>pCodecCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>sample_fmt<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>set_audio<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>dsp<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);"><</span> 0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"<span class="es1" style="padding: 0px; margin: 0px;">\n</span>-> can not set audio device<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">goto</span> fail<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* video devices */</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>open_video<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> 0<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> 0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">!=</span> 0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"<span class="es1" style="padding: 0px; margin: 0px;">\n</span>-> can not open video device<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">goto</span> fail<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> nframe <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">while</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>nframe <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);"><</span> opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">frames</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">||</span> opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">frames</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span>1<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> gettimeofday<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>elapsed1<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> NULL<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> err <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> av_read_frame<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>pCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>packet<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>err <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);"><</span> 0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"<span class="es1" style="padding: 0px; margin: 0px;">\n</span>->(av_read_frame)<span class="es1" style="padding: 0px; margin: 0px;">\t</span>ERROR:<span class="es1" style="padding: 0px; margin: 0px;">\t</span>%d<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> err<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw2" style="padding: 0px; margin: 0px; font-weight: bold;">break</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> gettimeofday<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>elapsed2<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> NULL<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> dusecs <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>elapsed2.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">tv_sec</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span> elapsed1.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">tv_sec</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>1000000 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">+</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>elapsed2.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">tv_usec</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span> elapsed1.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">tv_usec</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> usecs2 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">+=</span> dusecs<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> timestamp <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> av_rescale_q<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>packet.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">dts</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> pCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>streams<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>packet.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">stream_index</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>time_base<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>AVRational<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span>1<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> AV_TIME_BASE<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"<span class="es1" style="padding: 0px; margin: 0px;">\n</span>Frame No %5d stream#%d<span class="es1" style="padding: 0px; margin: 0px;">\t</span>size %6dB, timestamp:%6lld, dts:%6lld, pts:%6lld, "</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> nframe<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">++,</span> packet.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">stream_index</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> packet.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">size</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> timestamp<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> packet.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">dts</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> packet.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">pts</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>packet.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">stream_index</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">streamId</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#if 0 </span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">for</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>i <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> i <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);"><</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">16</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/*packet.size;*/</span> i<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">++</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>i<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">%</span>16 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> 0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"<span class="es1" style="padding: 0px; margin: 0px;">\n</span> pktdata: "</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"%2x "</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> packet.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">data</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>i<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#endif </span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>usefo<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> fwrite<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>packet.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">data</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> packet.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">size</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> 1<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> fpo1<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> fflush<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fpo1<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>pCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>streams<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">streamId</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>codec<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>codec_type <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> AVMEDIA_TYPE_VIDEO <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&&</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">!</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">nodec</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> picheight <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> pCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>streams<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">streamId</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>codec<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>height<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> picwidth <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> pCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>streams<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">streamId</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>codec<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>width<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> gettimeofday<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>elapsed1<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> NULL<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> avcodec_decode_video2<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>pCodecCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> pFrame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>got_picture<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>packet<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> decoded<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">++;</span> gettimeofday<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>elapsed2<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> NULL<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> dusecs <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>elapsed2.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">tv_sec</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span> elapsed1.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">tv_sec</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>1000000 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">+</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>elapsed2.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">tv_usec</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span> elapsed1.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">tv_usec</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> usecs1 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">+=</span> dusecs<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>got_picture<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"[Video: type %d, ref %d, pts %lld, pkt_pts %lld, pkt_dts %lld]"</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> pFrame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>pict_type<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> pFrame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>reference<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> pFrame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>pts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> pFrame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>pkt_pts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> pFrame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>pkt_dts<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>pCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>streams<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">streamId</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>codec<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>pix_fmt <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> PIX_FMT_YUV420P<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>usefo<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> linesize <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> pFrame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>linesize<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> pBuf <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> pFrame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>data<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">for</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>i <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> i <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);"><</span> picheight<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> i<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">++</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> fwrite<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>pBuf<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> picwidth<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> 1<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> fpo2<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> pBuf <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">+=</span> linesize<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> linesize <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> pFrame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>linesize<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>1<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> pBuf <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> pFrame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>data<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>1<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">for</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>i <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> i <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);"><</span> picheight<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">/</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">2</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> i<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">++</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> fwrite<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>pBuf<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> picwidth<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">/</span>2<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> 1<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> fpo2<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> pBuf <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">+=</span> linesize<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> linesize <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> pFrame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>linesize<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>2<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> pBuf <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> pFrame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>data<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>2<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">for</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>i <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> i <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);"><</span> picheight<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">/</span><span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">2</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> i<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">++</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> fwrite<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>pBuf<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> picwidth<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">/</span>2<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> 1<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> fpo2<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> pBuf <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">+=</span> linesize<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> fflush<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fpo2<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">bplay</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* show picture */</span> show_picture<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>fb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> pFrame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> picheight<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> picwidth<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> PIX_FMT_YUV420P<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> av_free_packet<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>packet<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">else</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>pCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>streams<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">streamId</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>codec<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>codec_type <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">==</span> AVMEDIA_TYPE_AUDIO <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&&</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">!</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">nodec</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> got<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> gettimeofday<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>elapsed1<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> NULL<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> avcodec_decode_audio4<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>pCodecCtx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> pFrame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>got<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>packet<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> decoded<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">++;</span> gettimeofday<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>elapsed2<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> NULL<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> dusecs <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">=</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>elapsed2.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">tv_sec</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span> elapsed1.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">tv_sec</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>1000000 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">+</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>elapsed2.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">tv_usec</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span> elapsed1.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">tv_usec</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> usecs1 <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">+=</span> dusecs<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>got<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"[Audio: %5dB raw data, decoding time: %d]"</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> pFrame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>linesize<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> dusecs<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>usefo<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> fwrite<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>pFrame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>data<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> pFrame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>linesize<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> 1<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> fpo2<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> fflush<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fpo2<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">bplay</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> play_pcm<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>dsp<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> pFrame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>data<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> pFrame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-></span>linesize<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>0<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">!</span>opt.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">nodec</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&&</span> pCodecCtx<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> avcodec_close<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>pCodecCtx<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"<span class="es1" style="padding: 0px; margin: 0px;">\n</span>%d frames parsed, average %.2f us per frame<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> nframe<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> usecs2<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">/</span>nframe<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <a target=_blank target="__blank" href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html" style="color: rgb(67, 105, 118); text-decoration: none; padding: 0px; margin: 0px;"><span class="kw3" style="padding: 0px; margin: 0px; color: rgb(0, 0, 102);">printf</span></a><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="st0" style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">"%d frames decoded, average %.2f us per frame<span class="es1" style="padding: 0px; margin: 0px;">\n</span>"</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> decoded<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> usecs1<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">/</span>decoded<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> fail<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">:</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>pCtx<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> avformat_close_input<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>pCtx<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fpo1<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> fclose<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fpo1<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fpo2<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> fclose<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fpo2<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">!</span>pFrame<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> av_free<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>pFrame<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">!</span>usefo <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&&</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>dsp.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">audio_fd</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">!=</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span>1<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> close<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>dsp.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">audio_fd</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">if</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">!</span>usefo <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&&</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>fb.<span class="me1" style="padding: 0px; margin: 0px; color: rgb(0, 102, 0);">video_fd</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">!=</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">-</span>1<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> close_video<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">&</span>fb<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> <span class="kw1" style="padding: 0px; margin: 0px; color: rgb(177, 177, 0);">return</span> <span class="nu0" style="padding: 0px; margin: 0px; color: rgb(204, 102, 204);">0</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span>
这一小段代码可以实现的功能包括:
-
打开一个多媒体文件并获取基本的媒体信息。
-
获取编码器句柄。
-
根据给定的时间标签进行一个跳转。
-
读取数据帧。
-
解码音频帧或者视频帧。
-
关闭多媒体文件。
这些功能足以支持一个功能强大的多媒体播放器,因为最复杂的解复用、解码、数据分析过程已经在FFMpeg内部实现了,需要关注的仅剩同步问题。
用户接口
数据结构
基本概念
编解码器、数据帧、媒体流和容器是数字媒体处理系统的四个基本概念。
首先需要统一术语:
-
容器/文件(Conainer/File):即特定格式的多媒体文件。
-
媒体流(Stream):指时间轴上的一段连续数据,如一段声音数据,一段视频数据或一段字幕数据,可以是压缩的,也可以是非压缩的,压缩的数据需要关联特定的编解码器。
-
数据帧/数据包(Frame/Packet):通常,一个媒体流由大量的数据帧组成,对于压缩数据,帧对应着编解码器的最小处理单元。通常,分属于不同媒体流的数据帧交错复用于容器之中,参见 交错。
-
编解码器:编解码器以帧为单位实现压缩数据和原始数据之间的相互转换。
在FFMPEG中,使用AVFormatContext、AVStream、AVCodecContext、AVCodec及AVPacket等结构来抽象这些基本要素,它们的关系如下图所示:
AVCodecContext
这是一个描述编解码器上下文的数据结构,包含了众多编解码器需要的参数信息,如下列出了部分比较重要的域:
<span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">typedef</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> AVCodecContext <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> ...... <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * some codecs need / can use extradata like Huffman tables. * mjpeg: Huffman tables * rv10: additional flags * mpeg4: global headers (they can be in the bitstream or here) * The allocated memory should be FF_INPUT_BUFFER_PADDING_SIZE bytes larger * than extradata_size to avoid prolems if it is read with the bitstream reader. * The bytewise contents of extradata must not depend on the architecture or CPU endianness. * - encoding: Set/allocated/freed by libavcodec. * - decoding: Set/allocated/freed by user. */</span> uint8_t <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>extradata<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> extradata_size<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * This is the fundamental unit of time (in seconds) in terms * of which frame timestamps are represented. For fixed-fps content, * timebase should be 1/framerate and timestamp increments should be * identically 1. * - encoding: MUST be set by user. * - decoding: Set by libavcodec. */</span> AVRational time_base<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* video only */</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * picture width / height. * - encoding: MUST be set by user. * - decoding: Set by libavcodec. * Note: For compatibility it is possible to set this instead of * coded_width/height before decoding. */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> width<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> height<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> ...... <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* audio only */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> sample_rate<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="co1" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">///< samples per second</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> channels<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="co1" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">///< number of audio channels</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * audio sample format * - encoding: Set by user. * - decoding: Set by libavcodec. */</span> <span class="kw2" style="padding: 0px; margin: 0px; font-weight: bold;">enum</span> SampleFormat sample_fmt<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="co1" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">///< sample format</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* The following data should not be initialized. */</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * Samples per packet, initialized when calling 'init'. */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> frame_size<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> frame_number<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="co1" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">///< audio or video frame number</span> ...... <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> codec_name<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>32<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw2" style="padding: 0px; margin: 0px; font-weight: bold;">enum</span> AVMediaType codec_type<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* see AVMEDIA_TYPE_xxx */</span> <span class="kw2" style="padding: 0px; margin: 0px; font-weight: bold;">enum</span> CodecID codec_id<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* see CODEC_ID_xxx */</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A'). * This is used to work around some encoder bugs. * A demuxer should set this to what is stored in the field used to identify the codec. * If there are multiple such fields in a container then the demuxer should choose the one * which maximizes the information about the used codec. * If the codec tag field in a container is larger then 32 bits then the demuxer should * remap the longer ID to 32 bits with a table or other structure. Alternatively a new * extra_codec_tag + size could be added but for this a clear advantage must be demonstrated * first. * - encoding: Set by user, if not then the default based on codec_id will be used. * - decoding: Set by user, will be converted to uppercase by libavcodec during init. */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">unsigned</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> codec_tag<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> ...... <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * Size of the frame reordering buffer in the decoder. * For MPEG-2 it is 1 IPB or 0 low delay IP. * - encoding: Set by libavcodec. * - decoding: Set by libavcodec. */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> has_b_frames<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * number of bytes per packet if constant and known or 0 * Used by some WAV based audio codecs. */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> block_align<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> ...... <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * bits per sample/pixel from the demuxer (needed for huffyuv). * - encoding: Set by libavcodec. * - decoding: Set by user. */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> bits_per_coded_sample<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> ...... <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> AVCodecContext<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
如果是单纯使用libavcodec,这部分信息需要调用者进行初始化;如果是使用整个FFMPEG库,这部分信息在调用avformat_open_input和avformat_find_stream_info的过程中根据文件的头信息及媒体流内的头部信息完成初始化。其中几个主要域的释义如下:
-
extradata/extradata_size:这个buffer中存放了解码器可能会用到的额外信息,在av_read_frame中填充。一般来说,首先,某种具体格式的demuxer在读取格式头信息的时候会填充extradata,其次,如果demuxer没有做这个事情,比如可能在头部压根儿就没有相关的编解码信息,则相应的parser会继续从已经解复用出来的媒体流中继续寻找。在没有找到任何额外信息的情况下,这个buffer指针为空。
-
time_base:编解码器的时间基准,实际上就是视频的帧率(或场率)。
-
width/height:视频的宽和高。
-
sample_rate/channels:音频的采样率和信道数目。
-
sample_fmt: 音频的原始采样格式。
-
codec_name/codec_type/codec_id/codec_tag:编解码器的信息。
AVStream
该结构体描述一个媒体流,定义如下:
<span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">typedef</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> AVStream <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> index<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/**< stream index in AVFormatContext */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> id<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/**< format-specific stream ID */</span> AVCodecContext <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>codec<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/**< codec context */</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * Real base framerate of the stream. * This is the lowest framerate with which all timestamps can be * represented accurately (it is the least common multiple of all * framerates in the stream). Note, this value is just a guess! * For example, if the time base is 1/90000 and all frames have either * approximately 3600 or 1800 timer ticks, then r_frame_rate will be 50/1. */</span> AVRational r_frame_rate<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> ...... <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * This is the fundamental unit of time (in seconds) in terms * of which frame timestamps are represented. For fixed-fps content, * time base should be 1/framerate and timestamp increments should be 1. */</span> AVRational time_base<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> ...... <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * Decoding: pts of the first frame of the stream, in stream time base. * Only set this if you are absolutely 100% sure that the value you set * it to really is the pts of the first frame. * This may be undefined (AV_NOPTS_VALUE). * @note The ASF header does NOT contain a correct start_time the ASF * demuxer must NOT set this. */</span> int64_t start_time<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * Decoding: duration of the stream, in stream time base. * If a source file does not specify a duration, but does specify * a bitrate, this value will be estimated from bitrate and file size. */</span> int64_t duration<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#if LIBAVFORMAT_VERSION_INT < (53<<16)</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> language<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>4<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** ISO 639-2/B 3-letter language code (empty string if undefined) */</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#endif</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* av_read_frame() support */</span> <span class="kw2" style="padding: 0px; margin: 0px; font-weight: bold;">enum</span> AVStreamParseType need_parsing<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> AVCodecParserContext <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>parser<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> ...... <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* av_seek_frame() support */</span> AVIndexEntry <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>index_entries<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/**< Only used if the format does not support seeking natively. */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> nb_index_entries<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">unsigned</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> index_entries_allocated_size<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> int64_t nb_frames<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="co1" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">///< number of frames in this stream if known or 0</span> ...... <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * Average framerate */</span> AVRational avg_frame_rate<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> ...... <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> AVStream<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
主要域的释义如下,其中大部分域的值可以由avformat_open_input根据文件头的信息确定,缺少的信息需要通过调用avformat_find_stream_info读帧及软解码进一步获取:
-
index/id:index对应流的索引,这个数字是自动生成的,根据index可以从AVFormatContext::streams表中索引到该流;而id则是流的标识,依赖于具体的容器格式。比如对于MPEG TS格式,id就是pid。
-
time_base:流的时间基准,是一个实数,该流中媒体数据的pts和dts都将以这个时间基准为粒度。通常,使用av_rescale/av_rescale_q可以实现不同时间基准的转换。
-
start_time:流的起始时间,以流的时间基准为单位,通常是该流中第一个帧的pts。
-
duration:流的总时间,以流的时间基准为单位。
-
need_parsing:对该流parsing过程的控制域。
-
nb_frames:流内的帧数目。
-
r_frame_rate/framerate/avg_frame_rate:帧率相关。
-
codec:指向该流对应的AVCodecContext结构,调用avformat_open_input时生成。
-
parser:指向该流对应的AVCodecParserContext结构,调用avformat_find_stream_info时生成。。
AVFormatContext
这个结构体描述了一个媒体文件或媒体流的构成和基本信息,定义如下:
<span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">typedef</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> AVFormatContext <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">const</span> AVClass <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>av_class<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/**< Set by avformat_alloc_context. */</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* Can only be iformat or oformat, not both at the same time. */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> AVInputFormat <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>iformat<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> AVOutputFormat <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>oformat<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">void</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>priv_data<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> ByteIOContext <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>pb<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">unsigned</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> nb_streams<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> AVStream <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>streams<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>MAX_STREAMS<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> filename<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>1024<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/**< input or output filename */</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* stream info */</span> int64_t timestamp<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#if LIBAVFORMAT_VERSION_INT < (53<<16)</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> title<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>512<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> author<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>512<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> copyright<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>512<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> comment<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>512<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> album<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>512<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> year<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/**< ID3 year, 0 if none */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> track<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/**< track number, 0 if none */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> genre<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>32<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/**< ID3 genre */</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#endif</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> ctx_flags<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/**< Format-specific flags, see AVFMTCTX_xx */</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* private data for pts handling (do not modify directly). */</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** This buffer is only needed when packets were already buffered but not decoded, for example to get the codec parameters in MPEG streams. */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> AVPacketList <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>packet_buffer<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** Decoding: position of the first frame of the component, in AV_TIME_BASE fractional seconds. NEVER set this value directly: It is deduced from the AVStream values. */</span> int64_t start_time<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** Decoding: duration of the stream, in AV_TIME_BASE fractional seconds. Only set this value if you know none of the individual stream durations and also dont set any of them. This is deduced from the AVStream values if not set. */</span> int64_t duration<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** decoding: total file size, 0 if unknown */</span> int64_t file_size<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** Decoding: total stream bitrate in bit/s, 0 if not available. Never set it directly if the file_size and the duration are known as FFmpeg can compute it automatically. */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> bit_rate<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* av_read_frame() support */</span> AVStream <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>cur_st<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#if LIBAVFORMAT_VERSION_INT < (53<<16)</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">const</span> uint8_t <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>cur_ptr_deprecated<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> cur_len_deprecated<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> AVPacket cur_pkt_deprecated<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#endif</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/* av_seek_frame() support */</span> int64_t data_offset<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** offset of the first packet */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> index_built<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> mux_rate<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">unsigned</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> packet_size<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> preload<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> max_delay<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#define AVFMT_NOOUTPUTLOOP -1</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#define AVFMT_INFINITEOUTPUTLOOP 0</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** number of times to loop output in formats that support it */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> loop_output<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> flags<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#define AVFMT_FLAG_GENPTS 0x0001 ///< Generate missing pts even if it requires parsing future frames.</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#define AVFMT_FLAG_IGNIDX 0x0002 ///< Ignore index.</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#define AVFMT_FLAG_NONBLOCK 0x0004 ///< Do not block when reading packets from input.</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#define AVFMT_FLAG_IGNDTS 0x0008 ///< Ignore DTS on frames that contain both DTS & PTS</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#define AVFMT_FLAG_NOFILLIN 0x0010 ///< Do not infer any values from other values, just return what is stored in the container</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#define AVFMT_FLAG_NOPARSE 0x0020 ///< Do not use AVParsers, you also must set AVFMT_FLAG_NOFILLIN as the fillin code works on frames and no parsing -> no frames. Also seeking to frames can not work if parsing to find frame boundaries has been disabled</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#define AVFMT_FLAG_RTP_HINT 0x0040 ///< Add RTP hinting to the output file</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> loop_input<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** decoding: size of data to probe; encoding: unused. */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">unsigned</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> probesize<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * Maximum time (in AV_TIME_BASE units) during which the input should * be analyzed in avformat_find_stream_info(). */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> max_analyze_duration<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">const</span> uint8_t <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>key<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> keylen<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">unsigned</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> nb_programs<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> AVProgram <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">**</span>programs<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * Forced video codec_id. * Demuxing: Set by user. */</span> <span class="kw2" style="padding: 0px; margin: 0px; font-weight: bold;">enum</span> CodecID video_codec_id<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * Forced audio codec_id. * Demuxing: Set by user. */</span> <span class="kw2" style="padding: 0px; margin: 0px; font-weight: bold;">enum</span> CodecID audio_codec_id<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * Forced subtitle codec_id. * Demuxing: Set by user. */</span> <span class="kw2" style="padding: 0px; margin: 0px; font-weight: bold;">enum</span> CodecID subtitle_codec_id<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * Maximum amount of memory in bytes to use for the index of each stream. * If the index exceeds this size, entries will be discarded as * needed to maintain a smaller size. This can lead to slower or less * accurate seeking (depends on demuxer). * Demuxers for which a full in-memory index is mandatory will ignore * this. * muxing : unused * demuxing: set by user */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">unsigned</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> max_index_size<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * Maximum amount of memory in bytes to use for buffering frames * obtained from realtime capture devices. */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">unsigned</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> max_picture_buffer<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">unsigned</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> nb_chapters<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> AVChapter <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">**</span>chapters<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * Flags to enable debugging. */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> debug<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#define FF_FDEBUG_TS 0x0001</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * Raw packets from the demuxer, prior to parsing and decoding. * This buffer is used for buffering packets until the codec can * be identified, as parsing cannot be done without knowing the * codec. */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> AVPacketList <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>raw_packet_buffer<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> AVPacketList <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>raw_packet_buffer_end<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> AVPacketList <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>packet_buffer_end<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> AVMetadata <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>metadata<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * Remaining size available for raw_packet_buffer, in bytes. * NOT PART OF PUBLIC API */</span> <span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#define RAW_PACKET_BUFFER_SIZE 2500000</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> raw_packet_buffer_remaining_size<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * Start time of the stream in real world time, in microseconds * since the unix epoch (00:00 1st January 1970). That is, pts=0 * in the stream was captured at this real world time. * - encoding: Set by user. * - decoding: Unused. */</span> int64_t start_time_realtime<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> AVFormatContext<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
这是FFMpeg中最为基本的一个结构,是其他所有结构的根,是一个多媒体文件或流的根本抽象。其中:
-
nb_streams和streams所表示的AVStream结构指针数组包含了所有内嵌媒体流的描述;
-
iformat和oformat指向对应的demuxer和muxer指针;
-
pb则指向一个控制底层数据读写的ByteIOContext结构。
-
start_time和duration是从streams数组的各个AVStream中推断出的多媒体文件的起始时间和长度,以微妙为单位。
通常,这个结构由avformat_open_input在内部创建并以缺省值初始化部分成员。但是,如果调用者希望自己创建该结构,则需要显式为该结构的一些成员置缺省值——如果没有缺省值的话,会导致之后的动作产生异常。以下成员需要被关注:
-
probesize
-
mux_rate
-
packet_size
-
flags
-
max_analyze_duration
-
key
-
max_index_size
-
max_picture_buffer
-
max_delay
AVPacket
AVPacket定义在avcodec.h中,如下:
<span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">typedef</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> AVPacket <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * Presentation timestamp in AVStream->time_base units; the time at which * the decompressed packet will be presented to the user. * Can be AV_NOPTS_VALUE if it is not stored in the file. * pts MUST be larger or equal to dts as presentation cannot happen before * decompression, unless one wants to view hex dumps. Some formats misuse * the terms dts and pts/cts to mean something different. Such timestamps * must be converted to true pts/dts before they are stored in AVPacket. */</span> int64_t pts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * Decompression timestamp in AVStream->time_base units; the time at which * the packet is decompressed. * Can be AV_NOPTS_VALUE if it is not stored in the file. */</span> int64_t dts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> uint8_t <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>data<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> size<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> stream_index<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> flags<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * Duration of this packet in AVStream->time_base units, 0 if unknown. * Equals next_pts - this_pts in presentation order. */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> duration<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">void</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>destruct<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> AVPacket <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">void</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>priv<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> int64_t pos<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="co1" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">///< byte position in stream, -1 if unknown</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** * Time difference in AVStream->time_base units from the pts of this * packet to the point at which the output from the decoder has converged * independent from the availability of previous frames. That is, the * frames are virtually identical no matter if decoding started from * the very first frame or from this keyframe. * Is AV_NOPTS_VALUE if unknown. * This field is not the display duration of the current packet. * * The purpose of this field is to allow seeking in streams that have no * keyframes in the conventional sense. It corresponds to the * recovery point SEI in H.264 and match_time_delta in NUT. It is also * essential for some types of subtitle streams to ensure that all * subtitles are correctly displayed after seeking. */</span> int64_t convergence_duration<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> AVPacket<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
FFMPEG使用AVPacket来暂存媒体数据包及附加信息(解码时间戳、显示时间戳、时长等),这样的媒体数据包所承载的往往不是原始格式的音视频数据,而是以某种方式编码后的数据,编码信息由对应的媒体流结构AVStream给出。AVPacket包含以下数据域:
-
dts表示解码时间戳,pts表示显示时间戳,它们的单位是所属媒体流的时间基准。
-
stream_index给出所属媒体流的索引;
-
data为数据缓冲区指针,size为长度;
-
duration为数据的时长,也是以所属媒体流的时间基准为单位;
-
pos表示该数据在媒体流中的字节偏移量;
-
destruct为用于释放数据缓冲区的函数指针;
-
flags为标志域,其中,最低为置1表示该数据是一个关键帧。
AVPacket结构本身只是个容器,它使用data成员引用实际的数据缓冲区。这个缓冲区的管理方式有两种,其一是通过调用av_new_packet直接创建缓冲区,其二是引用已经存在的缓冲区。缓冲区的释放通过调用av_free_packet实现,其内部实现也采用了两种不同的释放方式,第一种方式是调用AVPacket的destruct函数,这个destruct函数可能是缺省的av_destruct_packet,对应av_new_packet或av_dup_packet创建的缓冲区,也可能是某个自定义的释放函数,表示缓冲区的提供者希望使用者在结束缓冲区的时候按照提供者期望的方式将其释放,第二种方式是仅仅将data和size的值清0,这种情况下往往是引用了一个已经存在的缓冲区,AVPacket的destruct指针为空。
在使用AVPacket时,对于缓冲区的提供者,必须注意通过设置destruct函数指针指定正确的释放方式,如果缓冲区提供者打算自己释放缓冲区,则切记将destruct置空;而对于缓冲区的使用者,务必在使用结束时调用av_free_packet释放缓冲区(虽然释放操作可能只是一个假动作)。如果某个使用者打算较长时间内占用一个AVPacket——比如不打算在函数返回之前释放它——最好调用av_dup_packet进行缓冲区的克隆,将其转化为自有分配的缓冲区,以免对缓冲区的不当占用造成异常错误。av_dup_packet会为destruct指针为空的AVPacket新建一个缓冲区,然后将原缓冲区的数据拷贝至新缓冲区,置data的值为新缓冲区的地址,同时设destruct指针为av_destruct_packet。
时间信息
时间信息用于实现多媒体同步。
同步的目的在于展示多媒体信息时,能够保持媒体对象之间固有的时间关系。同步有两类,一类是流内同步,其主要任务是保证单个媒体流内的时间关系,以满足感知要求,如按照规定的帧率播放一段视频;另一类是流间同步,主要任务是保证不同媒体流之间的时间关系,如音频和视频之间的关系(lipsync)。
对于固定速率的媒体,如固定帧率的视频或固定比特率的音频,可以将时间信息(帧率或比特率)置于文件首部(header),如AVI的hdrl List、MP4的moov box,还有一种相对复杂的方案是将时间信息嵌入媒体流的内部,如MPEG TS和Real video,这种方案可以处理变速率的媒体,亦可有效避免同步过程中的时间漂移。
FFMPEG会为每一个数据包打上时间标签,以更有效地支持上层应用的同步机制。时间标签有两种,一种是DTS,称为解码时间标签,另一种是PTS,称为显示时间标签。对于声音来说 ,这两个时间标签是相同的,但对于某些视频编码格式,由于采用了双向预测技术,会造成DTS和PTS的不一致。
无双向预测帧的情况:
图像类型: I P P P P P P ... I P P DTS: 0 1 2 3 4 5 6... 100 101 102 PTS: 0 1 2 3 4 5 6... 100 101 102
有双向预测帧的情况:
图像类型: I P B B P B B ... I P B DTS: 0 1 2 3 4 5 6 ... 100 101 102 PTS: 0 3 1 2 6 4 5 ... 100 104 102
对于存在双向预测帧的情况,通常要求解码器对图像重排序,以保证输出的图像顺序为显示顺序:
解码器输入:I P B B P B B (DTS) 0 1 2 3 4 5 6 (PTS) 0 3 1 2 6 4 5 解码器输出:X I B B P B B P (PTS) X 0 1 2 3 4 5 6
时间信息的获取:
通过调用avformat_find_stream_info,多媒体应用可以从AVFormatContext对象中拿到媒体文件的时间信息:主要是总时间长度和开始时间,此外还有与时间信息相关的比特率和文件大小。其中时间信息的单位是AV_TIME_BASE:微秒。
<span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">typedef</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> AVFormatContext <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> ...... <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** Decoding: position of the first frame of the component, in AV_TIME_BASE fractional seconds. NEVER set this value directly: It is deduced from the AVStream values. */</span> int64_t start_time<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** Decoding: duration of the stream, in AV_TIME_BASE fractional seconds. Only set this value if you know none of the individual stream durations and also dont set any of them. This is deduced from the AVStream values if not set. */</span> int64_t duration<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** decoding: total file size, 0 if unknown */</span> int64_t file_size<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> <span class="coMULTI" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">/** Decoding: total stream bitrate in bit/s, 0 if not available. Never set it directly if the file_size and the duration are known as FFmpeg can compute it automatically. */</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> bit_rate<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> ...... <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> AVFormatContext<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
以上4个成员变量都是只读的,基于FFMpeg的中间件需要将其封装到某个接口中,如:
LONG GetDuratioin<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>IntfX<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> LONG GetStartTime<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>IntfX<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> LONG GetFileSize<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>IntfX<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> LONG GetBitRate<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>IntfX<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span><span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
APIs
FFMpeg的API大部分以0作为成功返回值而一个负数作为错误码。
读系列
读系列API的主要功能是根据某个指定的源获取媒体数据包,这个源可以是一个本地文件、一个RTSP或HTTP源、一个摄像头驱动或者其它。
avformat_open_input
<span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> avformat_open_input<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>AVFormatContext <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">**</span>ic_ptr<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">const</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>filename<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> AVInputFormat <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>fmt<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> AVDictionary <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">**</span>options<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
avformat_open_input完成两个任务:
-
打开一个文件或URL,基于字节流的底层输入模块得到初始化。
-
解析多媒体文件或多媒体流的头信息,创建AVFormatContext结构并填充其中的关键字段,依次为各个原始流建立AVStream结构。
一个多媒体文件或多媒体流与其包含的原始流的关系如下:
多媒体文件/多媒体流 (movie.mkv) 原始流 1 (h.264 video) 原始流 2 (aac audio for Chinese) 原始流 3 (aac audio for english) 原始流 4 (Chinese Subtitle) 原始流 5 (English Subtitle) ...
关于输入参数:
-
ic_ptr,这是一个指向指针的指针,用于返回avformat_open_input内部构造的一个AVFormatContext结构体。
-
filename,指定文件名。
-
fmt,用于显式指定输入文件的格式,如果设为空则自动判断其输入格式。
-
options
这个函数通过解析多媒体文件或流的头信息及其他辅助数据,能够获取足够多的关于文件、流和编解码器的信息,但由于任何一种多媒体格式提供的信息都是有限的,而且不同的多媒体内容制作软件对头信息的设置不尽相同,此外这些软件在产生多媒体内容时难免会引入一些错误,因此这个函数并不保证能够获取所有需要的信息,在这种情况下,则需要考虑另一个函数:avformat_find_stream_info。
avformat_find_stream_info
<span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> avformat_find_stream_info<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>AVFormatContext <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>ic<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> AVDictionary <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">**</span>options<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
这个函数主要用于获取必要的编解码器参数,设置到ic→streams[i]→codec中。
首先必须得到各媒体流对应编解码器的类型和id,这是两个定义在avutils.h和avcodec.h中的枚举:
enum AVMediaType { AVMEDIA_TYPE_UNKNOWN = -1, AVMEDIA_TYPE_VIDEO, AVMEDIA_TYPE_AUDIO, AVMEDIA_TYPE_DATA, AVMEDIA_TYPE_SUBTITLE, AVMEDIA_TYPE_ATTACHMENT, AVMEDIA_TYPE_NB }; enum CodecID { CODEC_ID_NONE, /* video codecs */ CODEC_ID_MPEG1VIDEO, CODEC_ID_MPEG2VIDEO, ///< preferred ID for MPEG-1/2 video decoding CODEC_ID_MPEG2VIDEO_XVMC, CODEC_ID_H261, CODEC_ID_H263, ... };
通常,如果某种媒体格式具备完备而正确的头信息,调用avformat_open_input即可以得到这两个参数,但若是因某种原因avformat_open_input无法获取它们,这一任务将由avformat_find_stream_info完成。
其次还要获取各媒体流对应编解码器的时间基准。
此外,对于音频编解码器,还需要得到:
-
采样率,
-
声道数,
-
位宽,
-
帧长度(对于某些编解码器是必要的),
对于视频编解码器,则是:
-
图像大小,
-
色彩空间及格式,
av_read_frame
<span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> av_read_frame<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>AVFormatContext <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>s<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> AVPacket <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>pkt<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
这个函数用于从多媒体文件或多媒体流中读取媒体数据,获取的数据由AVPacket结构pkt来存放。对于音频数据,如果是固定比特率,则pkt中装载着一个或多个音频帧;如果是可变比特率,则pkt中装载有一个音频帧。对于视频数据,pkt中装载有一个视频帧。需要注意的是:再次调用本函数之前,必须使用av_free_packet释放pkt所占用的资源。
通过pkt→stream_index可以查到获取的媒体数据的类型,从而将数据送交相应的解码器进行后续处理。
av_seek_frame
<span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> av_seek_frame<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>AVFormatContext <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>s<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> stream_index<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> int64_t timestamp<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> flags<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
这个函数通过改变媒体文件的读写指针来实现对媒体文件的随机访问,支持以下三种方式:
-
基于时间的随机访问:具体而言就是将媒体文件读写指针定位到某个给定的时间点上,则之后调用av_read_frame时能够读到时间标签等于给定时间点的媒体数据,通常用于实现媒体播放器的快进、快退等功能。
-
基于文件偏移的随机访问:相当于普通文件的seek函数,timestamp也成为文件的偏移量。
-
基于帧号的随机访问:timestamp为要访问的媒体数据的帧号。
关于参数:
-
s:是个AVFormatContext指针,就是avformat_open_input返回的那个结构。
-
stream_index:指定媒体流,如果是基于时间的随机访问,则第三个参数timestamp将以此媒体流的时间基准为单位;如果设为负数,则相当于不指定具体的媒体流,FFMPEG会按照特定的算法寻找缺省的媒体流,此时,timestamp的单位为AV_TIME_BASE(微秒)。
-
timestamp:时间标签,单位取决于其他参数。
-
flags:定位方式,AVSEEK_FLAG_BYTE表示基于字节偏移,AVSEEK_FLAG_FRAME表示基于帧号,其它表示基于时间。
av_close_input_file
<span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">void</span> av_close_input_file<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>AVFormatContext <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>s<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
关闭一个媒体文件:释放资源,关闭物理IO。
编解码系列
编解码API负责实现媒体原始数据的编码和媒体压缩数据的解码。
avcodec_find_decoder
AVCodec <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>avcodec_find_decoder<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="kw2" style="padding: 0px; margin: 0px; font-weight: bold;">enum</span> CodecID id<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span> AVCodec <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>avcodec_find_decoder_by_name<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span><span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">const</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>name<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
根据给定的codec id或解码器名称从系统中搜寻并返回一个AVCodec结构的指针。
avcodec_open2
<span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> avcodec_open2<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>AVCodecContext <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>avctx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">const</span> AVCodec <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>codec<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> AVDictionary <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">**</span>options<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
此函数根据输入的AVCodec指针具体化AVCodecContext结构。在调用该函数之前,需要首先调用avcodec_alloc_context分配一个AVCodecContext结构,或调用avformat_open_input获取媒体文件中对应媒体流的AVCodecContext结构;此外还需要通过avcodec_find_decoder获取AVCodec结构。
这一函数还将初始化对应的解码器。
avcodec_decode_video2
<span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> avcodec_decode_video2<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>AVCodecContext <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>avctx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> AVFrame <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>picture<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>got_picture_ptr<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> AVPacket <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>avpkt<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
解码一个视频帧。got_picture_ptr指示是否有解码数据输出。
输入数据在AVPacket结构中,输出数据在AVFrame结构中。AVFrame是定义在avcodec.h中的一个数据结构:
<span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">typedef</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">struct</span> AVFrame <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">{</span> FF_COMMON_FRAME <span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">}</span> AVFrame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
FF_COMMON_FRAME定义了诸多数据域,大部分由FFMpeg内部使用,对于用户来说,比较重要的主要包括:
<span class="co2" style="padding: 0px; margin: 0px; color: rgb(128, 128, 128); font-style: italic;">#define FF_COMMON_FRAME \ ......</span> uint8_t <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>data<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>4<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>\ <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> linesize<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">[</span>4<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">]</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>\ <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> key_frame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>\ <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> pict_type<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>\ int64_t pts<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>\ <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> reference<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>\ ......
FFMpeg内部以planar的方式存储原始图像数据,即将图像像素分为多个平面(R/G/B或Y/U/V),data数组内的指针分别指向四个像素平面的起始位置,linesize数组则存放各个存贮各个平面的缓冲区的行宽:
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++data[0]->#################################++++++++++++ ++++++++++++###########picture data##########++++++++++++ ++++++++++++#################################++++++++++++ ++++++++++++#################################++++++++++++ ........................ ++++++++++++#################################++++++++++++ |<-------------------line_size[0]---------------------->|
此外,key_frame标识该图像是否是关键帧;pict_type表示该图像的编码类型:I(1)/P(2)/B(3)……;pts是以time_base为单位的时间标签,对于部分解码器如H.261、H.263和MPEG4,可以从头信息中获取;reference表示该图像是否被用作参考。
avcodec_decode_audio4
<span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> avcodec_decode_audio4<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>AVCodecContext <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>avctx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> AVFrame <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>frame<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>got_frame_ptr<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> AVPacket <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>avpkt<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
解码一个音频帧。输入数据在AVPacket结构中,输出数据在frame中,got_frame_ptr表示是否有数据输出。
-
avcodec_close
<span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> avcodec_close<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>AVCodecContext <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>avctx<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
关闭解码器,释放avcodec_open中分配的资源。
写系列
写系列API负责将媒体数据以包的形式分发到指定的目标,这个目标可以是一个本地文件、一个RTSP或HTTP流或者其他。
avformat_alloc_output_context2
<span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> avformat_alloc_output_context2<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>AVFormatContext <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">**</span>ctx<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> AVOutputFormat <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>oformat<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">const</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>format_name<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">const</span> <span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">char</span> <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>filename<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
这个函数负责分配一个用于输出目的的AVFormatContext,输出格式由oformat、format_name和filename决定,oformat优先级最高,如果oformat为空则依据format_name,如果format_name为空则依据filename。
avformat_write_header
<span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> avformat_write_header<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>AVFormatContext <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>s<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> AVDictionary <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">**</span>options<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
此函数负责产生一个文件头并写入到输出目标中,调用之前,AVFormatContext结构中的oformat、pb必须正确设置,并且streams列表不能为空,列表中各stream的codec参数需要配置正确。
av_write_frame
<span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> av_write_frame<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>AVFormatContext <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>s<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> AVPacket <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>pkt<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
此函数负责输出一个媒体包。AVFormatContext参数给出输出目标及媒体流的格式设置,pkt是一个包含媒体数据的结构,其内部成员如dts/pts、stream_index等必须被正确设置。
av_interleaved_write_frame
<span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> av_interleaved_write_frame<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>AVFormatContext <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>s<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> AVPacket <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>pkt<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
此函数负责交错地输出一个媒体包。如果调用者无法保证来自各个媒体流的包正确交错,则最好调用此函数输出媒体包,反之,可以调用av_write_frame以提高性能。
av_write_trailer
<span class="kw4" style="padding: 0px; margin: 0px; color: rgb(153, 51, 51);">int</span> av_write_trailer<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>AVFormatContext <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>s<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
其他
avformat_new_stream
AVStream <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>avformat_new_stream<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">(</span>AVFormatContext <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>s<span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">,</span> AVCodec <span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">*</span>c<span class="br0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">)</span><span class="sy0" style="padding: 0px; margin: 0px; color: rgb(102, 204, 102);">;</span>
这个函数负责创建一个AVStream结构,并将其添加到指定的AVFormatContext中,此时,AVStream的大部分域处于非法状态。如果输入参数c不为空,AVStream的codec域根据c实现初始化。
核心架构和机制
过滤链
FFMPEG支持由多个过滤器结构组成的过滤链,以实现对视频帧和音频采样数据的后续处理,如图像缩放、图像增强、声音的重采样等。
数据结构
FFMPEG使用了的四个主要的数据结构来构造过滤链,如上图所示。其中,AVFilter是一个过滤器的抽象,它拥有若干AVFilterPad,分别实现过滤器数据的输入和输出。而AVFilterLink表示各个过滤器之间的连接,这种连接的实现是基于AVFilterPad的,每个连接都有一个实现输入的AVFilterPad和一个实现输出的AVFilterPad以及对应的源过滤器和目的过滤器。
此外,还有两个数据结构AVFilterBuffer和AVFilterBufferRef来表示过滤器的输入输出数据,其中AVFilterBufferRef是AVFilterBuffer的引用,这种设计的目的是避免不必要的数据拷贝。通过avfilter_get_buffer_ref_from_frame可以获得一个AVFrame结构的引用,从而实现过滤器对来自AVFrame的图像原数据或声音采样序列的处理。
APIs
avfilter_open
avfilter_free
avfilter_init_filter
avfilter_link
avfilter_link_free
avfilter_ref_buffer