ffplay frame queue 分析
参考: ffplay frame queue分析 FrameQueue数据结构ffplay 定义了 FrameQueue 来管理解码后的音频,视频以及字幕。 12345678910111213141516171819202122232425262728/* Common struct for handling all types of decoded data and allocated render buffers. */typedef struct Frame { AVFrame *frame; //audio/video frame AVSubtitle sub; //字幕 int serial; //序列号 double pts; /* presentation timestamp for the frame */ double duration; /* estimated duration of the frame */ int64_t pos; ...
ffplay packet queue 分析
参考: ffplay packet queue分析 ffplay 用 PacketQueue 来保存解封装后的数据,即AVPacket。定义MyAVPacketList表示队列中的元素,这里命名为MyAVPacketNode可能更合理。 12345678910111213141516171819202122232425typedef struct MyAVPacketList { //待解码的数据 AVPacket *pkt; //pkt序列号 int serial;} MyAVPacketList;typedef struct PacketQueue { /* ffmpeg封装的队列数据结构,先入先出 */ AVFifo *pkt_list; /* 当前队里的pkt的数量 */ int nb_packets; /* 当前所有节点占用的总内存大小 */ int size; /* 队列所有节点的合计时长 */ int64_t duration; /* 是否要中止队列操作,...
cmake find_package
参考: 官方文档 find_package Cmake之深入理解find_package()的用法 使用通过find_package命令,可以找到三方库对应的头文件路径和库文件路径,不用手动管理这些路径了。例如要引用CURL库,在CMakeLists文件可以简单写成下面的形式 12345678find_package(CURL)add_executable(curltest curltest.cc)if(CURL_FOUND) target_include_directories(clib PRIVATE ${CURL_INCLUDE_DIR}) target_link_libraries(curltest ${CURL_LIBRARY})else(CURL_FOUND) message(FATAL_ERROR ”CURL library not found”)endif(CURL_FOUND) 原理find_package 有两种搜索模式 Module mode在CMAKE_MODULE_PATH指定的路径下...
ffmpeg example 4.视频文件封装和编码
今天学习 ffmpeg/doc/examples/muxing.c 该程序接受一个参数,指定输出的文件的路径,例如/tmp/mux.mp4,/tmp/mux.mov。 文件名的后缀会用来推测生成的AVFormatContext的格式,如果没有指定,就使用mpeg。使用fmt 默认的视频编码器和音频编码器,编码10秒钟的音视频数据,交替写入文件。 操作封装需要操作AVFormatContext 创建AVFormatContext1234567//创建AVFormatContext, 根据文件后缀来推测output formatavformat_alloc_output_context2(&oc, NULL, NULL, filename);if (!oc) { printf("Could not deduce output format from file extension: using MPEG.\n"); //无法推测output format, 使用mpeg avformat_alloc_output_context2...
ffmpeg+nginx+rtmp搭建本地推流服务器
安装nginx+rtmp12brew tap denji/nginxbrew install nginx-full --with-rtmp-module 配置nginx.conf,路径/opt/homebrew/etc/nginx/nginx.conf123456789101112131415161718192021222324rtmp { server { listen 1935; chunk_size 4096; # live on application rtmp_live { live on; # hls on; #这个参数把直播服务器改造成实时回放服务器。 # wait_key on; #对视频切片进行保护,这样就不会产生马赛克了。 # hls_path ./sbin/html; #切片视频文件存放位置。 # hls_fragment 10s; #每个视频切片的...
ffmpeg example 5.硬件解码
在hw_decode.c示例中,ffmpeg展示了如何使用硬件加速来解码视频,我们来分析一下是怎么实现的。 硬件加速设备类型展示所有可用的硬件加速方法, 在mac上只找到了videotoolbox加速的方式。 123ffmpeg -hwaccelsHardware acceleration methods:videotoolbox 查看 AVHWDeviceType的定义,发现别的平台可以使用cuda,opencl, mediacodec,vulkan等来实现硬件加速。 1234567891011121314enum AVHWDeviceType { AV_HWDEVICE_TYPE_NONE, AV_HWDEVICE_TYPE_VDPAU, AV_HWDEVICE_TYPE_CUDA, AV_HWDEVICE_TYPE_VAAPI, AV_HWDEVICE_TYPE_DXVA2, AV_HWDEVICE_TYPE_QSV, AV_HWDEVICE_TYPE_VIDEOTOOLBOX, AV_HWDEVICE_TYPE_...
ffmpeg example 3.音频编码
关于如何源码调试,参考前面的文章ffmpeg example 视频编码 - 掘金 今天分析encode_audio.c学习ffmpeg如何编码音频数据,由于太简单了,直接贴代码 ##main函数 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128int main(int argc, char **argv){ const char *filename; const AVCodec *codec; AVCodecContext *c= NULL; AVFr...
ffmpeg example 2.视频编码
调试ffmpeg源码教程 如何使用vscode在macOS平台调试ffmpeg 使用Xcode调试ffmpeg 今天用Xcode调试分析 encode_video.c 配置ffmpeg 支持libx264和h264_videotoolbox来进行视频编码1234cd ffmpeg./configure --disable-optimizations --disable-stripping --enable-debug=3 --disable-doc --enable-libx264 --enable-gpl --enable-videotoolboxmmake -j 16make examples 如果没有libx264, 通过 Homebrew 安装一下 1brew install x264 ffmpeg 通过pkg-config可以找到x264对应的头文件和库的路径 12➜ ffmpeg git:(master) ✗ pkg-config --libs --cflags x264-DX264_API_IMPORTS -I/opt/homebre...
ffmpeg example 1.解封装,解码学习
背景学习ffmpeg,打算从源码入手,源码又太多太复杂。好在ffmpeg提供了示例代码,演示如何使用ffmpeg的api, 示例代码位于ffmpeg/doc/examples目录下,可以通过vscode 来调试这些示例代码,理解ffmpeg的调用方式。 该目录下的示例代码如下 decode_audio.c 演示如何解码音频 decode_video.c 演示如何解码视频 demuxing_decoding.c 演示如何解封装文件,和解码音视频 今天来分析 demuxing_decoding.c 流程使用的模块libavutil,libavcodec,libavformat libavutil 包含一些公共的工具函数 libavcodec 用于各种类型声音/图像编解码 libavformat 用于各种音视频封装格式的生成和解析,包括获取解码所需信息以生成解码上下文结构和读取音视频帧等功能,包含demuxers和muxer库 1.解封装 打开文件、获取封装信息上下文AVFormatContext(avformat_open_input) 获取...
使用Xcode调试ffmpeg
ffmpeg 源码 https://github.com/FFmpeg/FFmpeg.git ffmpeg 配置, 使其支持调试12./configure --disable-optimizations --disable-stripping --enable-debug=3 --disable-docmake -j `nproc` 以_g结尾的就是可以调试的程序ffmpeg_g, ffplay_g, ffprobe_g Xcode 配置 把 ffmpeg 目录拖进工程,等待添加完成,可能时间较久 等待加载完毕 添加target, 比如说调试ffplay_g 修改对应的路径 修改scheme,选择ffplay_g为可执行目标 给ffplay_g传递参数 开始打断点调试吧 调试 ffmpeg官方的示例程序,示例位于ffmpeg/doc/examples路径下面12cd ffmpegmake examples 后缀带_g的都是可以调试的 与调试ffplay_g一样,添加target,配置路径,配置可执行目标,添加参数,愉快地调试吧! 参考: Xcode...
