# 使用Visual Studio Code遠端開發和除錯Linux應用程式 本文記錄在Windows端使用Visual Studio Code連線至遠端Linux平台(使用VMware創造的Linux虛擬機也可以)開發和除錯ffmpeg的過程。 ## 1. 安裝Visual Studio Code 請至 https://code.visualstudio.com/download 下載並安裝即可。 ## 2. 安裝Visual Studio Code的Extension 絕對必需要安裝的Extension為: - Remote SSH (Microsoft) 也可以直接安裝 - Remote Development (Microsoft) 其中Remote Development包含了 - Remote SSH - Remote WSL - Remote Containers 我個人是只裝需要用的而已。 其他建議安裝的Extension有: - C/C++ (Microsoft) - Visual Studio IntelliCode (Microsoft) - Tabnine Autocomplete (TabNine) - 我目前還分不出Visual Studio IntelliCode和Tabnine的區別,就...都裝好了。 - Rainbow Bracket (2gua) - GitLens (Eric Amodio) 安裝後會在Extension列中出現Remote Explorer。 ```shell= git clone https://git.ffmpeg.org/ffmpeg.git ``` 利用`git tag`列出所有版本,目前是n4.4版。先利用`git checkout n4.4` checkout n4.4版,然後用`git checkout -b study_4.4`建立study_4.4的分支。完整命令如下: ```shell= git tag git checkout n4.4 git checkout -b study_4.4 ``` ## 建置ffmpeg 先安裝libsdl2-dev,否則ffplay會產生不出來。 ``` sudo apt-get install libsdl2-dev ``` 可以先用以下命令看有哪些設定選項 ```shell= ./configure --help ``` 接著可直接用 ```shell= ./configure --enable-debug=3 --optflags=O0 make -j4 ``` 建置。 若出現`nasm/yasm not found or too old. Use --disable-x86asm for a crippled build.`,可執行 ```shell= ./configure --enable-debug=3 --optflags=O0 --disable-x86asm ``` ## 除錯 Run --> Start Debugging --> C++ (GDB/LLDB) 會在當前目錄下的`.vscode`目錄內建立一個名為`launch.json`檔案。預設內容為: ```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": "(gdb) Launch", "type": "cppdbg", "request": "launch", "program": "enter program name, for example ${workspaceFolder}/a.out", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false, "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } ] } ``` 將其中的`program`欄位的值修改為`${workspaceFolder}/ffmpeg_g`。 注意名稱尾部有加`_g`的才是真的debug版本。 將`args` 改為`["-i", "test_video/Big_Buck_Bunny_1080_10s_1MB.mp4", "-s", "vga", "test_video/output.avi", "-loglevel", "debug"]`。意思是我們要將輸入影片`Big_Buck_Bunny_1080_10s_1MB.mp4`轉換為vga大小(即640x480)的影片,其輸出檔名為"output.avi",並將輸出訊息層級設為debug層級。 影片可以從以下網站抓取: https://test-videos.co.uk/bigbuckbunny/mp4-h265 ###### tags: `vscode`, `linux`, `ffmpeg`