macOS平台使用vscode调试ffmpeg

准备知识:Debug C++ in Visual Studio Code

ffmpeg 源码 github.com/FFmpeg/FFmp…

调试ffmpeg_g, ffplay_g

ffmpeg 配置, 使其支持调试

关于-g3相关知识gcc-g-vs-g3-gdb-flag-what-is-the-difference
 

./configure  --disable-optimizations --disable-stripping --enable-debug=3 --disable-doc
make -j `nproc`
macOS平台使用vscode调试ffmpeg_第1张图片

_g结尾的就是可以调试的程序ffmpeg_g, ffplay_g, ffprobe_g

vscode配置

macOS平台使用vscode调试ffmpeg_第2张图片

如下命令:

# macOS上列出所有的音视频设备
ffmpeg -f avfoundation -list_devices true -i ""

launch.json 对应的配置

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(lldb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/ffmpeg_g",
            "args": ["-f", "avfoundation", "-list_devices", "true", "-i", "\"\""],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb"
        }
    ]
}

打上断点,点击运行,就可以愉快的调试了

macOS平台使用vscode调试ffmpeg_第3张图片

附上链接:lldb 使用教程 Tutorial

调试ffmpeg/doc/example

make examples 

在ffmpeg/doc/example目录下, 以_g结尾的就是可以调试的

macOS平台使用vscode调试ffmpeg_第4张图片

配置launch.json

macOS平台使用vscode调试ffmpeg_第5张图片

开始调试吧

macOS平台使用vscode调试ffmpeg_第6张图片

修改代码重新编译

例如你在调试的时候,修改了ffmpeg的源码,想调试一下更改后的代码,需要重新编译生成。

cd ffmpeg
make -j 16
make examples

你想自动化这个过程,在调试之前自动编译,如何实现呢?

配置 prelaunchTask

  1. 在tasks.json中添加一个task
{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "make",
            "type": "shell",
            "command": "make -j 16; make examples",
            "problemMatcher": [],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "options": {
                "cwd": "${workspaceFolder}"
            }
        }
    ]
}

在launch.json中配置prelaunchTask

macOS平台使用vscode调试ffmpeg_第7张图片

然后修改代码,点击调试, vscode 自动执行make,编译修改后的文件,重新生成可执行程序。不用每次修改完想看看效果,还要手动去执行make,效率又提高了

备注:m1 芯片的mac 如果遇到调试问题

ERROR: Unable to start debugging. Unexpected LLDB output from command "-exec-run". process exited with status -1 (attach failed ((os/kern) invalid argument))

解决办法:

使用 CodeLLDB debugger插件,而不是vc code 原生的调试插件

macOS平台使用vscode调试ffmpeg_第8张图片



作者:yxibng
链接:https://juejin.cn/post/70730843

★文末名片可以免费领取音视频开发学习资料,内容包括(FFmpeg ,webRTC ,rtmp ,hls ,rtsp ,ffplay ,srs)以及音视频学习路线图等等。

见下方!↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

 

你可能感兴趣的:(ffmpeg)