概述
在 Ubuntu 20.04 系统上,由于包管理器版本可能滞后,建议通过源码编译安装最新版本的 scrcpy。
步骤 1:安装必要的依赖
sudo apt install ffmpeg libsdl2-2.0-0 adb wget gcc git pkg-config meson ninja-build libsdl2-dev \
libavcodec-dev libavdevice-dev libavformat-dev libavutil-dev \
libswresample-dev libusb-1.0-0 libusb-1.0-0-dev
步骤 2:克隆代码
git clone https://github.com/Genymobile/scrcpy
cd scrcpy
步骤 3:修改代码以适配编译环境
为了编译通过,需要针对 libavcodec 兼容性修改部分头文件引用。执行以下补丁操作:
diff --git a/app/src/decoder.c b/app/src/decoder.c
index 4d0a1daf..a7f7196 100644
--- a/app/src/decoder.c
+++ b/app/src/decoder.c
@@ -1,7 +1,8 @@
#include "decoder.h"
#include <errno.h>
-#include <libavcodec/packet.h>
+//#include <libavcodec/packet.h>
+#include <libavcodec/avcodec.h>
+#include <libavutil/avutil.h>
#include "util/log.h"
diff --git a/app/src/packet_merger.h b/app/src/packet_merger.h
index 3f9972ce..6b0da13 100644
--- a/app/src/packet_merger.h
+++ b/app/src/packet_merger.h
@@ -5,7 +5,8 @@
#include <stdbool.h>
#include <stdint.h>
-#include <libavcodec/packet.h>
+// #include <libavcodec/packet.h>
+#include <libavcodec/avcodec.h>
/**
* Config packets (containing the SPS/PPS) are sent in-band. A new config
diff --git a/app/src/recorder.h b/app/src/recorder.h
index 70b3836..4471108 100644
--- a/app/src/recorder.h
+++ b/app/src/recorder.h
@@ -5,7 +5,8 @@
#include <stdbool.h>
#include <stdint.h>
-#include <libavcodec/packet.h>
+// #include <libavcodec/packet.h>
+#include <libavcodec/avcodec.h>
+#include <libavformat/avformat.h>
#include "options.h"
步骤 4:执行编译安装
./install_release.sh
如果没有意外,编译将成功。检查 scrcpy 的版本:
scrcpy --version
输出示例:
scrcpy 3.3.4 <https://github.com/Genymobile/scrcpy>
Dependencies (compiled / linked):
- SDL: 2.0.10 / 2.0.10
- libavcodec: 58.54.100 / 58.54.100
- libavformat: 58.29.100 / 58.29.100
- libavutil: 56.31.100 / 56.31.100
- libavdevice: 58.8.100 / 58.8.100
- libusb: - / 1.0.28
确认安装路径:
which scrcpy
输出:/usr/local/bin/scrcpy
编译日志参考
以下为编译过程的关键日志片段(已脱敏):
[scrcpy] Downloading prebuilt server…
–2026-01-06 17:15:32-- https://github.com/Genymobile/scrcpy/releases/download/v3.3.4/scrcpy-server-v3.3.4
Resolving github.com (github.com)… connected.
HTTP request sent, awaiting response… 302 Found
Location: https://release-assets.githubusercontent.com/github-production-release-asset/...
Saving to: 'scrcpy-server'
scrcpy-server 100% [===============================================>] 88.85K 330KB/s in 0.3s
[scrcpy] Verifying prebuilt server…
scrcpy-server: OK
[scrcpy] Building client…
The Meson build system
Version: 0.53.2
Source dir: /home/user/workspace/tools/myscrcpy/scrcpy
Build dir: /home/user/workspace/tools/myscrcpy/scrcpy/build-auto
Build type: native build
name: scrcpy
version: .
compiler the host machine: cc (gcc .)
linker the host machine: cc ld.bfd
machine cpu family: x86_64
machine cpu: x86_64
pkgconfig: binpkgconfig (.)
time dependency libavformat found: .
time dependency libavcodec found: .
time dependency libavutil found: .
time dependency swresample found: .
time dependency sdl2 found: .
time dependency libavdevice found: .
time dependency libusb found: .
function 'strdup' :
function 'asprintf' :
function 'vasprintf' :
function 'nrand48' :
function 'jrand48' :
function 'reallocarray' :
syssocket.h has symbol '' :
config.h using configuration
targets project:
ninja. at binninja
[scrcpy.
[scrcpy] (sudo)
[] files.
appusrbin
target 'appscrcpy' using strip.
serverusrsharescrcpy
usertoolsscrcpyscrcpy. to localmanman1
usertoolsscrcpydatausrsharehicolorapps
usertoolsscrcpydata_scrcpy to localzshsitefunctions
usertoolsscrcpydatascrcpy to localbashcompletioncompletions
usertoolsscrcpydatausrshareapplications
usertoolsscrcpydatausrshareapplications
至此,scrcpy 已成功安装并可用。


